From 5818813cf57f36c4a3a0af4629d16f07d252434a Mon Sep 17 00:00:00 2001 From: Paul Robert Date: Wed, 9 Feb 2022 22:11:01 +0100 Subject: [PATCH] Added tests. --- Tests/BuilderTest.php | 60 +++++++++++++++++++++++++++++++++++++++++++ composer.json | 5 +++- phpunit.xml | 8 ++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Tests/BuilderTest.php create mode 100644 phpunit.xml diff --git a/Tests/BuilderTest.php b/Tests/BuilderTest.php new file mode 100644 index 0000000..fafd70f --- /dev/null +++ b/Tests/BuilderTest.php @@ -0,0 +1,60 @@ +builder = new ElementBuilder([ + 'name' => 'Safari', + 'value' => 'Forms' + ]); + } + + protected function tearDown(): void + { + $this->builder = null; + } + + public function testInput(){ + $input = $this->builder->input([]); + $this->assertInstanceOf(Element::class, $input); + $this->assertMatchesRegularExpression("#^html); + } + + public function testTextarea(){ + $textarea = $this->builder->textarea([]); + $this->assertInstanceOf(Element::class, $textarea); + $this->assertMatchesRegularExpression("#^html); + } + + public function testSelect(){ + $select = $this->builder->select([], []); + $this->assertInstanceOf(Element::class, $select); + $this->assertMatchesRegularExpression("#^html); + } + + public function testCheckbox(){ + $input = $this->builder->checkbox([]); + $this->assertInstanceOf(Element::class, $input); + $this->assertMatchesRegularExpression("#^html); + $this->assertMatchesRegularExpression("#type='checkbox'#", $input->html); + } + + public function testRadio(){ + $input = $this->builder->radio([]); + $this->assertInstanceOf(Element::class, $input); + $this->assertMatchesRegularExpression("#^html); + $this->assertMatchesRegularExpression("#type='radio'#", $input->html); + } + + public function testRaw(){ + $input = $this->builder->raw('safari'); + $this->assertInstanceOf(Element::class, $input); + $this->assertMatchesRegularExpression("#^safari$#", $input->html); + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 3109574..a144451 100644 --- a/composer.json +++ b/composer.json @@ -24,5 +24,8 @@ }, "require": { "php": ">=7.0.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" } -} \ No newline at end of file +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..2d7c805 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,8 @@ + + + + + Tests + + + \ No newline at end of file