문제

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?

도움이 되었습니까?

해결책

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;
        },
    ];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top