Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions lib/Compat/v6/Assert/MatchesRegularExpression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

declare(strict_types=1);

namespace RmpUp\PHPUnitCompat\Compat\v6\Assert;

trait MatchesRegularExpression
{
/**
* @param string $pattern
* @param string $string
* @param string $message
*
* @deprecated Removed in phpUnit 10. Please use ::assertMatchesRegularExpression() instead.
*/
public static function assertRegExp($pattern, $string, $message = '')
{
parent::assertRegExp($pattern, $string, $message);
}

/**
* @param string $pattern
* @param string $string
* @param string $message
*
* @deprecated Removed in phpUnit 10. Please use ::assertDoesNotMatchRegularExpression() instead.
*/
public static function assertNotRegExp($pattern, $string, $message = '')
{
parent::assertNotRegExp($pattern, $string, $message);
}

public static function assertMatchesRegularExpression($pattern, $string, string $message = '')
{
parent::assertRegExp($pattern, $string, $message);
}

public static function assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = '')
{
self::assertNotRegExp($pattern, $string, $message);
}
}
44 changes: 43 additions & 1 deletion lib/Compat/v6/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,53 @@

namespace RmpUp\PHPUnitCompat\Compat\v6;

use RmpUp\PHPUnitCompat\Compat\TestCaseTrait;

/**
* TestCase
*
* @copyright 2021 Pretzlaw (https://rmp-up.de)
*/
class TestCase extends \RmpUp\PHPUnitCompat\Compat\v7\TestCase
class TestCase extends \PHPUnit\Framework\TestCase
{
use TestCaseTrait;

/**
* Forward-compatibility
*/
use Assert\MatchesRegularExpression;

/**
* Replacing
*
* @deprecated Please use ::compatSetUp() instead
*/
protected function setUp()
{
$this->compatSetUp();
}

/**
* @deprecated Please use ::compatSetUpBeforeClass()
*/
public static function setUpBeforeClass()
{
static::compatSetUpBeforeClass();
}

/**
* @deprecated Please use ::compatTearDown()
*/
protected function tearDown()
{
$this->compatTearDown();
}

/**
* @deprecated Please use ::compatTearDownAfterClass()
*/
public static function tearDownAfterClass()
{
static::compatTearDownAfterClass();
}
}
43 changes: 43 additions & 0 deletions lib/Compat/v7/Assert/MatchesRegularExpression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

declare(strict_types=1);

namespace RmpUp\PHPUnitCompat\Compat\v7\Assert;

trait MatchesRegularExpression
{
/**
* @param string $pattern
* @param string $string
* @param string $message
*
* @deprecated Removed in phpUnit 10. Please use ::assertMatchesRegularExpression() instead
*/
public static function assertRegExp(string $pattern, string $string, $message = ''): void
{
parent::assertRegExp($pattern, $string, $message);
}

/**
* @param string $pattern
* @param string $string
* @param string $message
*
* @deprecated Removed in phpUnit 10. Please use ::assertDoesNotMatchRegularExpression() instead.
*/
public static function assertNotRegExp(string $pattern, string $string, $message = ''): void
{
parent::assertNotRegExp($pattern, $string, $message);
}

public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
{
parent::assertRegExp($pattern, $string, $message);
}

public static function assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void
{
self::assertNotRegExp($pattern, $string, $message);
}
}
15 changes: 12 additions & 3 deletions lib/Compat/v7/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ class TestCase extends \PHPUnit\Framework\TestCase
use TestCaseTrait;

/**
* Replacing
*
* Forward-compatibility
*/
use Assert\MatchesRegularExpression;

/**
* @deprecated Please use ::compatSetUp() instead
*/
protected function setUp()
Expand All @@ -44,18 +47,24 @@ protected function setUp()
}

/**
* @deprecated Please use ::
* @deprecated Please use ::compatSetUpBeforeClass()
*/
public static function setUpBeforeClass()
{
static::compatSetUpBeforeClass();
}

/**
* @deprecated Please use ::compatTearDown()
*/
protected function tearDown()
{
$this->compatTearDown();
}

