GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 53bcfa...6873de )
by SignpostMarv
03:59
created

dataProviderGetterSetterGood()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftObject\Tests;
8
9
use Generator;
10
use SignpostMarv\DaftObject\NotPublicGetterPropertyException;
11
use SignpostMarv\DaftObject\NotPublicSetterPropertyException;
12
use SignpostMarv\DaftObject\PasswordHashTestObject;
13
14
class DaftObjectGetterSetterTest extends TestCase
15
{
16
    public function dataProviderGetterSetterGood() : array
17
    {
18
        return [
19
            [
20
                PasswordHashTestObject::class,
21
                'password',
22
                'asdf',
23
                false,
24
                true,
25
                'passwordHash',
26
            ],
27
            [
28
                PasswordHashTestObject::class,
29
                'passwordHash',
30
                password_hash('asdf', PASSWORD_DEFAULT),
31
                true,
32
                false,
33
            ],
34
        ];
35
    }
36
37
    public function dataProviderGetterBad() : iterable
38
    {
39
        $sources = $this->dataProviderGetterSetterGood();
40
41
        $generator = function () use ($sources) : Generator {
42
            foreach ($sources as $source) {
43
                if (false === $source[3]) {
44
                    yield [
45
                        $source[0],
46
                        $source[1],
47
                        $source[2],
48
                    ];
49
                }
50
            }
51
        };
52
53
        return $generator();
54
    }
55
56
    public function dataProviderSetterBad() : iterable
57
    {
58
        $sources = $this->dataProviderGetterSetterGood();
59
60
        $generator = function () use ($sources) : Generator {
61
            foreach ($sources as $source) {
62
                if (false === $source[4]) {
63
                    yield [
64
                        $source[0],
65
                        $source[1],
66
                        $source[2],
67
                    ];
68
                }
69
            }
70
        };
71
72
        return $generator();
73
    }
74
75
    /**
76
    * @dataProvider dataProviderGetterSetterGood
77
    */
78
    public function testGetterSetterGood(
79
        string $implementation,
80
        string $property,
81
        string $value,
82
        bool $publicGetter,
83
        bool $publicSetter,
84
        string $changedProperty = null
85
    ) : void {
86
        if (false === $publicGetter && false === $publicSetter) {
87
            $this->markTestSkipped(
88
                'Cannot run a test if property is neither a getter or setter'
89
            );
90
        } else {
91
            $arr = [];
92
93
            if ($publicGetter) {
94
                $arr[$property] = $value;
95
            }
96
97
            $obj = new $implementation($arr);
98
99
            if ($publicSetter) {
100
                $obj->$property = $value;
101
            }
102
103
            if ($publicGetter) {
104
                $this->assertSame($value, $obj->$property);
105
            } elseif ($publicSetter) {
106
                $this->assertTrue($obj->HasPropertyChanged($changedProperty));
107
            }
108
        }
109
    }
110
111
    /**
112
    * @dataProvider dataProviderGetterBad
113
    *
114
    * @depends testGetterSetterGood
115
    */
116
    public function testGetterBad(
117
        string $implementation,
118
        string $property,
119
        string $value
120
    ) : void {
121
        $obj = new $implementation([
122
            $property => $value,
123
        ]);
124
125
        $this->expectException(NotPublicGetterPropertyException::class);
126
        $this->expectExceptionMessage(
127
            sprintf(
128
                'Property not a public getter: %s::$%s',
129
                $implementation,
130
                $property
131
            )
132
        );
133
134
        $foo = $obj->$property;
0 ignored issues
show
Unused Code introduced by
The assignment to $foo is dead and can be removed.
Loading history...
135
    }
136
137
    /**
138
    * @dataProvider dataProviderSetterBad
139
    *
140
    * @depends testGetterSetterGood
141
    */
142
    public function testSetterBad(
143
        string $implementation,
144
        string $property,
145
        string $value
146
    ) : void {
147
        $obj = new $implementation();
148
149
        $this->expectException(NotPublicSetterPropertyException::class);
150
        $this->expectExceptionMessage(
151
            sprintf(
152
                'Property not a public setter: %s::$%s',
153
                $implementation,
154
                $property
155
            )
156
        );
157
158
        $obj->$property = $value;
159
    }
160
}
161