Skip to content

Commit

Permalink
Increase test coverage implement interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtree committed Feb 20, 2021
1 parent c25aedb commit 1344005
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/Contract/ParserInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Ouxsoft\LuckByDice\Contract;

interface ParserInterface
{

public function run($expression) : array;

}
23 changes: 23 additions & 0 deletions src/Contract/TurnInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Ouxsoft\LuckByDice\Contract;

use Ouxsoft\LuckByDice\Cup;
use Ouxsoft\LuckByDice\Parser;

interface TurnInterface
{

public function __construct(
Parser $parser,
Cup $cup,
string $expression = null
);

public function set(string $expression) : void;

public function roll() : int;

public function __toString() : string;

}
4 changes: 3 additions & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

namespace Ouxsoft\LuckByDice;

class Parser
use Ouxsoft\LuckByDice\Contract\ParserInterface;

class Parser implements ParserInterface
{
/**
* @param $expression
Expand Down
9 changes: 6 additions & 3 deletions src/Turn.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

namespace Ouxsoft\LuckByDice;

use Ouxsoft\LuckByDice\Contract\TurnInterface;

/**
* Class Turn
* @package Ouxsoft\LuckByDice
*/
class Turn
class Turn implements TurnInterface
{
/**
* @var Cup
Expand All @@ -32,7 +34,7 @@ class Turn
private $total;

/**
* Expression constructor.
* Turn constructor.
* @param Parser $parser
* @param Cup $cup
* @param string|null $expression
Expand All @@ -52,6 +54,7 @@ public function __construct(
}

/**
* Set dice notation
* @param string $expression "1d4+3*2,1d5,d5,10d5"
*/
public function set(string $expression) : void
Expand Down Expand Up @@ -83,4 +86,4 @@ public function __toString() : string
{
return (string) $this->total;
}
}
}
20 changes: 20 additions & 0 deletions tests/src/Unit/TurnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public function tearDown(): void
unset($this->turn);
}

/**
* @covers \Ouxsoft\LuckByDice\Turn::set
*/
public function testSet()
{
$this->turn->set("d3+3*3");
$outcome = $this->turn->roll();
$this->assertIsInt($outcome);
}

/**
* @covers \Ouxsoft\LuckByDice\Turn::roll
*/
Expand All @@ -37,4 +47,14 @@ public function testRoll()
$this->assertIsInt($outcome);
}

/**
* @covers \Ouxsoft\LuckByDice\Turn::__toString
*/
public function test__toString()
{
$this->turn->set("d6");
$outcome = (string) $this->turn;
$this->assertIsString($outcome);
}

}

0 comments on commit 1344005

Please sign in to comment.