Skip to content

Instantly share code, notes, and snippets.

@shoyan
Last active December 19, 2015 23:28
Show Gist options
  • Save shoyan/6034390 to your computer and use it in GitHub Desktop.
Save shoyan/6034390 to your computer and use it in GitHub Desktop.
SimpleTestのMockを使ったテストのサンプル。 1.0.1はマニュアルのやり方とは違う(function returnsが定義されていない)のでこういう風にやらないといけない。
<?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