Completed
Push — master ( 37b487...f35336 )
by Jelle
21:42
created

TheSportsDbTest::testGetTeamsByLeague()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
namespace TheSportsDb\Test;
4
5
use TheSportsDb\Entity\EntityManagerInterface;
6
use TheSportsDb\Entity\EventInterface;
7
use TheSportsDb\Entity\LeagueInterface;
8
use TheSportsDb\Entity\PlayerInterface;
9
use TheSportsDb\Entity\SeasonInterface;
10
use TheSportsDb\Entity\SportInterface;
11
use TheSportsDb\Entity\TeamInterface;
12
use TheSportsDb\TheSportsDb;
13
14
/**
15
 * Generated by PHPUnit_SkeletonGenerator on 2016-08-31 at 11:28:14.
16
 */
17
class TheSportsDbTest extends \PHPUnit_Framework_TestCase {
18
19
  /**
20
   * @var TheSportsDb
21
   */
22
  protected $db;
23
24
  /**
25
   * Sets up the fixture, for example, opens a network connection.
26
   * This method is called before a test is executed.
27
   */
28
  protected function setUp() {
29
    include __DIR__ . '/../../default_bootstrap.php';
30
    $this->db = $db;
0 ignored issues
show
Bug introduced by
The variable $db does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
31
  }
32
33
  /**
34
   * Tears down the fixture, for example, closes a network connection.
35
   * This method is called after a test is executed.
36
   */
37
  protected function tearDown() {
38
39
  }
40
41
  /**
42
   * @covers TheSportsDb\TheSportsDb::getSports
43
   */
44
  public function testGetSports() {
45
    $sports = $this->db->getSports();
46
    $this->assertNotEmpty($sports);
47
    foreach ($sports as $sport) {
48
      // Should be a sport.
49
      $this->assertInstanceOf(SportInterface::class, $sport);
50
    }
51
  }
52
53
  /**
54
   * @covers TheSportsDb\TheSportsDb::getSport
55
   */
56 View Code Duplication
  public function testGetSport() {
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...
57
    $sport = $this->db->getSport('Soccer');
58
    // Should be a sport.
59
    $this->assertInstanceOf(SportInterface::class, $sport);
60
    $this->assertEquals('Soccer', $sport->getName());
61
62
    // Try a fake sport.
63
    $sport = $this->db->getSport('FakeSport123');
64
    // Should be a sport.
65
    $this->assertInstanceOf(SportInterface::class, $sport);
66
    $this->assertEquals('FakeSport123', $sport->getName());
67
68
    // Sport doesn't exist, so exception when we try to load its leagues.
69
    $this->expectException(\Exception::class);
70
    $this->expectExceptionMessage('Could not fully load sport with id FakeSport123.');
71
    $sport->getLeagues();
72
  }
73
74
  /**
75
   * @covers TheSportsDb\TheSportsDb::getLeagues
76
   */
77
  public function testGetLeagues() {
78
    $leagues = $this->db->getLeagues();
79
    $this->assertNotEmpty($leagues);
80
    foreach ($leagues as $league) {
81
      // Should be a league.
82
      $this->assertInstanceOf(LeagueInterface::class, $league);
83
    }
84
  }
85
86
  /**
87
   * @covers TheSportsDb\TheSportsDb::getLeague
88
   */
89 View Code Duplication
  public function testGetLeague() {
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...
90
    $league = $this->db->getLeague(4328);
91
    // Should be a sport.
92
    $this->assertInstanceOf(LeagueInterface::class, $league);
93
    $this->assertEquals('English Premier League', $league->getName());
94
95
    // Try a fake league.
96
    $league = $this->db->getLeague('FakeLeague123');
97
    // Should be a league.
98
    $this->assertInstanceOf(LeagueInterface::class, $league);
99
    $this->assertEquals('FakeLeague123', $league->getId());
100
101
    // League doesn't exist, so exception when we try to load its name.
102
    $this->expectException(\Exception::class);
103
    $this->expectExceptionMessage('Could not fully load league with id FakeLeague123.');
104
    $league->getName();
105
  }
106
107
  /**
108
   * @covers TheSportsDb\TheSportsDb::getLeaguesByCountry
109
   */
110 View Code Duplication
  public function testGetLeaguesByCountry() {
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...
111
    $leagues = $this->db->getLeaguesByCountry('Belgium');
112
    $this->assertNotEmpty($leagues);
113
    foreach ($leagues as $league) {
114
      // Should be a league.
115
      $this->assertInstanceOf(LeagueInterface::class, $league);
116
      $this->assertEquals('Belgium', $league->getCountry());
117
    }
118
119
    // Try a fake country.
120
    $leagues = $this->db->getLeaguesByCountry('FakeCountry123');
121
    $this->assertEmpty($leagues);
122
  }
123
124
  /**
125
   * @covers TheSportsDb\TheSportsDb::getLeaguesBySport
126
   */
127 View Code Duplication
  public function testGetLeaguesBySport() {
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...
128
    $leagues = $this->db->getLeaguesBySport('Soccer');
129
    $this->assertNotEmpty($leagues);
130
    foreach ($leagues as $league) {
131
      // Should be a league.
132
      $this->assertInstanceOf(LeagueInterface::class, $league);
133
      $this->assertEquals('Soccer', $league->getSport()->getName());
134
    }
135
136
    // Try a fake sport.
137
    $leagues = $this->db->getLeaguesByCountry('FakeSport123');
138
    $this->assertEmpty($leagues);
139
  }
140
141
  /**
142
   * @covers TheSportsDb\TheSportsDb::getLeaguesByCountryAndSport
143
   */
144
  public function testGetLeaguesByCountryAndSport() {
145
    $leagues = $this->db->getLeaguesByCountryAndSport('Belgium', 'Soccer');
146
    $this->assertNotEmpty($leagues);
147
    foreach ($leagues as $league) {
148
      // Should be a league.
149
      $this->assertInstanceOf(LeagueInterface::class, $league);
150
      $this->assertEquals('Belgium', $league->getCountry());
151
      $this->assertEquals('Soccer', $league->getSport()->getName());
152
    }
153
154
    // Try a fake country.
155
    $leagues = $this->db->getLeaguesByCountryAndSport('FakeCountry123', 'Soccer');
156
    $this->assertEmpty($leagues);
157
158
    // Try a fake sport.
159
    $leagues = $this->db->getLeaguesByCountryAndSport('Belgium', 'FakeSport123');
160
    $this->assertEmpty($leagues);
161
162
    // Try a fake country and sport.
163
    $leagues = $this->db->getLeaguesByCountryAndSport('FakeCountry123', 'FakeSport123');
164
    $this->assertEmpty($leagues);
165
  }
166
167
  /**
168
   * @covers TheSportsDb\TheSportsDb::getTeam
169
   */
170 View Code Duplication
  public function testGetTeam() {
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...
171
    $team = $this->db->getTeam(133604);
172
    // Should be a sport.
173
    $this->assertInstanceOf(TeamInterface::class, $team);
174
    $this->assertEquals('Arsenal', $team->getName());
175
176
    // Try a fake team.
177
    $team = $this->db->getTeam('FakeTeam123');
178
    // Should be a team.
179
    $this->assertInstanceOf(TeamInterface::class, $team);
180
    $this->assertEquals('FakeTeam123', $team->getId());
181
182
    // Sport doesn't exist, so exception when we try to load its teams.
183
    $this->expectException(\Exception::class);
184
    $this->expectExceptionMessage('Could not fully load team with id FakeTeam123.');
185
    $team->getName();
186
  }
187
188
  /**
189
   * @covers TheSportsDb\TheSportsDb::getTeamsByName
190
   */
191 View Code Duplication
  public function testGetTeamsByName() {
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...
192
    $teams = $this->db->getTeamsByName('Arsenal');
193
    $this->assertNotEmpty($teams);
194
195
    foreach ($teams as $team) {
196
      // Should be a team.
197
      $this->assertInstanceOf(TeamInterface::class, $team);
198
      $this->assertContains('Arsenal', $team->getName());
199
    }
200
201
    // Try a fake team.
202
    $teams = $this->db->getTeamsByName('FakeTeam123');
203
    $this->assertEmpty($teams);
204
  }
205
206
  /**
207
   * @covers TheSportsDb\TheSportsDb::getTeamsByLeague
208
   */
209 View Code Duplication
  public function testGetTeamsByLeague() {
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...
210
    $teams = $this->db->getTeamsByLeague(4328);
211
    $this->assertNotEmpty($teams);
212
213
    foreach ($teams as $team) {
214
      // Should be a team.
215
      $this->assertInstanceOf(TeamInterface::class, $team);
216
      $this->assertEquals(4328, $team->getLeague()->getId());
217
    }
218
219
    // Try a fake league.
220
    $teams = $this->db->getTeamsByLeague('FakeLeague123');
221
    $this->assertEmpty($teams);
222
  }
223
224
  /**
225
   * @covers TheSportsDb\TheSportsDb::getTeamsByLeagueName
226
   */
227 View Code Duplication
  public function testGetTeamsByLeagueName() {
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...
228
    $teams = $this->db->getTeamsByLeagueName('English Premier League');
229
    $this->assertNotEmpty($teams);
230
231
    foreach ($teams as $team) {
232
      // Should be a team.
233
      $this->assertInstanceOf(TeamInterface::class, $team);
234
      $this->assertEquals('English Premier League', $team->getLeague()->getName());
235
    }
236
237
    // Try a fake league.
238
    $teams = $this->db->getTeamsByLeagueName('FakeLeague123');
239
    $this->assertEmpty($teams);
240
  }
241
242
  /**
243
   * @covers TheSportsDb\TheSportsDb::getTeamsBySportAndCountry
244
   */
245
  public function testGetTeamsBySportAndCountry() {
246
    $teams = $this->db->getTeamsBySportAndCountry('Soccer', 'Belgium');
247
    $this->assertNotEmpty($teams);
248
    foreach ($teams as $team) {
249
      // Should be a team.
250
      $this->assertInstanceOf(TeamInterface::class, $team);
251
      $this->assertEquals('Belgium', $team->getCountry());
252
      $this->assertEquals('Soccer', $team->getSport()->getName());
253
    }
254
255
    // Try a fake country.
256
    $teams = $this->db->getTeamsBySportAndCountry('Soccer', 'FakeCountry123');
257
    $this->assertEmpty($teams);
258
259
    // Try a fake sport.
260
    $teams = $this->db->getTeamsBySportAndCountry('FakeSport123', 'Belgium');
261
    $this->assertEmpty($teams);
262
263
    // Try a fake country and sport.
264
    $teams = $this->db->getTeamsBySportAndCountry('FakeSport123', 'FakeCountry123');
265
    $this->assertEmpty($teams);
266
  }
267
268
  /**
269
   * @covers TheSportsDb\TheSportsDb::getPlayer
270
   */
271 View Code Duplication
  public function testGetPlayer() {
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...
272
    $player = $this->db->getPlayer(34145937);
273
    // Should be a sport.
274
    $this->assertInstanceOf(PlayerInterface::class, $player);
275
    $this->assertEquals('Mario Balotelli', $player->getName());
276
277
    // Try a fake player.
278
    $player = $this->db->getPlayer('FakePlayer123');
279
    // Should be a player.
280
    $this->assertInstanceOf(PlayerInterface::class, $player);
281
    $this->assertEquals('FakePlayer123', $player->getId());
282
283
    // Player doesn't exist, so exception when we try to load its sport.
284
    $this->expectException(\Exception::class);
285
    $this->expectExceptionMessage('Could not fully load player with id FakePlayer123.');
286
    $player->getSport();
287
  }
288
289
  /**
290
   * @covers TheSportsDb\TheSportsDb::getPlayersByTeam
291
   */
292 View Code Duplication
  public function testGetPlayersByTeam() {
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...
293
    $players = $this->db->getPlayersByTeam(133604);
294
    $this->assertNotEmpty($players);
295
296
    foreach ($players as $player) {
297
      // Should be a player.
298
      $this->assertInstanceOf(PlayerInterface::class, $player);
299
      $this->assertEquals(133604, $player->getTeam()->getId());
300
    }
301
302
    // Try a fake team.
303
    $players = $this->db->getPlayersByTeam('FakeTeam123');
304
    $this->assertEmpty($players);
305
  }
306
307
  /**
308
   * @covers TheSportsDb\TheSportsDb::getPlayersByTeamName
309
   */
310 View Code Duplication
  public function testGetPlayersByTeamName() {
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...
311
    $players = $this->db->getPlayersByTeamName('Arsenal');
312
    $this->assertNotEmpty($players);
313
314
    foreach ($players as $player) {
315
      // Should be a player.
316
      $this->assertInstanceOf(PlayerInterface::class, $player);
317
      $this->assertContains('Arsenal', $player->getTeam()->getName(), '', FALSE);
318
    }
319
320
    // Try a fake team.
321
    $players = $this->db->getPlayersByTeamName('FakeTeam123');
322
    $this->assertEmpty($players);
323
  }
324
325
  /**
326
   * @covers TheSportsDb\TheSportsDb::getPlayersByName
327
   */
328 View Code Duplication
  public function testGetPlayersByName() {
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...
329
    $players = $this->db->getPlayersByName('mario');
330
    $this->assertNotEmpty($players);
331
332
    foreach ($players as $player) {
333
      // Should be a player.
334
      $this->assertInstanceOf(PlayerInterface::class, $player);
335
      $this->assertContains('mario', $player->getName(), '', TRUE);
336
    }
337
338
    // Try a fake name.
339
    $players = $this->db->getPlayersByName('FakePlayer123');
340
    $this->assertEmpty($players);
341
  }
342
343
  /**
344
   * @covers TheSportsDb\TheSportsDb::getPlayersByTeamNameAndName
345
   */
346 View Code Duplication
  public function testGetPlayersByTeamNameAndName() {
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...
347
    $players = $this->db->getPlayersByTeamNameAndName('Arsenal', 'Ivan');
348
    $this->assertNotEmpty($players);
349
350
    foreach ($players as $player) {
351
      // Should be a player.
352
      $this->assertInstanceOf(PlayerInterface::class, $player);
353
      $this->assertContains('Ivan', $player->getName(), '', TRUE);
354
      $this->assertContains('Arsenal', $player->getTeam()->getName(), '', TRUE);
355
    }
356
357
    // Try a fake team.
358
    $players = $this->db->getPlayersByTeamNameAndName('FakeTeam123', 'Ivan');
359
    $this->assertEmpty($players);
360
361
    // Try a fake name.
362
    $players = $this->db->getPlayersByTeamNameAndName('Arsenal', 'FakePlayer123');
363
    $this->assertEmpty($players);
364
365
    // Try a fake team and name.
366
    $players = $this->db->getPlayersByTeamNameAndName('FakeTeam123', 'FakePlayer123');
367
    $this->assertEmpty($players);
368
  }
369
370
  /**
371
   * @covers TheSportsDb\TheSportsDb::getEvent
372
   */
373 View Code Duplication
  public function testGetEvent() {
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...
374
    $event = $this->db->getEvent(441613);
375
    // Should be an event.
376
    $this->assertInstanceOf(EventInterface::class, $event);
377
    $this->assertEquals('Liverpool vs Swansea', $event->getName());
378
379
    // Try a fake event.
380
    $event = $this->db->getEvent('FakeEvent123');
381
    // Should be an event.
382
    $this->assertInstanceOf(EventInterface::class, $event);
383
    $this->assertEquals('FakeEvent123', $event->getId());
384
385
    // Event doesn't exist, so exception when we try to load its sport.
386
    $this->expectException(\Exception::class);
387
    $this->expectExceptionMessage('Could not fully load event with id FakeEvent123.');
388
    $event->getLeague();
389
  }
390
391
  /**
392
   * @covers TheSportsDb\TheSportsDb::getEventsByName
393
   */
394 View Code Duplication
  public function testGetEventsByName() {
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...
395
    $events = $this->db->getEventsByName('Arsenal vs');
396
    $this->assertNotEmpty($events);
397
398
    foreach ($events as $event) {
399
      // Should be an event.
400
      $this->assertInstanceOf(EventInterface::class, $event);
401
      $this->assertContains('Arsenal vs', $event->getName(), '', TRUE);
402
    }
403
404
    // Try a fake name.
405
    $events = $this->db->getEventsByName('FakeTeam1 vs FakeTeam2');
406
    $this->assertEmpty($events);
407
  }
408
409
  /**
410
   * @covers TheSportsDb\TheSportsDb::getEventsByFileName
411
   */
412 View Code Duplication
  public function testGetEventsByFileName() {
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...
413
    $events = $this->db->getEventsByFileName('English Premier League');
414
    $this->assertNotEmpty($events);
415
416
    foreach ($events as $event) {
417
      // Should be an event.
418
      $this->assertInstanceOf(EventInterface::class, $event);
419
      $this->assertContains('English Premier League', $event->getFilename(), '', TRUE);
420
    }
421
422
    // Try a fake name.
423
    $events = $this->db->getEventsByFileName('FakeTeam1 vs FakeTeam2');
424
    $this->assertEmpty($events);
425
  }
426
427
  /**
428
   * @covers TheSportsDb\TheSportsDb::getEventsByNameAndSeason
429
   */
430 View Code Duplication
  public function testGetEventsByNameAndSeason() {
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...
431
    $events = $this->db->getEventsByNameAndSeason('Arsenal vs', '1415');
432
    $this->assertNotEmpty($events);
433
434
    foreach ($events as $event) {
435
      // Should be an event.
436
      $this->assertInstanceOf(EventInterface::class, $event);
437
      $this->assertContains('Arsenal vs', $event->getName(), '', TRUE);
438
      $this->assertEquals('1415', $event->getSeason()->getName());
439
    }
440
441
    // Try a fake name.
442
    $events = $this->db->getEventsByNameAndSeason('FakeTeam1 vs FakeTeam2', '1415');
443
    $this->assertEmpty($events);
444
445
    // Try a fake season.
446
    $events = $this->db->getEventsByNameAndSeason('Arsenal vs', 'FakeSeason123');
447
    $this->assertEmpty($events);
448
449
    // Try a fake name and season.
450
    $events = $this->db->getEventsByNameAndSeason('FakeTeam1 vs FakeTeam2', 'FakeSeason123');
451
    $this->assertEmpty($events);
452
  }
453
454
  /**
455
   * @covers TheSportsDb\TheSportsDb::getNextFiveEventsByTeam
456
   */
457 View Code Duplication
  public function testGetNextFiveEventsByTeam() {
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...
458
    $events = $this->db->getNextFiveEventsByTeam(133604);
459
    $this->assertNotEmpty($events);
460
    $this->assertEquals(5, count($events));
461
462
    foreach ($events as $event) {
463
      // Should be an event.
464
      $this->assertInstanceOf(EventInterface::class, $event);
465
      $this->assertContains(133604, array($event->getHomeTeam()->getId(), $event->getAwayTeam()->getId()));
466
    }
467
468
    // Try a fake name.
469
    // Bug in the api, see http://www.thesportsdb.com/forum/viewtopic.php?f=6&t=196&sid=99a29ba57ec8ee0a1b12d5f429348121
470
    //$events = $this->db->getNextFiveEventsByTeam('FakeTeam123');
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
471
    //$this->assertEmpty($events);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
472
  }
473
474
  /**
475
   * @covers TheSportsDb\TheSportsDb::getNextFifteenEventsByLeague
476
   */
477 View Code Duplication
  public function testGetNextFifteenEventsByLeague() {
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...
478
    $events = $this->db->getNextFifteenEventsByLeague(4328);
479
    $this->assertNotEmpty($events);
480
    $this->assertEquals(15, count($events));
481
482
    foreach ($events as $event) {
483
      // Should be an event.
484
      $this->assertInstanceOf(EventInterface::class, $event);
485
      $this->assertEquals(4328, $event->getLeague()->getId());
486
    }
487
488
    // Try a fake name.
489
    $events = $this->db->getNextFifteenEventsByLeague('FakeLeague123');
490
    $this->assertEmpty($events);
491
  }
492
493
  /**
494
   * @covers TheSportsDb\TheSportsDb::getNextFifteenEventsByLeagueAndRound
495
   */
496
  public function testGetNextFifteenEventsByLeagueAndRound() {
497
    $events = $this->db->getNextFifteenEventsByLeagueAndRound(4328, 38);
498
    $this->assertNotEmpty($events);
499
    $this->assertLessThanOrEqual(15, count($events));
500
501
    foreach ($events as $event) {
502
      // Should be an event.
503
      $this->assertInstanceOf(EventInterface::class, $event);
504
      $this->assertEquals(4328, $event->getLeague()->getId());
505
      $this->assertEquals(38, $event->getRound());
506
    }
507
508
    // Try a fake name.
509
    $events = $this->db->getNextFifteenEventsByLeague('FakeLeague123');
510
    $this->assertEmpty($events);
511
  }
512
513
  /**
514
   * @covers TheSportsDb\TheSportsDb::getLastFiveEventsByTeam
515
   */
516 View Code Duplication
  public function testGetLastFiveEventsByTeam() {
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...
517
    $events = $this->db->getLastFiveEventsByTeam(133604);
518
    $this->assertNotEmpty($events);
519
    $this->assertLessThanOrEqual(5, count($events));
520
521
    foreach ($events as $event) {
522
      // Should be an event.
523
      $this->assertInstanceOf(EventInterface::class, $event);
524
      $this->assertContains(133604, array($event->getHomeTeam()->getId(), $event->getAwayTeam()->getId()));
525
    }
526
527
    // Try a fake name.
528
    // Bug in the api, see http://www.thesportsdb.com/forum/viewtopic.php?f=6&t=196&sid=99a29ba57ec8ee0a1b12d5f429348121
529
    //$events = $this->db->getLastFiveEventsByTeam('FakeTeam123');
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
530
    //$this->assertEmpty($events);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
531
  }
532
533
  /**
534
   * @covers TheSportsDb\TheSportsDb::getLastFifteenEventsByLeague
535
   */
536 View Code Duplication
  public function testGetLastFifteenEventsByLeague() {
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...
537
    $events = $this->db->getLastFifteenEventsByLeague(4328);
538
    $this->assertNotEmpty($events);
539
    $this->assertLessThanOrEqual(15, count($events));
540
541
    foreach ($events as $event) {
542
      // Should be an event.
543
      $this->assertInstanceOf(EventInterface::class, $event);
544
      $this->assertEquals(4328, $event->getLeague()->getId());
545
    }
546
547
    // Try a fake name.
548
    $events = $this->db->getLastFifteenEventsByLeague('FakeLeague123');
549
    $this->assertEmpty($events);
550
  }
551
552
  /**
553
   * @covers TheSportsDb\TheSportsDb::getEventsByDay
554
   */
555
  public function testGetEventsByDay() {
556
    //http://www.thesportsdb.com/api/v1/json/1/eventsday.php?d=2014-10-10
557
    $day = new \DateTime();
558
    $day->setDate(2014, 1, 13);
559
    $events = $this->db->getEventsByDay($day);
560
    $this->assertNotEmpty($events);
561
562
    foreach ($events as $event) {
563
      // Should be an event.
564
      $this->assertInstanceOf(EventInterface::class, $event);
565
      $this->assertEquals($day->format('Y-m-d'), $event->getDate());
566
    }
567
568
    $events = $this->db->getEventsByDay($day, 'Soccer');
569
    $this->assertNotEmpty($events);
570
571
    foreach ($events as $event) {
572
      // Should be an event.
573
      $this->assertInstanceOf(EventInterface::class, $event);
574
      $this->assertEquals($day->format('Y-m-d'), $event->getDate());
575
      $this->assertEquals('Soccer', $event->getLeague()->getSport()->getName());
576
    }
577
578
    $events = $this->db->getEventsByDay($day, NULL, 'English Premier League');
579
    $this->assertNotEmpty($events);
580
581
    foreach ($events as $event) {
582
      // Should be an event.
583
      $this->assertInstanceOf(EventInterface::class, $event);
584
      $this->assertEquals($day->format('Y-m-d'), $event->getDate());
585
      $this->assertEquals('English Premier League', $event->getLeague()->getName());
586
    }
587
588
    $events = $this->db->getEventsByDay($day, 'Soccer', 'English Premier League');
589
    $this->assertNotEmpty($events);
590
591 View Code Duplication
    foreach ($events as $event) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
592
      // Should be an event.
593
      $this->assertInstanceOf(EventInterface::class, $event);
594
      $this->assertEquals($day->format('Y-m-d'), $event->getDate());
595
      $this->assertEquals('English Premier League', $event->getLeague()->getName());
596
      $this->assertEquals('Soccer', $event->getLeague()->getSport()->getName());
597
    }
598
599
    // Fake sport.
600
    // Bug in the api, see http://www.thesportsdb.com/forum/viewtopic.php?f=6&t=196&sid=99a29ba57ec8ee0a1b12d5f429348121
601
    //$events = $this->db->getEventsByDay($day, 'FakeSport123', 'English Premier League');
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
602
    //$this->assertEmpty($events);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
603
604
    // Fake league.
605
    $events = $this->db->getEventsByDay($day, 'Soccer', 'FakeLeague123');
606
    $this->assertEmpty($events);
607
608
    // Fake sport and league.
609
    $events = $this->db->getEventsByDay($day, 'FakeSport123', 'FakeLeague123');
610
    $this->assertEmpty($events);
611
612
  }
