-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from jrfnl/feature/allow-install-on-php-lt-7.3
Allow installation on PHP < 7.3 icw PHPUnit < 9
- Loading branch information
Showing
15 changed files
with
304 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace DMS\PHPUnitExtensions\ArraySubset; | ||
|
||
if (\class_exists('DMS\PHPUnitExtensions\ArraySubset\Autoload', false) === false) { | ||
|
||
/** | ||
* Custom autoloader. | ||
* | ||
* {@internal The code in this file must be PHP cross-version compatible for PHP 5.4 - current!} | ||
*/ | ||
class Autoload | ||
{ | ||
/** | ||
* Loads a class. | ||
* | ||
* @param string $className The name of the class to load. | ||
* | ||
* @return bool | ||
*/ | ||
public static function load($className) | ||
{ | ||
// Only load classes belonging to this library. | ||
if (\stripos($className, 'DMS\PHPUnitExtensions\ArraySubset') !== 0) { | ||
return false; | ||
} | ||
|
||
switch ($className) { | ||
case 'DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts': | ||
if (\method_exists('\PHPUnit\Framework\Assert', 'assertArraySubset') === false) { | ||
// PHPUnit >= 9.0.0. | ||
require_once __DIR__ . '/src/ArraySubsetAsserts.php'; | ||
|
||
return true; | ||
} | ||
|
||
// PHPUnit < 9.0.0. | ||
require_once __DIR__ . '/src/ArraySubsetAssertsEmpty.php'; | ||
|
||
return true; | ||
|
||
case 'DMS\PHPUnitExtensions\ArraySubset\Assert': | ||
if (\method_exists('\PHPUnit\Framework\Assert', 'assertArraySubset') === false) { | ||
// PHPUnit >= 9.0.0. | ||
require_once __DIR__ . '/src/Assert.php'; | ||
|
||
return true; | ||
} | ||
|
||
// PHPUnit < 9.0.0. | ||
require_once __DIR__ . '/src/AssertFallThrough.php'; | ||
|
||
return true; | ||
|
||
/* | ||
* Handle arbitrary additional classes via PSR-4, but only allow loading on PHPUnit >= 9.0.0, | ||
* as additional classes should only ever _need_ to be loaded when using PHPUnit >= 9.0.0. | ||
*/ | ||
default: | ||
if (\method_exists('\PHPUnit\Framework\Assert', 'assertArraySubset') === true) { | ||
// PHPUnit < 9.0.0. | ||
throw new \RuntimeException( | ||
\sprintf( | ||
'Using class "%s" is only supported in combination with PHPUnit >= 9.0.0', | ||
$className | ||
) | ||
); | ||
} | ||
|
||
// PHPUnit >= 9.0.0. | ||
$file = \realpath( | ||
__DIR__ . \DIRECTORY_SEPARATOR | ||
. 'src' . \DIRECTORY_SEPARATOR | ||
. \strtr(\substr($className, 33), '\\', \DIRECTORY_SEPARATOR) . '.php' | ||
); | ||
|
||
if (\file_exists($file) === true) { | ||
require_once $file; | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
\spl_autoload_register(__NAMESPACE__ . '\Autoload::load'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace DMS\PHPUnitExtensions\ArraySubset; | ||
|
||
/** | ||
* ArraySubsetAsserts trait for use with PHPUnit 4.x - 8.x. | ||
* | ||
* As this trait is empty, calls to `assertArraySubset()` will automatically fall through | ||
* to PHPUnit itself and will use the PHPUnit native `assertArraySubset()` method. | ||
* | ||
* {@internal The code in this file must be PHP cross-version compatible for PHP 5.4 - current!} | ||
*/ | ||
trait ArraySubsetAsserts | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace DMS\PHPUnitExtensions\ArraySubset; | ||
|
||
use PHPUnit\Framework\Assert as PhpUnitAssert; | ||
|
||
/** | ||
* Assert class for use with PHPUnit 4.x - 8.x. | ||
* | ||
* The method in this class will fall through to PHPUnit itself and use the PHPUnit | ||
* native `assertArraySubset()` method. | ||
* | ||
* {@internal The code in this file must be PHP cross-version compatible for PHP 5.4 - current!} | ||
*/ | ||
final class Assert | ||
{ | ||
/** | ||
* Asserts that an array has a specified subset. | ||
* | ||
* @param array|ArrayAccess|mixed[] $subset | ||
* @param array|ArrayAccess|mixed[] $array | ||
* @param bool $checkForObjectIdentity | ||
* @param string $message | ||
* | ||
* @throws ExpectationFailedException | ||
* @throws InvalidArgumentException | ||
* @throws Exception | ||
*/ | ||
public static function assertArraySubset($subset, $array, $checkForObjectIdentity = false, $message = '') | ||
{ | ||
PhpUnitAssert::assertArraySubset($subset, $array, $checkForObjectIdentity, $message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace DMS\PHPUnitExtensions\ArraySubset\Tests\Availibility; | ||
|
||
use DMS\PHPUnitExtensions\ArraySubset\Constraint\ArraySubset; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Testing that autoloading classes which should only ever be loaded on PHPUnit >= 9 will | ||
* generate an exception when attempted on PHPUnit < 9.. | ||
* | ||
* Note: the autoloading in combination with PHPUnit 9+ is automatically tested via the | ||
* actual tests for the polyfill as the class will be called upon. | ||
* | ||
* {@internal The code in this file must be PHP cross-version compatible for PHP 5.4 - current!} | ||
* | ||
* @requires PHPUnit < 9 | ||
*/ | ||
final class AutoloadExceptionTest extends TestCase | ||
{ | ||
public function testAutoloadException() | ||
{ | ||
$expection = '\RuntimeException'; | ||
$message = 'Using class "DMS\PHPUnitExtensions\ArraySubset\Constraint\ArraySubset" is only supported in combination with PHPUnit >= 9.0.0'; | ||
|
||
if (\method_exists('\PHPUnit\Framework\TestCase', 'expectException') === true) { | ||
$this->expectException($expection); | ||
$this->expectExceptionMessage($message); | ||
} else { | ||
$this->setExpectedException($expection, $message); | ||
} | ||
|
||
new ArraySubset(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace DMS\PHPUnitExtensions\ArraySubset\Tests\Availibility; | ||
|
||
use DMS\PHPUnitExtensions\ArraySubset\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Testing that the autoloading of the fall-through `Assert` class for PHPUnit 4.x - 8.x works correctly. | ||
* | ||
* {@internal The code in this file must be PHP cross-version compatible for PHP 5.4 - current!} | ||
*/ | ||
final class AvailibilityViaClassTest extends TestCase | ||
{ | ||
public function testAssertArraySubsetisAvailabe() | ||
{ | ||
Assert::assertArraySubset([1, 2], [1, 2, 3]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace DMS\PHPUnitExtensions\ArraySubset\Tests\Availibility; | ||
|
||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Testing that the autoloading of the empty `ArraySubsetAsserts` trait for PHPUnit 4.x - 8.x works correctly. | ||
* | ||
* {@internal The code in this file must be PHP cross-version compatible for PHP 5.4 - current!} | ||
*/ | ||
final class AvailibilityViaTraitTest extends TestCase | ||
{ | ||
use ArraySubsetAsserts; | ||
|
||
public function testAssertArraySubsetisAvailabe() | ||
{ | ||
static::assertArraySubset([1, 2], [1, 2, 3]); | ||
$this->assertArraySubset([1, 2], [1, 2, 3]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.