tests/Unit/PostsServiceTest.php
/**
     * Test that calling create will call the correct method on the PostsRepository.
     * We can assume the repo creates the database entry.
     */
Test that calling create will call the correct method on the PostsRepository.
We can assume the repo creates the database entry.
Test that calling create will call the correct method on the PostsRepository . We can assume the repo creates the database entry .
public function testCreate(): void
    {
        $this->mock(PostsRepository::class, static function ($mock) {
            $mock->shouldReceive('create')->once();
        });
        $service = resolve(PostsService::class);
        $request = $this->createRequest($this->createParams());
        $service->create($request, null);
    }
public function testCreate ( ) : void { $ this -> mock ( PostsRepository :: class , static function ( $ mock ) { $ mock -> shouldReceive ( 'create' ) -> once ( ) ; } ) ; $ service = resolve ( PostsService :: class ) ; $ request = $ this -> createRequest ( $ this -> createParams ( ) ) ; $ service -> create ( $ request , null ) ; }
Test that calling create will call the correct method on the PostsRepository.
Test that calling create will call the correct method on the PostsRepository .
// Mock the repository: // Test that it is called exactly once: // Instanciate service, the mocked repo will be injected: // Not testing the request, just mock it and what it returns. // Call the service method (assets are done above).