I don't think you need that shouldRecieve as an array
$view->shouldReceive('with')
->with([
'categories',
Category::getParents()
])
->once();
I'm new to testing so please forgive me if I am missing something obvious.
I'm trying to test the following view composer:
namespace App\Http\View\Composers;
use App\Models\Category;
use Illuminate\View\View;
class CategoryComposer
{
public function compose(View $view)
{
$view->with(
'categories',
Category::getParents()
);
}
}
The test:
class CategoryComposerTest extends TestCase
{
/** @test **/
public function it_passes_the_parent_categories_to_the_view(): void
{
$composer = new CategoryComposer;
$view = $this->mock(View::class);
$view->shouldReceive(['with'])
->with([
'categories',
Category::getParents()
])
->once();
$composer->compose($view);
}
}
The following error occurs when running the test:
Mockery\Exception\BadMethodCallException : Received Mockery_2_Illuminate_View_View::with(), but no expectations were specified
What am I doing wrong?
Please or to participate in this conversation.