CombatLoggerTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 44
dl 0
loc 71
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A generateCharacter() 0 6 1
A testCount() 0 6 1
A testGetIterator() 0 11 3
A setUp() 0 2 1
A testInvalidStates() 0 7 1
A testTitle() 0 9 1
A testRendering() 0 15 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
require __DIR__ . "/../../bootstrap.php";
7
8
use Tester\Assert;
9
10
/**
11
 * @author Jakub Konečný
12
 * @testCase
13
 */
14
final class CombatLoggerTest extends \Tester\TestCase {
15
  use \Testbench\TCompiledContainer;
16
  
17
  protected function setUp() {
18
    $this->refreshContainer();
19
  }
20
  
21
  public function testInvalidStates(): void {
22
    /** @var CombatLogger $logger */
23
    $logger = $this->getService(CombatLogger::class);
24
    $logger->setTeams(new Team("Team1"), new Team("Team 2"));
25
    Assert::exception(function() use($logger) {
26
      $logger->setTeams(new Team("Team1"), new Team("Team 2"));
27
    }, ImmutableException::class);
28
  }
29
  
30
  public function testTitle(): void {
31
    $title = "ABC";
32
    /** @var CombatLogger $logger */
33
    $logger = $this->getService(CombatLogger::class);
34
    $logger->setTeams(new Team("Team1"), new Team("Team 2"));
35
    $logger->title = $title;
36
    Assert::same($title, $logger->title);
37
    $log = (string) $logger;
38
    Assert::contains("<title>$title Combat</title>", $log);
39
  }
40
  
41
  public function testCount(): void {
42
    /** @var CombatLogger $logger */
43
    $logger = $this->getService(CombatLogger::class);
44
    Assert::count(0, $logger);
45
    $logger->logText("abc");
46
    Assert::count(1, $logger);
47
  }
48
  
49
  protected function generateCharacter(int $id): Character {
50
    $stats = [
51
      "id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10,
52
      "dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10
53
    ];
54
    return new Character($stats);
55
  }
56
  
57
  public function testRendering(): void {
58
    /** @var CombatLogger $logger */
59
    $logger = $this->getService(CombatLogger::class);
60
    $team1 = new Team("Team 1");
61
    $team1[] = $this->generateCharacter(1);
62
    $team2 = new Team("Team 2");
63
    $team2[] = $this->generateCharacter(2);
64
    $logger->setTeams($team1, $team2);
65
    $logger->round = 1;
66
    $logger->logText("abc.abc");
67
    $logger->logText("abc.abc");
68
    $logger->round = 2;
69
    $logger->logText("abc.abc");
70
    $logger->logText("abc.abc");
71
    Assert::type("string", (string) $logger);
72
  }
73
  
74
  public function testGetIterator(): void {
75
    /** @var CombatLogger $logger */
76
    $logger = $this->getService(CombatLogger::class);
77
    $logger->round = 1;
78
    for($i = 1; $i <= 5; $i++) {
79
      $logger->logText("abc");
80
    }
81
    foreach($logger as $round => $actions) {
82
      Assert::same(1, $round);
83
      Assert::type("array", $actions);
84
      Assert::count(5, $actions);
85
    }
86
  }
87
}
88
89
$test = new CombatLoggerTest();
90
$test->run();
91
?>