Skip to content

Commit

Permalink
Add tests for custom integer return values.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Feb 25, 2017
1 parent 9f9ba13 commit 5e74332
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/TestCase/Console/ShellDispatcherTest.php
Expand Up @@ -214,6 +214,60 @@ public function testDispatchShellWithMain()
$this->assertEquals([], $dispatcher->args);
}

/**
* Verifies correct dispatch of Shell subclasses with integer exit codes.
*
* @return void
*/
public function testDispatchShellWithIntegerSuccessCode()
{
$dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
->setMethods(['findShell'])
->getMock();
$Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();

$Shell->expects($this->once())->method('initialize');
$Shell->expects($this->once())->method('runCommand')
->with(['initdb'])
->will($this->returnValue(Shell::CODE_SUCCESS));

$dispatcher->expects($this->any())
->method('findShell')
->with('mock_without_main')
->will($this->returnValue($Shell));

$dispatcher->args = ['mock_without_main', 'initdb'];
$result = $dispatcher->dispatch();
$this->assertEquals(Shell::CODE_SUCCESS, $result);
}

/**
* Verifies correct dispatch of Shell subclasses with custom integer exit codes.
*
* @return void
*/
public function testDispatchShellWithCustomIntegerCodes()
{
$dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
->setMethods(['findShell'])
->getMock();
$Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();

$Shell->expects($this->once())->method('initialize');
$Shell->expects($this->once())->method('runCommand')
->with(['initdb'])
->will($this->returnValue(3));

$dispatcher->expects($this->any())
->method('findShell')
->with('mock_without_main')
->will($this->returnValue($Shell));

$dispatcher->args = ['mock_without_main', 'initdb'];
$result = $dispatcher->dispatch();
$this->assertEquals(3, $result);
}

/**
* Verify correct dispatch of Shell subclasses without a main method
*
Expand Down

0 comments on commit 5e74332

Please sign in to comment.