Completed
Push — master ( 84309c...24e320 )
by Vincenzo
02:46
created

ModelsTest::testGetRandomMatchesOneTeam()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 36
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 36
rs 8.5806
cc 4
eloc 25
nc 4
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
	public function testGetRandomPlayer()
15
	{
16
		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller();
17
		$player = $rndF->getPlayer(null, $rndF->getLocale());
18
		$array = $player->toArray();
19
		print_r($array);
20
21
		$newPlayer = \App\Lib\DsManager\Models\Player::fromArray($array);
22
		print_r($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
		print_r($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', 'api/') as $nat) {
0 ignored issues
show
Bug introduced by
The expression \App\Lib\Helpers\Config:....localesSmall', 'api/') of type null is not traversable.
Loading history...
41
			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat);
42
			$coach = $rndF->getCoach();
43
			print_r($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', 'api/') as $nat) {
0 ignored issues
show
Bug introduced by
The expression \App\Lib\Helpers\Config:....localesSmall', 'api/') of type null is not traversable.
Loading history...
53
			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat);
54
			$player = $rndF->getPlayer();
55
			print_r($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
67
		//var_dump($team->toArray());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
68
		echo "\n" . $team->name . " avg:";
69
		echo $team->getAvgSkill();
70
71
		echo "\n Adding player:";
72
		$player = $rndF->getPlayer();
73
		var_dump($player->toArray());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($player->toArray()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
74
		$team->roster[] = $player;
75
		echo "\n new avg: ";
76
		echo $team->getAvgSkill();
77
		echo "\n age avg: ";
78
		echo $team->getAvgAge();
79
80
		echo "\ncoach:";
81
		print_r($team->coach->toArray());
82
83
		$teamArray = $team->toArray();
84
		print_r($teamArray);
85
86
		$newTeam = \App\Lib\DsManager\Models\Team::fromArray($teamArray);
87
		print_r($newTeam->toArray());
88
89
	}
90
91
	/**
92
	 * @group Teams
93
	 */
94
	public function testGetRandomTeams()
95
	{
96
		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
97
98
		for ($i = 1; $i <= 20; $i++) {
99
			echo "\n\n-------------";
100
			$team = $rndF->getTeam();
101
			echo "\n team: " . $team->name;
102
			echo "\n nat:  " . $team->nationality;
103
			echo "\n skill avg: ";
104
			echo $team->getAvgSkill();
105
			echo "\n age avg: ";
106
			echo $team->getAvgAge();
107
		}
108
	}
109
110
	/**
111
	 * @group Match
112
	 */
113
	public function testGetRandomMatch()
114
	{
115
		for ($i = 1; $i <= 30; $i++) {
116
			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
117
			$spanish = $rndF->getTeam();
118
			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
119
			$italian = $rndF->getTeam();
120
121
			echo "\n" . $italian->name . "(" . $italian->getAvgSkill() . ") - " . $spanish->name . "(" . $spanish->getAvgSkill() . ") ...... ";
122
			$result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray();
123
			echo $result['goalHome'] . " - " . $result['goalAway'];
124
			echo "\n\n";
125
		}
126
127
	}
128
129
	/**
130
	 * @group Matches
131
	 */
132
	public function testGetRandomMatchesOneTeam()
133
	{
134
		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
135
		$myTeam = $rndF->getTeam();
136
		$win = 0;
137
		$lost = 0;
138
		$draw = 0;
139
140
		for ($i = 1; $i <= 30; $i++) {
141
142
			$randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall', 'api/');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $randomLocale is correct as \App\Lib\Helpers\Config:....localesSmall', 'api/') (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...
143
			shuffle($randomLocale);
144
			$randomLocale = $randomLocale[0];
145
146
			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale);
147
			$opponent = $rndF->getTeam();
148
149
			echo "\n" . $opponent->name . "(" . $opponent->getAvgSkill() . ") - " . $myTeam->name . "(" . $myTeam->getAvgSkill() . ") ...... ";
150
			$result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray();
151
			echo $result['goalHome'] . " - " . $result['goalAway'];
152
			$result = $result['info'];
153
			if (!$result['isDraw']) {
154
				if ($result['winner']->name == $myTeam->name) {
155
					$win++;
156
				} else {
157
					$lost++;
158
				}
159
			} else {
160
				$draw++;
161
			}
162
			echo "\n";
163
		}
164
165
		echo "\nw:$win l:$lost d:$draw\n\n";
166
167
	}
168
169
	/**
170
	 * @group Module
171
	 */
172
	public function testModule()
173
	{
174
		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
175
		$team = $rndF->getTeam();
176
177
		$modules = \App\Lib\Helpers\Config::get("modules.modules", "api/");
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $modules is correct as \App\Lib\Helpers\Config:...dules.modules', 'api/') (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...
178
		$modules = array_keys($modules);
179
		foreach ($modules as $mod) {
180
			$module = new \App\Lib\DsManager\Models\Module($mod);
181
			echo "\n------------\n\n" . $module;
182
			echo "\nD: " . $module->isDefensive();
183
			echo "\nB: " . $module->isBalanced();
184
			echo "\nO: " . $module->isOffensive();
185
			echo "\n";
186
			print_r($module->getRoleNeeded());
187
			echo "\napplicable? ";
188
			if ($module->isApplicableToTeam($team)) {
189
				echo " yes";
190
			} else {
191
				echo " no";
192
			}
193
		}
194
		echo "\n";
195
		print_r($team->playersPerRoleArray());
196
	}
197
198
}
199