tests/Unit/PostsServiceTest.php
/**
     * Test that the update method calls the correct repo calls.
     *
     * The update() method works directly on the Eloquent model - this should be refactored.
     */
Test that the update method calls the correct repo calls.
The update() method works directly on the Eloquent model - this should be refactored.
Test that the update method calls the correct repo calls . The update () method works directly on the Eloquent model - this should be refactored .
public function testUpdate(): void
    {
        $belongsToMany = $this->mock(BelongsToMany::class, static function ($mock) {
            $mock->shouldReceive('sync');
        });
        $mockedModel = $this->mock(Post::class, static function ($mock) use ($belongsToMany) {
            $mock->shouldReceive('fill')->once();
            $mock->shouldReceive('save')->once();
            $mock->shouldReceive('categories')->andReturn($belongsToMany);
        });
        $this->mock(PostsRepository::class, static function ($mock) use ($mockedModel) {
            $mock->shouldReceive('find')->once()->andReturn($mockedModel);
        });
        $this->mock(UploadsService::class, static function ($mock) {
            $mock->shouldReceive('processFeaturedUpload')->once();
        });
        $service = resolve(PostsService::class);
        $request = $this->createRequest($this->createParams());
        $this->expectsEvents(BlogPostEdited::class);
        $service->update(1, $request);
    }
public function testUpdate ( ) : void { $ belongsToMany = $ this -> mock ( BelongsToMany :: class , static function ( $ mock ) { $ mock -> shouldReceive ( 'sync' ) ; } ) ; $ mockedModel = $ this -> mock ( Post :: class , static function ( $ mock ) use ( $ belongsToMany ) { $ mock -> shouldReceive ( 'fill' ) -> once ( ) ; $ mock -> shouldReceive ( 'save' ) -> once ( ) ; $ mock -> shouldReceive ( 'categories' ) -> andReturn ( $ belongsToMany ) ; } ) ; $ this -> mock ( PostsRepository :: class , static function ( $ mock ) use ( $ mockedModel ) { $ mock -> shouldReceive ( 'find' ) -> once ( ) -> andReturn ( $ mockedModel ) ; } ) ; $ this -> mock ( UploadsService :: class , static function ( $ mock ) { $ mock -> shouldReceive ( 'processFeaturedUpload' ) -> once ( ) ; } ) ; $ service = resolve ( PostsService :: class ) ; $ request = $ this -> createRequest ( $ this -> createParams ( ) ) ; $ this -> expectsEvents ( BlogPostEdited :: class ) ; $ service -> update ( 1 , $ request ) ; }
Test that the update method calls the correct repo calls.
Test that the update method calls the correct repo calls .
// Mock the repository: // Test that it is called exactly once: // Instanciate service, the mocked repo will be injected: // Call the service method (assets are done above).