for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Dice;
use PHPUnit\Framework\TestCase;
/**
* Test cases for class Dice.
*/
class DiceTest extends TestCase
{
* Construct object and verify that the object has the expected
* properties, use no arguments.
public function testCreateDice(): void
$die = new Dice();
$this->assertInstanceOf("\App\Dice\Dice", $die);
$res = $die->getAsString();
$this->assertNotEmpty($res);
}
* Roll the dice and assert value is within bounds.
public function testRollDice(): void
$res = $die->roll();
$res
$res = $die->getValue();
$this->assertTrue($res >= 1);
$this->assertTrue($res <= 6);
* Test that getValue returns the same value as returned by roll().
public function testGetValueAfterRoll(): void
$rolled = $die->roll();
$this->assertSame($rolled, $die->getValue());
* Test that getValue throws an exception if the dice has not been rolled yet.
public function testGetValueThrowsException(): void
$this->expectException(\LogicException::class);
$this->expectExceptionMessage("Dice has not been rolled yet.");
$die->getValue();