Commit 9af785f8 authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #283 from noplanman/improve_command_contructor_test

Improve command constructor test
parents a7113c99 bba116ef
...@@ -65,25 +65,30 @@ class CommandTest extends TestCase ...@@ -65,25 +65,30 @@ class CommandTest extends TestCase
$this->command_stub_with_config->__construct($this->telegram_with_config); $this->command_stub_with_config->__construct($this->telegram_with_config);
} }
// Test idea from here: http://stackoverflow.com/a/4371606
public function testCommandConstructorNeedsTelegramObject() public function testCommandConstructorNeedsTelegramObject()
{ {
$error_message = 'must be an instance of Longman\TelegramBot\Telegram'; $exception_count = 0;
$params_to_test = [ $params_to_test = [
[], [],
[null], [null],
[12345],
['something'], ['something'],
[new \stdClass], [new \stdClass],
[$this->telegram], // only this one is valid
]; ];
foreach ($params_to_test as $param) { foreach ($params_to_test as $param) {
try { try {
$this->getMockForAbstractClass($this->command_namespace, $param); $this->getMockForAbstractClass($this->command_namespace, $param);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertContains($error_message, $e->getMessage()); $exception_count++;
} catch (\Throwable $e) { //For PHP7 } catch (\Throwable $e) { //For PHP7
$this->assertContains($error_message, $e->getMessage()); $exception_count++;
} }
} }
$this->assertEquals(5, $exception_count);
} }
public function testCommandHasCorrectTelegramObject() public function testCommandHasCorrectTelegramObject()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment