What I'm trying to achieve is:
- to check if factory method was called on ContextItem
- to check if provided entity exists in the collection
Questions:
- how to provide specific entity to factory method of collaborator?
- how to check how many times ContextItem static factory's method was called?
I'm using laravel with phpspec extension: http://ift.tt/2aQH9EB
The problem is that ->push method on Collection collaborator is not being executed from which phpspec is returning.
class ContextSpec extends ObjectBehavior
{
function it_builds_a_collection_of_context_items(ContextItem $contextItem, Collection $collector)
{
$item = ContextItem::factory(1,2);
$items = [1, 2, 3];
$collector->push($contextItem)->shouldBeCalledTimes(3);
$this->beConstructedThrough("factory", [$items]);
// $collector->push($contextItem)->willReturn($item);
// $contextItem->beConstructedThrough("factory", [0,1])->shouldBeCalled();
// $contextItem::factory(1,2)->shouldBeCalledTimes(3);
// $contextItem->factory()->shouldBeCalledTimes(3);
$this->items()->shouldHaveCount(3);
$this->items()->shouldContain($item);
}
}
Context class:
class Context implements ContextInterface
{
/**
* @var Collection
*/
private $_items;
public static function factory($entries) {
$items = collect([]);
collect($entries)->each(function($value, $key) use ($items) {
$items->push(ContextItem::factory($key, $value));
});
return new static($items);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire