From e10ced37ba4248c0a068aada4cf594e21cfe90cb Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Thu, 23 Aug 2018 01:42:12 +0300 Subject: [PATCH] unit test of config class added --- tests/ConfigTest.php | 90 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 7 deletions(-) diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 8956028..8be748b 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -1,30 +1,106 @@ assertInternalType('object', $obj); + } catch (\Exception $e) { + $this->assertContains('Must be initialized ', $e->getMessage()); + } + } public function testGetParameters() { + $obj = new Config(); + $params = $obj->getParameters(); + $this->assertCount(5, $params); + $this->assertEquals($params['legacy'], false); + $this->assertEquals($params['ssl'], false); + $this->assertEquals($params['timeout'], 10); + $this->assertEquals($params['attempts'], 10); + $this->assertEquals($params['delay'], 1); } public function testSet() { + $obj = new Config(); + $obj->set('timeout', 111); + $params = $obj->getParameters(); + $this->assertEquals($params['timeout'], 111); + } + + public function testDelete() + { + $obj = new Config(); + $obj->delete('timeout'); + $params = $obj->getParameters(); + + $this->assertArrayNotHasKey('timeout', $params); + } + + public function testDeleteEx() + { + $this->expectException(Exception::class); + + $obj = new Config(); + $obj->delete('wrong'); + } + + /** + * @throws Exception + */ + public function testSetEx1() + { + $this->expectException(Exception::class); + + $obj = new Config(); + $obj->set('delay', 'some string'); + } + + public function testSetEx2() + { + $this->expectException(Exception::class); + + $obj = new Config(); + $obj->set('wrong', 'some string'); } public function testGet() { + $obj = new Config(); + $test1 = $obj->get('legacy'); + $this->assertEquals($test1, false); + + $test2 = $obj->get('port'); + $this->assertEquals($test2, 8728); + + $obj->set('port', 10000); + $test3 = $obj->get('port'); + $this->assertEquals($test3, 10000); + + + $obj->delete('port'); + $obj->set('ssl', true); + $test3 = $obj->get('port'); + $this->assertEquals($test3, 8729); + } + + public function testGetEx() + { + $this->expectException(Exception::class); + $obj = new Config(); + $test = $obj->get('wrong'); } }