Created
September 4, 2014 09:44
-
-
Save mvriel/110b100261847a7ccb62 to your computer and use it in GitHub Desktop.
Why does my test not fail on the second mockedMethod call?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"autoload": { | |
"psr-0": { "": "src/" } | |
}, | |
"require": { | |
}, | |
"require-dev": { | |
"phpunit/phpunit": "3.7.*", | |
"mockery/mockery": ">=0.8", | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyClass | |
{ | |
public function test($dependency) | |
{ | |
$dependency->mockedMethod('I have random arguments'); | |
$dependency->mockedMethod( | |
array( | |
'choices' => array( | |
'Y' => 'YES', | |
'N' => 'NO', | |
'A' => 'ALWAYS', | |
) | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'vendor/autoload.php'; | |
include 'MyClass.php'; | |
use Mockery as m; | |
class MyClassTest extends \PHPUnit_Framework_TestCase | |
{ | |
/** @var MyClass */ | |
private $fixture; | |
/** | |
* Initializes the fixture for this test. | |
*/ | |
public function setUp() | |
{ | |
$this->fixture = new MyClass(); | |
} | |
/** | |
* @covers AutoTrack\InventoryBundle\Form\Type\ApkType::setDefaultOptions | |
*/ | |
public function testIfCorrectDefaultsAreSet() | |
{ | |
$mock = m::mock('stdClass'); | |
$mock->shouldReceive('mockedMethod')->with( | |
array( | |
'choices' => array( | |
'Y' => 'YESH', | |
'N' => 'NO', | |
'A' => 'ALWAYS', | |
) | |
) | |
); | |
$mock->shouldReceive('mockedMethod')->withAnyArgs(); | |
$this->fixture->test($mock); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made 2 changes to make the test fail:
Added phpunit.xml to include the Mockery listener:
And added call count validation to the mocked methods:
And now the tests fail with:
There was 1 error:
Also the order of expectations set should not matter.