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

Rename ReactionType weight to mass #88

Merged
merged 2 commits into from
Jul 28, 2019
Merged
Changes from 1 commit
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
Next Next commit
Rename ReactionType weight to mass
antonkomarev committed Jul 28, 2019
commit 718034a80516b653469ec99faaafc9ffda8ae027
2 changes: 1 addition & 1 deletion contracts/ReactionType/Models/ReactionType.php
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ public function getId(): string;

public function getName(): string;

public function getWeight(): int;
public function getMass(): int;

public function isEqualTo(self $that): bool;

Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public function up(): void
Schema::create('love_reaction_types', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->tinyInteger('weight');
$table->tinyInteger('mass');
$table->timestamps();

$table->index('name');
24 changes: 12 additions & 12 deletions src/Console/Commands/ReactionTypeAdd.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ final class ReactionTypeAdd extends Command
protected $signature = 'love:reaction-type-add
{--default : Create default Like & Dislike reactions}
{--name= : The name of the reaction}
{--weight= : The weight of the reaction}';
{--mass= : The mass of the reaction}';

/**
* The console command description.
@@ -70,7 +70,7 @@ public function handle(): int
return 1;
}

$this->createReactionType($name, $this->resolveWeight());
$this->createReactionType($name, $this->resolveMass());

return 0;
}
@@ -80,11 +80,11 @@ private function createDefaultReactionTypes(): void
$types = [
[
'name' => 'Like',
'weight' => 1,
'mass' => 1,
],
[
'name' => 'Dislike',
'weight' => -1,
'mass' => -1,
],
];

@@ -97,21 +97,21 @@ private function createDefaultReactionTypes(): void
continue;
}

$this->createReactionType($type['name'], $type['weight']);
$this->createReactionType($type['name'], $type['mass']);
}
}

private function createReactionType(string $name, int $weight): void
private function createReactionType(string $name, int $mass): void
{
ReactionType::query()->create([
'name' => $name,
'weight' => $weight,
'mass' => $mass,
]);

$this->line(sprintf(
'Reaction type with name `%s` and weight `%d` was added.',
'Reaction type with name `%s` and mass `%d` was added.',
$name,
$weight
$mass
));
}

@@ -122,10 +122,10 @@ private function resolveName(): string
?? $this->resolveName();
}

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

private function sanitizeName(string $name): string
2 changes: 1 addition & 1 deletion src/Reaction/Models/Reaction.php
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ public function getType(): ReactionTypeContract

public function getWeight(): int
{
return $this->getType()->getWeight();
return $this->getType()->getMass();
}

public function isOfType(
10 changes: 5 additions & 5 deletions src/ReactionType/Models/ReactionType.php
Original file line number Diff line number Diff line change
@@ -25,17 +25,17 @@ final class ReactionType extends Model implements
protected $table = 'love_reaction_types';

protected $attributes = [
'weight' => 0,
'mass' => 0,
];

protected $fillable = [
'name',
'weight',
'mass',
];

protected $casts = [
'id' => 'string',
'weight' => 'integer',
'mass' => 'integer',
];

private static $nameCache = [];
@@ -87,9 +87,9 @@ public function getName(): string
return $this->getAttributeValue('name');
}

public function getWeight(): int
public function getMass(): int
{
return $this->getAttributeValue('weight');
return $this->getAttributeValue('mass');
}

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

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

$this->assertSame(0, $status);
@@ -141,19 +141,19 @@ public function it_cannot_create_type_when_name_exists_in_other_text_case(): voi
}

/** @test */
public function it_can_create_type_with_weight_argument(): void
public function it_can_create_type_with_mass_argument(): void
{
$this->withoutMockingConsoleOutput();
$typesCount = ReactionType::query()->count();
$status = $this->artisan('love:reaction-type-add', [
'--name' => 'TestName',
'--weight' => -4,
'--mass' => -4,
]);

$this->assertSame(0, $status);
$this->assertSame($typesCount + 1, ReactionType::query()->count());
$reactionType = ReactionType::query()->latest()->first();
$this->assertSame(-4, $reactionType->getWeight());
$this->assertSame(-4, $reactionType->getMass());
}

/** @test */
@@ -163,7 +163,7 @@ public function it_not_creates_default_types_without_default_option(): void
$typesCount = ReactionType::query()->count();
$status = $this->artisan('love:reaction-type-add', [
'--name' => 'TestName',
'--weight' => 4,
'--mass' => 4,
]);

$this->assertSame(0, $status);
@@ -177,8 +177,8 @@ public function it_has_valid_output_after_default_types_add(): void
{
$this
->artisan('love:reaction-type-add', ['--default' => true])
->expectsOutput('Reaction type with name `Like` and weight `1` was added.')
->expectsOutput('Reaction type with name `Dislike` and weight `-1` was added.')
->expectsOutput('Reaction type with name `Like` and mass `1` was added.')
->expectsOutput('Reaction type with name `Dislike` and mass `-1` was added.')
->assertExitCode(0);
}

@@ -187,7 +187,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', ['--mass' => '4'])
->expectsQuestion('How to name reaction type?', 'TestName')
->assertExitCode(0);

@@ -201,7 +201,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', ['--mass' => '4'])
->expectsQuestion('How to name reaction type?', null)
->expectsQuestion('How to name reaction type?', 'TestName')
->assertExitCode(0);
@@ -216,7 +216,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', ['--mass' => '4'])
->expectsQuestion('How to name reaction type?', ' ')
->expectsOutput('Reaction type with name `` is invalid.')
->assertExitCode(1);
@@ -225,40 +225,40 @@ public function it_throws_error_if_name_question_answered_with_whitespace(): voi
}

