Skip to content

Commit aede0b8

Browse files
authored
Add new API to allow require the test framework adapters to declare the minimum supported version (#2)
1 parent f3ec6fc commit aede0b8

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed

src/InvalidVersion.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Infection\AbstractTestFramework;
6+
7+
use UnexpectedValueException;
8+
9+
final class InvalidVersion extends UnexpectedValueException
10+
{
11+
}

src/TestFrameworkAdapter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ public function getMutantCommandLine(
6565
string $extraOptions
6666
): array;
6767

68+
/**
69+
* @throws InvalidVersion
70+
*/
6871
public function getVersion(): string;
6972

73+
/**
74+
* @throws UnsupportedTestFrameworkVersion
75+
*/
76+
public function checkVersion(): void;
77+
7078
public function getInitialTestsFailRecommendations(string $commandLine): string;
7179
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* This code is licensed under the BSD 3-Clause License.
4+
*
5+
* Copyright (c) 2017, Maks Rafalko
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
*
14+
* * Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* * Neither the name of the copyright holder nor the names of its
19+
* contributors may be used to endorse or promote products derived from
20+
* this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
declare(strict_types=1);
35+
36+
namespace Infection\AbstractTestFramework;
37+
38+
use RuntimeException;
39+
40+
final class UnsupportedTestFrameworkVersion extends RuntimeException
41+
{
42+
private $detectedVersion;
43+
private $minimumSupportedVersion;
44+
45+
public function __construct(string $detectedVersion, string $minimumSupportedVersion)
46+
{
47+
parent::__construct('', 0, null);
48+
49+
$this->detectedVersion = $detectedVersion;
50+
$this->minimumSupportedVersion = $minimumSupportedVersion;
51+
}
52+
53+
public function getDetectedVersion(): string
54+
{
55+
return $this->detectedVersion;
56+
}
57+
58+
public function getMinimumSupportedVersion(): string
59+
{
60+
return $this->minimumSupportedVersion;
61+
}
62+
}

tests/InvalidVersionTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* This code is licensed under the BSD 3-Clause License.
4+
*
5+
* Copyright (c) 2017, Maks Rafalko
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
*
14+
* * Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* * Neither the name of the copyright holder nor the names of its
19+
* contributors may be used to endorse or promote products derived from
20+
* this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
declare(strict_types=1);
35+
36+
namespace Infection\AbstractTestFramework;
37+
38+
use Error;
39+
use PHPUnit\Framework\TestCase;
40+
41+
/**
42+
* @covers \Infection\AbstractTestFramework\InvalidVersion
43+
*/
44+
final class InvalidVersionTest extends TestCase
45+
{
46+
public function test_it_can_be_instantiated(): void
47+
{
48+
$error = new Error();
49+
$exception = new InvalidVersion('Foo', 0, $error);
50+
51+
$this->assertSame('Foo', $exception->getMessage());
52+
$this->assertSame(0, $exception->getCode());
53+
$this->assertSame($error, $exception->getPrevious());
54+
}
55+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* This code is licensed under the BSD 3-Clause License.
4+
*
5+
* Copyright (c) 2017, Maks Rafalko
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
*
14+
* * Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* * Neither the name of the copyright holder nor the names of its
19+
* contributors may be used to endorse or promote products derived from
20+
* this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
declare(strict_types=1);
35+
36+
namespace Infection\AbstractTestFramework;
37+
38+
use PHPUnit\Framework\TestCase;
39+
40+
/**
41+
* @covers \Infection\AbstractTestFramework\UnsupportedTestFrameworkVersion
42+
*/
43+
final class UnsupportedTestFrameworkVersionTest extends TestCase
44+
{
45+
public function test_it_can_be_instantiated(): void
46+
{
47+
$exception = new UnsupportedTestFrameworkVersion('3.2.0', '6.0.0');
48+
49+
$this->assertSame('3.2.0', $exception->getDetectedVersion());
50+
$this->assertSame('6.0.0', $exception->getMinimumSupportedVersion());
51+
52+
$this->assertSame('', $exception->getMessage());
53+
$this->assertSame(0, $exception->getCode());
54+
$this->assertNull($exception->getPrevious());
55+
}
56+
}

0 commit comments

Comments
 (0)