Skip to content

Commit

Permalink
Add example tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mosbth committed Apr 23, 2024
1 parent 7c097a7 commit a935057
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
38 changes: 38 additions & 0 deletions example/phpunit/.tests/Dice/DiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Mos\Dice;

use PHPUnit\Framework\TestCase;

/**
* Test cases for class Dice.
*/
class DiceTest extends TestCase
{
/**
* Construct object and verify it it a Dice object.
*/
public function testCreateObject()
{
$die = new Dice();
$this->assertInstanceOf("\Mos\Dice\Dice", $die);

$res = $die->getValue();
$exp = null;
$this->assertEquals($exp, $res);
}

/**
* Roll the dice and assert value is within bounds.
*/
public function testRollDice()
{
$die = new Dice();
$res = $die->roll();
$this->assertIsInt($res);

$res = $die->getValue();
$this->assertTrue($res >= 1);
$this->assertTrue($res <= 6);
}
}
33 changes: 33 additions & 0 deletions example/phpunit/.tests/Guess/GuessExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Mos\Guess;

use PHPUnit\Framework\TestCase;

/**
* Test cases for class Guess.
*/
class GuessExceptionTest extends TestCase
{
/**
* Verify GuessException when guess is to high.
*/
public function testGuessToHigh()
{
$guess = new Guess();

$this->expectException(GuessException::class);
$guess->makeGuess(101);
}

/**
* Verify GuessException when guess is to low.
*/
public function testGuessToLow()
{
$guess = new Guess();

$this->expectException(GuessException::class);
$guess->makeGuess(0);
}
}

0 comments on commit a935057

Please sign in to comment.