613
614
  /**
615
   * @covers TheSportsDb\TheSportsDb::getEventsByLeagueRoundAndSeason
616
   */
617
  public function testGetEventsByLeagueRoundAndSeason() {
618
    $events = $this->db->getEventsByLeagueRoundAndSeason(4328, 38, '1415');
619
    $this->assertNotEmpty($events);
620
621 View Code Duplication
    foreach ($events as $event) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
622
      // Should be an event.
623
      $this->assertInstanceOf(EventInterface::class, $event);
624
      $this->assertEquals(4328, $event->getLeague()->getId());
625
      $this->assertEquals(38, $event->getRound());
626
      $this->assertEquals('1415', $event->getSeason()->getName());
627
    }
628
629
    // Fake league.
630
    $events = $this->db->getEventsByLeagueRoundAndSeason('FakeLeague123', 38, '1415');
631
    $this->assertEmpty($events);
632
633
    // Fake round.
634
    $events = $this->db->getEventsByLeagueRoundAndSeason(4328, 'FakeRound123', '1415');
635
    $this->assertEmpty($events);
636
637
    // Fake season.
638
    $events = $this->db->getEventsByLeagueRoundAndSeason(4328, 38, 'FakeSeason123');
639
    $this->assertEmpty($events);
640
641
    // Fake league and round.
