goodVersionComponentParseMethodArgumentsProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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