Skip to content
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
25 changes: 13 additions & 12 deletions tests/Unit/CSSList/AtRuleBlockListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -17,8 +18,8 @@
final class AtRuleBlockListTest extends TestCase
{
/*
* Tests for the implemented interfaces
*/
* Tests for the implemented interfaces and superclasses
*/

/**
* @test
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
171 changes: 171 additions & 0 deletions tests/Unit/CSSList/CSSListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php

declare(strict_types=1);

namespace Sabberworm\CSS\Tests\Unit\CSSList;

use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Comment\Commentable;
use Sabberworm\CSS\Renderable;
use Sabberworm\CSS\RuleSet\DeclarationBlock;
use Sabberworm\CSS\Tests\Unit\CSSList\Fixtures\ConcreteCSSList;

/**
* @covers \Sabberworm\CSS\CSSList\CSSList
*/
final class CSSListTest extends TestCase
{
/**
* @test
*/
public function implementsRenderable(): void
{
$subject = new ConcreteCSSList();

self::assertInstanceOf(Renderable::class, $subject);
}

/**
* @test
*/
public function implementsCommentable(): void
{
$subject = new ConcreteCSSList();

self::assertInstanceOf(Commentable::class, $subject);
}

/**
* @test
*/
public function getLineNoByDefaultReturnsZero(): void
{
$subject = new ConcreteCSSList();

self::assertSame(0, $subject->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<string, array{0: list<DeclarationBlock>}>
*/
public static function contentsDataProvider(): array
{
return [
'empty array' => [[]],
'1 item' => [[new DeclarationBlock()]],
'2 items' => [[new DeclarationBlock(), new DeclarationBlock()]],
];
}

/**
* @test
*
* @param list<DeclarationBlock> $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());
}
}
115 changes: 7 additions & 108 deletions tests/Unit/CSSList/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,8 +24,8 @@
final class DocumentTest extends TestCase
{
/*
* Tests for the implemented interfaces
*/
* Tests for the implemented interfaces and superclasses
*/

/**
* @test
Expand All @@ -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<string, array{0: list<DeclarationBlock>}>
*/
public static function contentsDataProvider(): array
{
return [
'empty array' => [[]],
'1 item' => [[new DeclarationBlock()]],
'2 items' => [[new DeclarationBlock(), new DeclarationBlock()]],
];
}

/**
* @test
*
* @param list<DeclarationBlock> $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
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/CSSList/Fixtures/ConcreteCSSList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Sabberworm\CSS\Tests\Unit\CSSList\Fixtures;

use Sabberworm\CSS\CSSList\CSSList;
use Sabberworm\CSS\OutputFormat;

final class ConcreteCSSList extends CSSList
{
public function isRootList(): bool
{
throw new \BadMethodCallException('Not implemented', 1740395831);
}

public function render(OutputFormat $outputFormat): string
{
throw new \BadMethodCallException('Not implemented', 1740395836);
}
}
Loading
Loading