Skip to content

Commit c8dcdf7

Browse files
committed
chore: add tests for make specification command
1 parent 9392d12 commit c8dcdf7

6 files changed

+167
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"phpstan/phpstan-deprecation-rules": "^1.0",
3131
"phpstan/phpstan-phpunit": "^1.0",
3232
"phpunit/phpunit": "^9.5",
33-
"spatie/laravel-ray": "^1.26"
33+
"spatie/laravel-ray": "^1.26",
34+
"spatie/phpunit-snapshot-assertions": "^4.2"
3435
},
3536
"autoload": {
3637
"psr-4": {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Maartenpaauw\Specifications\Tests\Commands;
6+
7+
use Illuminate\Testing\PendingCommand;
8+
use Maartenpaauw\Specifications\Commands\MakeSpecificationCommand;
9+
use Maartenpaauw\Specifications\Tests\TestCase;
10+
use Spatie\Snapshots\MatchesSnapshots;
11+
use Symfony\Component\Console\Command\Command;
12+
13+
class MakeSpecificationCommandTest extends TestCase
14+
{
15+
use MatchesSnapshots;
16+
17+
/** @test */
18+
public function it_should_be_possible_to_create_a_basic_specification_class(): void
19+
{
20+
// Act
21+
/** @var PendingCommand $command */
22+
$command = $this->artisan(MakeSpecificationCommand::class, [
23+
'name' => 'MyBasicSpecification',
24+
]);
25+
26+
// Assert
27+
$command->assertExitCode(Command::SUCCESS);
28+
$this->assertSpecificationMatchesSnapshot('MyBasicSpecification');
29+
}
30+
31+
/** @test */
32+
public function it_should_be_possible_to_create_a_composite_specification_class(): void
33+
{
34+
// Act
35+
/** @var PendingCommand $command */
36+
$command = $this->artisan(MakeSpecificationCommand::class, [
37+
'name' => 'MyCompositeSpecification',
38+
'--composite' => true,
39+
]);
40+
41+
// Assert
42+
$command->assertExitCode(Command::SUCCESS);
43+
$this->assertSpecificationMatchesSnapshot('MyCompositeSpecification');
44+
}
45+
46+
/** @test */
47+
public function it_should_be_possible_to_create_a_basic_specification_with_a_candidate_type(): void
48+
{
49+
// Act
50+
/** @var PendingCommand $command */
51+
$command = $this->artisan(MakeSpecificationCommand::class, [
52+
'name' => 'MyStrictBasicSpecification',
53+
'--candidate' => 'string',
54+
]);
55+
56+
// Assert
57+
$command->assertExitCode(Command::SUCCESS);
58+
$this->assertSpecificationMatchesSnapshot('MyStrictBasicSpecification');
59+
}
60+
61+
/** @test */
62+
public function it_should_be_possible_to_create_a_composite_specification_with_a_candidate_type(): void
63+
{
64+
// Act
65+
/** @var PendingCommand $command */
66+
$command = $this->artisan(MakeSpecificationCommand::class, [
67+
'name' => 'MyStrictCompositeSpecification',
68+
'--composite' => true,
69+
'--candidate' => 'string',
70+
]);
71+
72+
// Assert
73+
$command->assertExitCode(Command::SUCCESS);
74+
$this->assertSpecificationMatchesSnapshot('MyStrictCompositeSpecification');
75+
}
76+
77+
protected function assertSpecificationMatchesSnapshot(string $name): void
78+
{
79+
$this->assertMatchesFileSnapshot(app_path(sprintf('Specifications/%s.php', $name)));
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Specifications;
6+
7+
use Maartenpaauw\Specifications\Specification;
8+
9+
/**
10+
* @implements Specification<mixed>
11+
*/
12+
class MyBasicSpecification implements Specification
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public function isSatisfiedBy(mixed $candidate): bool
18+
{
19+
return true;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Specifications;
6+
7+
use Maartenpaauw\Specifications\Specification;
8+
9+
/**
10+
* @implements Specification<string>
11+
*/
12+
class MyStrictBasicSpecification implements Specification
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public function isSatisfiedBy(mixed $candidate): bool
18+
{
19+
return true;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Specifications;
6+
7+
use Maartenpaauw\Specifications\CompositeSpecification;
8+
9+
/**
10+
* @extends CompositeSpecification<mixed>
11+
*/
12+
class MyCompositeSpecification extends CompositeSpecification
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public function isSatisfiedBy(mixed $candidate): bool
18+
{
19+
return true;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Specifications;
6+
7+
use Maartenpaauw\Specifications\CompositeSpecification;
8+
9+
/**
10+
* @extends CompositeSpecification<string>
11+
*/
12+
class MyStrictCompositeSpecification extends CompositeSpecification
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public function isSatisfiedBy(mixed $candidate): bool
18+
{
19+
return true;
20+
}
21+
}

0 commit comments

Comments
 (0)