문제

I have problem in using ExceptionMatcher...My example spec:

class DescribeBall extends \PHPSpec\Context {

private $_ball = null;

function before() {
    $this->_ball = $this->spec(new Ball);
}

function itShouldHaveStatusRolledOnRoll() {
        $this->_ball->roll();
        $this->_ball->getStatus()->should->be('Rolled');
}

function itShouldThrowException() {
    $this->_ball->getException()->should->throwException('Exception','Error');
}
}

My example class

class Ball {
    private $status = null;

    public function roll() {
        $this->status = 'Rolled';
    }

    public function getStatus() {
        return $this->status;
    }

    public function getException() {
        throw new Exception('Error');
    }

}

Anyone used this matcher with success?

$this->_ball->getException()->should->throwException('Exception','Error');
도움이 되었습니까?

해결책

Thanks to my colleagues:

"The last time I looked at it, it used closures (unless Marcello changed it meanwhile) it should still work like this":

function itShouldThrowException() { 
    $ball = $this->_ball;
    $this->spec(function() use ($ball) {
            $ball->getException();
        })->should->throwException('Exception','Error');
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top