Skip to content

Commit 1d2aea0

Browse files
committed
- Added test for custom stubs
- Bumped generator-helpers package version
1 parent d88ca79 commit 1d2aea0

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"illuminate/support": "^9.0 || ^10.0 || ^11.0 || ^12.0",
1515
"symfony/process": "^6.0 || ^7.0",
1616
"doctrine/dbal": "^3.6 || ^4.0",
17-
"javaabu/generator-helpers": "^1.1"
17+
"javaabu/generator-helpers": "^1.2"
1818
},
1919
"require-dev": {
2020
"orchestra/testbench": "^7.0 || ^8.0 || ^9.0 || ^10.0",

tests/Unit/Generators/BaseGeneratorTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Javaabu\Generators\Tests\Unit\Generators;
44

5+
use Illuminate\Support\Facades\Artisan;
56
use Javaabu\Generators\FieldTypes\BooleanField;
67
use Javaabu\Generators\FieldTypes\DateField;
78
use Javaabu\Generators\FieldTypes\DateTimeField;
@@ -16,6 +17,7 @@
1617
use Javaabu\Generators\FieldTypes\YearField;
1718
use Javaabu\Generators\Generators\BaseGenerator;
1819
use Illuminate\Foundation\Testing\RefreshDatabase;
20+
use Javaabu\Generators\Generators\ExportGenerator;
1921
use Javaabu\Generators\Tests\TestCase;
2022

2123
class MockBaseGenerator extends BaseGenerator
@@ -30,6 +32,40 @@ class BaseGeneratorTest extends TestCase
3032
{
3133
use RefreshDatabase;
3234

35+
protected function setUp(): void
36+
{
37+
parent::setUp();
38+
39+
Artisan::call('vendor:publish', [
40+
'--provider' => 'Javaabu\\Generators\\GeneratorsServiceProvider',
41+
'--tag' => 'generators-stubs',
42+
]);
43+
44+
// setup skeleton service provider
45+
$this->copyFile(
46+
$this->getTestStubPath('Exports/ModelExport.stub'),
47+
$this->app->basePath('stubs/vendor/generators/Exports/ModelExport.stub')
48+
);
49+
}
50+
51+
protected function tearDown(): void
52+
{
53+
$this->deleteDirectory($this->app->basePath('stubs'));
54+
55+
parent::tearDown();
56+
}
57+
58+
/** @test */
59+
public function it_can_generate_from_custom_stubs(): void
60+
{
61+
$export_generator = new ExportGenerator('products');
62+
63+
$expected_content = $this->getTestStubContents('Exports/ProductsExport.php');
64+
$actual_content = $export_generator->render();
65+
66+
$this->assertEquals($expected_content, $actual_content);
67+
}
68+
3369
/** @test */
3470
public function it_can_determine_if_the_model_has_any_fillable_fields(): void
3571
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* {{pluralTitle}} Export
4+
*/
5+
6+
namespace App\Exports;
7+
8+
use App\Models\{{singularStudly}};
9+
use Javaabu\Exports\ModelExport;
10+
11+
class {{pluralStudly}}Export extends ModelExport
12+
{
13+
public function modelClass(): string
14+
{
15+
return {{singularStudly}}::class;
16+
}
17+
18+
public function map(): array
19+
{
20+
return [];
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Products Export
4+
*/
5+
6+
namespace App\Exports;
7+
8+
use App\Models\Product;
9+
use Javaabu\Exports\ModelExport;
10+
11+
class ProductsExport extends ModelExport
12+
{
13+
public function modelClass(): string
14+
{
15+
return Product::class;
16+
}
17+
18+
public function map(): array
19+
{
20+
return [];
21+
}
22+
}

0 commit comments

Comments
 (0)