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\TestCase; |
||
21 | |||
22 | use InvalidArgumentException; |
||
23 | use NelsonMartell\Extensions\Text; |
||
24 | use NelsonMartell\Version; |
||
25 | use NelsonMartell\Test\DataProviders\VersionTestProvider; |
||
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(): string |
||
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
![]() |
|||
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
|
|||
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 |