Failed Conditions
Push — complex_graph_v3 ( fca431...2b444c )
by Donald
01:28
created

GetTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 26 1
A happyPathDataProvider() 0 8 1
A testHappyPath() 0 2 1
A testInvalidKeyThrowsInvalidArgumentException() 0 7 1
1
<?php namespace Integration\Chekote\NounStore\Store;
2
3
use InvalidArgumentException;
4
5
class GetTest extends StoreTest
6
{
7
    /** @var string */
8
    const NOUN = 'Person';
9
10
    /** @var Car */
11
    protected $chevy;
12
13
    /** @var Car */
14
    protected $ford;
15
16
    /** @var Car */
17
    protected $kia;
18
19
    /** @var Car */
20
    protected $toyota;
21
22
    /** @var Person */
23
    protected $alice;
24
25
    /** @var Person */
26
    protected $bob;
27
28
    public function setUp()
29
    {
30
        parent::setUp();
31
32
        $this->kia = new Car();
33
        $this->kia->make = 'Kia';
34
35
        $this->toyota = new Car();
36
        $this->toyota->make = 'Toyota';
37
38
        $this->bob = new Person();
39
        $this->bob->name = 'Bob';
40
        $this->bob->car = [$this->kia, $this->toyota];
41
42
        $this->ford = new Car();
43
        $this->ford->make = 'Ford';
44
45
        $this->chevy = new Car();
46
        $this->chevy->make = 'Chevrolet';
47
48
        $this->alice = new Person();
49
        $this->alice-> name = 'Alice';
50
        $this->alice->car = [$this->ford, $this->chevy];
51
52
        $this->store->set(self::NOUN, $this->bob);
53
        $this->store->set(self::NOUN, $this->alice);
54
    }
55
56
    /**
57
     * @dataProvider happyPathDataProvider
58
     * @param string $key
59
     * @param mixed  $expectedValue
60
     */
61
    public function testHappyPath($key, $expectedValue, $message) {
62
        $this->assertSame($expectedValue, $this->store->get($key), $message);
63
    }
64
65
    public function happyPathDataProvider() {
66
        return [
67
            'Noun'                       => ['Person',               $this->alice,  'Alice is the most recent Person in the store'],
68
            'Nth Noun'                   => ['1st Person',           $this->bob,    'Bob is the 1st Person in the store'],
69
            'Related Noun'               => ["Person's car",         $this->chevy,  'Alice is the most recent Person in the store, and her most recent car is the Chevrolet'],
70
            'Related Nth Noun'           => ["Person's 1st car",     $this->ford,   'Alice is the most recent Person in the store, and her 1st car is the Ford'],
71
            'Nth Nouns Related Noun'     => ["1st Person's car",     $this->toyota, 'Bob is the 1st Person in the store, and his most recent car is the Toyota'],
72
            'Nth Nouns Related Nth Noun' => ["1st Person's 1st car", $this->kia,    'Bob is the 1st Person in the store, and his 1st car is the Kia'],
73
        ];
74
    }
75
76
    public function testInvalidKeyThrowsInvalidArgumentException() {
77
        $invalidKey = "Customer's's Car";
78
79
        $this->expectException(InvalidArgumentException::class);
80
        $this->expectExceptionMessage('Key syntax is invalid');
81
82
        $this->store->get($invalidKey);
83
    }
84
}
85
86
class Car
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
87
{
88
    /** @var string */
89
    public $make;
90
}
91
92
class Person
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
93
{
94
    /** @var Car[] */
95
    public $car;
96
97
    /** @var string */
98
    public $name;
99
}
100