Skip to content

Instantly share code, notes, and snippets.

@jubianchi
Forked from anonymous/gist:4353149
Last active December 10, 2015 00:39
Show Gist options
  • Save jubianchi/4353155 to your computer and use it in GitHub Desktop.
Save jubianchi/4353155 to your computer and use it in GitHub Desktop.
<?php
namespace foo {
interface client
{
public function execute($query, array $params);
}
class api
{
protected $client;
public function __construct(client $client)
{
$this->client = $client;
}
public function doSomething($query)
{
$datas = $this->client->execute($query, array('foo' => 'bar'));
return true;
}
}
}
namespace tests\units\foo {
use mageekguy\atoum as atoum;
use foo\api as testedClass;
class api extends atoum\test
{
public function testdoSomething()
{
$this
->if($client = new \mock\foo\client())
->and($this->calling($client)->execute = function($query) {
// ==
//->and($client->getMockController()->execute = function($query) {
if($query === 'str') {
return array(42);
} else {
return array(43);
}
})
->and($api = new testedClass($client))
->then
->boolean($api->doSomething('str'))->isTrue()
->boolean($api->doSomething('some query'))->isTrue()
->mock($client)
->call('execute')->withArguments('some query')->once()
;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment