@@ -5,22 +5,22 @@ |
||
| 5 | 5 | |
| 6 | 6 | class CreateMatchPlayersTable |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Run the migrations. |
|
| 10 | - * |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 13 | - public function run() |
|
| 14 | - { |
|
| 15 | - Capsule::schema()->dropIfExists('match_players'); |
|
| 16 | - Capsule::schema()->create('match_players', function (Blueprint $table) { |
|
| 17 | - $table->increments('id'); |
|
| 18 | - $table->integer('match_id'); |
|
| 19 | - $table->integer('team_id'); |
|
| 20 | - $table->integer('player_id')->default(0); |
|
| 21 | - $table->unsignedTinyInteger('goals')->default(0); |
|
| 22 | - $table->unsignedTinyInteger('vote')->default(6); |
|
| 23 | - $table->timestamps(); |
|
| 24 | - }); |
|
| 25 | - } |
|
| 8 | + /** |
|
| 9 | + * Run the migrations. |
|
| 10 | + * |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | + public function run() |
|
| 14 | + { |
|
| 15 | + Capsule::schema()->dropIfExists('match_players'); |
|
| 16 | + Capsule::schema()->create('match_players', function (Blueprint $table) { |
|
| 17 | + $table->increments('id'); |
|
| 18 | + $table->integer('match_id'); |
|
| 19 | + $table->integer('team_id'); |
|
| 20 | + $table->integer('player_id')->default(0); |
|
| 21 | + $table->unsignedTinyInteger('goals')->default(0); |
|
| 22 | + $table->unsignedTinyInteger('vote')->default(6); |
|
| 23 | + $table->timestamps(); |
|
| 24 | + }); |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | public function run() |
| 14 | 14 | { |
| 15 | 15 | Capsule::schema()->dropIfExists('match_players'); |
| 16 | - Capsule::schema()->create('match_players', function (Blueprint $table) { |
|
| 16 | + Capsule::schema()->create('match_players', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->integer('match_id'); |
| 19 | 19 | $table->integer('team_id'); |
@@ -8,227 +8,227 @@ |
||
| 8 | 8 | {
|
| 9 | 9 | |
| 10 | 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 | - $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 | - public function testGetRandomCoaches() |
|
| 39 | - {
|
|
| 40 | - foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
|
|
| 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 | - public function testGetRandomPlayers() |
|
| 51 | - {
|
|
| 52 | - foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
|
|
| 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->assertGreaterThanOrEqual( |
|
| 97 | - \App\Lib\Helpers\Config::get('generic.rosters')['min'],
|
|
| 98 | - count($team->roster) |
|
| 99 | - ); |
|
| 100 | - $this->assertNotEmpty($team->name); |
|
| 101 | - $this->assertNotEmpty($team->nationality); |
|
| 102 | - $this->assertNotEmpty($team->getAvgSkill()); |
|
| 103 | - $this->assertNotEmpty($team->getAvgAge()); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @group Match |
|
| 109 | - */ |
|
| 110 | - public function testGetRandomMatch() |
|
| 111 | - {
|
|
| 112 | - for ($i = 1; $i <= 30; $i++) {
|
|
| 113 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
|
|
| 114 | - $spanish = $rndF->getTeam(); |
|
| 115 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
|
|
| 116 | - $italian = $rndF->getTeam(); |
|
| 117 | - $this->assertNotEmpty($spanish); |
|
| 118 | - $this->assertNotEmpty($italian); |
|
| 119 | - $this->assertNotEmpty($italian->name); |
|
| 120 | - $this->assertNotEmpty($spanish); |
|
| 121 | - $this->assertNotEmpty($spanish->name); |
|
| 122 | - |
|
| 123 | - $this->assertNotEmpty($italian->getAvgSkill()); |
|
| 124 | - $this->assertNotEmpty($spanish->getAvgSkill()); |
|
| 125 | - $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray(); |
|
| 126 | - $this->assertNotEmpty($result); |
|
| 127 | - $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
| 128 | - $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
| 129 | - |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @group Match |
|
| 135 | - * @group MatchResult |
|
| 136 | - * @group matchresultoutput |
|
| 137 | - */ |
|
| 138 | - public function testMatchFromExistingTeams() |
|
| 139 | - {
|
|
| 140 | - $teamHome = 1; |
|
| 141 | - $teamAway = 2; |
|
| 142 | - $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first();
|
|
| 143 | - $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first();
|
|
| 144 | - $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray()); |
|
| 145 | - $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray()); |
|
| 146 | - |
|
| 147 | - $match = new \App\Lib\DsManager\Models\Match($home, $away); |
|
| 148 | - $result = $match->simulate()->toArray(); |
|
| 149 | - $this->assertNotEmpty($result); |
|
| 150 | - $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
| 151 | - $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
| 152 | - if ($result['goal_home'] > 0) {
|
|
| 153 | - $this->assertNotEmpty($result['info']['scorers']['home']); |
|
| 154 | - foreach ($result['info']['scorers']['home'] as $scorerHome) {
|
|
| 155 | - $this->assertEquals($scorerHome->team_id, $teamHome); |
|
| 156 | - } |
|
| 157 | - } else {
|
|
| 158 | - $this->assertEmpty($result['info']['scorers']['home']); |
|
| 159 | - } |
|
| 160 | - if ($result['goal_away'] > 0) {
|
|
| 161 | - $this->assertNotEmpty($result['info']['scorers']['away']); |
|
| 162 | - foreach ($result['info']['scorers']['away'] as $scorerAway) {
|
|
| 163 | - $this->assertEquals($scorerAway->team_id, $teamAway); |
|
| 164 | - } |
|
| 165 | - } else {
|
|
| 166 | - $this->assertEmpty($result['info']['scorers']['away']); |
|
| 167 | - } |
|
| 168 | - if ($result['goal_home'] == $result['goal_away']) {
|
|
| 169 | - $this->assertTrue($result['info']['is_draw']); |
|
| 170 | - } else {
|
|
| 171 | - $this->assertFalse($result['info']['is_draw']); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @group Matches |
|
| 177 | - */ |
|
| 178 | - public function testGetRandomMatchesOneTeam() |
|
| 179 | - {
|
|
| 180 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
|
|
| 181 | - $myTeam = $rndF->getTeam(); |
|
| 182 | - $myTeam->id = 1000; |
|
| 183 | - $win = 0; |
|
| 184 | - $lost = 0; |
|
| 185 | - $draw = 0; |
|
| 186 | - |
|
| 187 | - for ($i = 1; $i <= 2; $i++) {
|
|
| 188 | - |
|
| 189 | - $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall');
|
|
| 190 | - shuffle($randomLocale); |
|
| 191 | - $randomLocale = $randomLocale[0]; |
|
| 192 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale); |
|
| 193 | - $opponent = $rndF->getTeam(); |
|
| 194 | - $opponent->id = 6000; |
|
| 195 | - $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray(); |
|
| 196 | - $this->assertNotEmpty($result); |
|
| 197 | - $result = $result['info']; |
|
| 198 | - if (!$result['is_draw']) {
|
|
| 199 | - if ($result['winner_id'] == $myTeam->id) {
|
|
| 200 | - $win++; |
|
| 201 | - } else {
|
|
| 202 | - $lost++; |
|
| 203 | - } |
|
| 204 | - } else {
|
|
| 205 | - $draw++; |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - $this->assertGreaterThanOrEqual(0, $win); |
|
| 209 | - $this->assertGreaterThanOrEqual(0, $lost); |
|
| 210 | - $this->assertGreaterThanOrEqual(0, $draw); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @group Module |
|
| 215 | - */ |
|
| 216 | - public function testModule() |
|
| 217 | - {
|
|
| 218 | - $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
|
|
| 219 | - $team = $rndF->getTeam(); |
|
| 220 | - |
|
| 221 | - $modules = \App\Lib\Helpers\Config::get("modules.modules");
|
|
| 222 | - $modules = array_keys($modules); |
|
| 223 | - foreach ($modules as $mod) {
|
|
| 224 | - $module = new \App\Lib\DsManager\Models\Module($mod); |
|
| 225 | - $this->assertNotEmpty($module); |
|
| 226 | - $this->assertNotNull($module->isDefensive()); |
|
| 227 | - $this->assertNotNull($module->isBalanced()); |
|
| 228 | - $this->assertNotNull($module->isOffensive()); |
|
| 229 | - $this->assertTrue(is_array($module->getRoleNeeded())); |
|
| 230 | - } |
|
| 231 | - $this->assertGreaterThan(0, $team->playersPerRoleArray()); |
|
| 232 | - } |
|
| 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 | + $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 | + public function testGetRandomCoaches() |
|
| 39 | + {
|
|
| 40 | + foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
|
|
| 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 | + public function testGetRandomPlayers() |
|
| 51 | + {
|
|
| 52 | + foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
|
|
| 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->assertGreaterThanOrEqual( |
|
| 97 | + \App\Lib\Helpers\Config::get('generic.rosters')['min'],
|
|
| 98 | + count($team->roster) |
|
| 99 | + ); |
|
| 100 | + $this->assertNotEmpty($team->name); |
|
| 101 | + $this->assertNotEmpty($team->nationality); |
|
| 102 | + $this->assertNotEmpty($team->getAvgSkill()); |
|
| 103 | + $this->assertNotEmpty($team->getAvgAge()); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @group Match |
|
| 109 | + */ |
|
| 110 | + public function testGetRandomMatch() |
|
| 111 | + {
|
|
| 112 | + for ($i = 1; $i <= 30; $i++) {
|
|
| 113 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
|
|
| 114 | + $spanish = $rndF->getTeam(); |
|
| 115 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
|
|
| 116 | + $italian = $rndF->getTeam(); |
|
| 117 | + $this->assertNotEmpty($spanish); |
|
| 118 | + $this->assertNotEmpty($italian); |
|
| 119 | + $this->assertNotEmpty($italian->name); |
|
| 120 | + $this->assertNotEmpty($spanish); |
|
| 121 | + $this->assertNotEmpty($spanish->name); |
|
| 122 | + |
|
| 123 | + $this->assertNotEmpty($italian->getAvgSkill()); |
|
| 124 | + $this->assertNotEmpty($spanish->getAvgSkill()); |
|
| 125 | + $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray(); |
|
| 126 | + $this->assertNotEmpty($result); |
|
| 127 | + $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
| 128 | + $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
| 129 | + |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @group Match |
|
| 135 | + * @group MatchResult |
|
| 136 | + * @group matchresultoutput |
|
| 137 | + */ |
|
| 138 | + public function testMatchFromExistingTeams() |
|
| 139 | + {
|
|
| 140 | + $teamHome = 1; |
|
| 141 | + $teamAway = 2; |
|
| 142 | + $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first();
|
|
| 143 | + $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first();
|
|
| 144 | + $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray()); |
|
| 145 | + $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray()); |
|
| 146 | + |
|
| 147 | + $match = new \App\Lib\DsManager\Models\Match($home, $away); |
|
| 148 | + $result = $match->simulate()->toArray(); |
|
| 149 | + $this->assertNotEmpty($result); |
|
| 150 | + $this->assertGreaterThanOrEqual(0, $result['goal_away']); |
|
| 151 | + $this->assertGreaterThanOrEqual(0, $result['goal_home']); |
|
| 152 | + if ($result['goal_home'] > 0) {
|
|
| 153 | + $this->assertNotEmpty($result['info']['scorers']['home']); |
|
| 154 | + foreach ($result['info']['scorers']['home'] as $scorerHome) {
|
|
| 155 | + $this->assertEquals($scorerHome->team_id, $teamHome); |
|
| 156 | + } |
|
| 157 | + } else {
|
|
| 158 | + $this->assertEmpty($result['info']['scorers']['home']); |
|
| 159 | + } |
|
| 160 | + if ($result['goal_away'] > 0) {
|
|
| 161 | + $this->assertNotEmpty($result['info']['scorers']['away']); |
|
| 162 | + foreach ($result['info']['scorers']['away'] as $scorerAway) {
|
|
| 163 | + $this->assertEquals($scorerAway->team_id, $teamAway); |
|
| 164 | + } |
|
| 165 | + } else {
|
|
| 166 | + $this->assertEmpty($result['info']['scorers']['away']); |
|
| 167 | + } |
|
| 168 | + if ($result['goal_home'] == $result['goal_away']) {
|
|
| 169 | + $this->assertTrue($result['info']['is_draw']); |
|
| 170 | + } else {
|
|
| 171 | + $this->assertFalse($result['info']['is_draw']); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @group Matches |
|
| 177 | + */ |
|
| 178 | + public function testGetRandomMatchesOneTeam() |
|
| 179 | + {
|
|
| 180 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
|
|
| 181 | + $myTeam = $rndF->getTeam(); |
|
| 182 | + $myTeam->id = 1000; |
|
| 183 | + $win = 0; |
|
| 184 | + $lost = 0; |
|
| 185 | + $draw = 0; |
|
| 186 | + |
|
| 187 | + for ($i = 1; $i <= 2; $i++) {
|
|
| 188 | + |
|
| 189 | + $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall');
|
|
| 190 | + shuffle($randomLocale); |
|
| 191 | + $randomLocale = $randomLocale[0]; |
|
| 192 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale); |
|
| 193 | + $opponent = $rndF->getTeam(); |
|
| 194 | + $opponent->id = 6000; |
|
| 195 | + $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray(); |
|
| 196 | + $this->assertNotEmpty($result); |
|
| 197 | + $result = $result['info']; |
|
| 198 | + if (!$result['is_draw']) {
|
|
| 199 | + if ($result['winner_id'] == $myTeam->id) {
|
|
| 200 | + $win++; |
|
| 201 | + } else {
|
|
| 202 | + $lost++; |
|
| 203 | + } |
|
| 204 | + } else {
|
|
| 205 | + $draw++; |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + $this->assertGreaterThanOrEqual(0, $win); |
|
| 209 | + $this->assertGreaterThanOrEqual(0, $lost); |
|
| 210 | + $this->assertGreaterThanOrEqual(0, $draw); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @group Module |
|
| 215 | + */ |
|
| 216 | + public function testModule() |
|
| 217 | + {
|
|
| 218 | + $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
|
|
| 219 | + $team = $rndF->getTeam(); |
|
| 220 | + |
|
| 221 | + $modules = \App\Lib\Helpers\Config::get("modules.modules");
|
|
| 222 | + $modules = array_keys($modules); |
|
| 223 | + foreach ($modules as $mod) {
|
|
| 224 | + $module = new \App\Lib\DsManager\Models\Module($mod); |
|
| 225 | + $this->assertNotEmpty($module); |
|
| 226 | + $this->assertNotNull($module->isDefensive()); |
|
| 227 | + $this->assertNotNull($module->isBalanced()); |
|
| 228 | + $this->assertNotNull($module->isOffensive()); |
|
| 229 | + $this->assertTrue(is_array($module->getRoleNeeded())); |
|
| 230 | + } |
|
| 231 | + $this->assertGreaterThan(0, $team->playersPerRoleArray()); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | } |
@@ -8,91 +8,91 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class MatchResult extends Match |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var array |
|
| 13 | - */ |
|
| 14 | - protected $fillable = [ |
|
| 15 | - 'goal_home', |
|
| 16 | - 'goal_away', |
|
| 17 | - 'info', |
|
| 18 | - 'simulated' |
|
| 19 | - ]; |
|
| 11 | + /** |
|
| 12 | + * @var array |
|
| 13 | + */ |
|
| 14 | + protected $fillable = [ |
|
| 15 | + 'goal_home', |
|
| 16 | + 'goal_away', |
|
| 17 | + 'info', |
|
| 18 | + 'simulated' |
|
| 19 | + ]; |
|
| 20 | 20 | |
| 21 | - protected $hidden = [ |
|
| 22 | - 'home_team_id', |
|
| 23 | - 'away_team_id', |
|
| 24 | - 'created_at', |
|
| 25 | - 'updated_at' |
|
| 26 | - ]; |
|
| 21 | + protected $hidden = [ |
|
| 22 | + 'home_team_id', |
|
| 23 | + 'away_team_id', |
|
| 24 | + 'created_at', |
|
| 25 | + 'updated_at' |
|
| 26 | + ]; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $casts = [ |
|
| 32 | - 'info' => 'json', |
|
| 33 | - 'simulated' => 'boolean' |
|
| 34 | - ]; |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $casts = [ |
|
| 32 | + 'info' => 'json', |
|
| 33 | + 'simulated' => 'boolean' |
|
| 34 | + ]; |
|
| 35 | 35 | |
| 36 | - public static function resolveAttributes(array $attributes, $matchId) |
|
| 37 | - { |
|
| 38 | - if (array_key_exists('info', $attributes)) { |
|
| 39 | - if (array_key_exists('scorers', $attributes['info'])) { |
|
| 40 | - foreach ($attributes['info']['scorers']['home'] as $scorerHome) { |
|
| 41 | - self::addScorer($matchId, $attributes['home_team_id'], $scorerHome->id); |
|
| 42 | - } |
|
| 43 | - foreach ($attributes['info']['scorers']['away'] as $scorerAway) { |
|
| 44 | - self::addScorer($matchId, $attributes['away_team_id'], $scorerAway->id); |
|
| 45 | - } |
|
| 46 | - unset($attributes['info']['scorers']); |
|
| 47 | - } |
|
| 48 | - $attributes['info'] = json_encode($attributes['info']); |
|
| 49 | - } |
|
| 50 | - return $attributes; |
|
| 51 | - } |
|
| 36 | + public static function resolveAttributes(array $attributes, $matchId) |
|
| 37 | + { |
|
| 38 | + if (array_key_exists('info', $attributes)) { |
|
| 39 | + if (array_key_exists('scorers', $attributes['info'])) { |
|
| 40 | + foreach ($attributes['info']['scorers']['home'] as $scorerHome) { |
|
| 41 | + self::addScorer($matchId, $attributes['home_team_id'], $scorerHome->id); |
|
| 42 | + } |
|
| 43 | + foreach ($attributes['info']['scorers']['away'] as $scorerAway) { |
|
| 44 | + self::addScorer($matchId, $attributes['away_team_id'], $scorerAway->id); |
|
| 45 | + } |
|
| 46 | + unset($attributes['info']['scorers']); |
|
| 47 | + } |
|
| 48 | + $attributes['info'] = json_encode($attributes['info']); |
|
| 49 | + } |
|
| 50 | + return $attributes; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - private static function addScorer($matchId, $teamId, $playerId) |
|
| 54 | - { |
|
| 55 | - $scorer = MatchPlayer::where( |
|
| 56 | - [ |
|
| 57 | - 'match_id' => $matchId, |
|
| 58 | - 'team_id' => $teamId, |
|
| 59 | - 'player_id' => $playerId |
|
| 60 | - ] |
|
| 61 | - )->where('goals', '>', 0)->first(); |
|
| 62 | - if (!empty($scorer)) { |
|
| 63 | - $scorer->goals = $scorer->goals + 1; |
|
| 64 | - $scorer->vote = $scorer->vote + rand(0, 1); |
|
| 65 | - $scorer->save(); |
|
| 66 | - } else { |
|
| 67 | - MatchPlayer::create( |
|
| 68 | - [ |
|
| 69 | - 'match_id' => $matchId, |
|
| 70 | - 'team_id' => $teamId, |
|
| 71 | - 'player_id' => $playerId, |
|
| 72 | - 'goals' => 1 |
|
| 73 | - ] |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 53 | + private static function addScorer($matchId, $teamId, $playerId) |
|
| 54 | + { |
|
| 55 | + $scorer = MatchPlayer::where( |
|
| 56 | + [ |
|
| 57 | + 'match_id' => $matchId, |
|
| 58 | + 'team_id' => $teamId, |
|
| 59 | + 'player_id' => $playerId |
|
| 60 | + ] |
|
| 61 | + )->where('goals', '>', 0)->first(); |
|
| 62 | + if (!empty($scorer)) { |
|
| 63 | + $scorer->goals = $scorer->goals + 1; |
|
| 64 | + $scorer->vote = $scorer->vote + rand(0, 1); |
|
| 65 | + $scorer->save(); |
|
| 66 | + } else { |
|
| 67 | + MatchPlayer::create( |
|
| 68 | + [ |
|
| 69 | + 'match_id' => $matchId, |
|
| 70 | + 'team_id' => $teamId, |
|
| 71 | + 'player_id' => $playerId, |
|
| 72 | + 'goals' => 1 |
|
| 73 | + ] |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function scorers() |
|
| 79 | - { |
|
| 80 | - return $this->belongsToMany( |
|
| 81 | - Player::class, |
|
| 82 | - 'match_players', |
|
| 83 | - 'match_id' |
|
| 84 | - )->withPivot( |
|
| 85 | - 'team_id', |
|
| 86 | - 'goals' |
|
| 87 | - )->where( |
|
| 88 | - 'goals', '>', 0 |
|
| 89 | - ); |
|
| 90 | - } |
|
| 78 | + public function scorers() |
|
| 79 | + { |
|
| 80 | + return $this->belongsToMany( |
|
| 81 | + Player::class, |
|
| 82 | + 'match_players', |
|
| 83 | + 'match_id' |
|
| 84 | + )->withPivot( |
|
| 85 | + 'team_id', |
|
| 86 | + 'goals' |
|
| 87 | + )->where( |
|
| 88 | + 'goals', '>', 0 |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - public function scopeComplete($query) |
|
| 93 | - { |
|
| 94 | - return parent::scopeComplete($query)->with('scorers'); |
|
| 95 | - } |
|
| 92 | + public function scopeComplete($query) |
|
| 93 | + { |
|
| 94 | + return parent::scopeComplete($query)->with('scorers'); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | } |
| 99 | 99 | \ No newline at end of file |