Skip to content

Commit de5ed89

Browse files
committed
Make the existing tests for Document for fine-grained
1 parent 9c2a9ca commit de5ed89

File tree

2 files changed

+84
-16
lines changed

2 files changed

+84
-16
lines changed

tests/CSSList/DocumentTest.php

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,78 @@
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+
* @test
34+
*/
35+
public function setContentsWithEmptyArrayDoesNotAddAnyContents()
36+
{
37+
$this->subject->setContents([]);
38+
39+
self::assertSame([], $this->subject->getContents());
40+
}
41+
1042
/**
1143
* @test
1244
*/
13-
public function overrideContents()
45+
public function setContentsCanAddOneItem()
1446
{
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);
47+
$item = new DeclarationBlock();
48+
49+
$this->subject->setContents([$item]);
50+
51+
self::assertSame([$item], $this->subject->getContents());
52+
}
53+
54+
/**
55+
* @test
56+
*/
57+
public function setContentsCanAddTwoItemsInOneCall()
58+
{
59+
$item1 = new DeclarationBlock();
60+
$item2 = new DeclarationBlock();
61+
62+
$this->subject->setContents([$item1, $item2]);
63+
64+
self::assertSame([$item1, $item2], $this->subject->getContents());
65+
}
66+
67+
/**
68+
* @test
69+
*/
70+
public function setContentsReplacesItemsSetInPreviousCall()
71+
{
72+
$item1 = new DeclarationBlock();
73+
$item2 = new DeclarationBlock();
74+
75+
$this->subject->setContents([$item1]);
76+
$this->subject->setContents([$item2]);
77+
78+
self::assertSame([$item2], $this->subject->getContents());
2979
}
3080
}

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)