Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created May 17, 2014 18:15
Show Gist options
  • Save shadowhand/1fbc2e8c10e997171e77 to your computer and use it in GitHub Desktop.
Save shadowhand/1fbc2e8c10e997171e77 to your computer and use it in GitHub Desktop.
usecase spec for creating a tag
<?php
namespace spec\Ushahidi\Usecase\Tag;
use Ushahidi\Tool\Validator;
use Ushahidi\Usecase\Tag\CreateTagRepository;
use Ushahidi\Usecase\Tag\CreateTagRequest;
use PhpSpec\ObjectBehavior;
class CreateSpec extends ObjectBehavior
{
function let(CreateTagRepository $repo, Validator $valid, CreateTagRequest $req)
{
$this->beConstructedWith($repo, $valid);
}
function it_is_initializable()
{
$this->shouldHaveType('Ushahidi\Usecase\Tag\Create');
}
function it_fails_with_invalid_input($req, $valid)
{
$valid->check($req)->shouldBeCalled()->willReturn(false);
$valid->errors('tag')->shouldBeCalled()->willReturn([
'tag' => 'fail',
]);
$this->shouldThrow('Ushahidi\Exception\ValidatorException')->duringInteract($req);
}
function it_can_create_a_tag_with_valid_input($req, $valid, $repo)
{
$valid->check($req)->shouldBeCalled()->willReturn(true);
$repo->createTag($req)->shouldBeCalled();
$repo->getCreatedTagId()->shouldBeCalled();
$repo->getCreatedTagTimestamp()->shouldBeCalled();
$this->shouldNotThrow('Ushahidi\Exception\ValidatorException')->duringInteract($req);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment