From d8d483bd6afe9175fe8e7c6ff81e525750e89890 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Mon, 11 Feb 2019 00:12:19 +0000 Subject: [PATCH] Add some component level tests --- phpunit.xml.dist | 3 +- psalm.xml | 21 +++--- .../src/Components/Inlines/PlainTextTest.php | 22 ++++++ tests/src/Html/Renderables/ContainerTest.php | 31 +++++++++ tests/src/Html/Renderables/ElementTest.php | 67 +++++++++++++++++++ tests/src/StateTest.php | 32 +++++++++ 6 files changed, 166 insertions(+), 10 deletions(-) create mode 100644 tests/src/Components/Inlines/PlainTextTest.php create mode 100644 tests/src/Html/Renderables/ContainerTest.php create mode 100644 tests/src/Html/Renderables/ElementTest.php create mode 100644 tests/src/StateTest.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c1207fb..5e78f38 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,8 @@ tests/ParsedownTest.php - tests/CommonMarkTest.php + tests/CommonMarkTest.php + ./tests/src diff --git a/psalm.xml b/psalm.xml index d3f2f25..0ad9b82 100644 --- a/psalm.xml +++ b/psalm.xml @@ -13,16 +13,7 @@ - - - - - - - - - @@ -37,5 +28,17 @@ + + + + + + + + + + + + diff --git a/tests/src/Components/Inlines/PlainTextTest.php b/tests/src/Components/Inlines/PlainTextTest.php new file mode 100644 index 0000000..de1bd4b --- /dev/null +++ b/tests/src/Components/Inlines/PlainTextTest.php @@ -0,0 +1,22 @@ +assertSame('foo', $Plaintext->text()); + } +} diff --git a/tests/src/Html/Renderables/ContainerTest.php b/tests/src/Html/Renderables/ContainerTest.php new file mode 100644 index 0000000..d7cdff1 --- /dev/null +++ b/tests/src/Html/Renderables/ContainerTest.php @@ -0,0 +1,31 @@ +contents(); + + $this->assertTrue($Contents[0] instanceof Element); + $this->assertSame($Contents[0]->name(), 'foo'); + $this->assertTrue($Contents[1] instanceof Text); + $this->assertSame($Contents[1]->getHtml(), 'bar'); + } +} diff --git a/tests/src/Html/Renderables/ElementTest.php b/tests/src/Html/Renderables/ElementTest.php new file mode 100644 index 0000000..036a9d9 --- /dev/null +++ b/tests/src/Html/Renderables/ElementTest.php @@ -0,0 +1,67 @@ + 'baz', + 'boo' => 'bim', + ], + [new Text('zoo')] + ); + + $this->assertSame($Element->name(), 'foo'); + $this->assertSame( + $Element->attributes(), + [ + 'bar' => 'baz', + 'boo' => 'bim', + ] + ); + $this->assertTrue($Element->contents()[0] instanceof Text); + $this->assertSame($Element->contents()[0]->getHtml(), 'zoo'); + } + + /** + * @return void + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + */ + public function testSettingElementProperties() + { + $Element = new Element( + 'foo', + [ + 'bar' => 'baz', + 'boo' => 'bim', + ], + [new Text('zoo')] + ); + + $Element = $Element + ->settingAttributes(['bar' => 'bim']) + ->settingContents(null) + ; + + $this->assertSame($Element->name(), 'foo'); + $this->assertSame($Element->attributes(), ['bar' => 'bim']); + $this->assertSame($Element->contents(), null); + + $Element = $Element->settingName('foo1'); + $this->assertSame($Element->name(), 'foo1'); + } +} diff --git a/tests/src/StateTest.php b/tests/src/StateTest.php new file mode 100644 index 0000000..22d5311 --- /dev/null +++ b/tests/src/StateTest.php @@ -0,0 +1,32 @@ +assertFalse($State->get(SafeMode::class)->isEnabled()); + $this->assertFalse($State->get(StrictMode::class)->isEnabled()); + $this->assertFalse($State->get(Breaks::class)->isEnabled()); + + $UpdatedState = $State->mergingWith(new State([SafeMode::enabled()])); + + $this->assertTrue($UpdatedState->get(SafeMode::class)->isEnabled()); + $this->assertFalse($UpdatedState->get(StrictMode::class)->isEnabled()); + $this->assertFalse($UpdatedState->get(Breaks::class)->isEnabled()); + } +}