|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* Created by PhpStorm. |
|
5
|
|
|
* User: benedikt |
|
6
|
|
|
* Date: 10/1/17 |
|
7
|
|
|
* Time: 2:08 PM |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Exceptions; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use Tfboe\FmLib\Exceptions\PlayerAlreadyExists; |
|
14
|
|
|
use Tfboe\FmLib\Tests\Entity\Player; |
|
15
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class ValueNotValidTest |
|
19
|
|
|
* @package Tfboe\FmLib\Tests\Unit\Exceptions |
|
20
|
|
|
*/ |
|
21
|
|
|
class PlayerAlreadyExistsTest extends UnitTestCase |
|
22
|
|
|
{ |
|
23
|
|
|
//<editor-fold desc="Public Methods"> |
|
24
|
|
|
/** |
|
25
|
|
|
* @covers \Tfboe\FmLib\Exceptions\PlayerAlreadyExists::__construct |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testConstructor() |
|
28
|
|
|
{ |
|
29
|
|
|
$exc = new PlayerAlreadyExists([]); |
|
30
|
|
|
self::assertEquals($exc->getMessage(), "Some players do already exist!"); |
|
31
|
|
|
self::assertEquals(409, $exc->getCode()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @covers \Tfboe\FmLib\Exceptions\PlayerAlreadyExists::getJsonMessage |
|
36
|
|
|
* @uses \Tfboe\FmLib\Exceptions\PlayerAlreadyExists::__construct |
|
37
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\NumericalId::getId |
|
38
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Player |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testJsonMessage() |
|
41
|
|
|
{ |
|
42
|
|
|
$exc = new PlayerAlreadyExists([]); |
|
43
|
|
|
self::assertEquals(['message' => 'Some players do already exist', 'players' => []], $exc->getJsonMessage()); |
|
44
|
|
|
|
|
45
|
|
|
$player = new Player(); |
|
46
|
|
|
$player->setFirstName('first'); |
|
47
|
|
|
$player->setLastName('last'); |
|
48
|
|
|
$player->setBirthday(new \DateTime('1990-02-02')); |
|
49
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
|
50
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
|
51
|
|
|
$idProperty = self::getProperty(Player::class, 'id'); |
|
52
|
|
|
$idProperty->setValue($player, 0); |
|
53
|
|
|
|
|
54
|
|
|
$exc2 = new PlayerAlreadyExists([$player]); |
|
55
|
|
|
self::assertEquals(['message' => 'Some players do already exist', 'players' => [['firstName' => 'first', |
|
56
|
|
|
'lastName' => 'last', 'id' => 0, 'birthday' => '1990-02-02']]], $exc2->getJsonMessage()); |
|
57
|
|
|
|
|
58
|
|
|
$player2 = new Player(); |
|
59
|
|
|
$player2->setFirstName('first2'); |
|
60
|
|
|
$player2->setLastName('last2'); |
|
61
|
|
|
$player2->setBirthday(new \DateTime('1992-04-04')); |
|
62
|
|
|
$idProperty->setValue($player2, 1); |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$exc3 = new PlayerAlreadyExists([$player, $player2]); |
|
66
|
|
|
self::assertEquals(['message' => 'Some players do already exist', 'players' => [ |
|
67
|
|
|
['firstName' => 'first', 'lastName' => 'last', 'id' => 0, 'birthday' => '1990-02-02'], |
|
68
|
|
|
['firstName' => 'first2', 'lastName' => 'last2', 'id' => 1, 'birthday' => '1992-04-04']]], |
|
69
|
|
|
$exc3->getJsonMessage()); |
|
70
|
|
|
} |
|
71
|
|
|
//</editor-fold desc="Public Methods"> |
|
72
|
|
|
} |