1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: alec |
4
|
|
|
* Date: 09.11.18 |
5
|
|
|
* Time: 16:16 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Tests\Unit\Money; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use AlecRabbit\Money\CalculatorFactory; |
12
|
|
|
use AlecRabbit\Money\Contracts\CalculatorInterface; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class CalculatorFactorySecondTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public static $backupCalculator; |
18
|
|
|
public static $backupCalculators; |
19
|
|
|
|
20
|
|
|
/** @var \ReflectionProperty */ |
21
|
|
|
public static $calculator; |
22
|
|
|
/** @var \ReflectionProperty */ |
23
|
|
|
public static $calculators; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @test |
27
|
|
|
*/ |
28
|
|
|
public function throwsAnExceptionWhenCalculatorIsInvalidaddsCalculator(): void |
29
|
|
|
{ |
30
|
|
|
$this->expectException(\RuntimeException::class); |
31
|
|
|
CalculatorFactory::getCalculator(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function CalculatorIsValid(): void |
38
|
|
|
{ |
39
|
|
|
static::$calculators->setValue(static::$backupCalculators); |
40
|
|
|
/** @noinspection UnnecessaryAssertionInspection */ |
41
|
|
|
$this->assertInstanceOf(CalculatorInterface::class, CalculatorFactory::getCalculator()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @throws \ReflectionException |
46
|
|
|
*/ |
47
|
|
|
protected function setUp(): void |
48
|
|
|
{ |
49
|
|
|
$reflection = new \ReflectionClass(CalculatorFactory::class); |
50
|
|
|
|
51
|
|
|
static::$calculator = $reflection->getProperty('calculator'); |
52
|
|
|
static::$calculator->setAccessible(true); |
53
|
|
|
static::$backupCalculator = static::$calculator->getValue(); |
54
|
|
|
static::$calculator->setValue(null); |
55
|
|
|
|
56
|
|
|
static::$calculators = $reflection->getProperty('calculators'); |
57
|
|
|
static::$calculators->setAccessible(true); |
58
|
|
|
static::$backupCalculators = static::$calculators->getValue(); |
59
|
|
|
static::$calculators->setValue([]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function tearDown() |
63
|
|
|
{ |
64
|
|
|
static::$calculator->setValue(static::$backupCalculator); |
65
|
|
|
static::$calculators->setValue(static::$backupCalculators); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
} |