Passed
Push — master ( 39c97e...cdd54f )
by Nelson
02:32
created

VersionTest::testPerformsConversionFromString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
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\TestCase;
18
19
use InvalidArgumentException;
20
21
use NelsonMartell\Extensions\Text;
22
use NelsonMartell\Version;
23
24
use NelsonMartell\Test\DataProviders\VersionTestProvider;
25
26
use PHPUnit\Framework\TestCase;
27
28
/**
29
 * @coversDefaultClass NelsonMartell\Version
30
 *
31
 * @author Nelson Martell <[email protected]>
32
 * @internal
33
 * @since 0.6.0
34
 * */
35
class VersionTest extends TestCase
36
{
37
    use VersionTestProvider;
38
39
    public function getTargetClassName()
40
    {
41
        return Version::class;
42
    }
43
44
    /**
45
     * @depends NelsonMartell\Test\TestCase\VersionComponentTest::testParseMethod
46
     * @dataProvider parseableStringsProvider
47
     * @dataProvider parseableArraysProvider
48
     * @covers ::parse
49
     *
50
     * @param string|array $value
51
     */
52
    public function testPerformsConversionFromParseableStringAndArrays($value) : void
53
    {
54
        $version = Version::parse($value);
0 ignored issues
show
Unused Code introduced by
The assignment to $version is dead and can be removed.
Loading history...
55
56
        $this->addToAssertionCount(1);
57
    }
58
59
    /**
60
     * @depends testPerformsConversionFromParseableStringAndArrays
61
     * @dataProvider nonParseableValuesProvider
62
     * @covers ::parse
63
     *
64
     * @param mixed $value
65
     */
66
    public function testThrowsExceptionOnParsinInvalidValue($value) : void
67
    {
68
        $this->expectException(InvalidArgumentException::class);
69
70
        $version = Version::parse($value);
0 ignored issues
show
Unused Code introduced by
The assignment to $version is dead and can be removed.
Loading history...
71
    }
72
73
74
    /**
75
     * @testdox Can check if Version instance is valid
76
     * @depends testPerformsConversionFromParseableStringAndArrays
77
     * @dataProvider isValidProvider
78
     * @covers ::isValid
79
     *
80
     * @param  bool    $expected
81
     * @param  Version $version
82
     */
83
    public function testIsValid(bool $expected, Version $version) : void
84
    {
85
        $actual = $version->isValid();
86
87
        $message = Text::format(
88
            '$version->{method}(); // {actual}',
89
            [
90
                'method' => 'isValid',
91
                'obj'    => static::export($version),
92
                'actual' => static::export($actual)
93
            ]
94
        );
95
96
        $this->assertIsBool($actual, $message.' # Should return a boolean #');
97
98
        if ($expected === true) {
99
            $this->assertTrue($actual, $message);
100
        } else {
101
            $this->assertFalse($actual, $message);
102
        }
103
    }
104
}
105