testing icon indicating copy to clipboard operation
testing copied to clipboard

Asserting relationships not working correctly

Open rut4 opened this issue 9 years ago • 0 comments

Hi,

I have two models: User and his Event.

class Event extends \Eloquent {
    // some code

    /**
     * User relation
     *
     * @return \Builder
     */
    public function user()
    {
        return $this->belongsTo('User');
    }
}

In tests I'd like to test this relationship and I did the following:

    /**
     * Test belongs to user
     *
     * @return void
     */
    public function testBelongsToUser()
    {
        $this->assertBelongsTo($this->event, 'user');
    }

The test is passed, ok. But if I change the test like:

    /**
     * Test belongs to user
     *
     * @return void
     */
    public function testBelongsToUser()
    {
        $this->assertBelongsToMany($this->event, 'user');
        // or different relationship, i.e. assertHasMany or assertHasOne
    }

The test is passed to. I'm not sure that it's ok. How can I test exactly a kind of a relationship?

Thanks.

rut4 avatar Mar 10 '15 09:03 rut4