Test Failed
Push — master ( 322b96...cb950d )
by Nelson
03:16
created

VersionComponentTestProvider::toStringProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 12
rs 9.9332
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Copyright © 2016-2019 Nelson Martell (http://nelson6e65.github.io)
6
 *
7
 * Licensed under The MIT License (MIT)
8
 * For full copyright and license information, please see the LICENSE
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright 2016-2019 Nelson Martell
12
 * @link      http://nelson6e65.github.io/php_nml/
13
 * @since     0.6.0
14
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
15
 * */
16
17
namespace NelsonMartell\Test\DataProviders;
18
19
use InvalidArgumentException;
20
21
use NelsonMartell\Test\Helpers\ConstructorMethodTester;
22
use NelsonMartell\Test\Helpers\ExporterPlugin;
23
use NelsonMartell\Test\Helpers\HasReadOnlyProperties;
24
use NelsonMartell\Test\Helpers\HasUnaccesibleProperties;
25
use NelsonMartell\Test\Helpers\IComparableTester;
26
use NelsonMartell\Test\Helpers\IComparerTester;
27
use NelsonMartell\Test\Helpers\IEquatableTester;
28
use NelsonMartell\Test\Helpers\ImplementsIConvertibleToString;
29
use NelsonMartell\Test\Helpers\ImplementsIStrictPropertiesContainer;
30
31
use NelsonMartell\VersionComponent;
32
33
/**
34
 * Data providers for NelsonMartell\Test\VersionComponent.
35
 *
36
 * @author Nelson Martell <[email protected]>
37
 * @since 0.6.0
38
 *
39
 * @internal
40
 * */
41
trait VersionComponentTestProvider
42
{
43
    use ConstructorMethodTester;
44
    use ExporterPlugin;
45
    use HasReadOnlyProperties;
46
    use HasUnaccesibleProperties;
47
    use IComparableTester;
48
    use IComparerTester;
49
    use IEquatableTester;
50
    use ImplementsIConvertibleToString;
51
    use ImplementsIStrictPropertiesContainer;
52
53
    public function unaccesiblePropertiesProvider()
54
    {
55
        $obj = new VersionComponent(null, 'beta');
56
57
        return [
58
            '$stringValue with case changed' => [$obj, 'StringValue'],
59
            '$intValue with case changed'    => [$obj, 'IntValue'],
60
        ];
61
    }
62
63
    public function goodConstructorArgumentsProvider()
64
    {
65
        return [
66
            'No args'           => [],
67
            'null values'       => [null, null],
68
            'Only integer part' => [1, null],
69
            'Only string part'  => [null, '-alpha'],
70
            'All arguments'     => [5, '-beta'],
71
            'Git describe'      => [19, '-g7575872'],
72
        ];
73
    }
74
75
    public function badConstructorArgumentsProvider()
76
    {
77
        return [
78
            'Negative integer part'        => [InvalidArgumentException::class, -1, null],
79
            'Invalid string value part'    => [InvalidArgumentException::class, 0, 'erróneo'],
80
            'Invalid type (float) for string part'  => [InvalidArgumentException::class, 0, 23.912],
81
            'Invalid type (object) for string part'  => [InvalidArgumentException::class, 0, new \stdClass],
82
            'Invalid type (array) for string part'  => [InvalidArgumentException::class, 0, ['no']],
83
        ];
84
    }
85
86
    public function objectInstanceProvider()
87
    {
88
        return [[new VersionComponent(1, '-beta')]];
89
    }
90
91
    public function readOnlyPropertiesProvider()
92
    {
93
        $obj = new VersionComponent(1, '-beta');
94
95
        return [
96
            [$obj, 'intValue', 1],
97
            [$obj, 'stringValue', '-beta'],
98
        ];
99
    }
100
101
    public function IComparableCompareToMethodArgumentsProvider()
102
    {
103
        $v                = new VersionComponent(1, '-alpha');
104
        $obj              = new \stdClass();
105
        $obj->intValue    = 1;
106
        $obj->stringValue = '-alpha';
107
108
        $args = [
109
            'Equals by reference' => [0, $v, $v],
110
            'Equals by value'     => [
111
                0,
112
                new VersionComponent(1, '-alpha'),
113
                VersionComponent::parse('1-alpha')
114
            ],
115
            'VersionComponent: >' => [
116
                1,
117
                new VersionComponent(1, '-beta'),
118
                VersionComponent::parse('1-alpha')
119
            ],
120
            'VersionComponent: <' => [
121
                -1,
122
                new VersionComponent(1, '-alpha'),
123
                VersionComponent::parse('1-beta')
124
            ],
125
            'VersionComponent | stdClass: null' => [
126
                null,
127
                $v,
128
                $obj
129
            ],
130
            'VersionComponent | null' => [
131
                1,
132
                $v,
133
                null
134
            ],
135
            'VersionComponent | VersionComponent (null)' => [
136
                -1,
137
                new VersionComponent(),
138
                new VersionComponent(1)
139
            ],
140
        ];
141
142
        return $args;
143
    }
144
145
146
    public function compareMethodArgumentsProvider()
147
    {
148
        $v                = new VersionComponent(1, '-alpha');
149
        $obj              = new \stdClass();
150
        $obj->intValue    = 1;
151
        $obj->stringValue = '-alpha';
152
153
        return [
154
            [-1, 'array', $v],
155
            [null, $v, $obj],
156
            [-1, [], $v],
157
        ];
158
    }
159
160
    public function compareMethodArraysProvider()
161
    {
162
        return [
163
            'VersionComponent[]' => [[
164
                VersionComponent::parse('0-4-g'),
165
                VersionComponent::parse('1-4-g'),
166
                VersionComponent::parse('2-3-g'),
167
                VersionComponent::parse('2-3-g726356'),
168
                VersionComponent::parse('2-4-g'),
169
                VersionComponent::parse('4-3-g'),
170
                VersionComponent::parse('4-3-gsh4hajk7'),
171
                VersionComponent::parse('4-3-gsh4hbjk7'),
172
                VersionComponent::parse('11-4-g'),
173
            ]],
174
            'VersionComponent[] + integer[]' => [[
175
                1,
176
                new VersionComponent(2, '-alpha'),
177
            ]],
178
            'VersionComponent[] + string[]'  => [[
179
                new VersionComponent(1, '-alpha'),
180
                '1-beta',
181
            ]],
182
            'VersionComponent[] + string[] (non parseable)'  => [[
183
                '----------',
184
                new VersionComponent(),
185
            ]],
186
            'VersionComponent[] + array[]'   => [[
187
                [],
188
                [0, 1, 0],
189
                new VersionComponent(1, '-alpha'),
190
            ]],
191
        ];
192
    }
193
194
    public function goodVersionComponentParseMethodArgumentsProvider()
195
    {
196
        return [
197
            [new VersionComponent(1, 'a0'), '1a0'],
198
            [new VersionComponent(2, '-3-g726351'), '2-3-g726351'],
199
            [new VersionComponent(3, '-beta'), '3-beta'],
200
            [new VersionComponent(0, '-alpha'), '0-alpha'],
201
            [new VersionComponent(0, '-beta2'), '0-beta2'],
202
            'string | empty'        => [new VersionComponent(), '      '], // Maybe should throw exception?
203
            'string | only spaces'  => [new VersionComponent(), ''], // Maybe should throw exception?
204
            'null'                  => [new VersionComponent(), null], // Maybe should throw exception?
205
            'integer'               => [new VersionComponent(7), 7],
206
            'VersionComponent'      => [new VersionComponent(999), new VersionComponent(999)],
207
        ];
208
    }
209
210
    public function badVersionComponentParseMethodArgumentsProvider()
211
    {
212
        return [
213
            'string | consecutive "-"'          => ['1a--0'],
214
            'string | invalid char: ó'          => ['1-erróneo'],
215
            'string | not starting in number'   => ['beta0'],
216
            'integer | < 0'                     => [-13],
217
            'stdClass'                          => [new \stdClass],
218
        ];
219
    }
220
221
    public function IEquatableMethodArgumentsProvider()
222
    {
223
        return [
224
            [true, new VersionComponent(1, '-alpha'), new VersionComponent(1, '-alpha')],
225
            [false, new VersionComponent(1, '-beta'), new VersionComponent(1, '-bet')],
226
            [false, new VersionComponent(3, '-dev'), new VersionComponent(1, '-dev')],
227
            [false, new VersionComponent(), null],
228
            [false, new VersionComponent(0), 0],
229
            [false, new VersionComponent(2), 2],
230
            [false, new VersionComponent(23), 2345654675675675673453],
231
            [false, new VersionComponent(0, '-dev'), '0-dev'],
232
            [false, new VersionComponent(1, '-alpha'), [1, '-alpha']],
233
            [false, new VersionComponent(), new \stdClass],
234
        ];
235
    }
236
237
    public function toStringProvider()
238
    {
239
        return [
240
            ['0', new VersionComponent(0)],
241
            ['', new VersionComponent()],
242
            ['', new VersionComponent(null, '')],
243
            ['', new VersionComponent(null, '  ')],
244
            ['', new VersionComponent(null)],
245
            ['', new VersionComponent(null, null)],
246
            ['1a', new VersionComponent(1, 'a')],
247
            ['1-beta', new VersionComponent(1, '-beta')],
248
            ['2-rc1-20-g8c5b85c', new VersionComponent(2, '-rc1-20-g8c5b85c')],
249
        ];
250
    }
251
252
253
    public function nullOrDefaultStatesProvider()
254
    {
255
        return [
256
            ['default', new VersionComponent(0)],
257
            ['null', new VersionComponent()],
258
            ['null', new VersionComponent(null, '')],
259
            ['null', new VersionComponent(null, '  ')],
260
            ['null', new VersionComponent(null)],
261
            ['null', new VersionComponent(null, null)],
262
            ['defined', new VersionComponent(1, 'a')],
263
            ['defined', new VersionComponent(1, '-beta')],
264
            ['defined', new VersionComponent(2, '-rc1-20-g8c5b85c')],
265
        ];
266
    }
267
}
268