I'm trying to test that my class is correctly applying orderBy()'s
I have a test like this:
<?php
use App\Services\FilterService;
use Tests\TestCase;
use Illuminate\Contracts\Database\Query\Builder;
class FilterServiceTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
public function test_sort_method_applies_order_by_correctly()
{
$query = Mockery::mock(Builder::class);
$query->shouldReceive('orderBy')
->with('name', 'asc')
->once();
$query->shouldReceive('orderBy')
->with('age', 'desc')
->once();
$yourClass = new FilterService();
$sort = [
['field' => 'name', 'order' => 1],
['field' => 'age', 'order' => -1],
];
$exceptions = [];
$substitutes = [];
$yourClass->sort($query, $sort, $exceptions, $substitutes);
}
}
If I change ->with('name', 'asc') to ->with('name', 'ascxyz') I get an ugly Exception from Mockery:
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_0_Illuminate_Contracts_Database_Query_Builder::orderBy('name', 'asc'). Either the method was unexpected or its arguments matched no expected argument list for this method
If I change ['field' => 'age', 'order' => -1], to anything else ['field' => 'age', 'order' => 'somevalue'], then it makes literally no difference?
I'm obviously completely new to this lol