Skip to content

Commit

Permalink
Improve Reaction tests (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev authored Apr 9, 2023
1 parent 8bf5ff0 commit f75363d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 46 deletions.
70 changes: 34 additions & 36 deletions tests/Unit/Reaction/Models/ReactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function it_can_fill_rate(): void
'rate' => 4.0,
]);

$this->assertSame(4.0, $reaction->getAttribute('rate'));
$this->assertSame(4.0, $reaction->getRate());
}

/** @test */
Expand All @@ -79,37 +79,58 @@ public function it_throws_rate_out_of_range_on_fill_rate_with_overflow_value():
]);
}

/** @test */
public function it_has_default_rate_value(): void
{
$reaction = new Reaction();

$this->assertSame(Reaction::RATE_DEFAULT, $reaction->getAttribute('rate'));
$this->assertSame(Reaction::RATE_DEFAULT, $reaction->getRate());
}

/** @test */
public function it_casts_id_to_string(): void
{
$reaction = Reaction::factory()->make([
'id' => 4,
]);

$this->assertSame('4', $reaction->getAttribute('id'));
$this->assertSame('4', $reaction->getId());
}

/** @test */
public function it_casts_rate_to_float(): void
public function it_casts_int_rate_to_float(): void
{
$reaction = new Reaction([
'rate' => '4',
]);

$this->assertSame(4.0, $reaction->getAttribute('rate'));
$this->assertSame(4.0, $reaction->getRate());
}

/** @test */
public function it_casts_string_rate_to_float(): void
{
$reaction1 = new Reaction([
'rate' => '4',
]);
$reaction2 = new Reaction([
'rate' => '4.1',
]);

$this->assertSame(4.0, $reaction1->getRate());
$this->assertSame(4.1, $reaction2->getRate());
}

/** @test */
public function it_casts_null_rate_to_default_value(): void
{
$reaction = Reaction::factory()->create([
'rate' => null,
]);

$this->assertSame(Reaction::RATE_DEFAULT, $reaction->getRate());
}

/** @test */
public function it_casts_not_set_rate_to_default_value(): void
{
$reaction = new Reaction();

$this->assertSame(Reaction::RATE_DEFAULT, $reaction->getRate());
}

/** @test */
public function it_can_belong_to_type(): void
{
Expand Down Expand Up @@ -148,16 +169,6 @@ public function it_can_belong_to_reacter(): void
$this->assertTrue($reaction->reacter->is($reacter));
}

/** @test */
public function it_can_get_id(): void
{
$reaction = Reaction::factory()->make([
'id' => '4',
]);

$this->assertSame('4', $reaction->getId());
}

/** @test */
public function it_throws_exception_on_get_id_when_id_is_null(): void
{
Expand Down Expand Up @@ -242,19 +253,6 @@ public function it_throws_exception_on_get_type_when_type_is_null(): void
$reaction->getType();
}

/** @test */
public function it_can_get_rate(): void
{
/** @var \Cog\Laravel\Love\Reaction\Models\Reaction $reaction */
$reaction = Reaction::factory()->create([
'rate' => 2.0,
]);

$assertRate = $reaction->getRate();

$this->assertSame(2.0, $assertRate);
}

/** @test */
public function it_can_get_weight(): void
{
Expand Down
10 changes: 0 additions & 10 deletions tests/Unit/Reaction/Observers/ReactionObserverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@

final class ReactionObserverTest extends TestCase
{
/** @test */
public function it_sets_default_rate_value_when_rate_value_is_null(): void
{
$counter = Reaction::factory()->create([
'rate' => null,
]);

$this->assertSame(Reaction::RATE_DEFAULT, $counter->getAttribute('rate'));
}

/** @test */
public function it_creates_counter_on_reaction_created_when_counter_not_exists(): void
{
Expand Down

0 comments on commit f75363d

Please sign in to comment.