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
9 changed files
with
183 additions
and
31 deletions.
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
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,34 @@ | ||
<?php | ||
|
||
use Cerbero\Enum\Enums; | ||
|
||
it('warns that no enums were synced if invalid enums are provided', function() { | ||
expect(runEnum('ts InvalidEnum')) | ||
->output->toContain('No enums to synchronize.') | ||
->status->toBe(0); | ||
}); | ||
|
||
it('warns that no enums were synced if no enums can be found', function() { | ||
expect(runEnum('ts --all')) | ||
->output->toContain('No enums to synchronize.') | ||
->status->toBe(0); | ||
}); | ||
|
||
it('synchronizes all the discoverable enums', function() { | ||
Enums::setBasePath(__DIR__ . '/../Skeleton'); | ||
Enums::setPaths('app/Enums', 'domain/*/Enums'); | ||
|
||
expect($namespaces = [...Enums::namespaces()])->toBe([ | ||
App\Enums\Enum1::class, | ||
App\Enums\Enum2::class, | ||
Domain\Common\Enums\Enum3::class, | ||
Domain\Payouts\Enums\Enum4::class, | ||
]); | ||
|
||
$enums = array_map(fn($namespace) => "\"{$namespace}\"", $namespaces); | ||
|
||
expect(fn() => runEnum('ts ' . implode(' ', $enums)))->toTypeScript($namespaces); | ||
|
||
(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
use Cerbero\Enum\Enums; | ||
use Cerbero\Enum\Services\TypeScript; | ||
|
||
use function Cerbero\Enum\className; | ||
|
||
it('creates and appends enums', function() { | ||
Enums::setBasePath(__DIR__ . '/../Skeleton'); | ||
|
||
$enums = [ | ||
App\Enums\Enum1::class, | ||
App\Enums\Enum2::class, | ||
Domain\Common\Enums\Enum3::class, | ||
]; | ||
|
||
foreach ($enums as $enum) { | ||
expect((new TypeScript($enum))->sync())->toBeTrue(); | ||
} | ||
|
||
expect(fn() => (new TypeScript('Domain\Payouts\Enums\Enum4'))->sync())->toTypeScript([$enum]); | ||
|
||
(fn() => self::$basePath = null)->bindTo(null, Enums::class)(); | ||
}); | ||
|
||
it('replaces enums', function() { | ||
Enums::setBasePath(__DIR__ . '/../Skeleton'); | ||
|
||
$enums = [ | ||
App\Enums\Enum1::class, | ||
App\Enums\Enum2::class, | ||
Domain\Common\Enums\Enum3::class, | ||
Domain\Payouts\Enums\Enum4::class, | ||
]; | ||
|
||
foreach ($enums as $enum) { | ||
expect((new TypeScript($enum))->sync())->toBeTrue(); | ||
} | ||
|
||
expect(fn() => (new TypeScript('Domain\Payouts\Enums\Enum4'))->sync(overwrite: true))->toTypeScript([$enum]); | ||
|
||
(fn() => self::$basePath = null)->bindTo(null, Enums::class)(); | ||
}); | ||
|
||
it('creates custom TypeScript files', function(string $enum) { | ||
Enums::setBasePath(__DIR__ . '/../Skeleton'); | ||
Enums::setTypeScript(fn (string $enum) => 'resources/js/enums/' . className($enum) . '.ts'); | ||
|
||
expect(fn() => (new TypeScript($enum))->sync())->toTypeScript([$enum], oneFile: false); | ||
|
||
(fn() => self::$typeScript = 'resources/js/enums/index.ts')->bindTo(null, Enums::class)(); | ||
(fn() => self::$basePath = null)->bindTo(null, Enums::class)(); | ||
})->with([ | ||
App\Enums\Enum1::class, | ||
App\Enums\Enum2::class, | ||
Domain\Common\Enums\Enum3::class, | ||
Domain\Payouts\Enums\Enum4::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,5 @@ | ||
export enum Enum1 { | ||
One = 1, | ||
Two = 2, | ||
Three = 3, | ||
} |
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,3 @@ | ||
export enum Enum2 { | ||
|
||
} |
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,5 @@ | ||
export enum Enum3 { | ||
One = 'number 1', | ||
Two = 'number 2', | ||
Three = 'number 3', | ||
} |
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,5 @@ | ||
export enum Enum4 { | ||
One = 1, | ||
Two = 2, | ||
Three = 4, | ||
} |
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,21 @@ | ||
export enum Enum1 { | ||
One = 1, | ||
Two = 2, | ||
Three = 3, | ||
} | ||
|
||
export enum Enum2 { | ||
|
||
} | ||
|
||
export enum Enum3 { | ||
One = 'number 1', | ||
Two = 'number 2', | ||
Three = 'number 3', | ||
} | ||
|
||
export enum Enum4 { | ||
One = 1, | ||
Two = 2, | ||
Three = 4, | ||
} |