From 2fe366cfc7ee418eeb4305cfa4dfecac0053a0ab Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 1 Apr 2022 21:06:51 +0200 Subject: [PATCH] Implement the --force option --- .../Commands/HydeMakePageCommandTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Feature/Commands/HydeMakePageCommandTest.php b/tests/Feature/Commands/HydeMakePageCommandTest.php index 795df84..99465b7 100644 --- a/tests/Feature/Commands/HydeMakePageCommandTest.php +++ b/tests/Feature/Commands/HydeMakePageCommandTest.php @@ -83,4 +83,27 @@ public function test_command_creates_blade_file() $this->assertFileExists($this->bladePath); } + + // Assert the command fails if the file already exists + public function test_command_fails_if_file_already_exists() + { + file_put_contents($this->markdownPath, 'This should not be overwritten'); + + $this->expectException(Exception::class); + $this->expectExceptionMessage("File $this->markdownPath already exists!"); + $this->expectExceptionCode(409); + $this->artisan('make:page "8450de2 test page"')->assertExitCode(409); + + $this->assertEquals('This should not be overwritten', file_get_contents($this->markdownPath)); + } + + // Assert the command overwrites existing files when the force option is used + public function test_command_overwrites_existing_files_when_force_option_is_used() + { + file_put_contents($this->markdownPath, 'This should be overwritten'); + + $this->artisan('make:page "8450de2 test page" --force')->assertExitCode(0); + + $this->assertNotEquals('This should be overwritten', file_get_contents($this->markdownPath)); + } }