Skip to content

Commit 94390f1

Browse files
committed
[TASK] Add more tests for OutputFormat
1 parent 5fe6db9 commit 94390f1

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

tests/Unit/OutputFormatTest.php

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\TestCase;
88
use Sabberworm\CSS\OutputFormat;
9+
use Sabberworm\CSS\OutputFormatter;
910

1011
/**
1112
* @covers \Sabberworm\CSS\OutputFormat
@@ -684,4 +685,165 @@ public function setIndentationLevelProvidesFluentInterface(): void
684685
{
685686
self::assertSame($this->subject, $this->subject->setIndentationLevel(4));
686687
}
688+
689+
/**
690+
* @test
691+
*/
692+
public function indentWithTabsByDefaultSetsIndentationToOneTab(): void
693+
{
694+
$this->subject->indentWithTabs();
695+
696+
self::assertSame("\t", $this->subject->getIndentation());
697+
}
698+
699+
/**
700+
* @return array<string, array{0: int<0, max>, 1: string}>
701+
*/
702+
public static function provideTabIndentation(): array
703+
{
704+
return [
705+
'zero tabs' => [0, ''],
706+
'one tab' => [1, "\t"],
707+
'two tabs' => [2, "\t\t"],
708+
'three tabs' => [3, "\t\t\t"],
709+
];
710+
}
711+
712+
/**
713+
* @test
714+
* @dataProvider provideTabIndentation
715+
*/
716+
public function indentWithTabsSetsIndentationToTheProvidedNumberOfTabs(
717+
int $numberOfTabs,
718+
string $expectedIndentation
719+
): void {
720+
$this->subject->indentWithTabs($numberOfTabs);
721+
722+
self::assertSame($expectedIndentation, $this->subject->getIndentation());
723+
}
724+
725+
/**
726+
* @test
727+
*/
728+
public function indentWithSpacesByDefaultSetsIndentationToTwoSpaces(): void
729+
{
730+
$this->subject->indentWithSpaces();
731+
732+
self::assertSame(' ', $this->subject->getIndentation());
733+
}
734+
735+
/**
736+
* @return array<string, array{0: int<0, max>, 1: string}>
737+
*/
738+
public static function provideSpaceIndentation(): array
739+
{
740+
return [
741+
'zero spaces' => [0, ''],
742+
'one space' => [1, ' '],
743+
'two spaces' => [2, ' '],
744+
'three spaces' => [3, ' '],
745+
'four spaces' => [4, ' '],
746+
];
747+
}
748+
749+
/**
750+
* @test
751+
* @dataProvider provideSpaceIndentation
752+
*/
753+
public function indentWithSpacesSetsIndentationToTheProvidedNumberOfSpaces(
754+
int $numberOfSpaces,
755+
string $expectedIndentation
756+
): void {
757+
$this->subject->indentWithSpaces($numberOfSpaces);
758+
759+
self::assertSame($expectedIndentation, $this->subject->getIndentation());
760+
}
761+
762+
/**
763+
* @test
764+
*/
765+
public function nextLevelReturnsOutputFormatInstance(): void
766+
{
767+
self::assertInstanceOf(OutputFormat::class, $this->subject->nextLevel());
768+
}
769+
770+
/**
771+
* @test
772+
*/
773+
public function nextLevelReturnsDifferentInstance(): void
774+
{
775+
self::assertNotSame($this->subject, $this->subject->nextLevel());
776+
}
777+
778+
/**
779+
* @test
780+
*/
781+
public function nextLevelReturnsInstanceWithIndentationLevelIncreasedByOne(): void
782+
{
783+
$originalIndentationLevel = 2;
784+
$this->subject->setIndentationLevel($originalIndentationLevel);
785+
786+
self::assertSame($originalIndentationLevel + 1, $this->subject->nextLevel()->getIndentationLevel());
787+
}
788+
789+
/**
790+
* @test
791+
*/
792+
public function beLenientSetsIgnoreExceptionsToTrue(): void
793+
{
794+
$this->subject->setIgnoreExceptions(false);
795+
796+
$this->subject->beLenient();
797+
798+
self::assertTrue($this->subject->getIgnoreExceptions());
799+
}
800+
801+
/**
802+
* @test
803+
*/
804+
public function getFormatterReturnsOutputFormatterInstance(): void
805+
{
806+
self::assertInstanceOf(OutputFormatter::class, $this->subject->getFormatter());
807+
}
808+
809+
/**
810+
* @test
811+
*/
812+
public function getFormatterCalledTwoTimesReturnsSameInstance(): void
813+
{
814+
$firstCallResult = $this->subject->getFormatter();
815+
$secondCallResult = $this->subject->getFormatter();
816+
817+
self::assertSame($firstCallResult, $secondCallResult);
818+
}
819+
820+
/**
821+
* @test
822+
*/
823+
public function levelReturnsIndentationLevel(): void
824+
{
825+
$value = 4;
826+
$this->subject->setIndentationLevel($value);
827+
828+
self::assertSame($value, $this->subject->level());
829+
}
830+
831+
/**
832+
* @test
833+
*/
834+
public function createReturnsNewOutputFormatInstance(): void
835+
{
836+
self::assertInstanceOf(OutputFormat::class, OutputFormat::create());
837+
}
838+
839+
/**
840+
* @test
841+
*/
842+
public function createCalledTwoTimesReturnsDifferentInstances(): void
843+
{
844+
$firstCallResult = OutputFormat::create();
845+
$secondCallResult = OutputFormat::create();
846+
847+
self::assertNotSame($firstCallResult, $secondCallResult);
848+
}
687849
}

0 commit comments

Comments
 (0)