Skip to content

Instantly share code, notes, and snippets.

@iambrianreich
Last active October 8, 2017 02:15
Show Gist options
  • Save iambrianreich/0021227a04d0f41430a583469b177fce to your computer and use it in GitHub Desktop.
Save iambrianreich/0021227a04d0f41430a583469b177fce to your computer and use it in GitHub Desktop.
Testing a Trivial Exception Scenario in PHPUnit
<?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;
}
}
<?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