Question

I have a method which queries the database and either returns an array with the results or false if there are no results.

All I need PHPSpec to do in this case is test whether it returns an array or false, but I can't work out how to do that.

Or do I need to mock the database query and separate it out of my method?

Was it helpful?

Solution

You're not showing any code so we can work with, but if current matchers doesn't work for you, you can create new ones:

function it_should_return_array_or_false()
{
    $this->getOptions()->shouldBeArrayOrFalse();
}

public function getMatchers()
{
    return [
        'beArrayOrFalse' => function($subject, $value) {
            return is_array($value) || $value === false;
        },
    ];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top