diff --git a/tests/Unit/CSSList/AtRuleBlockListTest.php b/tests/Unit/CSSList/AtRuleBlockListTest.php index 0537f7d1..86411142 100644 --- a/tests/Unit/CSSList/AtRuleBlockListTest.php +++ b/tests/Unit/CSSList/AtRuleBlockListTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase; use Sabberworm\CSS\Comment\Commentable; use Sabberworm\CSS\CSSList\AtRuleBlockList; +use Sabberworm\CSS\CSSList\CSSList; use Sabberworm\CSS\Renderable; /** @@ -17,8 +18,8 @@ final class AtRuleBlockListTest extends TestCase { /* - * Tests for the implemented interfaces - */ + * Tests for the implemented interfaces and superclasses + */ /** * @test @@ -50,6 +51,16 @@ public function implementsCommentable(): void self::assertInstanceOf(Commentable::class, $subject); } + /** + * @test + */ + public function isCSSList(): void + { + $subject = new AtRuleBlockList('supports'); + + self::assertInstanceOf(CSSList::class, $subject); + } + /* * not grouped yet */ @@ -66,16 +77,6 @@ public function atRuleNameReturnsTypeProvidedToConstructor(): void self::assertSame($type, $subject->atRuleName()); } - /** - * @test - */ - public function getLineNoByDefaultReturnsZero(): void - { - $subject = new AtRuleBlockList('supports'); - - self::assertSame(0, $subject->getLineNo()); - } - /** * @test */ diff --git a/tests/Unit/CSSList/CSSListTest.php b/tests/Unit/CSSList/CSSListTest.php new file mode 100644 index 00000000..69ee4d05 --- /dev/null +++ b/tests/Unit/CSSList/CSSListTest.php @@ -0,0 +1,171 @@ +getLineNo()); + } + + /** + * @test + */ + public function getLineNoReturnsLineNumberProvidedToConstructor(): void + { + $lineNumber = 42; + + $subject = new ConcreteCSSList($lineNumber); + + self::assertSame($lineNumber, $subject->getLineNo()); + } + + /** + * @test + */ + public function getContentsInitiallyReturnsEmptyArray(): void + { + $subject = new ConcreteCSSList(); + + self::assertSame([], $subject->getContents()); + } + + /** + * @return array}> + */ + public static function contentsDataProvider(): array + { + return [ + 'empty array' => [[]], + '1 item' => [[new DeclarationBlock()]], + '2 items' => [[new DeclarationBlock(), new DeclarationBlock()]], + ]; + } + + /** + * @test + * + * @param list $contents + * + * @dataProvider contentsDataProvider + */ + public function setContentsSetsContents(array $contents): void + { + $subject = new ConcreteCSSList(); + + $subject->setContents($contents); + + self::assertSame($contents, $subject->getContents()); + } + + /** + * @test + */ + public function setContentsReplacesContentsSetInPreviousCall(): void + { + $subject = new ConcreteCSSList(); + + $contents2 = [new DeclarationBlock()]; + + $subject->setContents([new DeclarationBlock()]); + $subject->setContents($contents2); + + self::assertSame($contents2, $subject->getContents()); + } + + /** + * @test + */ + public function insertBeforeInsertsContentBeforeSibling(): void + { + $subject = new ConcreteCSSList(); + + $bogusOne = new DeclarationBlock(); + $bogusOne->setSelectors('.bogus-one'); + $bogusTwo = new DeclarationBlock(); + $bogusTwo->setSelectors('.bogus-two'); + + $item = new DeclarationBlock(); + $item->setSelectors('.item'); + + $sibling = new DeclarationBlock(); + $sibling->setSelectors('.sibling'); + + $subject->setContents([$bogusOne, $sibling, $bogusTwo]); + + self::assertCount(3, $subject->getContents()); + + $subject->insertBefore($item, $sibling); + + self::assertCount(4, $subject->getContents()); + self::assertSame([$bogusOne, $item, $sibling, $bogusTwo], $subject->getContents()); + } + + /** + * @test + */ + public function insertBeforeAppendsIfSiblingNotFound(): void + { + $subject = new ConcreteCSSList(); + + $bogusOne = new DeclarationBlock(); + $bogusOne->setSelectors('.bogus-one'); + $bogusTwo = new DeclarationBlock(); + $bogusTwo->setSelectors('.bogus-two'); + + $item = new DeclarationBlock(); + $item->setSelectors('.item'); + + $sibling = new DeclarationBlock(); + $sibling->setSelectors('.sibling'); + + $orphan = new DeclarationBlock(); + $orphan->setSelectors('.forever-alone'); + + $subject->setContents([$bogusOne, $sibling, $bogusTwo]); + + self::assertCount(3, $subject->getContents()); + + $subject->insertBefore($item, $orphan); + + self::assertCount(4, $subject->getContents()); + self::assertSame([$bogusOne, $sibling, $bogusTwo, $item], $subject->getContents()); + } +} diff --git a/tests/Unit/CSSList/DocumentTest.php b/tests/Unit/CSSList/DocumentTest.php index 3d1b1257..5ac66b5b 100644 --- a/tests/Unit/CSSList/DocumentTest.php +++ b/tests/Unit/CSSList/DocumentTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase; use Sabberworm\CSS\Comment\Commentable; use Sabberworm\CSS\CSSList\AtRuleBlockList; +use Sabberworm\CSS\CSSList\CSSList; use Sabberworm\CSS\CSSList\Document; use Sabberworm\CSS\Property\Charset; use Sabberworm\CSS\Property\Import; @@ -23,8 +24,8 @@ final class DocumentTest extends TestCase { /* - * Tests for the implemented interfaces - */ + * Tests for the implemented interfaces and superclasses + */ /** * @test @@ -42,121 +43,19 @@ public function implementsCommentable(): void self::assertInstanceOf(Commentable::class, new Document()); } - /* - * not grouped yet - */ - - /** - * @test - */ - public function getContentsInitiallyReturnsEmptyArray(): void - { - $subject = new Document(); - - self::assertSame([], $subject->getContents()); - } - - /** - * @return array}> - */ - public static function contentsDataProvider(): array - { - return [ - 'empty array' => [[]], - '1 item' => [[new DeclarationBlock()]], - '2 items' => [[new DeclarationBlock(), new DeclarationBlock()]], - ]; - } - - /** - * @test - * - * @param list $contents - * - * @dataProvider contentsDataProvider - */ - public function setContentsSetsContents(array $contents): void - { - $subject = new Document(); - - $subject->setContents($contents); - - self::assertSame($contents, $subject->getContents()); - } - - /** - * @test - */ - public function setContentsReplacesContentsSetInPreviousCall(): void - { - $subject = new Document(); - - $contents2 = [new DeclarationBlock()]; - - $subject->setContents([new DeclarationBlock()]); - $subject->setContents($contents2); - - self::assertSame($contents2, $subject->getContents()); - } - /** * @test */ - public function insertContentBeforeInsertsContentBeforeSibling(): void + public function isCSSList(): void { $subject = new Document(); - $bogusOne = new DeclarationBlock(); - $bogusOne->setSelectors('.bogus-one'); - $bogusTwo = new DeclarationBlock(); - $bogusTwo->setSelectors('.bogus-two'); - - $item = new DeclarationBlock(); - $item->setSelectors('.item'); - - $sibling = new DeclarationBlock(); - $sibling->setSelectors('.sibling'); - - $subject->setContents([$bogusOne, $sibling, $bogusTwo]); - - self::assertCount(3, $subject->getContents()); - - $subject->insertBefore($item, $sibling); - - self::assertCount(4, $subject->getContents()); - self::assertSame([$bogusOne, $item, $sibling, $bogusTwo], $subject->getContents()); + self::assertInstanceOf(CSSList::class, $subject); } - /** - * @test + /* + * not grouped yet */ - public function insertContentBeforeAppendsIfSiblingNotFound(): void - { - $subject = new Document(); - - $bogusOne = new DeclarationBlock(); - $bogusOne->setSelectors('.bogus-one'); - $bogusTwo = new DeclarationBlock(); - $bogusTwo->setSelectors('.bogus-two'); - - $item = new DeclarationBlock(); - $item->setSelectors('.item'); - - $sibling = new DeclarationBlock(); - $sibling->setSelectors('.sibling'); - - $orphan = new DeclarationBlock(); - $orphan->setSelectors('.forever-alone'); - - $subject->setContents([$bogusOne, $sibling, $bogusTwo]); - - self::assertCount(3, $subject->getContents()); - - $subject->insertBefore($item, $orphan); - - self::assertCount(4, $subject->getContents()); - self::assertSame([$bogusOne, $sibling, $bogusTwo, $item], $subject->getContents()); - } /** * @test diff --git a/tests/Unit/CSSList/Fixtures/ConcreteCSSList.php b/tests/Unit/CSSList/Fixtures/ConcreteCSSList.php new file mode 100644 index 00000000..250f2a1b --- /dev/null +++ b/tests/Unit/CSSList/Fixtures/ConcreteCSSList.php @@ -0,0 +1,21 @@ +getLineNo()); + self::assertInstanceOf(CSSList::class, $subject); } + /* + * not grouped yet + */ + /** * @test */