Improvements about namespace and PHPUnit version

This commit is contained in:
peter279k 2020-12-25 21:59:22 +08:00
parent 732be48504
commit 98828dd7e9
4 changed files with 26 additions and 25 deletions

View file

@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2

View file

@ -19,11 +19,16 @@
"php": ">=5.3" "php": ">=5.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": ">=4" "phpunit/phpunit": "^4.8.36 || ^9.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"joshtronic\\": "src/" "joshtronic\\": "src/"
} }
},
"autoload-dev": {
"psr-4": {
"joshtronic\\Tests\\": "tests/"
}
} }
} }

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit <phpunit
bootstrap="vendor/autoload.php"
colors="true" colors="true"
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"

View file

@ -1,14 +1,9 @@
<?php <?php
require_once './src/LoremIpsum.php'; namespace joshtronic\Tests;
use joshtronic\LoremIpsum;
use PHPUnit\Framework\TestCase;
if ( class LoremIpsumTest extends TestCase
!class_exists('\PHPUnit_Framework_TestCase')
&& class_exists('\PHPUnit\Framework\TestCase')
) {
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
}
class LoremIpsumTest extends PHPUnit_Framework_TestCase
{ {
/** /**
* @doesNotPerformAssertions * @doesNotPerformAssertions
@ -26,7 +21,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testWord($assertRegExp) public function testWord($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp('/^[a-z]+$/i', $lipsum->word()); $this->$assertRegExp('/^[a-z]+$/i', $lipsum->word());
} }
@ -35,7 +30,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testWords($assertRegExp) public function testWords($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp( $this->$assertRegExp(
'/^[a-z]+ [a-z]+ [a-z]+$/i', '/^[a-z]+ [a-z]+ [a-z]+$/i',
$lipsum->words(3) $lipsum->words(3)
@ -47,7 +42,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testWordsArray($assertRegExp) public function testWordsArray($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$words = $lipsum->wordsArray(3); $words = $lipsum->wordsArray(3);
$this->assertTrue(is_array($words)); $this->assertTrue(is_array($words));
$this->assertCount(3, $words); $this->assertCount(3, $words);
@ -62,7 +57,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testWordsExceedingVocab($assertRegExp) public function testWordsExceedingVocab($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->assertCount(500, $lipsum->wordsArray(500)); $this->assertCount(500, $lipsum->wordsArray(500));
} }
@ -71,7 +66,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testSentence($assertRegExp) public function testSentence($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp('/^[a-z, ]+\.$/i', $lipsum->sentence()); $this->$assertRegExp('/^[a-z, ]+\.$/i', $lipsum->sentence());
} }
@ -80,7 +75,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testSentences($assertRegExp) public function testSentences($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp( $this->$assertRegExp(
'/^[a-z, ]+\. [a-z, ]+\. [a-z, ]+\.$/i', '/^[a-z, ]+\. [a-z, ]+\. [a-z, ]+\.$/i',
$lipsum->sentences(3) $lipsum->sentences(3)
@ -92,7 +87,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testSentencesArray($assertRegExp) public function testSentencesArray($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$sentences = $lipsum->sentencesArray(3); $sentences = $lipsum->sentencesArray(3);
$this->assertTrue(is_array($sentences)); $this->assertTrue(is_array($sentences));
$this->assertCount(3, $sentences); $this->assertCount(3, $sentences);
@ -107,7 +102,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testParagraph($assertRegExp) public function testParagraph($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp('/^([a-z, ]+\.)+$/i', $lipsum->paragraph()); $this->$assertRegExp('/^([a-z, ]+\.)+$/i', $lipsum->paragraph());
} }
@ -116,7 +111,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testParagraphs($assertRegExp) public function testParagraphs($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp( $this->$assertRegExp(
'/^([a-z, ]+\.)+\n\n([a-z, ]+\.)+\n\n([a-z, ]+\.)+$/i', '/^([a-z, ]+\.)+\n\n([a-z, ]+\.)+\n\n([a-z, ]+\.)+$/i',
$lipsum->paragraphs(3) $lipsum->paragraphs(3)
@ -128,7 +123,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testParagraphsArray($assertRegExp) public function testParagraphsArray($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$paragraphs = $lipsum->paragraphsArray(3); $paragraphs = $lipsum->paragraphsArray(3);
$this->assertTrue(is_array($paragraphs)); $this->assertTrue(is_array($paragraphs));
$this->assertCount(3, $paragraphs); $this->assertCount(3, $paragraphs);
@ -143,7 +138,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testMarkupString($assertRegExp) public function testMarkupString($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp( $this->$assertRegExp(
'/^<li>[a-z]+<\/li>$/i', '/^<li>[a-z]+<\/li>$/i',
$lipsum->word('li') $lipsum->word('li')
@ -155,7 +150,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testMarkupArray($assertRegExp) public function testMarkupArray($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp( $this->$assertRegExp(
'/^<div><p>[a-z]+<\/p><\/div>$/i', '/^<div><p>[a-z]+<\/p><\/div>$/i',
$lipsum->word(array('div', 'p')) $lipsum->word(array('div', 'p'))
@ -167,7 +162,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testMarkupBackReference($assertRegExp) public function testMarkupBackReference($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$this->$assertRegExp( $this->$assertRegExp(
'/^<li><a href="[a-z]+">[a-z]+<\/a><\/li>$/i', '/^<li><a href="[a-z]+">[a-z]+<\/a><\/li>$/i',
$lipsum->word('<li><a href="$1">$1</a></li>') $lipsum->word('<li><a href="$1">$1</a></li>')
@ -179,7 +174,7 @@ class LoremIpsumTest extends PHPUnit_Framework_TestCase
*/ */
public function testMarkupArrayReturn($assertRegExp) public function testMarkupArrayReturn($assertRegExp)
{ {
$lipsum = new joshtronic\LoremIpsum(); $lipsum = new LoremIpsum();
$words = $lipsum->wordsArray(3, 'li'); $words = $lipsum->wordsArray(3, 'li');
$this->assertTrue(is_array($words)); $this->assertTrue(is_array($words));
$this->assertCount(3, $words); $this->assertCount(3, $words);