Skip to content

Instantly share code, notes, and snippets.

@everzet
Forked from gquemener/gist:5722064
Last active December 18, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everzet/5722238 to your computer and use it in GitHub Desktop.
Save everzet/5722238 to your computer and use it in GitHub Desktop.
<?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
Copy link

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

@everzet
Copy link
Author

everzet commented Jun 7, 2013

@whatthejeff you're right! Fixed.

@whatthejeff
Copy link

<?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