1
|
|
|
<?php namespace Unit\Chekote\NounStore\Store; |
|
|
|
|
2
|
|
|
|
3
|
|
|
use Chekote\NounStore\Key; |
4
|
|
|
use Chekote\NounStore\Store; |
5
|
|
|
use Phake\IMock; |
6
|
|
|
use stdClass; |
7
|
|
|
use Unit\Chekote\NounStore\Assert\KeyPhake; |
8
|
|
|
use Unit\Chekote\NounStore\TestCase; |
9
|
|
|
use Unit\Chekote\Phake\Phake; |
10
|
|
|
|
11
|
|
|
abstract class StoreTestCase extends TestCase |
12
|
|
|
{ |
13
|
|
|
protected IMock|KeyPhake $key; |
14
|
|
|
|
15
|
|
|
protected IMock|StorePhake $store; |
16
|
|
|
|
17
|
|
|
/** the first value stored under self::KEY */ |
18
|
|
|
protected static stdClass $firstValue; |
19
|
|
|
|
20
|
|
|
/** the second value stored under self::KEY */ |
21
|
|
|
protected static stdClass $secondValue; |
22
|
|
|
|
23
|
|
|
/** the most recent value stored under self::KEY */ |
24
|
|
|
public static stdClass $mostRecentValue; |
25
|
|
|
|
26
|
|
|
const KEY = 'Car'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Sets up the classes initial static state. |
30
|
|
|
*/ |
31
|
|
|
public static function initialize(): void |
32
|
|
|
{ |
33
|
|
|
$car1 = new stdClass(); |
34
|
|
|
$car1->color = 'Red'; |
35
|
|
|
$car1->option = ['GPS', 'Heated Seats']; |
36
|
|
|
|
37
|
|
|
$car2 = new stdClass(); |
38
|
|
|
$car2->color = 'Blue'; |
39
|
|
|
$car2->option = ['Cruise Control', 'Air Conditioning']; |
40
|
|
|
|
41
|
|
|
self::$firstValue = $car1; |
42
|
|
|
self::$secondValue = $car2; |
43
|
|
|
self::$mostRecentValue = $car2; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Sets up the environment before each test. |
48
|
|
|
*/ |
49
|
|
|
public function setUp(): void |
50
|
|
|
{ |
51
|
|
|
$this->key = Phake::strictMock(Key::class); |
52
|
|
|
$this->store = Phake::strictMockWithConstructor(Store::class, $this->key); |
53
|
|
|
|
54
|
|
|
/* @noinspection PhpUndefinedFieldInspection */ |
55
|
|
|
Phake::makeVisible($this->store)->nouns = [self::KEY => [self::$firstValue, self::$secondValue]]; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Tears down the environment after each test. |
60
|
|
|
*/ |
61
|
|
|
public function tearDown(): void |
62
|
|
|
{ |
63
|
|
|
unset($this->key); |
64
|
|
|
unset($this->store); |
65
|
|
|
|
66
|
|
|
Phake::verifyExpectations(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
StoreTestCase::initialize(); |
71
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.