1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 10/1/17 |
7
|
|
|
* Time: 12:52 PM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Entity\Helpers; |
11
|
|
|
|
12
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
13
|
|
|
use Tfboe\FmLib\Entity\Helpers\Result; |
14
|
|
|
use Tfboe\FmLib\Entity\Helpers\ResultEntity; |
15
|
|
|
use Tfboe\FmLib\Exceptions\ValueNotValid; |
16
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class BaseEntityTest |
20
|
|
|
* @package Tfboe\FmLib\Tests\Unit\Entity\Helpers |
21
|
|
|
*/ |
22
|
|
|
class ResultEntityTest extends UnitTestCase |
23
|
|
|
{ |
24
|
|
|
//<editor-fold desc="Public Methods"> |
25
|
|
|
/** |
26
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::setPlayed |
27
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::isPlayed |
28
|
|
|
*/ |
29
|
|
|
public function testPlayed() |
30
|
|
|
{ |
31
|
|
|
$entity = $this->mock(); |
32
|
|
|
$played = true; |
33
|
|
|
$entity->setPlayed($played); |
|
|
|
|
34
|
|
|
self::assertEquals($played, $entity->isPlayed()); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::setResult |
39
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::getResult |
40
|
|
|
* @uses \Tfboe\FmLib\Helpers\BasicEnum |
41
|
|
|
*/ |
42
|
|
|
public function testResult() |
43
|
|
|
{ |
44
|
|
|
$mock = $this->mock(); |
45
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
46
|
|
|
$mock->setResult(Result::DRAW); |
|
|
|
|
47
|
|
|
self::assertEquals(Result::DRAW, $mock->getResult()); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::setResultA |
52
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::getResultA |
53
|
|
|
*/ |
54
|
|
|
public function testResultA() |
55
|
|
|
{ |
56
|
|
|
$entity = $this->mock(); |
57
|
|
|
$res = 1; |
58
|
|
|
$entity->setResultA($res); |
|
|
|
|
59
|
|
|
self::assertEquals($res, $entity->getResultA()); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::setResultB |
64
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::getResultB |
65
|
|
|
*/ |
66
|
|
|
public function testResultB() |
67
|
|
|
{ |
68
|
|
|
$entity = $this->mock(); |
69
|
|
|
$res = 1; |
70
|
|
|
$entity->setResultB($res); |
|
|
|
|
71
|
|
|
self::assertEquals($res, $entity->getResultB()); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @covers \Tfboe\FmLib\Entity\Helpers\ResultEntity::setResult |
76
|
|
|
* @uses \Tfboe\FmLib\Exceptions\ValueNotValid::__construct |
77
|
|
|
* @uses \Tfboe\FmLib\Helpers\BasicEnum |
78
|
|
|
*/ |
79
|
|
|
public function testResultNotValidException() |
80
|
|
|
{ |
81
|
|
|
$mock = $this->mock(); |
82
|
|
|
$this->expectException(ValueNotValid::class); |
83
|
|
|
$this->expectExceptionMessage( |
84
|
|
|
'The following value is not valid: 100 in Tfboe\FmLib\Entity\Helpers\Result. Possible values: 0, 1, 2, 3, 4.'); |
85
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
86
|
|
|
$mock->setResult(100); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
//</editor-fold desc="Public Methods"> |
89
|
|
|
|
90
|
|
|
//<editor-fold desc="Private Methods"> |
91
|
|
|
/** |
92
|
|
|
* @return MockObject|ResultEntity |
93
|
|
|
*/ |
94
|
|
|
private function mock(): MockObject |
95
|
|
|
{ |
96
|
|
|
return $this->getMockForTrait(ResultEntity::class); |
97
|
|
|
} |
98
|
|
|
//</editor-fold desc="Private Methods"> |
99
|
|
|
} |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: