0

What is the proper syntax for "shouldReceive" with Laravel View class and the "with" argument? I have been trying all morning to let this simple test pass:

    $request = new Request([], [], [], [], []);

    $view = Mockery::mock(View::class);

    $dealData = [
        'products' => [],
        'response' => [
            'total' => 100
        ],
        'aggs' => []
    ];

    $pageData = [
        'productData' => $dealData
    ];

    $this->productService->shouldReceive('getDealsListData');
    $view->shouldReceive('with')->with($pageData);
    $this->productController->getDealsList($request);

The method I'm testing calls out to productService and then returns a view with arguments:

return view('products.list')->with($pageData);

Seemingly no matter what combination I try this is the output from phpunit:

Received Mockery_4_Illuminate_View_View::with(), but no expectations were specified

I am explicitly saying it shouldReceive "with" -- what can I do to allow phpunit to pass here?

caro
  • 863
  • 3
  • 15
  • 36
  • what about passing as array syntax, `return view('products.list', [ 'pageData' => $pageData ] );` – bhucho Oct 26 '20 at 20:51
  • yes that works but i should be able to have ->with in my code and not have to code around phpunit like this – caro Oct 27 '20 at 14:51
  • the with syntax should also have a key value pair systax, you can check it https://laravel.com/docs/8.x/views#passing-data-to-views – bhucho Oct 27 '20 at 14:57

0 Answers0