Skip to content

Instantly share code, notes, and snippets.

@guiled
Last active March 17, 2017 10:09
Show Gist options
  • Save guiled/03fbccaa89a43019072f56e2c957bde0 to your computer and use it in GitHub Desktop.
Save guiled/03fbccaa89a43019072f56e2c957bde0 to your computer and use it in GitHub Desktop.
Atoum How to mock a function
<?php
class myClass {
protected $creator;
public function set(callable $creator)
{
$this->creator = $creator
}
public function callIt($id)
{
return call_user_func($this->creator, $id);
}
}
<?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