642
    $events = $this->db->getEventsByLeagueRoundAndSeason('FakeLeague123', 'FakeRound123', '1415');
643
    $this->assertEmpty($events);
644
645
    // Fake round and season.
646
    $events = $this->db->getEventsByLeagueRoundAndSeason(4328, 'FakeRound123', 'FakeSeason123');
647
    $this->assertEmpty($events);
648
649
    // Fake league and season.
650
    $events = $this->db->getEventsByLeagueRoundAndSeason('FakeLeague123', 38, 'FakeSeason123');
651
    $this->assertEmpty($events);
652
653
    // Fake league round and season.
654
    $events = $this->db->getEventsByLeagueRoundAndSeason('FakeLeague123', 'FakeRound123', 'FakeSeason123');
655
    $this->assertEmpty($events);
656
  }
657
658
  /**
659
   * @covers TheSportsDb\TheSportsDb::getEventsByLeagueAndSeason
660
   */
661
  public function testGetEventsByLeagueAndSeason() {
662
    $events = $this->db->getEventsByLeagueAndSeason(4328, '1415');
663
    $this->assertNotEmpty($events);
664
665
    foreach ($events as $event) {
666
      // Should be an event.
667
      $this->assertInstanceOf(EventInterface::class, $event);
668
      $this->assertEquals(4328, $event->getLeague()->getId());
669
      $this->assertEquals('1415', $event->getSeason()->getName());
670
    }
671
672
    // Fake league.
673
    $events = $this->db->getEventsByLeagueAndSeason('FakeLeague123', 38);
674
    $this->assertEmpty($events);
675
676
    // Fake season.
677
    $events = $this->db->getEventsByLeagueAndSeason(4328, 'FakeSeason123');
678
    $this->assertEmpty($events);
679
680
    // Fake league and season.
681
    $events = $this->db->getEventsByLeagueAndSeason('FakeLeague123', 'FakeSeason123');
682
    $this->assertEmpty($events);
683
  }
684
685
  /**
686
   * @covers TheSportsDb\TheSportsDb::getSeasonsByLeague
687
   */
688 View Code Duplication
  public function testGetSeasonsByLeague() {
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...
689
    $seasons = $this->db->getSeasonsByLeague(4328);
690
    $this->assertNotEmpty($seasons);
691
692
    foreach ($seasons as $season) {
693
      // Should be an event.
694
      $this->assertInstanceOf(SeasonInterface::class, $season);
695
      $this->assertEquals(4328, $season->getLeague()->getId());
696
    }
697
698
    // Try a fake league.
699
    $seasons = $this->db->getSeasonsByLeague('FakeLeague123');
700
    $this->assertEmpty($seasons);
701
  }
702
703
  /**
704
   * @covers TheSportsDb\TheSportsDb::setEntityManager
705
   */
706
  public function testSetEntityManager() {
707
    // Entity manager should be set during bootstrap.
708
    $this->expectException(\Exception::class);
709
    $this->expectExceptionMessage('Entity manager already set.');
710
    $this->db->setEntityManager($this->createMock(EntityManagerInterface::class));
711
  }
712
713
}
714