Last active
October 8, 2017 02:15
-
-
Save iambrianreich/0021227a04d0f41430a583469b177fce to your computer and use it in GitHub Desktop.
Testing a Trivial Exception Scenario in PHPUnit
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
<?php | |
namespace RWC\Math; | |
class Divider | |
{ | |
public function divide(float $divided, float $divisor) : float | |
{ | |
if($divisor == 0) | |
{ | |
throw new \InvalidArgumentException("Divide by zero."); | |
} | |
return $divided / $divisor; | |
} | |
} |
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
<?php | |
namespace Tests\RWC\Divider; | |
require_once( '../vendor/autoload.php'); | |
require_once('../Divider.php'); | |
use PHPUnit\Framework\TestCase; | |
class DividerTest extends TestCase | |
{ | |
/** | |
* @expectedException \InvalidArgumentException | |
*/ | |
public function testDivideByZeroException() | |
{ | |
$divider = new \RWC\Divider(); | |
$divider->divide(5, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment