I just started playing around with PHPUnit and I was wondering if it is possible to overwrite/replace a method with a stub. I have some experience with Sinon, and with Sinon this is possible (http://ift.tt/1kUFzRX)
I want to something like this:
<?php
class Foo {
public $bar;
function __construct() {
$this->bar = new Bar();
}
public function getBarString() {
return $this->bar->getString();
}
}
class Bar {
public function getString() {
return 'Some string';
}
}
class FooTest extends PHPUnit_Framework_TestCase {
public function testStringThing() {
$foo = new Foo();
$mock = $this->getMockBuilder( 'Bar' )
->setMethods(array( 'getString' ))
->getMock();
$mock->method('getString')
->willReturn('Some other string');
$this->assertEquals( 'Some other string', $foo->getBarString() );
}
}
?>
Aucun commentaire:
Enregistrer un commentaire