Skip to content

Instantly share code, notes, and snippets.

@everzet everzet/gist:5722238 forked from gquemener/gist:5722064
Last active Dec 18, 2015

Embed
What would you like to do?
<?php
//PHPUnit
public function testApply() {
$mock = $this->getMock('My\Foo\Class', array('apply'));
$mock->expects($this->any())
->method('apply')
->with('foo')
->will($this->returnValue('bar'));
$target = new My\Bar\Class($mock);
$this->assertEquals('bar', $target->apply('foo'));
}
//PhpSpec2/Prophecy
function let(\My\Foo\Class $foo) {
$this->beConstructedWith($foo);
}
function it_applies_foo_modificator($foo) {
$foo->apply('foo')->willReturn('bar');
$this->apply('foo')->shouldReturn('bar');
}
@whatthejeff

This comment has been minimized.

Copy link

commented Jun 7, 2013

You can do ->with('foo') in the PHPUnit example.

@everzet

This comment has been minimized.

Copy link
Owner Author

commented Jun 7, 2013

@whatthejeff you're right! Fixed.

@whatthejeff

This comment has been minimized.

Copy link

commented Mar 11, 2014

<?php

// PHPUnit 4.0
public function testApply() {
    $mock = $this->getMock('My\Foo\Class', array('apply'));
    $mock->method('apply')->with('foo')->willReturn('bar');

    $target = new My\Bar\Class($mock);
    $this->assertEquals('bar', $target->apply('foo'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.