Skip to content

Commit 5afa8ff

Browse files
committed
use custom stub file, if provided
1 parent 72a4332 commit 5afa8ff

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/OneTimeOperationCreator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ protected function getPath(): string
5757

5858
protected function getStubFilepath(): string
5959
{
60+
// check for custom stub file
61+
if (File::exists(base_path('stubs/one-time-operation.stub'))) {
62+
return File::get(base_path('stubs/one-time-operation.stub'));
63+
}
64+
6065
if ($this->essential) {
6166
return File::get(__DIR__.'/../stubs/one-time-operation-essential.stub');
6267
}

tests/Feature/OneTimeOperationCreatorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,22 @@ public function it_creates_an_operation_file_instance()
2525

2626
File::delete($filepath);
2727
}
28+
29+
/** @test */
30+
public function it_creates_an_operation_file_with_custom_stub()
31+
{
32+
$mockFile = File::partialMock();
33+
$mockFile->allows('exists')->with(base_path('stubs/one-time-operation.stub'))->andReturnTrue();
34+
$mockFile->allows('get')->with(base_path('stubs/one-time-operation.stub'))->andReturns('This is a custom stub');
35+
36+
$directory = Config::get('one-time-operations.directory');
37+
$filepath = base_path($directory).DIRECTORY_SEPARATOR.'2015_10_21_072800_test_operation.php';
38+
39+
OneTimeOperationCreator::createOperationFile('TestOperation');
40+
41+
$this->assertFileExists($filepath);
42+
$this->assertStringContainsString('This is a custom stub', File::get($filepath));
43+
44+
File::delete($filepath);
45+
}
2846
}

0 commit comments

Comments
 (0)