|
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\TestCase;
|
8 | 8 | use Sabberworm\CSS\OutputFormat;
|
| 9 | +use Sabberworm\CSS\OutputFormatter; |
9 | 10 |
|
10 | 11 | /**
|
11 | 12 | * @covers \Sabberworm\CSS\OutputFormat
|
@@ -684,4 +685,181 @@ public function setIndentationLevelProvidesFluentInterface(): void
|
684 | 685 | {
|
685 | 686 | self::assertSame($this->subject, $this->subject->setIndentationLevel(4));
|
686 | 687 | }
|
| 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 indentWithTabsProvidesFluentInterface(): void |
| 729 | + { |
| 730 | + self::assertSame($this->subject, $this->subject->indentWithTabs()); |
| 731 | + } |
| 732 | + |
| 733 | + /** |
| 734 | + * @test |
| 735 | + */ |
| 736 | + public function indentWithSpacesByDefaultSetsIndentationToTwoSpaces(): void |
| 737 | + { |
| 738 | + $this->subject->indentWithSpaces(); |
| 739 | + |
| 740 | + self::assertSame(' ', $this->subject->getIndentation()); |
| 741 | + } |
| 742 | + |
| 743 | + /** |
| 744 | + * @return array<string, array{0: int<0, max>, 1: string}> |
| 745 | + */ |
| 746 | + public static function provideSpaceIndentation(): array |
| 747 | + { |
| 748 | + return [ |
| 749 | + 'zero spaces' => [0, ''], |
| 750 | + 'one space' => [1, ' '], |
| 751 | + 'two spaces' => [2, ' '], |
| 752 | + 'three spaces' => [3, ' '], |
| 753 | + 'four spaces' => [4, ' '], |
| 754 | + ]; |
| 755 | + } |
| 756 | + |
| 757 | + /** |
| 758 | + * @test |
| 759 | + * @dataProvider provideSpaceIndentation |
| 760 | + */ |
| 761 | + public function indentWithSpacesSetsIndentationToTheProvidedNumberOfSpaces( |
| 762 | + int $numberOfSpaces, |
| 763 | + string $expectedIndentation |
| 764 | + ): void { |
| 765 | + $this->subject->indentWithSpaces($numberOfSpaces); |
| 766 | + |
| 767 | + self::assertSame($expectedIndentation, $this->subject->getIndentation()); |
| 768 | + } |
| 769 | + |
| 770 | + /** |
| 771 | + * @test |
| 772 | + */ |
| 773 | + public function indentWithSpacesProvidesFluentInterface(): void |
| 774 | + { |
| 775 | + self::assertSame($this->subject, $this->subject->indentWithSpaces()); |
| 776 | + } |
| 777 | + |
| 778 | + /** |
| 779 | + * @test |
| 780 | + */ |
| 781 | + public function nextLevelReturnsOutputFormatInstance(): void |
| 782 | + { |
| 783 | + self::assertInstanceOf(OutputFormat::class, $this->subject->nextLevel()); |
| 784 | + } |
| 785 | + |
| 786 | + /** |
| 787 | + * @test |
| 788 | + */ |
| 789 | + public function nextLevelReturnsDifferentInstance(): void |
| 790 | + { |
| 791 | + self::assertNotSame($this->subject, $this->subject->nextLevel()); |
| 792 | + } |
| 793 | + |
| 794 | + /** |
| 795 | + * @test |
| 796 | + */ |
| 797 | + public function nextLevelReturnsInstanceWithIndentationLevelIncreasedByOne(): void |
| 798 | + { |
| 799 | + $originalIndentationLevel = 2; |
| 800 | + $this->subject->setIndentationLevel($originalIndentationLevel); |
| 801 | + |
| 802 | + self::assertSame($originalIndentationLevel + 1, $this->subject->nextLevel()->getIndentationLevel()); |
| 803 | + } |
| 804 | + |
| 805 | + /** |
| 806 | + * @test |
| 807 | + */ |
| 808 | + public function beLenientSetsIgnoreExceptionsToTrue(): void |
| 809 | + { |
| 810 | + $this->subject->setIgnoreExceptions(false); |
| 811 | + |
| 812 | + $this->subject->beLenient(); |
| 813 | + |
| 814 | + self::assertTrue($this->subject->getIgnoreExceptions()); |
| 815 | + } |
| 816 | + |
| 817 | + /** |
| 818 | + * @test |
| 819 | + */ |
| 820 | + public function getFormatterReturnsOutputFormatterInstance(): void |
| 821 | + { |
| 822 | + self::assertInstanceOf(OutputFormatter::class, $this->subject->getFormatter()); |
| 823 | + } |
| 824 | + |
| 825 | + /** |
| 826 | + * @test |
| 827 | + */ |
| 828 | + public function getFormatterCalledTwoTimesReturnsSameInstance(): void |
| 829 | + { |
| 830 | + $firstCallResult = $this->subject->getFormatter(); |
| 831 | + $secondCallResult = $this->subject->getFormatter(); |
| 832 | + |
| 833 | + self::assertSame($firstCallResult, $secondCallResult); |
| 834 | + } |
| 835 | + |
| 836 | + /** |
| 837 | + * @test |
| 838 | + */ |
| 839 | + public function levelReturnsIndentationLevel(): void |
| 840 | + { |
| 841 | + $value = 4; |
| 842 | + $this->subject->setIndentationLevel($value); |
| 843 | + |
| 844 | + self::assertSame($value, $this->subject->level()); |
| 845 | + } |
| 846 | + |
| 847 | + /** |
| 848 | + * @test |
| 849 | + */ |
| 850 | + public function createReturnsNewOutputFormatInstance(): void |
| 851 | + { |
| 852 | + self::assertInstanceOf(OutputFormat::class, OutputFormat::create()); |
| 853 | + } |
| 854 | + |
| 855 | + /** |
| 856 | + * @test |
| 857 | + */ |
| 858 | + public function createCalledTwoTimesReturnsDifferentInstances(): void |
| 859 | + { |
| 860 | + $firstCallResult = OutputFormat::create(); |
| 861 | + $secondCallResult = OutputFormat::create(); |
| 862 | + |
| 863 | + self::assertNotSame($firstCallResult, $secondCallResult); |
| 864 | + } |
687 | 865 | }
|
0 commit comments