Created
February 26, 2014 21:02
-
-
Save hussani/9238460 to your computer and use it in GitHub Desktop.
PHPUnit error on mock expecting interface
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
class SampleProduct | |
{ | |
/* implementation */ | |
public function setBougthBy(UserInterface $user) | |
{ | |
$this->bougthBy = $user; | |
} | |
} |
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
class SampleProductTest | |
{ | |
/* other tests */ | |
public function testSetBougthByWithValidUserShouldSuccess() | |
{ | |
$stubUser = $this->getMock('SampleUser'); | |
$product = new SampleProduct(); | |
/** | |
* PHPUnit_Framework_Error | |
* Expected UserInterface, got Mock_MockObject | |
*/ | |
$product->setBougthBy($stubUser); | |
} | |
} |
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 SampleUser implements UserInterface | |
{ | |
/* Implementation */ | |
} |
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 | |
interface UserInterface | |
{ | |
/* methods */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the
getMockBuilder
method:;)