Completed
Push — master ( 57d73d...015892 )
by Vincenzo
03:10
created

ModelsTest::testGetRandomTeams()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 3
Metric Value
c 3
b 0
f 3
dl 0
loc 12
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
4
/**
5
 * Class ModelsTest
6
 */
7
class ModelsTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
10
11
    /**
12
     * @group Player
13
     */
14 View Code Duplication
    public function testGetRandomPlayer()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    {
16
        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller();
17
        $player = $rndF->getPlayer(null, $rndF->getLocale());
18
        $array = $player->toArray();
19
        $this->assertNotEmpty($array);
20
21
        $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($array);
22
        $this->assertNotEmpty($newPlayer->toArray());
23
    }
24
25
    /**
26
     * @group Coach
27
     */
28
    public function testGetRandomCoach()
29
    {
30
        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller();
31
        $coach = $rndF->getCoach();
32
        $this->assertNotEmpty($coach->toArray());
33
    }
34
35
    /**
36
     * @group Coaches
37
     */
38 View Code Duplication
    public function testGetRandomCoaches()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
0 ignored issues
show
Bug introduced by
The expression \App\Lib\Helpers\Config:...'generic.localesSmall') of type null is not traversable.
Loading history...
41
            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat);
42
            $coach = $rndF->getCoach();
43
            $this->assertNotEmpty($coach->toArray());
44
        }
45
    }
46
47
    /**
48
     * @group Players
49
     */
50 View Code Duplication
    public function testGetRandomPlayers()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
0 ignored issues
show
Bug introduced by
The expression \App\Lib\Helpers\Config:...'generic.localesSmall') of type null is not traversable.
Loading history...
53
            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat);
54
            $player = $rndF->getPlayer();
55
            $this->assertNotEmpty($player->toArray());
56
        }
57
    }
58
59
    /**
60
     * @group Team
61
     */
62
    public function testGetRandomTeam()
63
    {
64
        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
65
        $team = $rndF->getTeam();
66
        $this->assertNotEmpty($team);
67
        $this->assertNotEmpty($team->name);
68
        $this->assertNotEmpty($team->getAvgSkill());
69
70
        //After Adding a player
71
        $player = $rndF->getPlayer();
72
        $this->assertNotEmpty($player->toArray());
73
        $team->roster[] = $player;
74
        $this->assertNotEmpty($team->getAvgSkill());
75
        $this->assertNotEmpty($team->getAvgAge());
76
77
        $this->assertNotEmpty($team->coach->toArray());
78
79
        $teamArray = $team->toArray();
80
        $this->assertNotEmpty($teamArray);
81
82
        $newTeam = \App\Lib\DsManager\Models\Team::fromArray($teamArray);
83
        $this->assertNotEmpty($newTeam->toArray());
84
85
    }
86
87
    /**
88
     * @group Teams
89
     */
90
    public function testGetRandomTeams()
91
    {
92
        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
93
94
        for ($i = 1; $i <= 20; $i++) {
95
            $team = $rndF->getTeam();
96
            $this->assertNotEmpty($team->name);
97
            $this->assertNotEmpty($team->nationality);
98
            $this->assertNotEmpty($team->getAvgSkill());
99
            $this->assertNotEmpty($team->getAvgAge());
100
        }
101
    }
102
103
    /**
104
     * @group Match
105
     */
106
    public function testGetRandomMatch()
107
    {
108
        for ($i = 1; $i <= 30; $i++) {
109
            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
110
            $spanish = $rndF->getTeam();
111
            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
112
            $italian = $rndF->getTeam();
113
            $this->assertNotEmpty($spanish);
114
            $this->assertNotEmpty($italian);
115
            $this->assertNotEmpty($italian->name);
116
            $this->assertNotEmpty($spanish);
117
            $this->assertNotEmpty($spanish->name);
118
119
            $this->assertNotEmpty($italian->getAvgSkill());
120
            $this->assertNotEmpty($spanish->getAvgSkill());
121
            $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray();
122
            $this->assertNotEmpty($result);
123
            $this->assertGreaterThanOrEqual(0, $result['goalHome']);
124
            $this->assertGreaterThanOrEqual(0, $result['goalAway']);
125
126
        }
127
128
    }
129
130
    /**
131
     * @group Matches
132
     */
133
    public function testGetRandomMatchesOneTeam()
134
    {
135
        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
136
        $myTeam = $rndF->getTeam();
137
        $win = 0;
138
        $lost = 0;
139
        $draw = 0;
140
141
        for ($i = 1; $i <= 30; $i++) {
142
143
            $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $randomLocale is correct as \App\Lib\Helpers\Config:...'generic.localesSmall') (which targets App\Lib\Helpers\Config::get()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
144
            shuffle($randomLocale);
145
            $randomLocale = $randomLocale[0];
146
147
            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale);
148
            $opponent = $rndF->getTeam();
149
            $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray();
150
            $this->assertNotEmpty($result);
151
            $result = $result['info'];
152
            if (!$result['isDraw']) {
153
                if ($result['winner']->name == $myTeam->name) {
154
                    $win++;
155
                } else {
156
                    $lost++;
157
                }
158
            } else {
159
                $draw++;
160
            }
161
        }
162
        $this->assertGreaterThan(0, $win);
163
        $this->assertGreaterThan(0, $lost);
164
    }
165
166
    /**
167
     * @group Module
168
     */
169
    public function testModule()
170
    {
171
        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
172
        $team = $rndF->getTeam();
173
174
        $modules = \App\Lib\Helpers\Config::get("modules.modules");
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $modules is correct as \App\Lib\Helpers\Config::get('modules.modules') (which targets App\Lib\Helpers\Config::get()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
175
        $modules = array_keys($modules);
176
        foreach ($modules as $mod) {
177
            $module = new \App\Lib\DsManager\Models\Module($mod);
178
            $this->assertNotEmpty($module);
179
            $this->assertNotNull($module->isDefensive());
180
            $this->assertNotNull($module->isBalanced());
181
            $this->assertNotNull($module->isOffensive());
182
            $this->assertTrue(is_array($module->getRoleNeeded()));
183
        }
184
        $this->assertGreaterThan(0, $team->playersPerRoleArray());
185
    }
186
187
}
188