Skip to content

Instantly share code, notes, and snippets.

@raveren
Created June 2, 2021 08:28
Show Gist options
  • Save raveren/05005bbbaf22ce8528e436d89b855221 to your computer and use it in GitHub Desktop.
Save raveren/05005bbbaf22ce8528e436d89b855221 to your computer and use it in GitHub Desktop.
<?php

namespace App\Http\Controllers;

class MyController extends Controller
{
    public function update(BBJUpdateRequest $request, MyService $myService)
    {
        $myService->myMethod();
    }
}
<?php

class MyService
{
    public function myMethod(): static
    {
    }
}
<?php

namespace Tests\app\Http\Controllers;

/* use ... */

/**
 * @covers \App\Http\Controllers\MyController
 */
class MyControllerTest extends TestCase
{
    public function testSuccessfulPath()
    {
        $this->mock(MyService::class, function (MockInterface $mock) {
            $mock->expects('myMethod')->once();
        });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment