SkillSpecialTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 39
dl 0
loc 65
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 2 1
A testDo() 0 29 2
A generateCharacter() 0 12 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat\CombatActions;
5
6
use Tester\Assert;
7
use HeroesofAbenez\Combat\Character;
8
use HeroesofAbenez\Combat\CombatBase;
9
use HeroesofAbenez\Combat\CombatLogger;
10
use HeroesofAbenez\Combat\StaticSuccessCalculator;
11
use HeroesofAbenez\Combat\CombatLogEntry;
12
use HeroesofAbenez\Combat\SkillSpecial as Skill;
13
use HeroesofAbenez\Combat\CharacterSpecialSkill as CharacterSkill;
14
15
require __DIR__ . "/../../../bootstrap.php";
16
17
/**
18
 * @author Jakub Konečný
19
 * @testCase
20
 */
21
final class SkillSpecialTest extends \Tester\TestCase {
22
  protected CombatLogger $logger;
23
24
  use \Testbench\TCompiledContainer;
25
26
  public function setUp() {
27
    $this->logger = $this->getService(CombatLogger::class); // @phpstan-ignore assign.propertyType
28
  }
29
30
  protected function generateCharacter(int $id): Character {
31
    $stats = [
32
      "id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10,
33
      "dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10
34
    ];
35
    $skillData = [
36
      "id" => 1, "name" => "Skill Special", "levels" => 5, "type" => Skill::TYPE_BUFF, "duration" => 3,
37
      "target" => Skill::TARGET_SELF, "stat" => Character::STAT_DAMAGE, "value" => 10, "valueGrowth" => 2,
38
    ];
39
    $skill = new Skill($skillData);
40
    $characterSkill = new CharacterSkill($skill, 2);
41
    return new Character($stats, [], [], [$characterSkill]);
42
  }
43
44
  /*public function testShouldUse(): void {
0 ignored issues
show
introduced by
This comment is 62% valid code; is this commented out code?
Loading history...
45
    $character1 = $this->generateCharacter(1);
46
    $character2 = $this->generateCharacter(2);
47
    $combat = new CombatBase(clone $this->logger, new StaticSuccessCalculator());
48
    $combat->setDuelParticipants($character1, $character2);
49
    $action = new SkillSpecial();
50
    Assert::false($action->shouldUse($combat, $character1));
51
    for($i = 1; $i <= $character1->skills[0]->skill->cooldown; $i++) {
52
      $character1->skills[0]->decreaseCooldown();
53
    }
54
    Assert::true($action->shouldUse($combat, $character1));
55
  }*/
56
57
  public function testDo(): void {
58
    $character1 = $this->generateCharacter(1);
59
    $character2 = $this->generateCharacter(2);
60
    $combat = new CombatBase(clone $this->logger, new StaticSuccessCalculator());
61
    $combat->setDuelParticipants($character1, $character2);
62
    $combat->onCombatStart($combat);
63
    $combat->onRoundStart($combat);
64
    for($i = 1; $i <= $character1->skills[0]->skill->cooldown; $i++) {
65
      $character1->skills[0]->decreaseCooldown();
66
    }
67
    $action = new SkillSpecial();
68
    $action->do($combat, $character1);
69
    Assert::count(1, $combat->log);
70
    Assert::count(1, $combat->log->getIterator()[1]);
71
    /** @var CombatLogEntry $record */
72
    $record = $combat->log->getIterator()[1][0];
73
    Assert::type(CombatLogEntry::class, $record);
74
    Assert::same(SkillSpecial::ACTION_NAME, $record->action);
75
    Assert::same("Skill Special", $record->name);
76
    Assert::true($record->result);
77
    Assert::same(0, $record->amount);
78
    Assert::same($character1->name, $record->character1->name);
79
    Assert::same($character1->name, $record->character2->name);
80
    Assert::count(1, $character1->effects);
81
    $effect = $character1->effects[0];
82
    Assert::same(Skill::TYPE_BUFF, $effect->type);
83
    Assert::same(Character::STAT_DAMAGE, $effect->stat);
84
    Assert::same(12, $effect->value);
85
    Assert::same(3, $effect->duration);
86
  }
87
}
88
89
$test = new SkillSpecialTest();
90
$test->run();
91
?>