Skip to content

[CLEANUP] Use a per-test subject for DocumentTest #963

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
Feb 20, 2025
Merged
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
56 changes: 28 additions & 28 deletions tests/Unit/CSSList/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,30 @@
*/
final class DocumentTest extends TestCase
{
/**
* @var Document
*/
private $subject;

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

/**
* @test
*/
public function implementsRenderable(): void
{
self::assertInstanceOf(Renderable::class, $this->subject);
self::assertInstanceOf(Renderable::class, new Document());
}

/**
* @test
*/
public function implementsCommentable(): void
{
self::assertInstanceOf(Commentable::class, $this->subject);
self::assertInstanceOf(Commentable::class, new Document());
}

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

self::assertSame([], $subject->getContents());
}

/**
Expand All @@ -70,29 +62,35 @@ public static function contentsDataProvider(): array
*/
public function setContentsSetsContents(array $contents): void
{
$this->subject->setContents($contents);
$subject = new Document();

$subject->setContents($contents);

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

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

$contents2 = [new DeclarationBlock()];

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

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

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

$bogusOne = new DeclarationBlock();
$bogusOne->setSelectors('.bogus-one');
$bogusTwo = new DeclarationBlock();
Expand All @@ -104,21 +102,23 @@ public function insertContentBeforeInsertsContentBeforeSibling(): void
$sibling = new DeclarationBlock();
$sibling->setSelectors('.sibling');

$this->subject->setContents([$bogusOne, $sibling, $bogusTwo]);
$subject->setContents([$bogusOne, $sibling, $bogusTwo]);

self::assertCount(3, $this->subject->getContents());
self::assertCount(3, $subject->getContents());

$this->subject->insertBefore($item, $sibling);
$subject->insertBefore($item, $sibling);

self::assertCount(4, $this->subject->getContents());
self::assertSame([$bogusOne, $item, $sibling, $bogusTwo], $this->subject->getContents());
self::assertCount(4, $subject->getContents());
self::assertSame([$bogusOne, $item, $sibling, $bogusTwo], $subject->getContents());
}

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

$bogusOne = new DeclarationBlock();
$bogusOne->setSelectors('.bogus-one');
$bogusTwo = new DeclarationBlock();
Expand All @@ -133,13 +133,13 @@ public function insertContentBeforeAppendsIfSiblingNotFound(): void
$orphan = new DeclarationBlock();
$orphan->setSelectors('.forever-alone');

$this->subject->setContents([$bogusOne, $sibling, $bogusTwo]);
$subject->setContents([$bogusOne, $sibling, $bogusTwo]);

self::assertCount(3, $this->subject->getContents());
self::assertCount(3, $subject->getContents());

$this->subject->insertBefore($item, $orphan);
$subject->insertBefore($item, $orphan);

self::assertCount(4, $this->subject->getContents());
self::assertSame([$bogusOne, $sibling, $bogusTwo, $item], $this->subject->getContents());
self::assertCount(4, $subject->getContents());
self::assertSame([$bogusOne, $sibling, $bogusTwo, $item], $subject->getContents());
}
}