Completed
Push — master ( 446f2e...32b2c3 )
by Nelson
11:26
created

goodVersionComponentParseMethodArgumentsProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Content:
6
 * - Trait definition.
7
 *
8
 * Copyright © 2016 Nelson Martell (http://nelson6e65.github.io)
9
 *
10
 * Licensed under The MIT License (MIT)
11
 * For full copyright and license information, please see the LICENSE
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright 2016 Nelson Martell
15
 * @link      http://nelson6e65.github.io/php_nml/
16
 * @since     v0.6.0
17
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
18
 * */
19
20
namespace NelsonMartell\Test\DataProviders;
21
22
use NelsonMartell\VersionComponent;
23
use NelsonMartell\Test\Helpers\ExporterPlugin;
24
use NelsonMartell\Test\Helpers\ConstructorMethodTester;
25
use NelsonMartell\Test\Helpers\IComparableTester;
26
use NelsonMartell\Test\Helpers\IComparerTester;
27
use NelsonMartell\Test\Helpers\IEquatableTester;
28
29
/**
30
 * Data providers for NelsonMartell\Test\VersionComponent.
31
 *
32
 * @author Nelson Martell <[email protected]>
33
 * @internal
34
 * */
35
trait VersionComponentTestProvider
36
{
37
    use ExporterPlugin;
38
    use ConstructorMethodTester;
39
    use IComparableTester;
40
    use IComparerTester;
41
    use IEquatableTester;
42
43
    public function goodConstructorArgumentsProvider()
44
    {
45
        return [
46
            'No args'           => [],
47
            'null values'       => [null, null],
48
            'Only integer part' => [1, null],
49
            'Only string part'  => [null, '-alpha'],
50
            'All arguments'     => [5, '-beta'],
51
            'Git describe'      => [19, '-g7575872'],
52
        ];
53
    }
54
55
    public function badConstructorArgumentsProvider()
56
    {
57
        return [
58
            'Negative integer part'        => [-1, null],
59
            'Invalid string value part'    => [0, 'erróneo'],
60
            'Invalid type (float) for string part'  => [0, 23.912],
61
            'Invalid type (object) for string part'  => [0, new \stdClass],
62
            'Invalid type (array) for string part'  => [0, ['no']],
63
        ];
64
    }
65
66
    public function IComparableCompareToMethodArgumentsProvider()
67
    {
68
        $v = new VersionComponent(1, '-alpha');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
69
        $obj = new \stdClass();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
70
        $obj->intValue = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
71
        $obj->stringValue = '-alpha';
72
73
        $args = [
74
            'Equals by reference' => [0, $v, $v],
75
            'Equals by value'     => [
76
                0,
77
                new VersionComponent(1, '-alpha'),
78
                VersionComponent::parse('1-alpha')
79
            ],
80
            'VersionComponent: >' => [
81
                1,
82
                new VersionComponent(1, '-beta'),
83
                VersionComponent::parse('1-alpha')
84
            ],
85
            'VersionComponent: <' => [
86
                -1,
87
                new VersionComponent(1, '-alpha'),
88
                VersionComponent::parse('1-beta')
89
            ],
90
            'VersionComponent | stdClass: null' => [
91
                null,
92
                $v,
93
                $obj
94
            ],
95
            'VersionComponent | null' => [
96
                1,
97
                $v,
98
                null
99
            ],
100
            'VersionComponent | VersionComponent (null)' => [
101
                -1,
102
                new VersionComponent(),
103
                new VersionComponent(1)
104
            ],
105
        ];
106
107
        return $args;
108
    }
109
110
111
    public function compareMethodArgumentsProvider()
112
    {
113
        $v = new VersionComponent(1, '-alpha');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
114
        $obj = new \stdClass();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
115
        $obj->intValue = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
116
        $obj->stringValue = '-alpha';
117
118
        return [
119
            [-1, 'array', $v],
120
            [null, $v, $obj],
121
            [-1, [], $v],
122
        ];
123
    }
124
125
    public function compareMethodArraysProvider()
126
    {
127
        return [
128
            'VersionComponent[]' => [[
129
                VersionComponent::parse("0-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 0-4-g does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
130
                VersionComponent::parse("1-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 1-4-g does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
131
                VersionComponent::parse("2-3-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2-3-g does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
132
                VersionComponent::parse("2-3-g726356"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2-3-g726356 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
133
                VersionComponent::parse("2-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2-4-g does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
134
                VersionComponent::parse("4-3-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 4-3-g does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
135
                VersionComponent::parse("4-3-gsh4hajk7"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 4-3-gsh4hajk7 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
136
                VersionComponent::parse("4-3-gsh4hbjk7"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 4-3-gsh4hbjk7 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
137
                VersionComponent::parse("11-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 11-4-g does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
138
            ]],
139
            'VersionComponent[] + integer[]' => [[
140
                1,
141
                new VersionComponent(2, '-alpha'),
142
            ]],
143
            'VersionComponent[] + string[]'  => [[
144
                new VersionComponent(1, '-alpha'),
145
                '1-beta',
146
            ]],
147
            'VersionComponent[] + string[] (non parseable)'  => [[
148
                '----------',
149
                new VersionComponent(),
150
            ]],
151
            'VersionComponent[] + array[]'   => [[
152
                [],
153
                [0, 1, 0],
154
                new VersionComponent(1, '-alpha'),
155
            ]],
156
        ];
157
    }
158
159
    public function goodVersionComponentParseMethodArgumentsProvider()
160
    {
161
        return [
162
            [new VersionComponent(1, 'a0'), '1a0'],
163
            [new VersionComponent(2, '-3-g726351'), '2-3-g726351'],
164
            [new VersionComponent(3, '-beta'), '3-beta'],
165
            [new VersionComponent(0, '-alpha'), '0-alpha'],
166
            [new VersionComponent(0, '-beta2'), '0-beta2'],
167
            'string | empty'        => [new VersionComponent(), '      '], // Maybe should throw exception?
168
            'string | only spaces'  => [new VersionComponent(), ''], // Maybe should throw exception?
169
            'null'                  => [new VersionComponent(), null], // Maybe should throw exception?
170
            'integer'               => [new VersionComponent(7), 7],
171
            'VersionComponent'      => [new VersionComponent(999), new VersionComponent(999)],
172
        ];
173
    }
174
175
    public function badVersionComponentParseMethodArgumentsProvider()
176
    {
177
        return [
178
            'string | consecutive "-"'          => ['1a--0'],
179
            'string | invalid char: ó'          => ['1-erróneo'],
180
            'string | not starting in number'   => ['beta0'],
181
            'integer | < 0'                     => [-13],
182
            'stdClass'                          => [new \stdClass],
183
        ];
184
    }
185
186
    public function IEquatableMethodArgumentsProvider()
187
    {
188
        return [
189
            [true, new VersionComponent(1, '-alpha'), new VersionComponent(1, '-alpha')],
190
            [false, new VersionComponent(1, '-beta'), new VersionComponent(1, '-bet')],
191
            [false, new VersionComponent(3, '-dev'), new VersionComponent(1, '-dev')],
192
            [false, new VersionComponent(), null],
193
            [false, new VersionComponent(0), 0],
194
            [false, new VersionComponent(2), 2],
195
            [false, new VersionComponent(23), 2345654675675675673453],
196
            [false, new VersionComponent(0, '-dev'), '0-dev'],
197
            [false, new VersionComponent(1, '-alpha'), [1, '-alpha']],
198
            [false, new VersionComponent(), new \stdClass],
199
        ];
200
    }
201
202 View Code Duplication
    public function versionComponentToStringMethodArgumentsProvider()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
203
    {
204
        return [
205
            ['0', new VersionComponent(0)],
206
            ['', new VersionComponent()],
207
            ['', new VersionComponent(null, '')],
208
            ['', new VersionComponent(null, '  ')],
209
            ['', new VersionComponent(null)],
210
            ['', new VersionComponent(null, null)],
211
            ['1a', new VersionComponent(1, 'a')],
212
            ['1-beta', new VersionComponent(1, '-beta')],
213
            ['2-rc1-20-g8c5b85c', new VersionComponent(2, "-rc1-20-g8c5b85c")],
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal -rc1-20-g8c5b85c does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
214
        ];
215
    }
216
217
218 View Code Duplication
    public function nullOrDefaultStatesProvider()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
219
    {
220
        return [
221
            ['default', new VersionComponent(0)],
222
            ['null', new VersionComponent()],
223
            ['null', new VersionComponent(null, '')],
224
            ['null', new VersionComponent(null, '  ')],
225
            ['null', new VersionComponent(null)],
226
            ['null', new VersionComponent(null, null)],
227
            ['defined', new VersionComponent(1, 'a')],
228
            ['defined', new VersionComponent(1, '-beta')],
229
            ['defined', new VersionComponent(2, "-rc1-20-g8c5b85c")],
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal -rc1-20-g8c5b85c does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
230
        ];
231
    }
232
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
233