Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created May 1, 2014 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadowhand/3a2c01a3487c9784cc0b to your computer and use it in GitHub Desktop.
Save shadowhand/3a2c01a3487c9784cc0b to your computer and use it in GitHub Desktop.
phpspec test with errors.
<?php
namespace spec\Ushahidi\Usecase\User;
use Ushahidi\Entity\User;
use Ushahidi\Entity\UserRepository;
use Ushahidi\Tool\Validator;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class RegisterSpec extends ObjectBehavior
{
function let(UserRepository $repo, Validator $valid, User $user)
{
$user->beConstructedWith([]);
$user->email = 'test@example.com';
$user->username = 'test';
$user->password = 'secret';
$this->beConstructedWith($repo, $valid);
}
function it_is_initializable()
{
$this->shouldHaveType('Ushahidi\Usecase\User\Register');
}
function it_can_be_interacted_with($repo, $valid, $user)
{
$data = [
'email' => 'test@example.com',
'verify_email' => 'test@example.com',
'username' => 'test',
'password' => 'secret',
];
$valid->check($data)->shouldBeCalled()->willReturn(true);
$repo->add($user)->shouldBeCalled()->willReturn(1);
$this->interact($data)->shouldBe(1);
}
}
@shadowhand
Copy link
Author

  24  ✔ is initializable
  29  ! can be interacted with
        method call:
          Double\UserRepository\P5->add(Ushahidi\Entity\User:000000005b9155c8000000003db9b499 Object (
            'id' => null
            'email' => 'test@example.com'
            'realname' => null
            'username' => 'test'
            'password' => 'secret'
            'logins' => 0
            'failed_attempts' => 0
            'last_login' => null
            'last_attempt' => null
            'created' => null
            'updated' => null
            'role' => 'user'
        ))
        was not expected.
        Expected calls are:
          - add(exact(Double\Ushahidi\Entity\User\P4:000000005b915539000000003db9b499 Object (
            'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)
            'id' => null
            'email' => 'test@example.com'
            'realname' => null
            'username' => 'test'
            'password' => 'secret'
            'logins' => 0
            'failed_attempts' => 0
            'last_login' => null
            'last_attempt' => null
            'created' => null
            'updated' => null
            'role' => 'user'
        )))

----  broken examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment