integra's avatar

Stubbing an eloquent model in a test with PhpSpec

Hello, I've googled this topic without getting useful results. Here is my question:

I have a very basic Eloquent Model, say Grades

class Grades extends Model {

}

and a GradeChecker that should perform some calculation over Grades.

class GradeChecker {
    protected $grade;

    public __construct(Grades $grade){
        $this->grade = $grade;
    }

    public function bonus(){
        if ($this->grade ->final_grade > 5)
            return true;
        else
            return false;
    }
}

So I need to test GradeChecker stubbing some values in Grades:

class SkillCheckerSpec extends ObjectBehavior{
    function let(Grades $grade){
        $this->beConstructedWith($grade);
    }
    // init omitted
    function it_should_return_no_bonus_for_low_grade(Grades $grade){
        $grade->final_grade->willReturn(0);  
        $this->bonus()->shouldBe(false);        
    }
}

Obvioulsy, I get "notice: Undefined property: Prophecy\Profecy\MethodProfecy::$final_grade in..."

Is there any chance to stub the DB value / property for grades and get the specs working?

Thank you all.

0 likes
0 replies

Please or to participate in this conversation.