Skip to content

Commit 0aa7b59

Browse files
authored
Merge pull request #330 from oliverklee/task/test/document
Make the existing tests for `Document` more fine-grained
2 parents 9c2a9ca + c5db1d5 commit 0aa7b59

File tree

2 files changed

+74
-16
lines changed

2 files changed

+74
-16
lines changed

tests/CSSList/DocumentTest.php

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,68 @@
33
namespace Sabberworm\CSS\Tests\CSSList;
44

55
use PHPUnit\Framework\TestCase;
6-
use Sabberworm\CSS\Parser;
6+
use Sabberworm\CSS\CSSList\Document;
7+
use Sabberworm\CSS\RuleSet\DeclarationBlock;
78

9+
/**
10+
* @covers \Sabberworm\CSS\CSSList\Document
11+
*/
812
class DocumentTest extends TestCase
913
{
14+
/**
15+
* @var Document
16+
*/
17+
private $subject;
18+
19+
protected function setUp()
20+
{
21+
$this->subject = new Document();
22+
}
23+
24+
/**
25+
* @test
26+
*/
27+
public function getContentsInitiallyReturnsEmptyArray()
28+
{
29+
self::assertSame([], $this->subject->getContents());
30+
}
31+
32+
/**
33+
* @param array<string, array<int, array<int, DeclarationBlock>>>
34+
*/
35+
public function contentsDataProvider()
36+
{
37+
return [
38+
'empty array' => [[]],
39+
'1 item' => [[new DeclarationBlock()]],
40+
'2 items' => [[new DeclarationBlock(), new DeclarationBlock()]],
41+
];
42+
}
43+
1044
/**
1145
* @test
46+
*
47+
* @param array<int, DeclarationBlock>
48+
*
49+
* @dataProvider contentsDataProvider
1250
*/
13-
public function overrideContents()
51+
public function setContentsSetsContents(array $contents)
1452
{
15-
$sCss = '.thing { left: 10px; }';
16-
$oParser = new Parser($sCss);
17-
$oDoc = $oParser->parse();
18-
$aContents = $oDoc->getContents();
19-
self::assertCount(1, $aContents);
20-
21-
$sCss2 = '.otherthing { right: 10px; }';
22-
$oParser2 = new Parser($sCss);
23-
$oDoc2 = $oParser2->parse();
24-
$aContents2 = $oDoc2->getContents();
25-
26-
$oDoc->setContents([$aContents[0], $aContents2[0]]);
27-
$aFinalContents = $oDoc->getContents();
28-
self::assertCount(2, $aFinalContents);
53+
$this->subject->setContents($contents);
54+
55+
self::assertSame($contents, $this->subject->getContents());
56+
}
57+
58+
/**
59+
* @test
60+
*/
61+
public function setContentsReplacesContentsSetInPreviousCall()
62+
{
63+
$contents2 = [new DeclarationBlock()];
64+
65+
$this->subject->setContents([new DeclarationBlock()]);
66+
$this->subject->setContents($contents2);
67+
68+
self::assertSame($contents2, $this->subject->getContents());
2969
}
3070
}

tests/ParserTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Sabberworm\CSS\Property\Selector;
1515
use Sabberworm\CSS\RuleSet\AtRuleSet;
1616
use Sabberworm\CSS\RuleSet\DeclarationBlock;
17+
use Sabberworm\CSS\RuleSet\RuleSet;
1718
use Sabberworm\CSS\Settings;
1819
use Sabberworm\CSS\Value\Color;
1920
use Sabberworm\CSS\Value\Size;
@@ -33,6 +34,23 @@
3334
*/
3435
class ParserTest extends TestCase
3536
{
37+
/**
38+
* @test
39+
*/
40+
public function parseForOneRuleSetReturnsDocumentWithOneRuleSet()
41+
{
42+
$css = '.thing { left: 10px; }';
43+
$parser = new Parser($css);
44+
45+
$document = $parser->parse();
46+
47+
self::assertInstanceOf(Document::class, $document);
48+
49+
$cssList = $document->getContents();
50+
self::assertCount(1, $cssList);
51+
self::assertInstanceOf(RuleSet::class, $cssList[0]);
52+
}
53+
3654
/**
3755
* @test
3856
*/

0 commit comments

Comments
 (0)