Skip to content

Commit

Permalink
Reescrevendo testes com as novas exceptions
Browse files Browse the repository at this point in the history
Agora que lançamos duas exceptions os testes devem esperar receber essas excpetions em alguns casos especificos
  • Loading branch information
DevCapu committed Jul 14, 2020
1 parent c7ea4d9 commit a94b791
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/Adapters/EnergeticNeeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function calculateTotalEnergyExpenditure(float $basalEnergyExpenditure, s

$elementNotExists = !in_array($activity, $avaliableActivities, true);
if ($elementNotExists) {
throw new InvalidArgumentException("Activity doesn't exists or basalEnergyExpenditure < 400");
throw new InvalidArgumentException("$activity doesn't exists");
}

if ($basalEnergyExpenditure < 400) {
Expand All @@ -86,7 +86,7 @@ public function calculateCaloriesToCommitObjective(float $totalEnergyExpenditure
$isNotAnObjective = !in_array($objective, $avaliableObjectives, true);

if ($isNotAnObjective) {
throw new InvalidArgumentException("$objective is not an objective or totalEnergyExpenditure < 400");
throw new InvalidArgumentException("$objective is not an objective");
}

if ($totalEnergyExpenditure < 400) {
Expand Down
15 changes: 12 additions & 3 deletions tests/Unit/Application/EnergeticNeedsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Unit\Application;

use App\Adapters\EnergeticNeeds;
use DomainException;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -79,7 +80,12 @@ public function testShouldCalculateTotalEnergyExependiture(): void
*/
public function testInvalidArgumentsShouldNotCalculateTotalEnergyExpenditure(float $basalEnergyExpenditure, string $activity): void
{
$this->expectException(InvalidArgumentException::class);
if ($basalEnergyExpenditure < 400) {
$this->expectException(DomainException::class);
} else {
$this->expectException(InvalidArgumentException::class);
}

$this->energeticNeeds->calculateTotalEnergyExpenditure($basalEnergyExpenditure, $activity);
}

Expand All @@ -96,7 +102,11 @@ public function testShouldCalculateCaloriesToCommitObjective(): void
*/
public function testShouldNotCalculateCaloriesToCommitObjective(float $totalEnergyExpenditure, string $objective): void
{
$this->expectException(InvalidArgumentException::class);
if ($totalEnergyExpenditure < 400) {
$this->expectException(DomainException::class);
} else {
$this->expectException(InvalidArgumentException::class);
}
$this->energeticNeeds->calculateCaloriesToCommitObjective($totalEnergyExpenditure, $objective);
}

Expand All @@ -121,7 +131,6 @@ public function calculateTotalEnergyExpenditureWithWrongArguments(): array
return [
[-78.0, 'littleActive'],
[1033.65, 'invalidArgument'],
[-8.0, 'invalidArgument']
];
}

Expand Down

0 comments on commit a94b791

Please sign in to comment.