Skip to content

Commit d9aed44

Browse files
committed
Use PHPUnit 5.x features in the tests
1 parent 5bf29fe commit d9aed44

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

config/php-cs-fixer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
// Disable constant visibility from the PSR12 rule set as this would break compatibility with PHP < 7.1.
1313
'visibility_required' => ['elements' => ['property', 'method']],
1414

15+
'@PHPUnit50Migration:risky' => true,
16+
'@PHPUnit52Migration:risky' => true,
17+
'@PHPUnit54Migration:risky' => true,
18+
'@PHPUnit55Migration:risky' => true,
19+
'@PHPUnit56Migration:risky' => true,
20+
'@PHPUnit57Migration:risky' => true,
21+
1522
'php_unit_construct' => true,
16-
'php_unit_dedicate_assert' => ['target' => '5.0'],
23+
'php_unit_dedicate_assert' => ['target' => '5.6'],
1724
'php_unit_expectation' => ['target' => '5.6'],
1825
'php_unit_fqcn_annotation' => true,
1926
'php_unit_method_casing' => true,

tests/OutputFormatTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Sabberworm\CSS\CSSList\Document;
77
use Sabberworm\CSS\OutputFormat;
88
use Sabberworm\CSS\Parser;
9+
use Sabberworm\CSS\Parsing\OutputException;
910

1011
/**
1112
* @covers \Sabberworm\CSS\OutputFormat
@@ -268,12 +269,12 @@ public function spaceBeforeBraces()
268269
}
269270

270271
/**
271-
* @expectedException \Sabberworm\CSS\Parsing\OutputException
272-
*
273272
* @test
274273
*/
275274
public function ignoreExceptionsOff()
276275
{
276+
$this->expectException(OutputException::class);
277+
277278
$aBlocks = $this->oDocument->getAllDeclarationBlocks();
278279
$oFirstBlock = $aBlocks[0];
279280
$oFirstBlock->removeSelector('.main');

tests/ParserTest.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Sabberworm\CSS\CSSList\KeyFrame;
88
use Sabberworm\CSS\OutputFormat;
99
use Sabberworm\CSS\Parser;
10+
use Sabberworm\CSS\Parsing\OutputException;
11+
use Sabberworm\CSS\Parsing\SourceException;
1012
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
1113
use Sabberworm\CSS\Property\AtRule;
1214
use Sabberworm\CSS\Property\Charset;
@@ -601,12 +603,12 @@ public function listValueRemoval()
601603
}
602604

603605
/**
604-
* @expectedException \Sabberworm\CSS\Parsing\OutputException
605-
*
606606
* @test
607607
*/
608608
public function selectorRemoval()
609609
{
610+
$this->expectException(OutputException::class);
611+
610612
$oDoc = self::parsedStructureForFile('1readme');
611613
$aBlocks = $oDoc->getAllDeclarationBlocks();
612614
$oBlock1 = $aBlocks[0];
@@ -805,22 +807,22 @@ public function keyframeSelectors()
805807
}
806808

807809
/**
808-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
809-
*
810810
* @test
811811
*/
812812
public function lineNameFailure()
813813
{
814+
$this->expectException(UnexpectedTokenException::class);
815+
814816
self::parsedStructureForFile('-empty-grid-linename', Settings::create()->withLenientParsing(false));
815817
}
816818

817819
/**
818-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
819-
*
820820
* @test
821821
*/
822822
public function calcFailure()
823823
{
824+
$this->expectException(UnexpectedTokenException::class);
825+
824826
self::parsedStructureForFile('-calc-no-space-around-minus', Settings::create()->withLenientParsing(false));
825827
}
826828

@@ -887,45 +889,46 @@ public function trailingWhitespace()
887889
}
888890

889891
/**
890-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
891-
*
892892
* @test
893893
*/
894894
public function charsetFailure1()
895895
{
896+
$this->expectException(UnexpectedTokenException::class);
897+
896898
self::parsedStructureForFile('-charset-after-rule', Settings::create()->withLenientParsing(false));
897899
}
898900

