TextCombatLogRenderTest::testRendering()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 53
rs 9.28
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
require __DIR__ . "/../../bootstrap.php";
7
8
use Tester\Assert;
9
use HeroesofAbenez\Combat\CombatActions;
10
11
/**
12
 * @author Jakub Konečný
13
 * @testCase
14
 */
15
final class TextCombatLogRenderTest extends \Tester\TestCase {
16
  use \Testbench\TCompiledContainer;
17
18
  protected function generateCharacter(int $id): Character {
19
    $stats = [
20
      "id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10,
21
      "dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10
22
    ];
23
    return new Character($stats);
24
  }
25
26
  public function testRendering(): void {
27
    /** @var TextCombatLogRender $render */
28
    $render = $this->getService(TextCombatLogRender::class);
29
    /** @var CombatLogger $logger */
30
    $logger = $this->getService(CombatLogger::class);
31
    $team1 = new Team("Team 1");
32
    $team1[] = $character1 = $this->generateCharacter(1);
33
    $team2 = new Team("Team 2");
34
    $team2[] = $character2 = $this->generateCharacter(2);
35
    $logger->setTeams($team1, $team2);
36
    $logger->round = 1;
37
    $logger->logText("abc.abc");
38
    $logger->log([
39
      "action" => CombatActions\Attack::ACTION_NAME, "name" => "", "result" => true, "amount" => 1,
40
      "character1" => $character1, "character2" => $character2,
41
    ]);
42
    $logger->log([
43
      "action" => CombatActions\Attack::ACTION_NAME, "name" => "", "result" => false, "amount" => 1,
44
      "character1" => $character2, "character2" => $character1,
45
    ]);
46
    $logger->round = 2;
47
    $logger->log([
48
      "action" => CombatActions\SkillAttack::ACTION_NAME, "name" => "Abc", "result" => true, "amount" => 1,
49
      "character1" => $character1, "character2" => $character2,
50
    ]);
51
    $logger->log([
52
      "action" => CombatActions\SkillAttack::ACTION_NAME, "name" => "Def", "result" => false, "amount" => 1,
53
      "character1" => $character2, "character2" => $character1,
54
    ]);
55
    $logger->log([
56
      "action" => CombatActions\SkillSpecial::ACTION_NAME, "name" => "Abc", "result" => true, "amount" => 1,
57
      "character1" => $character1, "character2" => $character2,
58
    ]);
59
    $logger->log([
60
      "action" => CombatActions\SkillSpecial::ACTION_NAME, "name" => "Def", "result" => false, "amount" => 1,
61
      "character1" => $character2, "character2" => $character1,
62
    ]);
63
    $logger->log([
64
      "action" => CombatActions\Heal::ACTION_NAME, "name" => "", "result" => true, "amount" => 1,
65
      "character1" => $character1, "character2" => $character2,
66
    ]);
67
    $logger->log([
68
      "action" => CombatActions\Heal::ACTION_NAME, "name" => "", "result" => false, "amount" => 1,
69
      "character1" => $character2, "character2" => $character1,
70
    ]);
71
    $logger->log([
72
      "action" => CombatLogEntry::ACTION_POISON, "name" => "", "result" => true, "amount" => 1,
73
      "character1" => $character1, "character2" => $character2,
74
    ]);
75
    $params = [
76
      "team1" => $team1, "team2" => $team2, "actions" => $logger->getIterator(), "title" => "",
77
    ];
78
    Assert::same(file_get_contents(__DIR__ . "/CombatLogExpected.latte"), $render->render($params));
79
  }
80
}
81
82
$test = new TextCombatLogRenderTest();
83
$test->run();
84
?>