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.
Feature/laravel stub integration (#12)
* Add ability to override stub location when generating * Fix styling * test stencil file processor * Fix styling * Disable formatting in tests * Fix tests * Fix styling * Ignore service provider for phpstan --------- Co-authored-by: Riley19280 <[email protected]>
- Loading branch information
1 parent
28f406e
commit da929e3
Showing
11 changed files
with
143 additions
and
2 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
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
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
10 changes: 10 additions & 0 deletions
10
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,10 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class test extends Model{ | ||
use HasFactory; | ||
} |
10 changes: 10 additions & 0 deletions
10
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,10 @@ | ||
<?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,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;') | ||
) | ||
->disableFormat(); |
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,14 @@ | ||
<?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;') | ||
) | ||
->disableFormat() | ||
->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(); | ||
}); |