These scopes are not valid - a scope mutates the Builder instance; it does not return a query result.
Jan 13, 2023
6
Level 2
How to test Elloquent local scope coming from trait?
Hello! How can I test local scopes that are coming from a trait?
This is the trait:
trait HasHashedID
{
public static function dehashID(string $hashedID):string
{
return Hashids::decode($hashedID)[0];
}
public function scopeFindByHashedID(Builder $query, string $hashedID):self
{
return $query->find(self::dehashID(hashedID: $hashedID));
}
public function scopeFindByHashedIDOrFail(Builder $query, string $hashedID):self
{
return $query->findOrFail(self::dehashID(hashedID: $hashedID));
}
}
I managed to write a test for the dehashID() method. However, I'd like to know how to test the other two methods? The local-scope ones.
Thank you!!
Level 104
2 likes
Please or to participate in this conversation.