-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace EasyMock\Test\Fixture; | ||
|
||
class CustomException extends \Exception | ||
{ | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
use EasyMock\EasyMock; | ||
use EasyMock\Test\Fixture\ClassFixture; | ||
use EasyMock\Test\Fixture\CustomException; | ||
use EasyMock\Test\Fixture\InterfaceFixture; | ||
|
||
/** | ||
* @author Matthieu Napoli <[email protected]> | ||
|
@@ -15,6 +17,7 @@ class MockClassTest extends \PHPUnit_Framework_TestCase | |
*/ | ||
public function should_mock_objects() | ||
{ | ||
/** @var ClassFixture $mock */ | ||
$mock = EasyMock::mock('EasyMock\Test\Fixture\ClassFixture'); | ||
|
||
$this->assertInstanceOf('PHPUnit_Framework_MockObject_MockObject', $mock); | ||
|
@@ -26,12 +29,24 @@ public function should_mock_objects() | |
*/ | ||
public function should_mock_interfaces() | ||
{ | ||
/** @var InterfaceFixture $mock */ | ||
$mock = EasyMock::mock('EasyMock\Test\Fixture\InterfaceFixture'); | ||
|
||
$this->assertInstanceOf('PHPUnit_Framework_MockObject_MockObject', $mock); | ||
$this->assertNull($mock->foo()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function not_mocked_methods_should_return_null() | ||
{ | ||
/** @var ClassFixture $mock */ | ||
$mock = EasyMock::mock('EasyMock\Test\Fixture\ClassFixture'); | ||
|
||
$this->assertNull($mock->foo()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
|
@@ -62,12 +77,15 @@ public function should_mock_existing_method_with_a_callback() | |
|
||
/** | ||
* @test | ||
* @expectedException \EasyMock\Test\Fixture\CustomException | ||
* @expectedExceptionMessage My message | ||
*/ | ||
public function not_mocked_methods_should_return_null() | ||
public function should_mock_existing_method_to_throw_exception() | ||
{ | ||
/** @var ClassFixture $mock */ | ||
$mock = EasyMock::mock('EasyMock\Test\Fixture\ClassFixture'); | ||
|
||
$this->assertSame(null, $mock->foo()); | ||
$mock = EasyMock::mock('EasyMock\Test\Fixture\ClassFixture', array( | ||
'foo' => new CustomException('My message'), | ||
)); | ||
$mock->foo(); | ||
} | ||
} |