Skip to content

Commit cc24395

Browse files
committed
fix: execute command before matching snapshot
1 parent c8dcdf7 commit cc24395

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

src/Commands/MakeSpecificationCommand.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class MakeSpecificationCommand extends GeneratorCommand
1818
protected function getStub(): string
1919
{
2020
if ($this->option('composite')) {
21-
return __DIR__ . '/../../stubs/specification-composite.stub';
21+
return $this->resolveStubPath('/stubs/specification-composite.stub');
2222
}
2323

24-
return __DIR__ . '/../../stubs/specification.stub';
24+
return $this->resolveStubPath('/stubs/specification.stub');
2525
}
2626

2727
protected function getDefaultNamespace($rootNamespace): string
@@ -64,4 +64,12 @@ protected function getOptions(): array
6464
$candidate,
6565
];
6666
}
67+
68+
protected function resolveStubPath(string $stub): string
69+
{
70+
$custom = $this->laravel->basePath(trim($stub, '/'));
71+
$default = __DIR__ . $stub;
72+
73+
return file_exists($custom) ? $custom : $default;
74+
}
6775
}
File renamed without changes.

tests/Commands/MakeSpecificationCommandTest.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Maartenpaauw\Specifications\Commands\MakeSpecificationCommand;
99
use Maartenpaauw\Specifications\Tests\TestCase;
1010
use Spatie\Snapshots\MatchesSnapshots;
11-
use Symfony\Component\Console\Command\Command;
1211

1312
class MakeSpecificationCommandTest extends TestCase
1413
{
@@ -17,51 +16,66 @@ class MakeSpecificationCommandTest extends TestCase
1716
/** @test */
1817
public function it_should_be_possible_to_create_a_basic_specification_class(): void
1918
{
20-
// Act
19+
// Arrange
2120
/** @var PendingCommand $command */
2221
$command = $this->artisan(MakeSpecificationCommand::class, [
2322
'name' => 'MyBasicSpecification',
2423
]);
2524

2625
// Assert
27-
$command->assertExitCode(Command::SUCCESS);
26+
$command->assertSuccessful();
27+
28+
// Act
29+
$command->execute();
30+
31+
// Assert
2832
$this->assertSpecificationMatchesSnapshot('MyBasicSpecification');
2933
}
3034

3135
/** @test */
3236
public function it_should_be_possible_to_create_a_composite_specification_class(): void
3337
{
34-
// Act
38+
// Arrange
3539
/** @var PendingCommand $command */
3640
$command = $this->artisan(MakeSpecificationCommand::class, [
3741
'name' => 'MyCompositeSpecification',
3842
'--composite' => true,
3943
]);
4044

4145
// Assert
42-
$command->assertExitCode(Command::SUCCESS);
46+
$command->assertSuccessful();
47+
48+
// Act
49+
$command->execute();
50+
51+
// Assert
4352
$this->assertSpecificationMatchesSnapshot('MyCompositeSpecification');
4453
}
4554

4655
/** @test */
4756
public function it_should_be_possible_to_create_a_basic_specification_with_a_candidate_type(): void
4857
{
49-
// Act
58+
// Arrange
5059
/** @var PendingCommand $command */
5160
$command = $this->artisan(MakeSpecificationCommand::class, [
5261
'name' => 'MyStrictBasicSpecification',
5362
'--candidate' => 'string',
5463
]);
5564

5665
// Assert
57-
$command->assertExitCode(Command::SUCCESS);
66+
$command->assertSuccessful();
67+
68+
// Act
69+
$command->execute();
70+
71+
// Assert
5872
$this->assertSpecificationMatchesSnapshot('MyStrictBasicSpecification');
5973
}
6074

6175
/** @test */
6276
public function it_should_be_possible_to_create_a_composite_specification_with_a_candidate_type(): void
6377
{
64-
// Act
78+
// Arrange
6579
/** @var PendingCommand $command */
6680
$command = $this->artisan(MakeSpecificationCommand::class, [
6781
'name' => 'MyStrictCompositeSpecification',
@@ -70,7 +84,12 @@ public function it_should_be_possible_to_create_a_composite_specification_with_a
7084
]);
7185

7286
// Assert
73-
$command->assertExitCode(Command::SUCCESS);
87+
$command->assertSuccessful();
88+
89+
// Act
90+
$command->execute();
91+
92+
// Assert
7493
$this->assertSpecificationMatchesSnapshot('MyStrictCompositeSpecification');
7594
}
7695

0 commit comments

Comments
 (0)