Skip to content

Use PHPUnit 5.x features in the tests #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion config/php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
// Disable constant visibility from the PSR12 rule set as this would break compatibility with PHP < 7.1.
'visibility_required' => ['elements' => ['property', 'method']],

'@PHPUnit50Migration:risky' => true,
'@PHPUnit52Migration:risky' => true,
'@PHPUnit54Migration:risky' => true,
'@PHPUnit55Migration:risky' => true,
'@PHPUnit56Migration:risky' => true,
'@PHPUnit57Migration:risky' => true,

'php_unit_construct' => true,
'php_unit_dedicate_assert' => ['target' => '5.0'],
'php_unit_dedicate_assert' => ['target' => '5.6'],
'php_unit_expectation' => ['target' => '5.6'],
'php_unit_fqcn_annotation' => true,
'php_unit_method_casing' => true,
Expand Down
5 changes: 3 additions & 2 deletions tests/OutputFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Sabberworm\CSS\CSSList\Document;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parser;
use Sabberworm\CSS\Parsing\OutputException;

/**
* @covers \Sabberworm\CSS\OutputFormat
Expand Down Expand Up @@ -268,12 +269,12 @@ public function spaceBeforeBraces()
}

/**
* @expectedException \Sabberworm\CSS\Parsing\OutputException
*
* @test
*/
public function ignoreExceptionsOff()
{
$this->expectException(OutputException::class);

$aBlocks = $this->oDocument->getAllDeclarationBlocks();
$oFirstBlock = $aBlocks[0];
$oFirstBlock->removeSelector('.main');
Expand Down
41 changes: 22 additions & 19 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Sabberworm\CSS\CSSList\KeyFrame;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parser;
use Sabberworm\CSS\Parsing\OutputException;
use Sabberworm\CSS\Parsing\SourceException;
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
use Sabberworm\CSS\Property\AtRule;
use Sabberworm\CSS\Property\Charset;
Expand Down Expand Up @@ -601,12 +603,12 @@ public function listValueRemoval()
}

/**
* @expectedException \Sabberworm\CSS\Parsing\OutputException
*
* @test
*/
public function selectorRemoval()
{
$this->expectException(OutputException::class);

$oDoc = self::parsedStructureForFile('1readme');
$aBlocks = $oDoc->getAllDeclarationBlocks();
$oBlock1 = $aBlocks[0];
Expand Down Expand Up @@ -805,22 +807,22 @@ public function keyframeSelectors()
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function lineNameFailure()
{
$this->expectException(UnexpectedTokenException::class);

self::parsedStructureForFile('-empty-grid-linename', Settings::create()->withLenientParsing(false));
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function calcFailure()
{
$this->expectException(UnexpectedTokenException::class);

self::parsedStructureForFile('-calc-no-space-around-minus', Settings::create()->withLenientParsing(false));
}

Expand Down Expand Up @@ -887,45 +889,46 @@ public function trailingWhitespace()
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function charsetFailure1()
{
$this->expectException(UnexpectedTokenException::class);

self::parsedStructureForFile('-charset-after-rule', Settings::create()->withLenientParsing(false));
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function charsetFailure2()
{
$this->expectException(UnexpectedTokenException::class);

self::parsedStructureForFile('-charset-in-block', Settings::create()->withLenientParsing(false));
}

/**
* @expectedException \Sabberworm\CSS\Parsing\SourceException
*
* @test
*/
public function unopenedClosingBracketFailure()
{
$this->expectException(SourceException::class);

self::parsedStructureForFile('-unopened-close-brackets', Settings::create()->withLenientParsing(false));
}

/**
* Ensure that a missing property value raises an exception.
*
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
* @covers \Sabberworm\CSS\Value\Value::parseValue()
*
* @test
*/
public function missingPropertyValueStrict()
{
$this->expectException(UnexpectedTokenException::class);

self::parsedStructureForFile('missing-property-value', Settings::create()->withLenientParsing(false));
}

Expand Down Expand Up @@ -1025,12 +1028,12 @@ public function lineNumbersParsing()
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function unexpectedTokenExceptionLineNo()
{
$this->expectException(UnexpectedTokenException::class);

$oParser = new Parser("\ntest: 1;", Settings::create()->beStrict());
try {
$oParser->parse();
Expand All @@ -1041,12 +1044,12 @@ public function unexpectedTokenExceptionLineNo()
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function ieHacksStrictParsing()
{
$this->expectException(UnexpectedTokenException::class);

// We can't strictly parse IE hacks.
self::parsedStructureForFile('ie-hacks', Settings::create()->beStrict());
}
Expand Down Expand Up @@ -1138,12 +1141,12 @@ public function topLevelCommentExtracting()
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function microsoftFilterStrictParsing()
{
$this->expectException(UnexpectedTokenException::class);

$oDoc = self::parsedStructureForFile('ms-filter', Settings::create()->beStrict());
}

Expand Down
13 changes: 7 additions & 6 deletions tests/RuleSet/LenientParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parser;
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
use Sabberworm\CSS\Settings;

/**
Expand All @@ -21,12 +22,12 @@
class LenientParsingTest extends TestCase
{
/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function faultToleranceOff()
{
$this->expectException(UnexpectedTokenException::class);

$sFile = __DIR__ . '/../fixtures/-fault-tolerance.css';
$oParser = new Parser(file_get_contents($sFile), Settings::create()->beStrict());
$oParser->parse();
Expand All @@ -48,24 +49,24 @@ public function faultToleranceOn()
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function endToken()
{
$this->expectException(UnexpectedTokenException::class);

$sFile = __DIR__ . '/../fixtures/-end-token.css';
$oParser = new Parser(file_get_contents($sFile), Settings::create()->beStrict());
$oParser->parse();
}

/**
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
*
* @test
*/
public function endToken2()
{
$this->expectException(UnexpectedTokenException::class);

$sFile = __DIR__ . '/../fixtures/-end-token-2.css';
$oParser = new Parser(file_get_contents($sFile), Settings::create()->beStrict());
$oParser->parse();
Expand Down