From 73d15ee57a43fb6fcc3288dc1a7cdcb27cdcf178 Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 10 May 2018 16:53:52 +0800 Subject: [PATCH] Test enhancement --- .travis.yml | 11 +++++ composer.json | 8 +++- phpunit.xml.dist | 2 +- tests/Purl/Test/AutoloaderTest.php | 4 +- tests/Purl/Test/FragmentTest.php | 55 +++++++++++++++++++++++- tests/Purl/Test/ParserTest.php | 13 +++--- tests/Purl/Test/PathTest.php | 4 +- tests/Purl/Test/PublicSuffixListTest.php | 4 +- tests/Purl/Test/QueryTest.php | 4 +- tests/Purl/Test/UrlTest.php | 29 ++++++++++++- tests/bootstrap.php | 9 ---- 11 files changed, 114 insertions(+), 29 deletions(-) delete mode 100644 tests/bootstrap.php diff --git a/.travis.yml b/.travis.yml index cb1e1cf..237d326 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,16 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 + - 7.1 + - 7.2 + - nightly + +matrix: + allow_failures: + - php: nightly + include: + - php: 5.3 + dist: precise before_script: composer install diff --git a/composer.json b/composer.json index 628f3a5..846a082 100644 --- a/composer.json +++ b/composer.json @@ -9,10 +9,14 @@ {"name": "Jonathan H. Wage", "email": "jonwage@gmail.com"} ], "autoload": { - "psr-0": {"Purl": "src/"} + "psr-4": {"Purl\\": "src/Purl"} + }, + "autoload-dev": { + "psr-4": {"Purl\\Test\\": "tests/Purl/Test"} }, "require": { "php": ">=5.3.0", - "jeremykendall/php-domain-parser": "1.3.1" + "jeremykendall/php-domain-parser": "^1.3.1", + "phpunit/phpunit": "^4.8|^5.5|^6.5" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cb6739b..9541f6d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - + ./tests/Purl/Test/ diff --git a/tests/Purl/Test/AutoloaderTest.php b/tests/Purl/Test/AutoloaderTest.php index d3be168..2e497fa 100644 --- a/tests/Purl/Test/AutoloaderTest.php +++ b/tests/Purl/Test/AutoloaderTest.php @@ -2,10 +2,10 @@ namespace Purl\Test; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Purl\Autoloader; -class AutoloaderTest extends PHPUnit_Framework_TestCase +class AutoloaderTest extends TestCase { public function testRegister() { diff --git a/tests/Purl/Test/FragmentTest.php b/tests/Purl/Test/FragmentTest.php index 774923e..6c5cec0 100644 --- a/tests/Purl/Test/FragmentTest.php +++ b/tests/Purl/Test/FragmentTest.php @@ -2,12 +2,12 @@ namespace Purl\Test; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Purl\Fragment; use Purl\Path; use Purl\Query; -class FragmentTest extends PHPUnit_Framework_TestCase +class FragmentTest extends TestCase { public function testConstruct() { @@ -61,4 +61,55 @@ public function testToString() $fragment = new Fragment('test?param=value'); $this->assertEquals('test?param=value', (string) $fragment); } + + public function testIsInitialized() + { + $fragment = new Fragment('test?param=value'); + $this->assertFalse($fragment->isInitialized()); + } + + public function testHas() + { + $fragment = new Fragment('test?param=value'); + $fragment->setData(array('param' => 'value')); + $this->assertTrue($fragment->has('param')); + } + + public function testRemove() + { + $fragment = new Fragment('test?param=value'); + $fragment->setData(array('param' => 'value')); + $fragment->remove('param'); + $this->assertFalse($fragment->has('param')); + } + + public function testIsset() + { + $fragment = new Fragment('test?param=value'); + $fragment->setData(array('param' => 'value')); + $fragment->remove('param'); + $this->assertFalse($fragment->has('param')); + } + + public function testOffsetExists() + { + $fragment = new Fragment('test?param=value'); + $fragment->setData(array('param' => 'value')); + $this->assertTrue($fragment->offsetExists('param')); + } + + public function testOffsetGet() + { + $fragment = new Fragment('test?param=value'); + $fragment->setData(array('param' => 'value')); + $this->assertEquals('value', $fragment->offsetGet('param')); + } + + public function testOffsetUnset() + { + $fragment = new Fragment('test?param=value'); + $fragment->setData(array('param' => 'value')); + $fragment->offsetUnset('param'); + $this->assertFalse($fragment->offsetExists('param')); + } } diff --git a/tests/Purl/Test/ParserTest.php b/tests/Purl/Test/ParserTest.php index 7a3047f..97d15ca 100644 --- a/tests/Purl/Test/ParserTest.php +++ b/tests/Purl/Test/ParserTest.php @@ -2,13 +2,13 @@ namespace Purl\Test; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Purl\Parser; use Pdp\PublicSuffixList; use Pdp\PublicSuffixListManager; use Pdp\Parser as PslParser; -class ParserTest extends PHPUnit_Framework_TestCase +class ParserTest extends TestCase { private $parser; @@ -45,10 +45,13 @@ public function testParseUrl() 'resource' => '/about?param=value' ), $parts); } - + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid url http:///example.com + */ public function testParseBadUrlThrowsInvalidArgumentException() { - $this->setExpectedException('\InvalidArgumentException', 'Invalid url http:///example.com'); - $this->parser->parseUrl('http:///example.com'); + $this->parser->parseUrl('http:///example.com/one/two?one=two#value'); } } diff --git a/tests/Purl/Test/PathTest.php b/tests/Purl/Test/PathTest.php index 3e52f77..30bf804 100644 --- a/tests/Purl/Test/PathTest.php +++ b/tests/Purl/Test/PathTest.php @@ -2,10 +2,10 @@ namespace Purl\Test; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Purl\Path; -class PathTest extends PHPUnit_Framework_TestCase +class PathTest extends TestCase { public function testConstruct() { diff --git a/tests/Purl/Test/PublicSuffixListTest.php b/tests/Purl/Test/PublicSuffixListTest.php index 7023f2b..9e6b53f 100644 --- a/tests/Purl/Test/PublicSuffixListTest.php +++ b/tests/Purl/Test/PublicSuffixListTest.php @@ -2,10 +2,10 @@ namespace Purl\Test; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Purl\Url; -class PublicSuffixListTest extends PHPUnit_Framework_TestCase +class PublicSuffixListTest extends TestCase { /** * @dataProvider parseDataProvider diff --git a/tests/Purl/Test/QueryTest.php b/tests/Purl/Test/QueryTest.php index 77113d0..d359173 100644 --- a/tests/Purl/Test/QueryTest.php +++ b/tests/Purl/Test/QueryTest.php @@ -2,10 +2,10 @@ namespace Purl\Test; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Purl\Query; -class QueryTest extends PHPUnit_Framework_TestCase +class QueryTest extends TestCase { public function testConstruct() { diff --git a/tests/Purl/Test/UrlTest.php b/tests/Purl/Test/UrlTest.php index 8d4c18d..02ade58 100644 --- a/tests/Purl/Test/UrlTest.php +++ b/tests/Purl/Test/UrlTest.php @@ -2,7 +2,7 @@ namespace Purl\Test; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Purl\Fragment; use Purl\Parser; use Purl\ParserInterface; @@ -10,7 +10,7 @@ use Purl\Query; use Purl\Url; -class UrlTest extends PHPUnit_Framework_TestCase +class UrlTest extends TestCase { public function testConstruct() { @@ -96,6 +96,14 @@ public function testSetPath() $this->assertEquals('about', (string) $url->path); } + public function testGetPath() + { + $url = new Url('http://jwage.com'); + $url->path = 'about'; + $this->assertInstanceOf('Purl\Path', $url->path); + $this->assertEquals('about', (string) $url->getPath()); + } + public function testSetQuery() { $url = new Url('http://jwage.com'); @@ -105,6 +113,15 @@ public function testSetQuery() $this->assertEquals(array('param1' => 'value1'), $url->query->getData()); } + public function testGetQuery() + { + $url = new Url('http://jwage.com'); + $url->query->set('param1', 'value1'); + $this->assertInstanceOf('Purl\Query', $url->query); + $this->assertEquals('param1=value1', $url->getQuery()); + $this->assertEquals(array('param1' => 'value1'), $url->getQuery()->getData()); + } + public function testSetFragment() { $url = new Url('http://jwage.com'); @@ -113,6 +130,14 @@ public function testSetFragment() $this->assertEquals('http://jwage.com/#about?param1=value1', (string) $url); } + public function testGetFragment() + { + $url = new Url('http://jwage.com'); + $url->fragment->path = 'about'; + $url->fragment->query->set('param1', 'value1'); + $this->assertEquals('about?param1=value1', (string) $url->getFragment()); + } + public function testGetNetloc() { $url = new Url('https://user:pass@jwage.com:443'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 626d07a..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,9 +0,0 @@ -add('Purl\Test', __DIR__); - $loader->register(); -}); \ No newline at end of file