Created
May 19, 2014 17:41
-
-
Save shadowhand/44dac9ab2b783d9f9e59 to your computer and use it in GitHub Desktop.
Testing for (in)valid input without concrete validation setup rules
This file contains 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 spec\Ushahidi\Usecase\Tag; | |
use Ushahidi\Tool\Validator; | |
use Ushahidi\Usecase\Tag\CreateTagRepository; | |
use PhpSpec\ObjectBehavior; | |
class CreateSpec extends ObjectBehavior | |
{ | |
function let(CreateTagRepository $repo, Validator $valid) | |
{ | |
$this->beConstructedWith($repo, $valid); | |
} | |
function it_is_initializable() | |
{ | |
$this->shouldHaveType('Ushahidi\Usecase\Tag\Create'); | |
} | |
function it_fails_with_invalid_input($req, $valid) | |
{ | |
$input = [ | |
'tag' => '', | |
'slug' => '', | |
'type' => '', | |
]; | |
$valid->check($input)->willReturn(false); | |
$valid->errors()->willReturn([]); | |
$this->shouldThrow('Ushahidi\Exception\ValidatorException')->duringInteract($input); | |
} | |
function it_can_create_a_tag_with_valid_input($valid, $repo) | |
{ | |
$input = [ | |
'tag' => 'Tests', | |
'slug' => 'tests', | |
'type' => 'category', | |
]; | |
$valid->check($input)->willReturn(true); | |
$repo->createTag($input)->shouldBeCalled(); | |
$repo->getCreatedTagId()->shouldBeCalled(); | |
$repo->getCreatedTagTimestamp()->shouldBeCalled(); | |
$this->shouldNotThrow('Ushahidi\Exception\ValidatorException')->duringInteract($input); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment