Skip to content

Commit 6e80bef

Browse files
authored
Merge pull request #144 from RonasIT/49-add-command-tests
tests:add tests for different package and project configs
2 parents d191e02 + eb31a5c commit 6e80bef

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

tests/CommandTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace RonasIT\Support\Tests;
44

55
use Carbon\Carbon;
6+
use Illuminate\Support\Facades\Config;
7+
use org\bovigo\vfs\vfsStream;
8+
use org\bovigo\vfs\vfsStreamFile;
69
use RonasIT\Support\Exceptions\ClassNotExistsException;
710
use RonasIT\Support\Tests\Support\Command\CommandMockTrait;
811
use UnexpectedValueException;
@@ -11,6 +14,16 @@ class CommandTest extends TestCase
1114
{
1215
use CommandMockTrait;
1316

17+
public function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
vfsStream::newDirectory('config')->at($this->rootDirectory);
22+
vfsStream::newDirectory('routes')
23+
->at($this->rootDirectory)
24+
->addChild(new vfsStreamFile('api.php'));
25+
}
26+
1427
public function testCallWithInvalidCrudOption()
1528
{
1629
$this->assertExceptionThrew(
@@ -113,4 +126,24 @@ public function testMakeOnly()
113126
$this->assertFileDoesNotExist('tests/fixtures/NovaPostTest/create_post_response.json');
114127
$this->assertFileDoesNotExist('tests/fixtures/NovaPostTest/update_post_request.json');
115128
}
129+
130+
public function testCallWithNotDefaultConfig()
131+
{
132+
$this->app->instance('path.base', $this->generatedFileBasePath);
133+
134+
Config::set('entity-generator', ['test' => 'changed']);
135+
136+
$this
137+
->artisan('make:entity Post')
138+
->expectsOutput('Config has been updated')
139+
->assertExitCode(0);
140+
141+
$configPath = "{$this->generatedFileBasePath}/config/entity-generator.php";
142+
143+
$updated = include $configPath;
144+
145+
$this->assertFileExists($configPath);
146+
147+
$this->assertEqualsFixture('changed_config.json', $updated);
148+
}
116149
}

tests/TestCase.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Support\Str;
1010
use Orchestra\Testbench\TestCase as BaseTestCase;
1111
use org\bovigo\vfs\vfsStream;
12+
use org\bovigo\vfs\vfsStreamDirectory;
1213
use RonasIT\Support\EntityGeneratorServiceProvider;
1314
use RonasIT\Support\Traits\FixturesTrait;
1415

@@ -20,17 +21,19 @@ class TestCase extends BaseTestCase
2021
protected bool $globalExportMode = false;
2122
protected string $generatedFileBasePath;
2223

24+
protected vfsStreamDirectory $rootDirectory;
25+
2326
public function setUp(): void
2427
{
2528
parent::setUp();
2629

2730
$this->mockConfigurations();
2831

29-
vfsStream::setup();
30-
31-
Event::fake();
32+
$this->rootDirectory = vfsStream::setup();
3233

3334
$this->generatedFileBasePath = vfsStream::url('root');
35+
36+
Event::fake();
3437

3538
$this->app->setBasePath($this->generatedFileBasePath);
3639
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"paths": {
3+
"models": "app/Models",
4+
"services": "app/Services",
5+
"requests": "app/Http/Requests",
6+
"controllers": "app/Http/Controllers",
7+
"migrations": "database/migrations",
8+
"seeders": "database/seeders",
9+
"database_seeder": "database/seeders/DatabaseSeeder.php",
10+
"repositories": "app/Repositories",
11+
"tests": "tests",
12+
"routes": "routes/api.php",
13+
"factories": "database/factories",
14+
"translations": "lang/en/validation.php",
15+
"resources": "app/Http/Resources",
16+
"nova": "app/Nova"
17+
},
18+
"stubs": {
19+
"model": "entity-generator::model",
20+
"relation": "entity-generator::relation",
21+
"repository": "entity-generator::repository",
22+
"service": "entity-generator::service",
23+
"service_with_trait": "entity-generator::service_with_trait",
24+
"controller": "entity-generator::controller",
25+
"request": "entity-generator::request",
26+
"routes": "entity-generator::routes",
27+
"use_routes": "entity-generator::use_routes",
28+
"factory": "entity-generator::factory",
29+
"seeder": "entity-generator::seeder",
30+
"database_empty_seeder": "entity-generator::database_empty_seeder",
31+
"migration": "entity-generator::migration",
32+
"dump": "entity-generator::dumps.pgsql",
33+
"test": "entity-generator::test",
34+
"translation_not_found": "entity-generator::translation_not_found",
35+
"validation": "entity-generator::validation",
36+
"resource": "entity-generator::resource",
37+
"collection_resource": "entity-generator::collection_resource",
38+
"nova_resource": "entity-generator::nova_resource",
39+
"nova_test": "entity-generator::nova_test"
40+
},
41+
"test": "changed"
42+
}

0 commit comments

Comments
 (0)