From 721038d5be660d25f9f69d4e6a55771cf817dbc8 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 4 Nov 2018 15:00:35 +0100 Subject: [PATCH] Implemented unit tests for result --- application/tests/Unit/Logic/ResultTest.php | 88 +++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 application/tests/Unit/Logic/ResultTest.php diff --git a/application/tests/Unit/Logic/ResultTest.php b/application/tests/Unit/Logic/ResultTest.php new file mode 100644 index 0000000..ada614f --- /dev/null +++ b/application/tests/Unit/Logic/ResultTest.php @@ -0,0 +1,88 @@ +result = new Result(); + } + + public function testConstructor(): void + { + $this->expectException(\TypeError::class); + $this->result->getValue(); + $this->expectException(\TypeError::class); + $this->result->getBool(); + } + + public function testSetBool(): void + { + $bool = true; + $this->assertNull($this->result->setBool($bool)); + $this->assertEquals($bool, $this->result->getBool()); + $bool = false; + $this->assertNull($this->result->setBool($bool)); + $this->assertEquals($bool, $this->result->getBool()); + $this->expectException(\TypeError::class); + $bool = null; + $this->assertNull($this->result->setBool($bool)); + $this->assertEquals($bool, $this->result->getBool()); + } + + public function testSetValue(): void + { + $value = 'test'; + $this->assertNull($this->result->setValue($value)); + $this->assertEquals($value, $this->result->getValue()); + $value = null; + $this->assertNull($this->result->setValue($value)); + $this->assertEquals($value, $this->result->getValue()); + $value = 123; + $this->assertNull($this->result->setValue($value)); + $this->assertEquals($value, $this->result->getValue()); + $value = new class() { + }; + $this->assertNull($this->result->setValue($value)); + $this->assertEquals($value, $this->result->getValue()); + } + + public function testSetAll(): void + { + $value = 123; + $this->assertNull($this->result->setAll($value)); + $this->assertEquals($value, $this->result->getValue()); + $this->assertEquals(true, $this->result->getBool()); + $value = null; + $this->assertNull($this->result->setAll($value)); + $this->assertEquals($value, $this->result->getValue()); + $this->assertEquals(false, $this->result->getBool()); + $value = ''; + $this->assertNull($this->result->setAll($value)); + $this->assertEquals($value, $this->result->getValue()); + $this->assertEquals(false, $this->result->getBool()); + $value = true; + $this->assertNull($this->result->setAll($value)); + $this->assertEquals($value, $this->result->getValue()); + $this->assertEquals($value, $this->result->getBool()); + $value = false; + $this->assertNull($this->result->setAll($value)); + $this->assertEquals($value, $this->result->getValue()); + $this->assertEquals($value, $this->result->getBool()); + $value = new class() { + }; + $this->assertNull($this->result->setAll($value)); + $this->assertEquals($value, $this->result->getValue()); + $this->assertEquals(true, $this->result->getBool()); + } +}