Skip to content

operantions:make command to return real path of the newly create file #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Commands/OneTimeOperationsMakeCommand.php
Original file line number Diff line number Diff line change
@@ -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) {
5 changes: 5 additions & 0 deletions src/OneTimeOperationFile.php
Original file line number Diff line number Diff line change
@@ -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) {
9 changes: 7 additions & 2 deletions tests/Feature/OneTimeOperationCommandTest.php
Original file line number Diff line number Diff line change
@@ -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')));
1 change: 1 addition & 0 deletions tests/Feature/OneTimeOperationCreatorTest.php
Original file line number Diff line number Diff line change
@@ -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);
}