generated from cerbero90/skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
195 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Cerbero\Enum\Enums; | ||
|
||
it('fails if the enum name is not provided', function() { | ||
expect(runEnum('make')) | ||
->output->toContain('The name of the enum is missing.') | ||
->status->toBe(1); | ||
}); | ||
|
||
it('succeeds if an enum already exists', function() { | ||
expect(runEnum('make App/Enums/Enum1')) | ||
->output->toContain('The enum App\Enums\Enum1 already exists.') | ||
->status->toBe(0); | ||
}); | ||
|
||
it('fails if the enum cases are not provided', function() { | ||
expect(runEnum('make App/Enums/Test')) | ||
->output->toContain('The cases of the enum are missing.') | ||
->status->toBe(1); | ||
}); | ||
|
||
it('fails if the backed option is not supported', function() { | ||
expect(runEnum('make App/Enums/Test one --backed=test')) | ||
->output->toContain('The option --backed supports only') | ||
->status->toBe(1); | ||
}); | ||
|
||
it('generates annotated enums', function(string $enum, string $backed) { | ||
Enums::setBasePath(__DIR__ . '/../Skeleton'); | ||
Enums::setPaths('app/Enums', 'domain/*/Enums'); | ||
|
||
expect(fn() => runEnum("make \"{$enum}\" CaseOne CaseTwo --backed={$backed}"))->toGenerate($enum); | ||
|
||
(fn() => self::$paths = [])->bindTo(null, Enums::class)(); | ||
(fn() => self::$basePath = null)->bindTo(null, Enums::class)(); | ||
})->with([ | ||
['App\Enums\Generated1', 'bitwise'], | ||
['Domain\Common\Enums\Generated2', 'snake'], | ||
]); |
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,39 @@ | ||
<?php | ||
|
||
use Cerbero\Enum\Enums; | ||
use Cerbero\Enum\Services\Generator; | ||
|
||
it('returns true if an enum already exists', function() { | ||
$outcome = (new Generator('App\Enums\Enum1', []))->generate(); | ||
|
||
expect($outcome)->toBeTrue(); | ||
}); | ||
|
||
it('generates annotated enums', function(string $enum, ?string $backed) { | ||
Enums::setBasePath(__DIR__ . '/../Skeleton'); | ||
Enums::setPaths('app/Enums', 'domain/*/Enums'); | ||
|
||
expect(fn() => (new Generator($enum, ['CaseOne', 'CaseTwo'], $backed))->generate())->toGenerate($enum); | ||
|
||
(fn() => self::$paths = [])->bindTo(null, Enums::class)(); | ||
(fn() => self::$basePath = null)->bindTo(null, Enums::class)(); | ||
})->with([ | ||
['App\Enums\Generated1', 'bitwise'], | ||
['Domain\Common\Enums\Generated2', 'snake'], | ||
]); | ||
|
||
it('creates sub-directories if needed', function() { | ||
Enums::setBasePath(__DIR__ . '/../Skeleton'); | ||
Enums::setPaths('app/Enums', 'domain/*/Enums'); | ||
|
||
$enum = 'SubDirectory\Generated3'; | ||
|
||
try { | ||
expect(fn() => (new Generator($enum, ['CaseOne', 'CaseTwo']))->generate())->toGenerate($enum); | ||
} finally { | ||
rmdir(Enums::basePath('SubDirectory')); | ||
} | ||
|
||
(fn() => self::$paths = [])->bindTo(null, Enums::class)(); | ||
(fn() => self::$basePath = null)->bindTo(null, Enums::class)(); | ||
}); |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
use Cerbero\Enum\Concerns\Enumerates; | ||
|
||
enum Generated1: int | ||
{ | ||
use Enumerates; | ||
|
||
case CaseOne = 1 << 0; | ||
|
||
case CaseTwo = 1 << 1; | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Domain\Common\Enums; | ||
|
||
use Cerbero\Enum\Concerns\Enumerates; | ||
|
||
enum Generated2: string | ||
{ | ||
use Enumerates; | ||
|
||
case CaseOne = 'case_one'; | ||
|
||
case CaseTwo = 'case_two'; | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SubDirectory; | ||
|
||
use Cerbero\Enum\Concerns\Enumerates; | ||
|
||
enum Generated3 | ||
{ | ||
use Enumerates; | ||
|
||
case CaseOne; | ||
|
||
case CaseTwo; | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
use Cerbero\Enum\Concerns\Enumerates; | ||
|
||
/** | ||
* @method static int CaseOne() | ||
* @method static int CaseTwo() | ||
*/ | ||
enum Generated1: int | ||
{ | ||
use Enumerates; | ||
|
||
case CaseOne = 1 << 0; | ||
|
||
case CaseTwo = 1 << 1; | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Domain\Common\Enums; | ||
|
||
use Cerbero\Enum\Concerns\Enumerates; | ||
|
||
/** | ||
* @method static string CaseOne() | ||
* @method static string CaseTwo() | ||
*/ | ||
enum Generated2: string | ||
{ | ||
use Enumerates; | ||
|
||
case CaseOne = 'case_one'; | ||
|
||
case CaseTwo = 'case_two'; | ||
} |