From 3558e381c7360b5c5fdb6a7e3c838d7dd3e198eb Mon Sep 17 00:00:00 2001 From: Eimantas Kateiva Date: Fri, 5 May 2023 14:14:06 +0300 Subject: [PATCH] change the output of `operantions:make` command to return real path of the newly create file --- src/Commands/OneTimeOperationsMakeCommand.php | 2 +- src/OneTimeOperationFile.php | 5 +++++ tests/Feature/OneTimeOperationCommandTest.php | 9 +++++++-- tests/Feature/OneTimeOperationCreatorTest.php | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Commands/OneTimeOperationsMakeCommand.php b/src/Commands/OneTimeOperationsMakeCommand.php index b0f2bbd..970214c 100644 --- a/src/Commands/OneTimeOperationsMakeCommand.php +++ b/src/Commands/OneTimeOperationsMakeCommand.php @@ -17,7 +17,7 @@ public function handle(): int { try { $file = OneTimeOperationCreator::createOperationFile($this->argument('name'), $this->option('essential')); - $this->components->info(sprintf('One-time operation [%s] created successfully.', $file->getOperationName())); + $this->components->info(sprintf('One-time operation [%s] created successfully.', $file->getOperationFilePath())); return self::SUCCESS; } catch (Throwable $e) { diff --git a/src/OneTimeOperationFile.php b/src/OneTimeOperationFile.php index 61648d3..58b3d5c 100644 --- a/src/OneTimeOperationFile.php +++ b/src/OneTimeOperationFile.php @@ -31,6 +31,11 @@ public function getOperationName(): string return Str::remove('.php', $filename); } + public function getOperationFilePath(): string + { + return $this->file->getRealPath(); + } + public function getClassObject(): OneTimeOperation { if (! $this->classObject) { diff --git a/tests/Feature/OneTimeOperationCommandTest.php b/tests/Feature/OneTimeOperationCommandTest.php index 2dce60e..4e1e995 100644 --- a/tests/Feature/OneTimeOperationCommandTest.php +++ b/tests/Feature/OneTimeOperationCommandTest.php @@ -21,7 +21,7 @@ public function test_make_command_with_attributes() // create operation file $this->artisan('operations:make AwesomeOperation') ->assertSuccessful() - ->expectsOutputToContain('One-time operation [2015_10_21_072800_awesome_operation] created successfully.'); + ->expectsOutputToContain(sprintf('One-time operation [%s] created successfully.', $this->fileRealPath($filepath))); // file was created, but no operation entry yet $this->assertFileExists($filepath); @@ -86,7 +86,7 @@ public function test_the_whole_command_process() // create operation file $this->artisan('operations:make AwesomeOperation') ->assertSuccessful() - ->expectsOutputToContain('One-time operation [2015_10_21_072800_awesome_operation] created successfully.'); + ->expectsOutputToContain(sprintf('One-time operation [%s] created successfully.', $this->fileRealPath($filepath))); // file was created, but no operation entry yet $this->assertFileExists($filepath); @@ -433,6 +433,11 @@ protected function filepath(string $filename): string return base_path(config('one-time-operations.directory')).DIRECTORY_SEPARATOR.$filename; } + protected function fileRealPath(string $filepath): string + { + return realpath('.').DIRECTORY_SEPARATOR.Str::afterLast($filepath, '../'); + } + protected function tearDown(): void { File::deleteDirectory(base_path(config('one-time-operations.directory'))); diff --git a/tests/Feature/OneTimeOperationCreatorTest.php b/tests/Feature/OneTimeOperationCreatorTest.php index 8aabe32..12d64e7 100644 --- a/tests/Feature/OneTimeOperationCreatorTest.php +++ b/tests/Feature/OneTimeOperationCreatorTest.php @@ -22,6 +22,7 @@ public function it_creates_an_operation_file_instance() $this->assertInstanceOf(OneTimeOperationFile::class, $operationFile); $this->assertInstanceOf(OneTimeOperation::class, $operationFile->getClassObject()); $this->assertEquals('2015_10_21_072800_test_operation', $operationFile->getOperationName()); + $this->assertStringContainsString('tests/files/2015_10_21_072800_test_operation.php', $operationFile->getOperationFilePath()); File::delete($filepath); }