/** @test */
public function it_asks_for_weight_if_weight_argument_not_exists(): void
public function it_asks_for_mass_if_mass_argument_not_exists(): void
{
$typesCount = ReactionType::query()->count();
$this
->artisan('love:reaction-type-add', ['--name' => 'TestName'])
->expectsQuestion('What is the weight of this reaction type?', '4')
->expectsQuestion('What is the mass of this reaction type?', '4')
->assertExitCode(0);

$this->assertSame($typesCount + 1, ReactionType::query()->count());
$reactionType = ReactionType::query()->latest()->first();
$this->assertSame(4, $reactionType->getWeight());
$this->assertSame(4, $reactionType->getMass());
}

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

$this->assertSame($typesCount + 1, ReactionType::query()->count());
$reactionType = ReactionType::query()->latest()->first();
$this->assertSame(0, $reactionType->getWeight());
$this->assertSame(0, $reactionType->getMass());
}

/** @test */
public function it_has_valid_output_after_type_add(): void
{
$this
->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.')
->expectsQuestion('What is the mass of this reaction type?', 4)
->expectsOutput('Reaction type with name `TestName` and mass `4` was added.')
->assertExitCode(0);
}
}
4 changes: 2 additions & 2 deletions tests/Unit/Console/Commands/RecountTest.php
Original file line number Diff line number Diff line change
@@ -41,11 +41,11 @@ protected function setUp(): void

$this->likeType = factory(ReactionType::class)->create([
'name' => 'Like',
'weight' => 2,
'mass' => 2,
]);
$this->dislikeType = factory(ReactionType::class)->create([
'name' => 'Dislike',
'weight' => -2,
'mass' => -2,
]);
}

28 changes: 14 additions & 14 deletions tests/Unit/Reactable/Models/Traits/ReactableTest.php
Original file line number Diff line number Diff line change
@@ -293,10 +293,10 @@ public function it_can_get_reactables_join_reaction_counter_with_type(): void
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType1 = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactionType2 = factory(ReactionType::class)->create([
'weight' => 1,
'mass' => 1,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
@@ -395,7 +395,7 @@ public function it_can_select_custom_reactable_columns_on_get_reactable_join_rea
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType1 = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
@@ -537,7 +537,7 @@ public function it_can_order_by_reactions_weight(): void
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
@@ -573,7 +573,7 @@ public function it_select_default_reactable_columns_on_order_by_reactions_weight
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
@@ -608,7 +608,7 @@ public function it_can_select_custom_reactable_columns_on_order_by_reactions_wei
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
@@ -649,10 +649,10 @@ public function it_chain_join_reaction_counter_with_type_and_join_reaction_total
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType1 = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactionType2 = factory(ReactionType::class)->create([
'weight' => 1,
'mass' => 1,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
@@ -722,10 +722,10 @@ public function it_include_reaction_total_null_values_replaced_with_zero(): void
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType1 = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactionType2 = factory(ReactionType::class)->create([
'weight' => 1,
'mass' => 1,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
@@ -774,10 +774,10 @@ public function it_include_reaction_counter_null_values_replaced_with_zero(): vo
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType1 = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactionType2 = factory(ReactionType::class)->create([
'weight' => 1,
'mass' => 1,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
@@ -826,10 +826,10 @@ public function it_include_null_counter_and_total_values_in_chain_join_reaction_
{
factory(Reactant::class)->create(); // Needed to has not same ids with Reactant
$reactionType1 = factory(ReactionType::class)->create([
'weight' => 2,
'mass' => 2,
]);
$reactionType2 = factory(ReactionType::class)->create([
'weight' => 1,
'mass' => 1,
]);
$reactable1 = factory(Article::class)->create();
$reactable2 = factory(Article::class)->create();
Loading