-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
15 changed files
with
243 additions
and
72 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,45 @@ | ||
<?php | ||
|
||
use Laravel\Prompts\TextareaPrompt; | ||
|
||
it('succeeds if an enum already exists', function() { | ||
$this | ||
->artisan('enum:make', ['enum' => 'App/Enums/Enum1']) | ||
->expectsOutput('The enum App\Enums\Enum1 already exists.') | ||
->assertExitCode(0); | ||
}); | ||
|
||
it('fails if the backed option is not supported', function() { | ||
$this | ||
->artisan('enum:make', ['enum' => 'App/Enums/Test', 'cases' => ['one'], '--backed' => 'foo']) | ||
->expectsOutputToContain('The option --backed supports only') | ||
->assertExitCode(1); | ||
}); | ||
|
||
it('generates enums', function(string $enum, ?string $backed) { | ||
$command = $this->artisan('enum:make', [ | ||
'enum' => $enum, | ||
'cases' => ['CaseOne', 'CaseTwo'], | ||
'--backed' => $backed | ||
]); | ||
|
||
expect($command)->toGenerate($enum); | ||
})->with([ | ||
['App\Enums\Generated1', 'bitwise'], | ||
['Domain\Common\Enums\Generated2', 'snake'], | ||
['SubDirectory\Generated3', null], | ||
]); | ||
|
||
it('generates enums with prompts', function() { | ||
// Currently textarea() of Laravel Prompts seems to have some testing issues. | ||
// Apparently the method expectsQuestion() does not test textarea rightly. | ||
// In alternative, we fallback the prompt with the expected user input. | ||
TextareaPrompt::fallbackUsing(fn() => 'CaseOne' . PHP_EOL . 'CaseTwo'); | ||
|
||
$command = $this->artisan('enum:make') | ||
->expectsQuestion('The namespace of the enum', 'App\Enums\Generated1') | ||
->expectsQuestion('How cases should be backed', 'bitwise'); | ||
// ->expectsQuestion('The cases (one per line)', 'CaseOne' . PHP_EOL . 'CaseTwo'); | ||
|
||
expect($command)->toGenerate('App\Enums\Generated1'); | ||
}); |
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,30 @@ | ||
<?php | ||
|
||
use App\Enums\Enum1; | ||
use App\Enums\Enum2; | ||
use Cerbero\LaravelEnum\Enums; | ||
|
||
it('warns that no enums were annotated if invalid enums are provided', function() { | ||
$this | ||
->artisan('enum:ts', ['enums' => ['InvalidEnum']]) | ||
->expectsOutput('No enums to annotate.') | ||
->assertExitCode(0); | ||
}); | ||
|
||
it('warns that no enums were annotated if no enums can be found', function() { | ||
Enums::setPaths('noEnums'); | ||
|
||
$this | ||
->artisan('enum:ts', ['--all' => true]) | ||
->expectsOutput('No enums to annotate.') | ||
->assertExitCode(0); | ||
|
||
Enums::setPaths('app/Enums'); | ||
}); | ||
|
||
it('synchronizes all the discoverable enums', function() { | ||
expect($this->artisan('enum:ts', ['--all' => true]))->toTypeScript([ | ||
Enum1::class, | ||
Enum2::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 |
---|---|---|
@@ -1,102 +1,109 @@ | ||
<?php | ||
|
||
use Cerbero\LaravelEnum\SessionKeys; | ||
use Cerbero\LaravelEnum\Capsules\SessionKey; | ||
use Domain\Common\Enums\SessionKeys; | ||
use Illuminate\Support\Facades\Session; | ||
|
||
it('supports the exists() method', function() { | ||
Session::shouldReceive('exists')->with('PageViews')->andReturn(true); | ||
Session::shouldReceive('exists')->with('CartItems')->andReturn(true); | ||
|
||
expect(SessionKeys::PageViews->exists())->toBe(true); | ||
expect(SessionKeys::CartItems()->exists())->toBe(true); | ||
}); | ||
|
||
it('supports dynamic parameters', function() { | ||
Session::shouldReceive('exists')->with('Forms.123.Data')->andReturn(true); | ||
|
||
expect(SessionKeys::FormsData(123)->exists())->toBe(true); | ||
}); | ||
|
||
it('supports the missing() method', function() { | ||
Session::shouldReceive('missing')->with('PageViews')->andReturn(true); | ||
Session::shouldReceive('missing')->with('CartItems')->andReturn(true); | ||
|
||
expect(SessionKeys::PageViews->missing())->toBe(true); | ||
expect(SessionKeys::CartItems()->missing())->toBe(true); | ||
}); | ||
|
||
it('supports the has() method', function() { | ||
Session::shouldReceive('has')->with('PageViews')->andReturn(true); | ||
Session::shouldReceive('has')->with('CartItems')->andReturn(true); | ||
|
||
expect(SessionKeys::PageViews->hasValue())->toBe(true); | ||
expect(SessionKeys::CartItems()->hasValue())->toBe(true); | ||
}); | ||
|
||
it('supports the get() method', function() { | ||
Session::shouldReceive('get')->with('PageViews', 123)->andReturn('foo'); | ||
Session::shouldReceive('get')->with('CartItems', 123)->andReturn('foo'); | ||
|
||
expect(SessionKeys::PageViews->get(123))->toBe('foo'); | ||
expect(SessionKeys::CartItems()->get(123))->toBe('foo'); | ||
}); | ||
|
||
it('supports the pull() method', function() { | ||
Session::shouldReceive('pull')->with('PageViews', 123)->andReturn('foo'); | ||
Session::shouldReceive('pull')->with('CartItems', 123)->andReturn('foo'); | ||
|
||
expect(SessionKeys::PageViews->pull(123))->toBe('foo'); | ||
expect(SessionKeys::CartItems()->pull(123))->toBe('foo'); | ||
}); | ||
|
||
it('supports the hasOldInput() method', function() { | ||
Session::shouldReceive('hasOldInput')->with('PageViews')->andReturn(true); | ||
Session::shouldReceive('hasOldInput')->with('CartItems')->andReturn(true); | ||
|
||
expect(SessionKeys::PageViews->hasOldInput())->toBe(true); | ||
expect(SessionKeys::CartItems()->hasOldInput())->toBe(true); | ||
}); | ||
|
||
it('supports the getOldInput() method', function() { | ||
Session::shouldReceive('getOldInput')->with('PageViews', 123)->andReturn('foo'); | ||
Session::shouldReceive('getOldInput')->with('CartItems', 123)->andReturn('foo'); | ||
|
||
expect(SessionKeys::PageViews->getOldInput(123))->toBe('foo'); | ||
expect(SessionKeys::CartItems()->getOldInput(123))->toBe('foo'); | ||
}); | ||
|
||
it('supports the put() method', function() { | ||
Session::shouldReceive('put')->with('PageViews', 123); | ||
Session::shouldReceive('put')->with('CartItems', 123); | ||
|
||
expect(SessionKeys::PageViews->put(123))->toBe(SessionKeys::PageViews); | ||
expect(SessionKeys::CartItems()->put(123))->toBeInstanceOf(SessionKey::class); | ||
}); | ||
|
||
it('supports the remember() method', function() { | ||
$expectedCallback = Mockery::on(fn(Closure $callback) => $callback() === 'foo'); | ||
|
||
Session::shouldReceive('remember')->with('PageViews', $expectedCallback)->andReturn('foo'); | ||
Session::shouldReceive('remember')->with('CartItems', $expectedCallback)->andReturn('foo'); | ||
|
||
expect(SessionKeys::PageViews->remember(fn() => 'foo'))->toBe('foo'); | ||
expect(SessionKeys::CartItems()->remember(fn() => 'foo'))->toBe('foo'); | ||
}); | ||
|
||
it('supports the push() method', function() { | ||
Session::shouldReceive('push')->with('PageViews', 123); | ||
Session::shouldReceive('push')->with('CartItems', 123); | ||
|
||
expect(SessionKeys::PageViews->push(123))->toBe(SessionKeys::PageViews); | ||
expect(SessionKeys::CartItems()->push(123))->toBeInstanceOf(SessionKey::class); | ||
}); | ||
|
||
it('supports the increment() method', function() { | ||
Session::shouldReceive('increment')->with('PageViews', 2)->andReturn(10); | ||
Session::shouldReceive('increment')->with('CartItems', 2)->andReturn(10); | ||
|
||
expect(SessionKeys::PageViews->increment(2))->toBe(10); | ||
expect(SessionKeys::CartItems()->increment(2))->toBe(10); | ||
}); | ||
|
||
it('supports the decrement() method', function() { | ||
Session::shouldReceive('decrement')->with('PageViews', 2)->andReturn(10); | ||
Session::shouldReceive('decrement')->with('CartItems', 2)->andReturn(10); | ||
|
||
expect(SessionKeys::PageViews->decrement(2))->toBe(10); | ||
expect(SessionKeys::CartItems()->decrement(2))->toBe(10); | ||
}); | ||
|
||
it('supports the flash() method', function() { | ||
Session::shouldReceive('flash')->with('PageViews', 123); | ||
Session::shouldReceive('flash')->with('CartItems', 123); | ||
|
||
expect(SessionKeys::PageViews->flash(123))->toBe(SessionKeys::PageViews); | ||
expect(SessionKeys::CartItems()->flash(123))->toBeInstanceOf(SessionKey::class); | ||
}); | ||
|
||
it('supports the now() method', function() { | ||
Session::shouldReceive('now')->with('PageViews', 123); | ||
Session::shouldReceive('now')->with('CartItems', 123); | ||
|
||
expect(SessionKeys::PageViews->now(123))->toBe(SessionKeys::PageViews); | ||
expect(SessionKeys::CartItems()->now(123))->toBeInstanceOf(SessionKey::class); | ||
}); | ||
|
||
it('supports the remove() method', function() { | ||
Session::shouldReceive('remove')->with('PageViews')->andReturn('foo'); | ||
Session::shouldReceive('remove')->with('CartItems')->andReturn('foo'); | ||
|
||
expect(SessionKeys::PageViews->remove())->toBe('foo'); | ||
expect(SessionKeys::CartItems()->remove())->toBe('foo'); | ||
}); | ||
|
||
it('supports the forget() method', function() { | ||
Session::shouldReceive('forget')->with('PageViews'); | ||
Session::shouldReceive('forget')->with('CartItems'); | ||
|
||
expect(SessionKeys::PageViews->forget())->toBe(SessionKeys::PageViews); | ||
expect(SessionKeys::CartItems()->forget())->toBeInstanceOf(SessionKey::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 was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.