Skip to content

Commit

Permalink
Add tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtree committed Feb 25, 2021
1 parent f64da8a commit 6d66739
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

/**
* Class Collection
* A Collection resides inside a Cup and contains one or more Dice with same amount of sides that can be later rolled
* along with a modifier for the roll and a multiplier.
* A Collection resides inside a Cup and contains one or more Dice with same amount of sides as well as a modifier and
* a multiplier for the roll outcome.
* @package Ouxsoft\LuckByDice
*/
class Collection implements
Expand Down Expand Up @@ -54,7 +54,7 @@ class Collection implements
public function __construct(int $amount, int $sides, int $modifier, int $multiplier)
{
if ($amount < 1) {
throw new OutOfRangeException('A DiceGroup must have at least one dice.');
throw new OutOfRangeException('A collection must have at least one dice.');
}

for ($i = 1; $i <= $amount; $i++) {
Expand Down
5 changes: 4 additions & 1 deletion src/Cup.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public function next() : void
$this->index++;
}

public function key()
/**
* @return int
*/
public function key() : int
{
return $this->index;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Factory/TurnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
class TurnFactory
{
/**
* @param string|null $notation
* @return Turn
*/
public static function getInstance(): Turn
public static function getInstance(string $notation = null): Turn
{
$abstractFactory = new ConcreteFactory();

Expand All @@ -28,7 +29,8 @@ public static function getInstance(): Turn
return new Turn(
$container['notation'],
$container['cup'],
$container['luck']
$container['luck'],
$notation
);
}
}
4 changes: 2 additions & 2 deletions src/Turn.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public function setLuck(int $luck)
}

/**
* Roll each dice group and total
* @return int
* Roll each dice group, update luck, and return outcome
* @return int total
*/
public function roll() : int
{
Expand Down
7 changes: 7 additions & 0 deletions tests/src/Unit/LuckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@ public function test__construct()
*/
public function testUpdate()
{
// luck decreases
$this->luck->update(20, 100);
$this->assertEquals(5, $this->luck->get() );

// luck increases
$this->luck->update(70, 100);
$this->assertEquals(6, $this->luck->get() );

// luck remains the same
$this->luck->update(50, 100);
$this->assertEquals(6, $this->luck->get() );

// luck can no go below zero
$this->luck->set(0);
$this->luck->update(1, 100);
$this->assertEquals(0, $this->luck->get() );
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/src/Unit/TurnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Ouxsoft\LivingMarkup\Tests\Unit;

use Ouxsoft\LuckByDice\Turn;
use PHPUnit\Framework\TestCase;
use Ouxsoft\LuckByDice\Factory\TurnFactory;

Expand All @@ -27,6 +28,18 @@ public function tearDown(): void
unset($this->turn);
}

/**
* @covers \Ouxsoft\LuckByDice\Turn::__construct
*/
public function test__construct() {
$this->assertInstanceOf(Turn::class, $this->turn);

$notation = 'd6';
$this->turn = TurnFactory::getInstance($notation);
$outcome = $this->turn->getNotation();
$this->assertEquals($notation, $outcome);
}

/**
* @covers \Ouxsoft\LuckByDice\Turn::setNotation
*/
Expand Down

0 comments on commit 6d66739

Please sign in to comment.