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

IComparableCompareToMethodArgumentsProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 0
loc 29
rs 8.8571
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\Version;
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
 *
31
 * @author Nelson Martell <[email protected]>
32
 * @internal
33
 * */
34
trait VersionTestProvider
35
{
36
    use ExporterPlugin;
37
    use ConstructorMethodTester;
38
    use IComparableTester;
39
    use IComparerTester;
40
    use IEquatableTester;
41
42
    /**
43
     * Provides invalid arguments for constructor.
44
     *
45
     * @return array
46
     */
47
    public function badConstructorArgumentsProvider()
48
    {
49
        return [
50
            'Type: null (all)'               => [null, null],
51
            'Only first argument'            => [1, null],
52
            'Invalid $major and $minor type' => ['hello', 'world'],
53
            'Invalid $major type (string)'   => ['hello', 1],
54
            'Invalid $minor type (string)'   => [1, 'world'],
55
            '$major value < 0'               => [-1, 0],
56
            '$minor value < 0'               => [1, -3],
57
            '$build value < 0'               => [1, 0, -1, null],
58
            '$revision value < 0'            => [1, 0, 1, -1],
59
            '$revision while $build is not'  => [1, 0, null, -1],
60
        ];
61
    }
62
63
    /**
64
     * Provides valid arguments for constructor.
65
     *
66
     * @return array
67
     */
68
    public function goodConstructorArgumentsProvider()
69
    {
70
        return [
71
            'SemVer: Normal'                     => [1, 0, 0],
72
            'SemVer: Patch release '             => [1, 0, 1],
73
            'SemVer: Minor release'              => [1, 1, 0],
74
            'SemVer: Major release'              => [2, 0, 0],
75
            'SemVer: Pre-release alpha'          => [1, 0, '0-alpha'],
76
            'SemVer: Pre-release beta'           => [1, 0, '0-beta', 1],
77
            // 'SemVer: Pre-release build metadata' => [1, 0, '0-beta', '1+20130313144700'],
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
            'Windows version: Major'             => [1, 0, 0, 0],
79
            'Windows version: Minor'             => [1, 1, 0, 0],
80
            'Windows version: Build'             => [1, 2, 1, 0],
81
            'Windows version: Revision'          => [1, 3, 1, 2344234],
82
            'Git: describe'                      => [0, 5, '1-34-g6e5462c'],
83
            'Zero (minor)'                       => [0, 0], // is invalid, but can be created
84
            'Zero (build)'                       => [0, 0, 0], // is invalid, but can be created
85
            'Zero (revision)'                    => [0, 0, 0, 0], // is invalid, but can be created
86
        ];
87
    }
88
89
    public function IComparableCompareToMethodArgumentsProvider()
90
    {
91
        $v = new Version(1, 0, 9);
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 13 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...
92
        $obj = new \stdClass();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
93
        $obj->major = 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...
94
        $obj->minor = 0;
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...
95
        $obj->build = 9;
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...
96
        $obj->revision = null;
97
98
99
        $args = [
100
            'Equals by reference'               => [0, $v, $v],
101
            'Equals by value'                   => [0, new Version(1, 0, 1), Version::parse('1.0.1')],
102
            'Major difference'                  => [-1, Version::parse('1.0.0'), Version::parse('2.0.0')],
103
            'Minor difference'                  => [1, Version::parse('1.1.0'), Version::parse('1.0.0')],
104
            'Build difference'                  => [1, Version::parse('1.0.1'), Version::parse('1.0.0')],
105
            'Revision difference'               => [-1, Version::parse('1.0.0.254'), Version::parse('1.0.0.389')],
106
            'Version < object'                  => [null, $v, $obj],
107
            'Version > array parseable'         => [1, Version::parse('1.1.0'), [0, 1, 999]],
108
            'Version < array parseable'         => [-1, Version::parse('1.1.0'), [2, 0]],
109
            'Version > array not parseable'     => [1, Version::parse('0.0.0'), ['invalid array']],
110
            'Version > string parseable'        => [1, Version::parse('1.1.0'), '0.1.999'],
111
            'Version < string parseable'        => [-1, Version::parse('1.1.0'), '2.0'],
112
            'Version > string not parseable'    => [1, Version::parse('1.1.0'), 'invalid string'],
113
            'integer|Version'                   => [1, $v, 9976645645656],
114
        ];
115
116
        return $args;
117
    }
118
119
    public function compareMethodArgumentsProvider()
120
    {
121
        $v = new Version(1, 0, 9);
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 13 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...
122
        $obj = new \stdClass();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
123
        $obj->major = 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...
124
        $obj->minor = 0;
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...
125
        $obj->build = 9;
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...
126
        $obj->revision = null;
127
128
        $args = [
129
            'stdClass|Version' => [null, $obj, $v],
130
            'string|Version'   => [-1, '1.0.0.254', $v],
131
            'integer|Version'  => [-1, 9976645645656, $v],
132
            'float|Version'    => [-1, 1.342333, $v],
133
            'array|Version'    => [-1, [0, 1, 999], Version::parse('1.1.0')],
134
        ];
135
136
        return $args;
137
    }
138
139
    public function compareMethodArraysProvider()
140
    {
141
        return [
142
            'Version[]' => [[
143
                new Version(1, 0, 1, 3),
144
                new Version(1, 0, 11, 3),
145
                new Version(1, 1, 1, 0),
146
                new Version(1, 3, 1, 9),
147
                Version::parse("2.3.2-3-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.3.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...
148
                Version::parse("2.3.2-3-g726356"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.3.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...
149
                Version::parse("2.3.2-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.3.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...
150
                Version::parse("2.3.4-3-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.3.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...
151
                Version::parse("2.3.4-3-gsh4hajk7"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.3.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...
152
                Version::parse("2.3.4-3-gsh4hbjk7"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.3.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...
153
                Version::parse("2.31.0-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.31.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...
154
                Version::parse("2.31.1-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.31.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...
155
                Version::parse("2.31.11-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2.31.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...
156
            ]],
157
            'Version[] + integer[]' => [[
158
                1,
159
                new Version(1, 0, 1, 3),
160
                new Version(1, 0, 11, 3),
161
                new Version(1, 1, 1, 0),
162
            ]],
163
            'Version[] + string[]'  => [[
164
                '0.0',
165
                new Version(0, 0, 9, 3),
166
                '0.1.0',
167
            ]],
168
            'Version[] + string[] (1 non parseable string)'  => [[
169
                '0.1.0',
170
                'invalid string',
171
                new Version(1, 0, 1, 3),
172
            ]],
173
            'Version[] + array[]'   => [[
174
                [],
175
                [0, 1, 0],
176
                new Version(1, 0, 1, 3),
177
            ]],
178
        ];
179
    }
180
181
    public function IEquatableMethodArgumentsProvider()
182
    {
183
        return [
184
            [true, new Version(1, 2), new Version(1, 2)],
185
            [false, new Version(1, 4), new Version(1, 2)],
186
            [false, new Version(1, 2, 1), new Version(1, 2, 2)],
187
            [false, new Version(1, 2, 1), 123],
188
            [false, new Version(1, 2, 1), 2345654675675675673453],
189
            [false, new Version(1, 2, 1), '1.2.1'],
190
            [false, new Version(1, 2, 1), [1, 2, 1]],
191
            [false, new Version(1, 2, 1), new \stdClass],
192
        ];
193
    }
194
195
    protected $parseableStrings = [
196
        'valid' => [
197
            '1.0',
198
            '0.2',
199
            '2.3.2-3-g726351',
200
            '2.3.2.3-2-g726352',
201
            '3.0.1',
202
            '4.0.2.0',
203
            '5.0.0.3-beta',
204
            '6.0.0-alpha',
205
        ],
206
        'invalid' => [
207
            '0.0',
208
            '1.0..1',
209
            '2.0.0-alpha.0',
210
            '2.3.2-3-g726353.3',
211
            '2.3.2-3-g726356.1-2-gyt4f4',
212
            '3.0.1-alpha.1',
213
            '4.0.0-alpha.0-beta',
214
            '5.0.1-alpha.2-beta',
215
        ],
216
    ];
217
218
    public function isValidProvider()
219
    {
220
        $args = [];
221
222 View Code Duplication
        foreach ($this->parseableStrings['valid'] as $str) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
223
            $args[$str] = [true, Version::parse($str)];
224
        }
225
226 View Code Duplication
        foreach ($this->parseableStrings['invalid'] as $str) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
227
            $args[$str] = [false, Version::parse($str)];
228
        }
229
230
        return $args;
231
    }
232
233
    public function toStringMethodProvider()
234
    {
235
        return [
236
            ['1.0', new Version(1, 0)],
237
            ['0.2', new Version(0, 2)],
238
            ['2.3.2-3-g726351', new Version(2, 3, '2-3-g726351')],
239
            ['2.3.2.3-2-g726352', new Version(2, 3, 2, '3-2-g726352')],
240
            ['3.0.1', new Version(3, 0, 1)],
241
            ['4.0.2.0', new Version(4, 0, 2, 0)],
242
            ['5.0.0.3-beta', new Version(5, 0, 0, '3-beta')],
243
            ['6.0.0-alpha', new Version(6, 0, '0-alpha')],
244
        ];
245
    }
246
}
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...
247