/**
* @deprecated Please use ::compatTearDownAfterClass()
*/
public static function tearDownAfterClass()
{
static::compatTearDownAfterClass();
Expand Down
25 changes: 25 additions & 0 deletions lib/Compat/v8/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use PHPUnit\Util\InvalidArgumentHelper;
use RmpUp\PHPUnitCompat\Compat\TestCaseTrait;
use RmpUp\PHPUnitCompat\Compat\v7\Assert\MatchesRegularExpression;
use RmpUp\PHPUnitCompat\Compat\v8\Assert\ArraySubset;

/**
Expand All @@ -35,23 +36,47 @@ class TestCase extends \PHPUnit\Framework\TestCase
{
use TestCaseTrait;

/**
* Backward-compatibility
*
* Note: This may become heavily opinionated some day
* and very old methods may be dropped.
* Fingers crossed that we can keep BC up for all of them.
*/
use ArraySubset;

/**
* Forward-compatibility
*/
use MatchesRegularExpression;

/**
* @deprecated Please use ::compatSetUp() instead
*/
protected function setUp(): void
{
$this->compatSetUp();
}

/**
* @deprecated Please use ::compatSetUpBeforeClass() instead.
*/
public static function setUpBeforeClass(): void
{
static::compatSetUpBeforeClass();
}

/**
* @deprecated Please use ::compatTearDown() instead.
*/
protected function tearDown(): void
{
$this->compatTearDown();
}

/**
* @deprecated Please use compatTearDownAfterClass() instead.
*/
public static function tearDownAfterClass(): void
{
static::compatTearDownAfterClass();
Expand Down
46 changes: 45 additions & 1 deletion lib/Compat/v9/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,57 @@

namespace RmpUp\PHPUnitCompat\Compat\v9;

use RmpUp\PHPUnitCompat\Compat\TestCaseTrait;
use RmpUp\PHPUnitCompat\Compat\v8\Assert\ArraySubset;

/**
* TestCase
*/
class TestCase extends \RmpUp\PHPUnitCompat\Compat\v8\TestCase
class TestCase extends \PHPUnit\Framework\TestCase
{
use TestCaseTrait;

/**
* Backward-compatibility
*
* Note: This may become heavily opinionated some day
* and very old methods may be dropped.
* Fingers crossed that we can keep BC up for all of them.
*/
use ArraySubset;

/**
* @deprecated Please use ::compatSetUp() instead
*/
protected function setUp(): void
{
$this->compatSetUp();
}

/**
* @deprecated Please use ::compatSetUpBeforeClass() instead.
*/
public static function setUpBeforeClass(): void
{
static::compatSetUpBeforeClass();
}

/**
* @deprecated Please use ::compatTearDown() instead.
*/
protected function tearDown(): void
{
$this->compatTearDown();
}

/**
* @deprecated Please use compatTearDownAfterClass() instead.
*/
public static function tearDownAfterClass(): void
{
static::compatTearDownAfterClass();
}

/**
* @deprecated Use expectExceptionMessageMatches() instead
*/
Expand Down
40 changes: 25 additions & 15 deletions lib/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,34 @@
*/
class Versions
{
private static $version;

/**
* List of classes last seen in the mapped PHPUnit version
*
* Those classes are all deprecated.
* Their last occurrence tells us something about the PHPUnit version.
*
* @var int[]
*/
private static $classToVersion = [
\PHPUnit\Framework\BaseTestListener::class => 6,
\PHPUnit\Util\TestDox\TestResult::class => 7,
\PHPUnit\Util\Configuration::class => 8,
\PHPUnit\Util\Blacklist::class => 9
];

public static function getPhpUnitVersion(): int
{
if (class_exists(\PHPUnit\Framework\BaseTestListener::class)) {
return 6;
}

if (class_exists(\PHPUnit\Util\TestDox\TestResult::class)) {
return 7;
}

if (class_exists(\PHPUnit\Util\Configuration::class)) {
return 8;
}

if (class_exists(\PHPUnit\Util\Blacklist::class)) {
return 9;
if (null === self::$version) {
foreach (self::$classToVersion as $className => $phpUnitVersion) {
if (class_exists($className)) {
self::$version = $phpUnitVersion;
break;
}
}
}

return 0;
return self::$version;
}
}
24 changes: 24 additions & 0 deletions opt/doc/TestCase/v10/MatchesRegularExpressionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

declare(strict_types=1);

namespace TestCase\v10;

use RmpUp\PHPUnitCompat\TestCase;

/**
* MatchesRegularExpressionTest
*/
class MatchesRegularExpressionTest extends TestCase
{
public function testAssertMatchesRegularExpression()
{
static::assertMatchesRegularExpression('/wysiwyg/', 'wysiwyg');
}

public function testAssertDoesNotMatchRegularExpression()
{
static::assertDoesNotMatchRegularExpression('/wysiwyg/', uniqid('b', true));
}
}