generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fae0668
commit 76ae918
Showing
9 changed files
with
107 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace CodeStencil\Laravel; | ||
|
||
use CodeStencil\Stencil; | ||
|
||
trait RegistersOverrideStubLocationMacro | ||
{ | ||
private function registerOverrideStubLocationMacro(): void | ||
{ | ||
Stencil::macro('overrideStubLocation', function(string $path) { | ||
$newPath = $this->substituteVariables($path); | ||
$newPath = $this->applyFunctions($newPath); | ||
|
||
$this->variable('overrideStubLocation', $newPath); | ||
|
||
return $this; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/.pest/snapshots/StencilFileProcessorTest/process_file.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class test extends Model | ||
{ | ||
use HasFactory; | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/.pest/snapshots/StencilFileProcessorTest/process_file_custom_location.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class test extends Model | ||
{ | ||
use HasFactory; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
use CodeStencil\Stencil; | ||
|
||
return Stencil::make() | ||
->php() | ||
->namespace('App\Models') | ||
->use('Illuminate\Database\Eloquent\Factories\HasFactory') | ||
->use('Illuminate\Database\Eloquent\Model') | ||
->curlyStatement('class i_name extends Model', fn(Stencil $s) => $s | ||
->line('use HasFactory;') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
use CodeStencil\Stencil; | ||
|
||
return Stencil::make() | ||
->php() | ||
->namespace('App\Models') | ||
->use('Illuminate\Database\Eloquent\Factories\HasFactory') | ||
->use('Illuminate\Database\Eloquent\Model') | ||
->curlyStatement('class i_name extends Model', fn(Stencil $s) => $s | ||
->line('use HasFactory;') | ||
) | ||
->overrideStubLocation(__DIR__ . DIRECTORY_SEPARATOR . 'Output.php'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use CodeStencil\Laravel\RegistersOverrideStubLocationMacro; | ||
use CodeStencil\Laravel\StencilFileProcessor; | ||
|
||
uses(RegistersOverrideStubLocationMacro::class); | ||
|
||
test('process file', function() { | ||
$realStubPath = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'LaravelStub.php'; | ||
$tmpPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'LaravelStub.php'; | ||
copy($realStubPath, $tmpPath); | ||
|
||
(new StencilFileProcessor($tmpPath, ['i_name' => 'test']))(); | ||
|
||
$contents = file_get_contents($tmpPath); | ||
|
||
expect($contents)->toMatchSnapshot(); | ||
}); | ||
|
||
test('process file custom location', function() { | ||
$realStubPath = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'LaravelStubCustomLocation.php'; | ||
$tmpDir = sys_get_temp_dir(); | ||
$tmpPath = $tmpDir . DIRECTORY_SEPARATOR . 'LaravelStubCustomLocation.php'; | ||
copy($realStubPath, $tmpPath); | ||
|
||
$this->registerOverrideStubLocationMacro(); | ||
|
||
(new StencilFileProcessor($tmpPath, ['i_name' => 'test']))(); | ||
|
||
$contents = file_get_contents($tmpDir . DIRECTORY_SEPARATOR . 'Output.php'); | ||
|
||
expect($contents)->toMatchSnapshot(); | ||
|
||
expect(file_exists($tmpPath))->toBeFalse(); | ||
}); |