899901
/**
900-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
901-
*
902902
* @test
903903
*/
904904
public function charsetFailure2()
905905
{
906+
$this->expectException(UnexpectedTokenException::class);
907+
906908
self::parsedStructureForFile('-charset-in-block', Settings::create()->withLenientParsing(false));
907909
}
908910

909911
/**
910-
* @expectedException \Sabberworm\CSS\Parsing\SourceException
911-
*
912912
* @test
913913
*/
914914
public function unopenedClosingBracketFailure()
915915
{
916+
$this->expectException(SourceException::class);
917+
916918
self::parsedStructureForFile('-unopened-close-brackets', Settings::create()->withLenientParsing(false));
917919
}
918920

919921
/**
920922
* Ensure that a missing property value raises an exception.
921923
*
922-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
923924
* @covers \Sabberworm\CSS\Value\Value::parseValue()
924925
*
925926
* @test
926927
*/
927928
public function missingPropertyValueStrict()
928929
{
930+
$this->expectException(UnexpectedTokenException::class);
931+
929932
self::parsedStructureForFile('missing-property-value', Settings::create()->withLenientParsing(false));
930933
}
931934

@@ -1025,12 +1028,12 @@ public function lineNumbersParsing()
10251028
}
10261029

10271030
/**
1028-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
1029-
*
10301031
* @test
10311032
*/
10321033
public function unexpectedTokenExceptionLineNo()
10331034
{
1035+
$this->expectException(UnexpectedTokenException::class);
1036+
10341037
$oParser = new Parser("\ntest: 1;", Settings::create()->beStrict());
10351038
try {
10361039
$oParser->parse();
@@ -1041,12 +1044,12 @@ public function unexpectedTokenExceptionLineNo()
10411044
}
10421045

10431046
/**
1044-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
1045-
*
10461047
* @test
10471048
*/
10481049
public function ieHacksStrictParsing()
10491050
{
1051+
$this->expectException(UnexpectedTokenException::class);
1052+
10501053
// We can't strictly parse IE hacks.
10511054
self::parsedStructureForFile('ie-hacks', Settings::create()->beStrict());
10521055
}
@@ -1138,12 +1141,12 @@ public function topLevelCommentExtracting()
11381141
}
11391142

11401143
/**
1141-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
1142-
*
11431144
* @test
11441145
*/
11451146
public function microsoftFilterStrictParsing()
11461147
{
1148+
$this->expectException(UnexpectedTokenException::class);
1149+
11471150
$oDoc = self::parsedStructureForFile('ms-filter', Settings::create()->beStrict());
11481151
}
11491152

tests/RuleSet/LenientParsingTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Sabberworm\CSS\Parser;
7+
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
78
use Sabberworm\CSS\Settings;
89

910
/**
@@ -21,12 +22,12 @@
2122
class LenientParsingTest extends TestCase
2223
{
2324
/**
24-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
25-
*
2625
* @test
2726
*/
2827
public function faultToleranceOff()
2928
{
29+
$this->expectException(UnexpectedTokenException::class);
30+
3031
$sFile = __DIR__ . '/../fixtures/-fault-tolerance.css';
3132
$oParser = new Parser(file_get_contents($sFile), Settings::create()->beStrict());
3233
$oParser->parse();
@@ -48,24 +49,24 @@ public function faultToleranceOn()
4849
}
4950

5051
/**
51-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
52-
*
5352
* @test
5453
*/
5554
public function endToken()
5655
{
56+
$this->expectException(UnexpectedTokenException::class);
57+
5758
$sFile = __DIR__ . '/../fixtures/-end-token.css';
5859
$oParser = new Parser(file_get_contents($sFile), Settings::create()->beStrict());
5960
$oParser->parse();
6061
}
6162

6263
/**
63-
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
64-
*
6564
* @test
6665
*/
6766
public function endToken2()
6867
{
68+
$this->expectException(UnexpectedTokenException::class);
69+
6970
$sFile = __DIR__ . '/../fixtures/-end-token-2.css';
7071
$oParser = new Parser(file_get_contents($sFile), Settings::create()->beStrict());
7172
$oParser->parse();

0 commit comments

Comments
 (0)