generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
ba174cc
commit 41c349f
Showing
2 changed files
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace KbhandariWeb\UnitConversions; | ||
|
||
class Temperature | ||
{ | ||
private float $celsius; | ||
|
||
public static function forCelsius(float $celsius): self | ||
{ | ||
return new static($celsius); | ||
} | ||
|
||
public function __construct(float $celsius) | ||
{ | ||
$this->celsius = $celsius; | ||
} | ||
|
||
public function toFahrenheit(): float | ||
{ | ||
return ($this->celsius * 1.8) + 32; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace KbhandariWeb\UnitConversions\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use KbhandariWeb\UnitConversions\Temperature; | ||
|
||
class TemperatureTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_can_convert_celsius_to_fahrenheit() | ||
{ | ||
$fahrenheit = Temperature::forCelsius(100)->toFahrenheit(); | ||
|
||
$this->assertEquals(212, $fahrenheit ); | ||
} | ||
} |