Last active
December 19, 2015 23:28
-
-
Save shoyan/6034390 to your computer and use it in GitHub Desktop.
SimpleTestのMockを使ったテストのサンプル。
1.0.1はマニュアルのやり方とは違う(function returnsが定義されていない)のでこういう風にやらないといけない。
This file contains hidden or 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 | |
/* | |
* SimpleTestのmockサンプル | |
* SimpleTest version 1.0.1 | |
*/ | |
require_once 'tests/simpletest/autorun.php'; | |
class Object { | |
function getValue() {} | |
} | |
mock::generate('Object'); | |
class TestOfMockObject extends UnitTestCase { | |
function testSetReturnValue() { | |
$mock = new MockObject(); | |
$mock->setReturnValue('getValue', 'TheValue'); | |
$this->assertEqual($mock->getValue(), 'TheValue'); | |
} | |
function testSetReturnValueAt() { | |
$mock = new MockObject(); | |
$mock->setReturnValueAt(0, 'getValue', 'TheValue'); | |
$this->assertEqual($mock->getValue(), 'TheValue'); | |
$mock->setReturnValueAt(1, 'getValue', 'TheNewValue'); | |
$this->assertEqual($mock->getValue(), 'TheNewValue'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment