mercredi 11 mai 2016

Model function in laravel is not being called in unittest

In my Document.php model i have :

public function files()
{
    echo "\n\n--files--\n\n";
    return $this->hasMany(File::class);
}
public function filesDriver()
{
    echo "\n\n--filesDriver--\n\n";
    return $this->hasMany(File::class);
}
public function filesDriver2()
{
    echo "\n\n--filesDriver2--\n\n";
    return $this->hasMany(File::class);
}

In controller I have :

print_r('count filesDriver=' . \Auth::user()->document->filesDriver->count() . "\n");
print_r('count files=' . \Auth::user()->document->files->count() . "\n");
print_r('count files2=' . \Auth::user()->document->filesDriver2->count() . "\n");
exit;

When I run this from browser output is:

--filesDriver--
count filesDriver=1
--files--
count files=1
--filesDriver2--
count files2=1

But from unittest output is:

count filesDriver=0
--files--
count files=1
--filesDriver2--
count files2=1

Any idea why this is like that ? Why filesDriver is not beig called from unittest ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire