From 95eaaf91b606a2efe768fe6ac67d63b4090a5724 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Fri, 1 May 2015 10:18:15 +0200 Subject: [PATCH 1/2] [test] Replace assertTrue(instanceof) with assertInstanceOf --- test/ConsoleTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/ConsoleTest.php b/test/ConsoleTest.php index 471d7a5..a082348 100644 --- a/test/ConsoleTest.php +++ b/test/ConsoleTest.php @@ -28,7 +28,7 @@ public function testCanTestIsConsole() $this->assertTrue(Console::isConsole()); $className = Console::detectBestAdapter(); $adpater = new $className; - $this->assertTrue($adpater instanceof Adapter\AdapterInterface); + $this->assertInstanceOf('Zend\Console\Adapter\AdapterInterface', $adpater); Console::overrideIsConsole(false); @@ -56,7 +56,7 @@ public function testCanOverrideIsConsole() public function testCanGetInstance() { $console = Console::getInstance(); - $this->assertTrue($console instanceof Adapter\AdapterInterface); + $this->assertInstanceOf('Zend\Console\Adapter\AdapterInterface', $console); } public function testCanNotGetInstanceInNoConsoleMode() @@ -69,14 +69,14 @@ public function testCanNotGetInstanceInNoConsoleMode() public function testCanForceInstance() { $console = Console::getInstance('Posix'); - $this->assertTrue($console instanceof Adapter\AdapterInterface); - $this->assertTrue($console instanceof Adapter\Posix); + $this->assertInstanceOf('Zend\Console\Adapter\AdapterInterface', $console); + $this->assertInstanceOf('Zend\Console\Adapter\Posix', $console); Console::overrideIsConsole(null); Console::resetInstance(); $console = Console::getInstance('Windows'); - $this->assertTrue($console instanceof Adapter\AdapterInterface); - $this->assertTrue($console instanceof Adapter\Windows); + $this->assertInstanceOf('Zend\Console\Adapter\AdapterInterface', $console); + $this->assertInstanceOf('Zend\Console\Adapter\Windows', $console); } } From 7a8b1b1aeb56ce4904d565b952d7f2674db78db0 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Fri, 1 May 2015 16:55:33 +0200 Subject: [PATCH 2/2] [test] Replace assertTrue(preg_match/strpos/strstr) with assertContains Only when string offset is not relevant --- test/Prompt/NumberTest.php | 8 ++++---- test/Prompt/SelectTest.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/Prompt/NumberTest.php b/test/Prompt/NumberTest.php index 1f18ebf..5ccbb9e 100644 --- a/test/Prompt/NumberTest.php +++ b/test/Prompt/NumberTest.php @@ -58,7 +58,7 @@ public function testCanReadNumberOnMultilign() ob_start(); $response = $number->show(); $text = ob_get_clean(); - $this->assertTrue((bool) preg_match('#a is not a number#', $text)); + $this->assertContains('a is not a number', $text); $this->assertEquals('123', $response); } @@ -74,7 +74,7 @@ public function testCanNotReadFloatByDefault() ob_start(); $response = $number->show(); $text = ob_get_clean(); - $this->assertTrue((bool) preg_match('#Please enter a non-floating number#', $text)); + $this->assertContains('Please enter a non-floating number', $text); $this->assertEquals('123', $response); } @@ -108,8 +108,8 @@ public function testCanDefineAMax() $response = $number->show(); $text = ob_get_clean(); - $this->assertTrue((bool) preg_match('#Please enter a number not smaller than 5#', $text)); - $this->assertTrue((bool) preg_match('#Please enter a number not greater than 10#', $text)); + $this->assertContains('Please enter a number not smaller than 5', $text); + $this->assertContains('Please enter a number not greater than 10', $text); $this->assertEquals('6', $response); } } diff --git a/test/Prompt/SelectTest.php b/test/Prompt/SelectTest.php index 33a85f2..ef73184 100644 --- a/test/Prompt/SelectTest.php +++ b/test/Prompt/SelectTest.php @@ -42,8 +42,8 @@ public function testCanSelectOption() ob_start(); $response = $select->show(); $text = ob_get_clean(); - $this->assertTrue((bool) preg_match('#0\) foo#', $text)); - $this->assertTrue((bool) preg_match('#1\) bar#', $text)); + $this->assertContains('0) foo', $text); + $this->assertContains('1) bar', $text); $this->assertEquals('0', $response); } @@ -56,8 +56,8 @@ public function testCanSelectOptionWithCustomIndex() ob_start(); $response = $select->show(); $text = ob_get_clean(); - $this->assertTrue((bool) preg_match('#2\) foo#', $text)); - $this->assertTrue((bool) preg_match('#6\) bar#', $text)); + $this->assertContains('2) foo', $text); + $this->assertContains('6) bar', $text); $this->assertEquals('2', $response); } }