mock(AudioSourceRepository::class, function (MockInterface $mock) { $mock->shouldReceive('get')->once()->andReturn(Collection::make()); }); $action = new ReconcileAudioRepositoriesAction(); $source = App::make(AudioSourceRepository::class); $destination = App::make(AudioDestinationRepository::class); $result = $action->reconcileRepositories($source, $destination); static::assertTrue(ActionStatus::PASSED === $result->getStatus()); static::assertFalse($result->hasChanges()); static::assertDatabaseCount(Audio::class, 0); } /** * If audios are created, the Reconcile Audio Repository Action shall return created audios. * * @return void * * @throws Exception */ public function testCreated(): void { $createdAudioCount = $this->faker->numberBetween(2, 9); $audios = Audio::factory()->count($createdAudioCount)->make(); $this->mock(AudioSourceRepository::class, function (MockInterface $mock) use ($audios) { $mock->shouldReceive('get')->once()->andReturn($audios); }); $action = new ReconcileAudioRepositoriesAction(); $source = App::make(AudioSourceRepository::class); $destination = App::make(AudioDestinationRepository::class); $result = $action->reconcileRepositories($source, $destination); static::assertTrue(ActionStatus::PASSED === $result->getStatus()); static::assertTrue($result->hasChanges()); static::assertCount($createdAudioCount, $result->getCreated()); static::assertDatabaseCount(Audio::class, $createdAudioCount); } /** * If audios are deleted, the Reconcile Audio Repository Action shall return deleted audios. * * @return void * * @throws Exception */ public function testDeleted(): void { $deletedAudioCount = $this->faker->numberBetween(2, 9); $audios = Audio::factory()->count($deletedAudioCount)->create(); $this->mock(AudioSourceRepository::class, function (MockInterface $mock) { $mock->shouldReceive('get')->once()->andReturn(Collection::make()); }); $action = new ReconcileAudioRepositoriesAction(); $source = App::make(AudioSourceRepository::class); $destination = App::make(AudioDestinationRepository::class); $result = $action->reconcileRepositories($source, $destination); static::assertTrue(ActionStatus::PASSED === $result->getStatus()); static::assertTrue($result->hasChanges()); static::assertCount($deletedAudioCount, $result->getDeleted()); static::assertDatabaseCount(Audio::class, $deletedAudioCount); foreach ($audios as $audio) { static::assertSoftDeleted($audio); } } /** * If audios are updated, the Reconcile Audio Repository Action shall return updated audios. * * @return void * * @throws Exception */ public function testUpdated(): void { $updatedAudioCount = $this->faker->numberBetween(2, 9); $basenames = collect($this->faker->words($updatedAudioCount)); Audio::factory() ->count($updatedAudioCount) ->sequence(fn ($sequence) => [Audio::ATTRIBUTE_BASENAME => $basenames->get($sequence->index)]) ->create(); $sourceAudios = Audio::factory() ->count($updatedAudioCount) ->sequence(fn ($sequence) => [Audio::ATTRIBUTE_BASENAME => $basenames->get($sequence->index)]) ->make(); $this->mock(AudioRepository::class, function (MockInterface $mock) use ($sourceAudios) { $mock->shouldReceive('get')->once()->andReturn($sourceAudios); }); $action = new ReconcileAudioRepositoriesAction(); $source = App::make(AudioSourceRepository::class); $destination = App::make(AudioDestinationRepository::class); $result = $action->reconcileRepositories($source, $destination); static::assertTrue(ActionStatus::PASSED === $result->getStatus()); static::assertTrue($result->hasChanges()); static::assertCount($updatedAudioCount, $result->getUpdated()); static::assertDatabaseCount(Audio::class, $updatedAudioCount); } }