From 5e42c58b3bd9883fe156aa8f9b367c2c6aecc062 Mon Sep 17 00:00:00 2001 From: peter279k Date: Sun, 5 Apr 2020 02:06:31 +0800 Subject: [PATCH] Test enhancement --- .travis.yml | 2 +- composer.json | 4 ++-- phpunit.xml | 6 +++++ .../CSS/CSSList/AtRuleBlockListTest.php | 2 +- tests/Sabberworm/CSS/CSSList/DocumentTest.php | 2 +- tests/Sabberworm/CSS/OutputFormatTest.php | 2 +- tests/Sabberworm/CSS/ParserTest.php | 22 +++++++++---------- .../CSS/RuleSet/DeclarationBlockTest.php | 2 +- .../CSS/RuleSet/LenientParsingTest.php | 2 +- tests/bootstrap.php | 2 +- tests/quickdump.php | 1 - 11 files changed, 26 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 623e7f6a..fbaa6465 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ php: - "7.1" - "7.2" - "7.3" + - "7.4" - hhvm-3.30 sudo: false dist: trusty @@ -19,4 +20,3 @@ matrix: before_script: rm composer.lock && composer install script: ./vendor/bin/phpunit --coverage-clover build/coverage/xml after_script: ./vendor/bin/codacycoverage clover build/coverage/xml - diff --git a/composer.json b/composer.json index 6e004fed..c8efa113 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,10 @@ "php": ">=5.3.2" }, "require-dev": { - "phpunit/phpunit": "~4.8", + "phpunit/phpunit": "^4.8.36", "codacy/coverage": "^1.4" }, "autoload": { - "psr-0": { "Sabberworm\\CSS\\": "lib/" } + "psr-4": { "Sabberworm\\CSS\\": "lib/Sabberworm/CSS/" } } } diff --git a/phpunit.xml b/phpunit.xml index 33cbef56..f453d524 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,4 +7,10 @@ tests + + + + lib/Sabberworm/CSS + + diff --git a/tests/Sabberworm/CSS/CSSList/AtRuleBlockListTest.php b/tests/Sabberworm/CSS/CSSList/AtRuleBlockListTest.php index 551d0ea5..d3d1ec6b 100644 --- a/tests/Sabberworm/CSS/CSSList/AtRuleBlockListTest.php +++ b/tests/Sabberworm/CSS/CSSList/AtRuleBlockListTest.php @@ -4,7 +4,7 @@ use Sabberworm\CSS\Parser; -class AtRuleBlockListTest extends \PHPUnit_Framework_TestCase { +class AtRuleBlockListTest extends \PHPUnit\Framework\TestCase { public function testMediaQueries() { $sCss = '@media(min-width: 768px){.class{color:red}}'; diff --git a/tests/Sabberworm/CSS/CSSList/DocumentTest.php b/tests/Sabberworm/CSS/CSSList/DocumentTest.php index 00395809..b0ad811d 100644 --- a/tests/Sabberworm/CSS/CSSList/DocumentTest.php +++ b/tests/Sabberworm/CSS/CSSList/DocumentTest.php @@ -4,7 +4,7 @@ use Sabberworm\CSS\Parser; -class DocumentTest extends \PHPUnit_Framework_TestCase { +class DocumentTest extends \PHPUnit\Framework\TestCase { public function testOverrideContents() { $sCss = '.thing { left: 10px; }'; diff --git a/tests/Sabberworm/CSS/OutputFormatTest.php b/tests/Sabberworm/CSS/OutputFormatTest.php index 238b5ba5..d40e9edf 100644 --- a/tests/Sabberworm/CSS/OutputFormatTest.php +++ b/tests/Sabberworm/CSS/OutputFormatTest.php @@ -24,7 +24,7 @@ EOT; -class OutputFormatTest extends \PHPUnit_Framework_TestCase { +class OutputFormatTest extends \PHPunit\Framework\TestCase { private $oParser; private $oDocument; diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php index ea34f2e7..1191a63c 100644 --- a/tests/Sabberworm/CSS/ParserTest.php +++ b/tests/Sabberworm/CSS/ParserTest.php @@ -10,7 +10,7 @@ use Sabberworm\CSS\Value\URL; use Sabberworm\CSS\Parsing\UnexpectedTokenException; -class ParserTest extends \PHPUnit_Framework_TestCase { +class ParserTest extends \PHPunit\Framework\TestCase { function testFiles() { $sDirectory = dirname(__FILE__) . '/../../files'; @@ -214,23 +214,23 @@ function testManipulation() { $this->assertSame('#header {margin: 10px 2em 1cm 2%;color: red !important;frequency: 30Hz;} body {color: green;}', $oDoc->render()); } - + function testRuleGetters() { $oDoc = $this->parsedStructureForFile('values'); $aBlocks = $oDoc->getAllDeclarationBlocks(); $oHeaderBlock = $aBlocks[0]; $oBodyBlock = $aBlocks[1]; $aHeaderRules = $oHeaderBlock->getRules('background-'); - $this->assertSame(2, count($aHeaderRules)); + $this->assertCount(2, $aHeaderRules); $this->assertSame('background-color', $aHeaderRules[0]->getRule()); $this->assertSame('background-color', $aHeaderRules[1]->getRule()); $aHeaderRules = $oHeaderBlock->getRulesAssoc('background-'); - $this->assertSame(1, count($aHeaderRules)); - $this->assertSame(true, $aHeaderRules['background-color']->getValue() instanceof \Sabberworm\CSS\Value\Color); + $this->assertCount(1, $aHeaderRules); + $this->assertTrue($aHeaderRules['background-color']->getValue() instanceof \Sabberworm\CSS\Value\Color); $this->assertSame('rgba', $aHeaderRules['background-color']->getValue()->getColorDescription()); $oHeaderBlock->removeRule($aHeaderRules['background-color']); $aHeaderRules = $oHeaderBlock->getRules('background-'); - $this->assertSame(1, count($aHeaderRules)); + $this->assertCount(1, $aHeaderRules); $this->assertSame('green', $aHeaderRules[0]->getValue()); } @@ -319,7 +319,7 @@ function testNamespaces() { |test {gaga: 2;}'; $this->assertSame($sExpected, $oDoc->render()); } - + function testInnerColors() { $oDoc = $this->parsedStructureForFile('inner-color'); $sExpected = 'test {background: -webkit-gradient(linear,0 0,0 bottom,from(#006cad),to(hsl(202,100%,49%)));}'; @@ -359,7 +359,7 @@ function testListValueRemoval() { $this->assertSame('@media screen {html {some: -test(val2);}} #unrelated {other: yes;}', $oDoc->render()); } - + /** * @expectedException Sabberworm\CSS\Parsing\OutputException */ @@ -367,13 +367,13 @@ function testSelectorRemoval() { $oDoc = $this->parsedStructureForFile('1readme'); $aBlocks = $oDoc->getAllDeclarationBlocks(); $oBlock1 = $aBlocks[0]; - $this->assertSame(true, $oBlock1->removeSelector('html')); + $this->assertTrue($oBlock1->removeSelector('html')); $sExpected = '@charset "utf-8"; @font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");} body {font-size: 1.6em;}'; $this->assertSame($sExpected, $oDoc->render()); - $this->assertSame(false, $oBlock1->removeSelector('html')); - $this->assertSame(true, $oBlock1->removeSelector('body')); + $this->assertFalse($oBlock1->removeSelector('html')); + $this->assertTrue($oBlock1->removeSelector('body')); // This tries to output a declaration block without a selector and throws. $oDoc->render(); } diff --git a/tests/Sabberworm/CSS/RuleSet/DeclarationBlockTest.php b/tests/Sabberworm/CSS/RuleSet/DeclarationBlockTest.php index 16a4a2d1..f135684c 100644 --- a/tests/Sabberworm/CSS/RuleSet/DeclarationBlockTest.php +++ b/tests/Sabberworm/CSS/RuleSet/DeclarationBlockTest.php @@ -6,7 +6,7 @@ use Sabberworm\CSS\Rule\Rule; use Sabberworm\CSS\Value\Size; -class DeclarationBlockTest extends \PHPUnit_Framework_TestCase { +class DeclarationBlockTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider expandBorderShorthandProvider diff --git a/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php b/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php index d7005ba2..a119d8e7 100644 --- a/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php +++ b/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php @@ -5,7 +5,7 @@ use Sabberworm\CSS\Parser; use Sabberworm\CSS\Settings; -class LenientParsingTest extends \PHPUnit_Framework_TestCase { +class LenientParsingTest extends \PHPUnit\Framework\TestCase { /** * @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7c4de814..fe39a2a0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -7,4 +7,4 @@ require $file; return true; } -}); \ No newline at end of file +}); diff --git a/tests/quickdump.php b/tests/quickdump.php index 4b54c71e..a3b50bd1 100755 --- a/tests/quickdump.php +++ b/tests/quickdump.php @@ -17,4 +17,3 @@ print $oDoc->render(); echo "\n```\n"; -