Chris Warner
Chris Warner

Reputation: 31

PHPSpec TypeError when checking boolean value

I have a Boolean method called supportsClass (I know but I believe in BDD/TDD all the way) that is implemented as part of this interface.

Symfony\Component\Security\Core\User\UserProviderInterface

In my spec I am test this method like this

$this->supportsClass(get_class($user))->ShouldReturn(false).

Where user is a prophet object. When I run my specs I get this exception thrown

[err:TypeError("Argument 1 passed to PhpSpec\Exception\ExceptionFactory::methodNotFound() must be of the type string, null given

I can't find a way to make this spec pass using any of the === or == matchers. and the only boolean specific matchers I can find are these

$this->shouldBeActive(); // isActive() method should return true
$this->shouldHaveSomething(); // hasSomething() method should return true

$this->shouldNotBeActive(); // isActive() method should return false
$this->shouldNotHaveSomething(); // hasSomething() method should return false

As you can see the method under test doesn't match either of these. If anyone can clarify how to test Boolean Methods that do not have is/has I would appreciate it.

Upvotes: 0

Views: 157

Answers (1)

Sebastian Staniak
Sebastian Staniak

Reputation: 31

You should try $this->supportsClass(get_class($user))->shouldReturn(false). (lowercase should in shouldReturn method name)

Upvotes: 1

Related Questions