Last active
August 29, 2015 14:06
-
-
Save tomphp/eb58b1e7734103b54ec6 to your computer and use it in GitHub Desktop.
Testing Closures
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 | |
interface Item | |
{ | |
public function runAction(); | |
} | |
interface SomeCollection | |
{ | |
public function foreachItem(callable $fn); | |
} | |
class CollectionUseSpec extends ObjectBehavior | |
{ | |
function it_iterates_collection(SomeCollection $collection, Item $item) | |
{ | |
$collection->foreachItem(Argument::that( | |
function ($fn) use ($item) { | |
$fn($item); | |
return true; | |
} | |
))->willReturn(); | |
$this->run($collection); | |
$item->runAction()->shouldHaveBeenCalled(); | |
} | |
} | |
class CollectionUse | |
{ | |
public function run(SomeCollection $collection) | |
{ | |
$collection->foreachItem(function (Item $item) { | |
$item->runAction(); | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment