Last active
March 17, 2017 10:09
-
-
Save guiled/03fbccaa89a43019072f56e2c957bde0 to your computer and use it in GitHub Desktop.
Atoum How to mock a function
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 | |
class myClass { | |
protected $creator; | |
public function set(callable $creator) | |
{ | |
$this->creator = $creator | |
} | |
public function callIt($id) | |
{ | |
return call_user_func($this->creator, $id); | |
} | |
} |
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 mageekguy\atoum; | |
class test extends atoum\test | |
{ | |
public function testCall() | |
{ | |
$this | |
->given( | |
$this->newTestedInstance, | |
$this->function->dummy = function ($a) { return $a.$a;}, | |
$this->testedInstance->set($this->function->dummy) // Error "must be callable, object given" | |
) | |
->if($this->testedInstance->callIt('X')) | |
->function($this->function->dummy)->wasCalled()->once() | |
; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment