Skip to content

Make the existing tests for Document for fine-grained #330

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
Jul 12, 2021
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
72 changes: 56 additions & 16 deletions tests/CSSList/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,68 @@
namespace Sabberworm\CSS\Tests\CSSList;

use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parser;
use Sabberworm\CSS\CSSList\Document;
use Sabberworm\CSS\RuleSet\DeclarationBlock;

/**
* @covers \Sabberworm\CSS\CSSList\Document
*/
class DocumentTest extends TestCase
{
/**
* @var Document
*/
private $subject;

protected function setUp()
{
$this->subject = new Document();
}

/**
* @test
*/
public function getContentsInitiallyReturnsEmptyArray()
{
self::assertSame([], $this->subject->getContents());
}

/**
* @param array<string, array<int, array<int, DeclarationBlock>>>
*/
public function contentsDataProvider()
{
return [
'empty array' => [[]],
'1 item' => [[new DeclarationBlock()]],
'2 items' => [[new DeclarationBlock(), new DeclarationBlock()]],
];
}

/**
* @test
*
* @param array<int, DeclarationBlock>
*
* @dataProvider contentsDataProvider
*/
public function overrideContents()
public function setContentsSetsContents(array $contents)
{
$sCss = '.thing { left: 10px; }';
$oParser = new Parser($sCss);
$oDoc = $oParser->parse();
$aContents = $oDoc->getContents();
self::assertCount(1, $aContents);

$sCss2 = '.otherthing { right: 10px; }';
$oParser2 = new Parser($sCss);
$oDoc2 = $oParser2->parse();
$aContents2 = $oDoc2->getContents();

$oDoc->setContents([$aContents[0], $aContents2[0]]);
$aFinalContents = $oDoc->getContents();
self::assertCount(2, $aFinalContents);
$this->subject->setContents($contents);

self::assertSame($contents, $this->subject->getContents());
}

/**
* @test
*/
public function setContentsReplacesContentsSetInPreviousCall()
{
$contents2 = [new DeclarationBlock()];

$this->subject->setContents([new DeclarationBlock()]);
$this->subject->setContents($contents2);

self::assertSame($contents2, $this->subject->getContents());
}
}
18 changes: 18 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sabberworm\CSS\Property\Selector;
use Sabberworm\CSS\RuleSet\AtRuleSet;
use Sabberworm\CSS\RuleSet\DeclarationBlock;
use Sabberworm\CSS\RuleSet\RuleSet;
use Sabberworm\CSS\Settings;
use Sabberworm\CSS\Value\Color;
use Sabberworm\CSS\Value\Size;
Expand All @@ -33,6 +34,23 @@
*/
class ParserTest extends TestCase
{
/**
* @test
*/
public function parseForOneRuleSetReturnsDocumentWithOneRuleSet()
{
$css = '.thing { left: 10px; }';
$parser = new Parser($css);

$document = $parser->parse();

self::assertInstanceOf(Document::class, $document);

$cssList = $document->getContents();
self::assertCount(1, $cssList);
self::assertInstanceOf(RuleSet::class, $cssList[0]);
}

/**
* @test
*/
Expand Down