1

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?

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
alexleonard
  • 1,314
  • 3
  • 21
  • 37

1 Answers1

4

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;
        },
    ];
}
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • Ahhhhhh! You have, in one fell swoop, clarified how inline matchers work. That's awesome. Sorry, I should have included my code! Thank you so much! – alexleonard Apr 05 '14 at 04:47
  • I had to slightly modify this or else it failed. I needed to assign the method to a variable and pass it into my inline matcher. This is what I did: http://laravel.io/bin/9QrR - is there another way to do this? – alexleonard Apr 05 '14 at 05:40