-
-
Save jubianchi/4353155 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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