Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change signature of Artisan reaction-type-add command #83

Merged
merged 2 commits into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to `laravel-love` will be documented in this file.
- ([#79](https://github.com/cybercog/laravel-love/pull/79)) Reacter model `isNotReactedTo` & `isNotReactedToWithType` methods replaced with single `hasNotReactedTo` method
- ([#79](https://github.com/cybercog/laravel-love/pull/79)) Reactant model `isReactedBy`&& `isReactedByWithType` methods replaced with single `isReactedBy` method
- ([#79](https://github.com/cybercog/laravel-love/pull/79)) Reactant model `isNotReactedBy`&& `isNotReactedByWithType` methods replaced with single `isNotReactedBy` method
- ([#83](https://github.com/cybercog/laravel-love/pull/83)) Artisan command `love:reaction-type-add` awaits options instead of arguments

## [7.2.1] - 2019-07-11

Expand Down
10 changes: 5 additions & 5 deletions src/Console/Commands/ReactionTypeAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ final class ReactionTypeAdd extends Command
* @var string
*/
protected $signature = 'love:reaction-type-add
{--default}
{name?}
{weight?}';
{--default : Create default Like & Dislike reactions}
{--name= : The name of the reaction}
{--weight= : The weight of the reaction}';

/**
* The console command description.
Expand Down Expand Up @@ -117,14 +117,14 @@ private function createReactionType(string $name, int $weight): void

private function resolveName(): string
{
return $this->argument('name')
return $this->option('name')
?? $this->ask('How to name reaction type?')
?? $this->resolveName();
}

private function resolveWeight(): int
{
return intval($this->argument('weight')
return intval($this->option('weight')
?? $this->ask('What is the weight of this reaction type?'));
}

Expand Down
32 changes: 16 additions & 16 deletions tests/Unit/Console/Commands/ReactionTypeAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public function it_can_create_type_with_name_argument(): void
$this->disableMocking();
$typesCount = ReactionType::query()->count();
$status = $this->artisan('love:reaction-type-add', [
'name' => 'TestName',
'weight' => 4,
'--name' => 'TestName',
'--weight' => 4,
]);

$this->assertSame(0, $status);
Expand All @@ -101,8 +101,8 @@ public function it_convert_type_name_to_studly_case(): void
$this->disableMocking();
$typesCount = ReactionType::query()->count();
$status = $this->artisan('love:reaction-type-add', [
'name' => 'test-name',
'weight' => 4,
'--name' => 'test-name',
'--weight' => 4,
]);

$this->assertSame(0, $status);
Expand All @@ -119,7 +119,7 @@ public function it_cannot_create_type_when_name_exists(): void
]);
$typesCount = ReactionType::query()->count();
$this
->artisan('love:reaction-type-add', ['name' => 'TestName'])
->artisan('love:reaction-type-add', ['--name' => 'TestName'])
->expectsOutput('Reaction type with name `TestName` already exists.')
->assertExitCode(1);

Expand All @@ -134,7 +134,7 @@ public function it_cannot_create_type_when_name_exists_in_other_text_case(): voi
]);
$typesCount = ReactionType::query()->count();
$this
->artisan('love:reaction-type-add', ['name' => 'test-name'])
->artisan('love:reaction-type-add', ['--name' => 'test-name'])
->expectsOutput('Reaction type with name `TestName` already exists.')
->assertExitCode(1);

Expand All @@ -147,8 +147,8 @@ public function it_can_create_type_with_weight_argument(): void
$this->disableMocking();
$typesCount = ReactionType::query()->count();
$status = $this->artisan('love:reaction-type-add', [
'name' => 'TestName',
'weight' => -4,
'--name' => 'TestName',
'--weight' => -4,
]);

$this->assertSame(0, $status);
Expand All @@ -163,8 +163,8 @@ public function it_not_creates_default_types_without_default_option(): void
$this->disableMocking();
$typesCount = ReactionType::query()->count();
$status = $this->artisan('love:reaction-type-add', [
'name' => 'TestName',
'weight' => 4,
'--name' => 'TestName',
'--weight' => 4,
]);

$this->assertSame(0, $status);
Expand All @@ -188,7 +188,7 @@ public function it_asks_for_name_if_name_argument_not_exists(): void
{
$typesCount = ReactionType::query()->count();
$this
->artisan('love:reaction-type-add', ['weight' => '4'])
->artisan('love:reaction-type-add', ['--weight' => '4'])
->expectsQuestion('How to name reaction type?', 'TestName')
->assertExitCode(0);

Expand All @@ -202,7 +202,7 @@ public function it_repeat_ask_for_name_if_name_question_not_answered(): void
{
$typesCount = ReactionType::query()->count();
$this
->artisan('love:reaction-type-add', ['weight' => '4'])
->artisan('love:reaction-type-add', ['--weight' => '4'])
->expectsQuestion('How to name reaction type?', null)
->expectsQuestion('How to name reaction type?', 'TestName')
->assertExitCode(0);
Expand All @@ -217,7 +217,7 @@ public function it_throws_error_if_name_question_answered_with_whitespace(): voi
{
$typesCount = ReactionType::query()->count();
$this
->artisan('love:reaction-type-add', ['weight' => '4'])
->artisan('love:reaction-type-add', ['--weight' => '4'])
->expectsQuestion('How to name reaction type?', ' ')
->expectsOutput('Reaction type with name `` is invalid.')
->assertExitCode(1);
Expand All @@ -230,7 +230,7 @@ public function it_asks_for_weight_if_weight_argument_not_exists(): void
{
$typesCount = ReactionType::query()->count();
$this
->artisan('love:reaction-type-add', ['name' => 'TestName'])
->artisan('love:reaction-type-add', ['--name' => 'TestName'])
->expectsQuestion('What is the weight of this reaction type?', '4')
->assertExitCode(0);

Expand All @@ -244,7 +244,7 @@ public function it_creates_type_with_zero_weight_if_not_answered(): void
{
$typesCount = ReactionType::query()->count();
$this
->artisan('love:reaction-type-add', ['name' => 'TestName'])
->artisan('love:reaction-type-add', ['--name' => 'TestName'])
->expectsQuestion('What is the weight of this reaction type?', null)
->assertExitCode(0);

Expand All @@ -257,7 +257,7 @@ public function it_creates_type_with_zero_weight_if_not_answered(): void
public function it_has_valid_output_after_type_add(): void
{
$this
->artisan('love:reaction-type-add', ['name' => 'TestName'])
->artisan('love:reaction-type-add', ['--name' => 'TestName'])
->expectsQuestion('What is the weight of this reaction type?', 4)
->expectsOutput('Reaction type with name `TestName` and weight `4` was added.')
->assertExitCode(0);
Expand Down