createOne(); $action = new MoveScriptAction($script, $this->faker->word()); $storageResults = $action->handle(); $result = $storageResults->toActionResult(); static::assertTrue($result->hasFailed()); } /** * The Move Script Action shall pass if there are moves. */ public function testPassed(): void { /** @var FilesystemAdapter $fs */ $fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.txt', $this->faker->randomDigitNotNull()); $directory = $this->faker->unique()->word(); $script = VideoScript::factory()->createOne([ VideoScript::ATTRIBUTE_PATH => $fs->putFileAs($directory, $file, $file->getClientOriginalName()), ]); $action = new MoveScriptAction($script, Str::replace($directory, $this->faker->unique()->word(), $script->path)); $storageResults = $action->handle(); $result = $storageResults->toActionResult(); static::assertTrue($result->getStatus() === ActionStatus::PASSED); } /** * The Move Script Action shall move the file in the configured disks. */ public function testMovedInDisk(): void { /** @var FilesystemAdapter $fs */ $fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.txt', $this->faker->randomDigitNotNull()); $directory = $this->faker->unique()->word(); $script = VideoScript::factory()->createOne([ VideoScript::ATTRIBUTE_PATH => $fs->putFileAs($directory, $file, $file->getClientOriginalName()), ]); $from = $script->path; $to = Str::replace($directory, $this->faker->unique()->word(), $script->path); $action = new MoveScriptAction($script, $to); $action->handle(); $fs->assertMissing($from); $fs->assertExists($to); } /** * The Move Script Action shall move the script. */ public function testScriptUpdated(): void { /** @var FilesystemAdapter $fs */ $fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.txt', $this->faker->randomDigitNotNull()); $directory = $this->faker->unique()->word(); $script = VideoScript::factory()->createOne([ VideoScript::ATTRIBUTE_PATH => $fs->putFileAs($directory, $file, $file->getClientOriginalName()), ]); $to = Str::replace($directory, $this->faker->unique()->word(), $script->path); $action = new MoveScriptAction($script, $to); $result = $action->handle(); $action->then($result); static::assertDatabaseHas(VideoScript::class, [VideoScript::ATTRIBUTE_PATH => $to]); } }