Issue #3060391 by mondrake, Mile23, Lendude, alexpott: Cleanup usage of PHPUnit 4.8 aliased classes

merge-requests/55/head
catch 2019-08-23 10:05:21 +01:00
parent 1240a8a047
commit 50a6a9efc1
47 changed files with 275 additions and 310 deletions

View File

@ -7,7 +7,7 @@ use Drupal\Component\Annotation\Reflection\MockFileFinder;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Test\Exception\MissingGroupException;
use PHPUnit_Util_Test;
use PHPUnit\Util\Test;
/**
* Discovers available tests.
@ -418,14 +418,14 @@ class TestDiscovery {
* - module: A list of Drupal module dependencies that are required to
* exist.
*
* @see PHPUnit_Util_Test::parseTestMethodAnnotations()
* @see \PHPUnit\Util\Test::parseTestMethodAnnotations()
* @see http://phpunit.de/manual/current/en/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests.skipping-tests-using-requires
*/
public static function parseTestClassAnnotations(\ReflectionClass $class) {
$annotations = PHPUnit_Util_Test::parseTestMethodAnnotations($class->getName())['class'];
$annotations = Test::parseTestMethodAnnotations($class->getName())['class'];
// @todo Enhance PHPUnit upstream to allow for custom @requires identifiers.
// @see PHPUnit_Util_Test::getRequirements()
// @see \PHPUnit\Util\Test::getRequirements()
// @todo Add support for 'PHP', 'OS', 'function', 'extension'.
// @see https://www.drupal.org/node/1273478
if (isset($annotations['requires'])) {

View File

@ -24,7 +24,7 @@ class AggregatorPluginSettingsBaseTest extends UnitTestCase {
/**
* The stubbed config factory object.
*
* @var \PHPUnit_Framework_MockObject_MockBuilder
* @var \PHPUnit\Framework\MockObject\MockBuilder
*/
protected $configFactory;
@ -56,7 +56,7 @@ class AggregatorPluginSettingsBaseTest extends UnitTestCase {
->will($this->returnValue(['aggregator_test' => ['title' => '', 'description' => '']]));
}
/** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockBuilder $messenger */
/** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit\Framework\MockObject\MockBuilder $messenger */
$messenger = $this->createMock(MessengerInterface::class);
$messenger->expects($this->any())->method('addMessage');

View File

@ -10,6 +10,7 @@ use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\field\Entity\FieldStorageConfig;
use PHPUnit\Framework\AssertionFailedError;
/**
* Tests the new entity API for the date field type.
@ -255,7 +256,7 @@ class DateTimeItemTest extends FieldKernelTestBase {
* @dataProvider datetimeValidationProvider
*/
public function testDatetimeValidation($value) {
$this->expectException(\PHPUnit_Framework_AssertionFailedError::class);
$this->expectException(AssertionFailedError::class);
$this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATETIME);
$this->fieldStorage->save();
@ -315,7 +316,7 @@ class DateTimeItemTest extends FieldKernelTestBase {
* @dataProvider dateonlyValidationProvider
*/
public function testDateonlyValidation($value) {
$this->expectException(\PHPUnit_Framework_AssertionFailedError::class);
$this->expectException(AssertionFailedError::class);
$this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATE);
$this->fieldStorage->save();

View File

@ -12,6 +12,7 @@ use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
use Drupal\user\Entity\Role;
use PHPUnit\Framework\Error\Warning;
/**
* Tests using entity fields of the image field type.
@ -153,7 +154,7 @@ class ImageItemTest extends FieldKernelTestBase {
$this->fail('Exception did not fail');
}
catch (EntityStorageException $exception) {
$this->assertInstanceOf(\PHPUnit_Framework_Error_Warning::class, $exception->getPrevious());
$this->assertInstanceOf(Warning::class, $exception->getPrevious());
$this->assertEquals($exception->getMessage(), 'Missing file with ID 9999.');
$this->assertEmpty($entity->image_test->width);
$this->assertEmpty($entity->image_test->height);

View File

@ -46,7 +46,7 @@ class LocaleLookupTest extends UnitTestCase {
/**
* A mocked config factory built with UnitTestCase::getConfigFactoryStub().
*
* @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockBuilder
* @var \Drupal\Core\Config\ConfigFactory|\PHPUnit\Framework\MockObject\MockBuilder
*/
protected $configFactory;

View File

@ -7,7 +7,7 @@
<testsuite name="Drupal\Tests\Core\Cache\NullBackendTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
<testsuite name="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" namespace="Drupal\Tests\Core\Extension" fullPackage="Drupal.Tests.Core.Extension" tests="1" assertions="0" failures="0" errors="1" time="0.002680">
<testcase name="testloadInclude" class="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" line="37" assertions="0" time="0.002680">
<error type="PHPUnit_Framework_Error_Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude
<error type="PHPUnit\Framework\Error\Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude
Undefined index: foo
/home/chx/www/system/core/lib/Drupal/Core/Extension/ModuleHandler.php:219
@ -20,19 +20,19 @@ Undefined index: foo
<testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest" file="/var/www/d8/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTestkTest.php" namespace="Drupal\Tests\Core\Route" fullPackage="Drupal.Tests.Core.Route" tests="3" assertions="3" failures="3" errors="0" time="0.009176">
<testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess" tests="3" assertions="3" failures="3" errors="0" time="0.009176">
<testcase name="testRoleAccess with data set #0" assertions="1" time="0.004519">
<failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
<failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
Access granted for user with the roles role_test_1 on path: role_test_1
Failed asserting that false is true.
</failure>
</testcase>
<testcase name="testRoleAccess with data set #1" assertions="1" time="0.002354">
<failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
<failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
Access granted for user with the roles role_test_2 on path: role_test_2
Failed asserting that false is true.
</failure>
</testcase>
<testcase name="testRoleAccess with data set #2" assertions="1" time="0.002303">
<failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', array(Drupal\user\Entity\User))
<failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', array(Drupal\user\Entity\User))
Access granted for user with the roles role_test_1, role_test_2 on path: role_test_3
Failed asserting that false is true.
</failure>

View File

@ -7,6 +7,7 @@ use Drupal\Core\Url;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\RoleInterface;
use PHPUnit\Framework\ExpectationFailedException;
/**
* Tests breadcrumbs functionality.
@ -399,7 +400,7 @@ class BreadcrumbTest extends BrowserTestBase {
$this->assertBreadcrumb('menu-test/breadcrumb1', []);
$this->fail($message);
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->assertTrue(TRUE, $message);
}
@ -409,7 +410,7 @@ class BreadcrumbTest extends BrowserTestBase {
$this->assertBreadcrumb('menu-test/breadcrumb1', $home);
$this->fail($message);
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->assertTrue(TRUE, $message);
}
@ -426,7 +427,7 @@ class BreadcrumbTest extends BrowserTestBase {
$this->assertBreadcrumb('menu-test/breadcrumb1', $trail);
$this->fail($message);
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->assertTrue(TRUE, $message);
}
}

View File

@ -20,6 +20,7 @@ use Drupal\views\Plugin\views\query\Sql;
use Drupal\views\Plugin\views\pager\PagerPluginBase;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views_test_data\Plugin\views\display\DisplayTest;
use PHPUnit\Framework\Error\Warning;
use Symfony\Component\HttpFoundation\Response;
/**
@ -201,7 +202,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
$view->setDisplay('invalid');
$this->fail('Expected error, when setDisplay() called with invalid display ID');
}
catch (\PHPUnit_Framework_Error_Warning $e) {
catch (Warning $e) {
$this->assertEquals('setDisplay() called with invalid display ID "invalid".', $e->getMessage());
}

View File

@ -20,7 +20,6 @@ use Drupal\Core\Test\TestRunnerKernel;
use Drupal\simpletest\Form\SimpletestResultsForm;
use Drupal\Core\Test\TestDiscovery;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\Version;
use Symfony\Component\HttpFoundation\Request;
// Define some colors for display.
@ -144,14 +143,6 @@ if ($args['clean']) {
exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS);
}
// Ensure we have the correct PHPUnit version for the version of PHP.
if (class_exists('\PHPUnit_Runner_Version')) {
$phpunit_version = \PHPUnit_Runner_Version::id();
}
else {
$phpunit_version = Version::id();
}
$test_list = simpletest_script_get_test_list();
// Try to allocate unlimited time to run the tests.

View File

@ -3,6 +3,7 @@
namespace Drupal\FunctionalJavascriptTests;
use Behat\Mink\Driver\GoutteDriver;
use PHPUnit\Framework\AssertionFailedError;
/**
* Tests if we can execute JavaScript in the browser.
@ -56,7 +57,7 @@ JS;
// We expected the following assertion to fail because the window has been
// re-sized to have a width of 500 not 400.
$this->expectException(\PHPUnit_Framework_AssertionFailedError::class);
$this->expectException(AssertionFailedError::class);
$this->assertJsCondition($javascript, 100);
}

View File

@ -168,7 +168,7 @@ abstract class WebDriverTestBase extends BrowserTestBase {
* (optional) A message to display with the assertion. If left blank, a
* default message will be displayed.
*
* @throws \PHPUnit_Framework_AssertionFailedError
* @throws \PHPUnit\Framework\AssertionFailedError
*
* @see \Behat\Mink\Driver\DriverInterface::evaluateScript()
*/

View File

@ -8,6 +8,7 @@ use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\Traits\Core\CronRunTrait;
use PHPUnit\Framework\ExpectationFailedException;
/**
* Tests BrowserTestBase functionality.
@ -263,7 +264,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldByXPath("//input[@id = 'notexisting']");
$this->fail('The "notexisting" field was found.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass('assertFieldByXPath correctly failed. The "notexisting" field was not found.');
}
@ -279,7 +280,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'not the value');
$this->fail('The "edit-name" field is found with the value "not the value".');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass('The "edit-name" field is not found with the value "not the value".');
}
}
@ -320,7 +321,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertField('invalid_name_and_id');
$this->fail('The "invalid_name_and_id" field was found.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.');
}
@ -359,7 +360,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldById('edit-name');
$this->fail('The "edit-name" field with no value was found.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass('The "edit-name" field with no value was not found.');
}
@ -368,7 +369,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldById('edit-name', 'not the value');
$this->fail('The "name" field was found, using the wrong value.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass('The "name" field was not found, using the wrong value.');
}
@ -409,7 +410,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldByName('non-existing-name');
$this->fail('The "non-existing-name" field was found.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass('The "non-existing-name" field was not found');
}
@ -418,7 +419,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldByName('name', 'not the value');
$this->fail('The "name" field with incorrect value was found.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.');
}
@ -473,7 +474,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertOptionSelected('options', 1);
$this->fail('The select option "1" was selected.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass($e->getMessage());
}
@ -492,7 +493,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
$this->assertFieldById('Save', NULL);
$this->fail('The field with id of "Save" was found.');
}
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
catch (ExpectationFailedException $e) {
$this->pass($e->getMessage());
}

View File

@ -6,6 +6,7 @@ use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\PreExistingConfigException;
use Drupal\Core\Config\UnmetDependenciesException;
use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\Error\Warning;
/**
* Tests installation of configuration objects in installation functionality.
@ -257,7 +258,7 @@ class ConfigInstallTest extends KernelTestBase {
* Tests installing configuration where the filename and ID do not match.
*/
public function testIdMisMatch() {
$this->expectException(\PHPUnit_Framework_Error_Warning::class);
$this->expectException(Warning::class);
$this->expectExceptionMessage('The configuration name "config_test.dynamic.no_id_match" does not match the ID "does_not_match"');
$this->installModules(['config_test_id_mismatch']);
}

View File

@ -5,6 +5,7 @@ namespace Drupal\KernelTests\Core\Test;
use Drupal\FunctionalTests\BrowserMissingDependentModuleMethodTest;
use Drupal\FunctionalTests\BrowserMissingDependentModuleTest;
use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\SkippedTestError;
/**
* @group Test
@ -36,7 +37,7 @@ class BrowserTestBaseTest extends KernelTestBase {
$stub_test->publicCheckRequirements();
$this->fail('Missing required module throws skipped test exception.');
}
catch (\PHPUnit_Framework_SkippedTestError $e) {
catch (SkippedTestError $e) {
$this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
}
}
@ -63,7 +64,7 @@ class BrowserTestBaseTest extends KernelTestBase {
$stub_test->publicCheckRequirements();
$this->fail('Missing required module throws skipped test exception.');
}
catch (\PHPUnit_Framework_SkippedTestError $e) {
catch (SkippedTestError $e) {
$this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
}
}

View File

@ -22,6 +22,7 @@ use Drupal\Tests\ConfigTestTrait;
use Drupal\Tests\PhpunitCompatibilityTrait;
use Drupal\Tests\RandomGeneratorTrait;
use Drupal\Tests\TestRequirementsTrait;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
@ -477,7 +478,7 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
* @return \Drupal\Core\Extension\Extension[]
* Extension objects for $modules, keyed by module name.
*
* @throws \PHPUnit_Framework_Exception
* @throws \PHPUnit\Framework\Exception
* If a module is not available.
*
* @see \Drupal\Tests\KernelTestBase::enableModules()
@ -490,7 +491,7 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
$list = $discovery->scan('module');
foreach ($modules as $name) {
if (!isset($list[$name])) {
throw new \PHPUnit_Framework_Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'.");
throw new Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'.");
}
$extensions[$name] = $list[$name];
}

View File

@ -6,6 +6,7 @@ use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Core\Database\Database;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
use PHPUnit\Framework\SkippedTestError;
/**
* @coversDefaultClass \Drupal\KernelTests\KernelTestBase
@ -249,7 +250,7 @@ class KernelTestBaseTest extends KernelTestBase {
$stub_test->publicCheckRequirements();
$this->fail('Missing required module throws skipped test exception.');
}
catch (\PHPUnit_Framework_SkippedTestError $e) {
catch (SkippedTestError $e) {
$this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
}
}
@ -276,7 +277,7 @@ class KernelTestBaseTest extends KernelTestBase {
$stub_test->publicCheckRequirements();
$this->fail('Missing required module throws skipped test exception.');
}
catch (\PHPUnit_Framework_SkippedTestError $e) {
catch (SkippedTestError $e) {
$this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
}
}

View File

@ -25,12 +25,7 @@ class DiffOpTest extends TestCase {
* @covers ::reverse
*/
public function testReverse() {
if (method_exists($this, 'expectException')) {
$this->expectException(Error::class);
}
else {
$this->expectException(\PHPUnit_Framework_Error::class);
}
$this->expectException(Error::class);
$op = new DiffOp();
$result = $op->reverse();
}

View File

@ -3,6 +3,7 @@
namespace Drupal\Tests\Component;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
/**
@ -144,7 +145,7 @@ class DrupalComponentTest extends TestCase {
$pass = TRUE;
$this->assertNoCoreUsage($file_uri);
}
catch (\PHPUnit_Framework_AssertionFailedError $e) {
catch (AssertionFailedError $e) {
$pass = FALSE;
}
$this->assertEquals($expected_pass, $pass, $expected_pass ?

View File

@ -99,14 +99,8 @@ class FileStorageTest extends PhpStorageTestBase {
'bin' => 'test',
]);
$code = "<?php\n echo 'here';";
if (method_exists($this, 'expectException')) {
$this->expectException(Warning::class);
$this->expectExceptionMessage('mkdir(): Permission Denied');
}
else {
$this->expectException(\PHPUnit_Framework_Error_Warning::class);
$this->expectExceptionMessage('mkdir(): Permission Denied');
}
$this->expectException(Warning::class);
$this->expectExceptionMessage('mkdir(): Permission Denied');
$storage->save('subdirectory/foo.php', $code);
}

View File

@ -9,7 +9,7 @@ use Drupal\Component\Render\MarkupInterface;
use Drupal\FunctionalTests\AssertLegacyTrait;
use Drupal\Tests\UnitTestCase;
use Drupal\Tests\WebAssert;
use PHPUnit_Framework_ExpectationFailedException;
use PHPUnit\Framework\ExpectationFailedException;
/**
* @coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait
@ -66,7 +66,7 @@ class AssertLegacyTraitTest extends UnitTestCase {
*/
public function testAssertUniqueTextFail() {
$this->page->getText()->willReturn('foo bar bar');
$this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
$this->expectException(ExpectationFailedException::class);
$this->assertUniqueText('bar');
}
@ -75,7 +75,7 @@ class AssertLegacyTraitTest extends UnitTestCase {
*/
public function testAssertUniqueTextUnknown() {
$this->page->getText()->willReturn('foo bar bar');
$this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
$this->expectException(ExpectationFailedException::class);
$this->assertUniqueText('alice');
}
@ -102,7 +102,7 @@ class AssertLegacyTraitTest extends UnitTestCase {
*/
public function testAssertNoUniqueTextFail() {
$this->page->getText()->willReturn('foo bar bar');
$this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
$this->expectException(ExpectationFailedException::class);
$this->assertNoUniqueText('foo');
}
@ -111,7 +111,7 @@ class AssertLegacyTraitTest extends UnitTestCase {
*/
public function testAssertNoUniqueTextUnknown() {
$this->page->getText()->willReturn('foo bar bar');
$this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
$this->expectException(ExpectationFailedException::class);
$this->assertNoUniqueText('alice');
}
@ -150,7 +150,7 @@ class AssertLegacyTraitTest extends UnitTestCase {
->optionExists('myselect', 'two')
->willReturn($option_field->reveal());
$this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
$this->expectException(ExpectationFailedException::class);
$this->assertOptionSelected('myselect', 'two');
}

View File

@ -7,6 +7,7 @@ use Drupal\Core\Render\Markup;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigValueException;
use PHPUnit\Framework\Error\Warning;
/**
* Tests the Config.
@ -269,7 +270,7 @@ class ConfigTest extends UnitTestCase {
$this->config->set('testData', 1);
// Attempt to treat the single value as a nested item.
$this->expectException(\PHPUnit_Framework_Error_Warning::class);
$this->expectException(Warning::class);
$this->config->set('testData.illegalOffset', 1);
}

View File

@ -7,6 +7,7 @@ use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\PlaceholderInterface;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use PHPUnit\Framework\Error\Error;
/**
* @coversDefaultClass \Drupal\Core\Database\Query\Condition
@ -161,7 +162,7 @@ class ConditionTest extends UnitTestCase {
$condition = new Condition('AND');
$condition->condition('name', 'value', $operator);
$this->expectException(\PHPUnit_Framework_Error::class);
$this->expectException(Error::class);
$condition->compile($connection, $query_placeholder);
}

View File

@ -6,6 +6,7 @@ use Drupal\Core\EventSubscriber\RedirectResponseSubscriber;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\Utility\UnroutedUrlAssemblerInterface;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Error\Error;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\RedirectResponse;
@ -123,7 +124,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase {
$listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
$event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
$this->expectException(\PHPUnit_Framework_Error::class);
$this->expectException(Error::class);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
}
@ -171,7 +172,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase {
$listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
$event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
$this->expectException(\PHPUnit_Framework_Error::class);
$this->expectException(Error::class);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
}

View File

@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\EventSubscriber;
use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber;
use Drupal\Core\Routing\RouteBuildEvent;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Error\Warning;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@ -98,7 +99,7 @@ class SpecialAttributesRouteSubscriberTest extends UnitTestCase {
$event = new RouteBuildEvent($route_collection, 'test');
$subscriber = new SpecialAttributesRouteSubscriber();
$this->expectException(\PHPUnit_Framework_Error_Warning::class);
$this->expectException(Warning::class);
$this->expectExceptionMessage('uses reserved variable names');
$subscriber->onAlterRoutes($event);
}

View File

@ -7,6 +7,7 @@ use Drupal\Core\Access\AccessResult;
use Drupal\Core\Language\Language;
use Drupal\Core\Menu\ContextualLinkDefault;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Constraint\Count;
use Symfony\Component\HttpFoundation\RequestStack;
/**
@ -286,7 +287,7 @@ class ContextualLinkManagerTest extends UnitTestCase {
$this->moduleHandler->expects($this->at(1))
->method('alter')
->with($this->equalTo('contextual_links'), new \PHPUnit_Framework_Constraint_Count(2), $this->equalTo('group1'), $this->equalTo(['key' => 'value']));
->with($this->equalTo('contextual_links'), new Count(2), $this->equalTo('group1'), $this->equalTo(['key' => 'value']));
$result = $this->contextualLinkManager->getContextualLinksArrayByGroup('group1', ['key' => 'value']);
$this->assertCount(2, $result);

View File

@ -31,7 +31,7 @@ class PathProcessorTest extends UnitTestCase {
/**
* The language manager stub used to construct a PathProcessorLanguage object.
*
* @var \Drupal\language\ConfigurableLanguageManagerInterface|\PHPUnit_Framework_MockObject_MockBuilder
* @var \Drupal\language\ConfigurableLanguageManagerInterface|\PHPUnit\Framework\MockObject\MockBuilder
*/
protected $languageManager;

View File

@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Plugin;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
/**
* @coversDefaultClass \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
@ -15,7 +16,7 @@ class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase
/**
* {@inheritdoc}
*/
protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL) {
protected function setupPluginCollection(InvokedRecorder $create_count = NULL) {
$definitions = $this->getPluginDefinitions();
$this->pluginInstances['apple'] = new ConfigurablePlugin(['id' => 'apple', 'key' => 'value'], 'apple', $definitions['apple']);
$this->pluginInstances['banana'] = new ConfigurablePlugin(['id' => 'banana', 'key' => 'other_value'], 'banana', $definitions['banana']);

View File

@ -4,6 +4,7 @@ namespace Drupal\Tests\Core\Plugin;
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
/**
* Provides a base class for plugin collection tests.
@ -53,12 +54,12 @@ abstract class LazyPluginCollectionTestBase extends UnitTestCase {
/**
* Sets up the default plugin collection.
*
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder|null $create_count
* @param \PHPUnit\Framework\MockObject\Matcher\InvokedRecorder|null $create_count
* (optional) The number of times that createInstance() is expected to be
* called. For example, $this->any(), $this->once(), $this->exactly(6).
* Defaults to $this->never().
*/
protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL) {
protected function setupPluginCollection(InvokedRecorder $create_count = NULL) {
$this->pluginInstances = [];
$map = [];
foreach ($this->getPluginDefinitions() as $plugin_id => $definition) {

View File

@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Render;
use Drupal\Core\Access\AccessResult;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Render\Element;
use PHPUnit\Framework\Error\Error;
/**
* @coversDefaultClass \Drupal\Core\Render\Element
@ -106,7 +107,7 @@ class ElementTest extends UnitTestCase {
$element = [
'foo' => 'bar',
];
$this->expectException(\PHPUnit_Framework_Error::class);
$this->expectException(Error::class);
$this->expectExceptionMessage('"foo" is an invalid render array key');
Element::children($element);
}

View File

@ -1118,7 +1118,7 @@ HTML;
}
/**
* @return \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_Builder_InvocationMocker
* @return \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit\Framework\MockObject\Builder\InvocationMocker
*/
protected function setupThemeManagerForDetails() {
return $this->themeManager->expects($this->any())

View File

@ -25,7 +25,7 @@ class StringTranslationTraitTest extends UnitTestCase {
* The mock under test that uses StringTranslationTrait.
*
* @var object
* @see PHPUnit_Framework_MockObject_Generator::getObjectForTrait()
* @see \PHPUnit\Framework\MockObject\Generator::getObjectForTrait()
*/
protected $translation;

View File

@ -160,7 +160,7 @@ class UrlTest extends UnitTestCase {
* @param string $path
* The path.
*
* @return \PHPUnit_Framework_Constraint_Callback
* @return \PHPUnit\Framework\Constraint\Callback
* The constraint checks whether a Request object has the right path.
*/
protected function getRequestConstraint($path) {

View File

@ -6,28 +6,19 @@ use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Drupal\Tests\Listeners\Legacy\AfterSymfonyListener', 'Drupal\Tests\Listeners\AfterSymfonyListener');
// Using an early return instead of an else does not work when using the
// PHPUnit phar due to some weird PHP behavior (the class gets defined without
// executing the code before it and so the definition is not properly
// conditional).
}
else {
/**
* Listens to PHPUnit test runs.
*
* @internal
*/
class AfterSymfonyListener implements TestListener {
use TestListenerDefaultImplementation;
/**
* Listens to PHPUnit test runs.
*
* @internal
* {@inheritdoc}
*/
class AfterSymfonyListener implements TestListener {
use TestListenerDefaultImplementation;
/**
* {@inheritdoc}
*/
public function endTest(Test $test, $time) {
restore_error_handler();
}
public function endTest(Test $test, $time) {
restore_error_handler();
}
}

View File

@ -4,6 +4,7 @@ namespace Drupal\Tests\Listeners;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Test;
/**
* Removes deprecations that we are yet to fix.
@ -24,7 +25,7 @@ trait DeprecationListenerTrait {
private $previousHandler;
protected function deprecationStartTest($test) {
if ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase) {
if ($test instanceof TestCase) {
if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {
$this->registerErrorHandler($test);
}
@ -37,7 +38,7 @@ trait DeprecationListenerTrait {
/**
* Reacts to the end of a test.
*
* @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
* @param \PHPUnit\Framework\Test $test
* The test object that has ended its test run.
* @param float $time
* The time the test took.
@ -52,13 +53,12 @@ trait DeprecationListenerTrait {
}
}
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
$util_test_class = class_exists('PHPUnit_Util_Test') ? 'PHPUnit_Util_Test' : 'PHPUnit\Util\Test';
$method = $test->getName(FALSE);
if (strpos($method, 'testLegacy') === 0
|| strpos($method, 'provideLegacy') === 0
|| strpos($method, 'getLegacy') === 0
|| strpos(get_class($test), '\Legacy')
|| in_array('legacy', $util_test_class::getGroups(get_class($test), $method), TRUE)) {
|| in_array('legacy', Test::getGroups(get_class($test), $method), TRUE)) {
// This is a legacy test don't skip deprecations.
return;
}
@ -83,7 +83,7 @@ trait DeprecationListenerTrait {
/**
* Determines if a test is isolated.
*
* @param \PHPUnit_Framework_TestCase|\PHPUnit\Framework\TestCase $test
* @param \PHPUnit\Framework\TestCase $test
* The test to check.
*
* @return bool

View File

@ -17,7 +17,7 @@ trait DrupalComponentTestListenerTrait {
/**
* Reacts to the end of a test.
*
* @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
* @param \PHPUnit\Framework\Test $test
* The test object that has ended its test run.
* @param float $time
* The time the test took.

View File

@ -6,40 +6,31 @@ use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Drupal\Tests\Listeners\Legacy\DrupalListener', 'Drupal\Tests\Listeners\DrupalListener');
// Using an early return instead of a else does not work when using the
// PHPUnit phar due to some weird PHP behavior (the class gets defined without
// executing the code before it and so the definition is not properly
// conditional).
}
else {
/**
* Listens to PHPUnit test runs.
*
* @internal
*/
class DrupalListener implements TestListener {
use TestListenerDefaultImplementation;
use DeprecationListenerTrait;
use DrupalComponentTestListenerTrait;
use DrupalStandardsListenerTrait;
/**
* Listens to PHPUnit test runs.
*
* @internal
* {@inheritdoc}
*/
class DrupalListener implements TestListener {
use TestListenerDefaultImplementation;
use DeprecationListenerTrait;
use DrupalComponentTestListenerTrait;
use DrupalStandardsListenerTrait;
/**
* {@inheritdoc}
*/
public function startTest(Test $test) {
$this->deprecationStartTest($test);
}
/**
* {@inheritdoc}
*/
public function endTest(Test $test, $time) {
$this->deprecationEndTest($test, $time);
$this->componentEndTest($test, $time);
$this->standardsEndTest($test, $time);
}
public function startTest(Test $test) {
$this->deprecationStartTest($test);
}
/**
* {@inheritdoc}
*/
public function endTest(Test $test, $time) {
$this->deprecationEndTest($test, $time);
$this->componentEndTest($test, $time);
$this->standardsEndTest($test, $time);
}
}

View File

@ -5,6 +5,7 @@ namespace Drupal\Tests\Listeners;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Util\ErrorHandler;
/**
* Listens for PHPUnit tests and fails those with invalid coverage annotations.
@ -167,8 +168,7 @@ trait DrupalStandardsListenerTrait {
if ($type === E_USER_DEPRECATED) {
return;
}
$error_handler = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_ErrorHandler' : 'PHPUnit\Util\ErrorHandler';
return $error_handler::handleError($type, $msg, $file, $line, $context);
return ErrorHandler::handleError($type, $msg, $file, $line, $context);
}
/**
@ -182,7 +182,7 @@ trait DrupalStandardsListenerTrait {
*
* @group legacy
*
* @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
* @param \PHPUnit\Framework\Test $test
* The test object that has ended its test run.
* @param float $time
* The time the test took.
@ -190,7 +190,7 @@ trait DrupalStandardsListenerTrait {
* @see http://symfony.com/doc/current/components/phpunit_bridge.html#mark-tests-as-legacy
*/
private function doEndTest($test, $time) {
// \PHPUnit_Framework_Test does not have any useful methods of its own for
// \PHPUnit\Framework\Test does not have any useful methods of its own for
// our purpose, so we have to distinguish between the different known
// subclasses.
if ($test instanceof TestCase) {
@ -212,16 +212,13 @@ trait DrupalStandardsListenerTrait {
/**
* Determine if a test object is a test suite regardless of PHPUnit version.
*
* @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
* @param \PHPUnit\Framework\Test $test
* The test object to test if it is a test suite.
*
* @return bool
* TRUE if it is a test suite, FALSE if not.
*/
private function isTestSuite($test) {
if (class_exists('\PHPUnit_Framework_TestSuite') && $test instanceof \PHPUnit_Framework_TestSuite) {
return TRUE;
}
if (class_exists('PHPUnit\Framework\TestSuite') && $test instanceof TestSuite) {
return TRUE;
}
@ -231,7 +228,7 @@ trait DrupalStandardsListenerTrait {
/**
* Reacts to the end of a test.
*
* @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
* @param \PHPUnit\Framework\Test $test
* The test object that has ended its test run.
* @param float $time
* The time the test took.

View File

@ -5,39 +5,30 @@ namespace Drupal\Tests\Listeners;
use PHPUnit\Framework\TestResult;
use PHPUnit\TextUI\ResultPrinter;
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Drupal\Tests\Listeners\Legacy\HtmlOutputPrinter', 'Drupal\Tests\Listeners\HtmlOutputPrinter');
// Using an early return instead of a else does not work when using the
// PHPUnit phar due to some weird PHP behavior (the class gets defined without
// executing the code before it and so the definition is not properly
// conditional).
}
else {
/**
* Defines a class for providing html output results for functional tests.
*
* @internal
*/
class HtmlOutputPrinter extends ResultPrinter {
use HtmlOutputPrinterTrait;
/**
* Defines a class for providing html output results for functional tests.
*
* @internal
* {@inheritdoc}
*/
class HtmlOutputPrinter extends ResultPrinter {
use HtmlOutputPrinterTrait;
/**
* {@inheritdoc}
*/
public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80, $reverse = FALSE) {
parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
$this->setUpHtmlOutput();
}
/**
* {@inheritdoc}
*/
public function printResult(TestResult $result) {
parent::printResult($result);
$this->printHtmlOutput();
}
public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80, $reverse = FALSE) {
parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
$this->setUpHtmlOutput();
}
/**
* {@inheritdoc}
*/
public function printResult(TestResult $result) {
parent::printResult($result);
$this->printHtmlOutput();
}
}

View File

@ -1,19 +0,0 @@
<?php
namespace Drupal\Tests\Listeners\Legacy;
/**
* Listens to PHPUnit test runs.
*
* @internal
*/
class AfterSymfonyListener extends \PHPUnit_Framework_BaseTestListener {
/**
* {@inheritdoc}
*/
public function endTest(\PHPUnit_Framework_Test $test, $time) {
restore_error_handler();
}
}

View File

@ -1,36 +0,0 @@
<?php
namespace Drupal\Tests\Listeners\Legacy;
use Drupal\Tests\Listeners\DeprecationListenerTrait;
use Drupal\Tests\Listeners\DrupalComponentTestListenerTrait;
use Drupal\Tests\Listeners\DrupalStandardsListenerTrait;
/**
* Listens to PHPUnit test runs.
*
* @internal
* This class is not public Drupal API.
*/
class DrupalListener extends \PHPUnit_Framework_BaseTestListener {
use DeprecationListenerTrait;
use DrupalComponentTestListenerTrait;
use DrupalStandardsListenerTrait;
/**
* {@inheritdoc}
*/
public function startTest(\PHPUnit_Framework_Test $test) {
$this->deprecationStartTest($test);
}
/**
* {@inheritdoc}
*/
public function endTest(\PHPUnit_Framework_Test $test, $time) {
$this->deprecationEndTest($test, $time);
$this->componentEndTest($test, $time);
$this->standardsEndTest($test, $time);
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace Drupal\Tests\Listeners\Legacy;
use Drupal\Tests\Listeners\HtmlOutputPrinterTrait;
/**
* Defines a class for providing html output results for functional tests.
*
* @internal
*/
class HtmlOutputPrinter extends \PHPUnit_TextUI_ResultPrinter {
use HtmlOutputPrinterTrait;
/**
* {@inheritdoc}
*/
public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80) {
parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns);
$this->setUpHtmlOutput();
}
/**
* {@inheritdoc}
*/
public function printResult(\PHPUnit_Framework_TestResult $result) {
parent::printResult($result);
$this->printHtmlOutput();
}
}

View File

@ -0,0 +1,89 @@
<?php
namespace Drupal\Tests;
/**
* Tests existence of the PHPUnit4 backward compatibility classes.
*
* @group Tests
*/
class Phpunit4CompatibilityTest extends UnitTestCase {
/**
* Tests existence of \PHPUnit_Framework_AssertionFailedError.
*/
public function testFrameworkAssertionFailedError() {
$this->assertTrue(class_exists('\PHPUnit_Framework_AssertionFailedError'));
}
/**
* Tests existence of \PHPUnit_Framework_Constraint_Count.
*/
public function testFrameworkConstraintCount() {
$this->assertTrue(class_exists('\PHPUnit_Framework_Constraint_Count'));
}
/**
* Tests existence of \PHPUnit_Framework_Error.
*/
public function testFrameworkError() {
$this->assertTrue(class_exists('\PHPUnit_Framework_Error'));
}
/**
* Tests existence of \PHPUnit_Framework_Error_Warning.
*/
public function FrameworkErrorWarning() {
$this->assertTrue(class_exists('\PHPUnit_Framework_Error_Warning'));
}
/**
* Tests existence of \PHPUnit_Framework_Exception.
*/
public function testFrameworkException() {
$this->assertTrue(class_exists('\PHPUnit_Framework_Exception'));
}
/**
* Tests existence of \PHPUnit_Framework_ExpectationFailedException.
*/
public function testFrameworkExpectationFailedException() {
$this->assertTrue(class_exists('\PHPUnit_Framework_ExpectationFailedException'));
}
/**
* Tests existence of \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder.
*/
public function testFrameworkMockObjectMatcherInvokedRecorder() {
$this->assertTrue(class_exists('\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder'));
}
/**
* Tests existence of \PHPUnit_Framework_SkippedTestError.
*/
public function testFrameworkSkippedTestError() {
$this->assertTrue(class_exists('\PHPUnit_Framework_SkippedTestError'));
}
/**
* Tests existence of \PHPUnit_Framework_TestCase.
*/
public function testFrameworkTestCase() {
$this->assertTrue(class_exists('\PHPUnit_Framework_TestCase'));
}
/**
* Tests existence of \PHPUnit_Util_Test.
*/
public function testUtilTest() {
$this->assertTrue(class_exists('\PHPUnit_Util_Test'));
}
/**
* Tests existence of \PHPUnit_Util_XML.
*/
public function testUtilXml() {
$this->assertTrue(class_exists('\PHPUnit_Util_XML'));
}
}

View File

@ -38,7 +38,6 @@ trait PhpunitCompatibilityTrait {
* @param object $proxyTarget
* Sets the proxy target.
*
* @see \PHPUnit_Framework_TestCase::getMock
* @see https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0
*
* @return \PHPUnit_Framework_MockObject_MockObject

View File

@ -3,12 +3,13 @@
namespace Drupal\Tests;
use Drupal\Core\Extension\ExtensionDiscovery;
use PHPUnit\Framework\SkippedTestError;
/**
* Allows test classes to require Drupal modules as dependencies.
*
* This trait is assumed to be on a subclass of \PHPUnit_Framework_TestCase, and
* overrides \PHPUnit_Framework_TestCase::checkRequirements(). This allows the
* This trait is assumed to be on a subclass of \PHPUnit\Framework\TestCase, and
* overrides \PHPUnit\Framework\TestCase::checkRequirements(). This allows the
* test to be marked as skipped before any kernel boot processes have happened.
*/
trait TestRequirementsTrait {
@ -26,9 +27,9 @@ trait TestRequirementsTrait {
* Check module requirements for the Drupal use case.
*
* This method is assumed to override
* \PHPUnit_Framework_TestCase::checkRequirements().
* \PHPUnit\Framework\TestCase::checkRequirements().
*
* @throws \PHPUnit_Framework_SkippedTestError
* @throws \PHPUnit\Framework\SkippedTestError
* Thrown when the requirements are not met, and this test should be
* skipped. Callers should not catch this exception.
*/
@ -59,7 +60,7 @@ trait TestRequirementsTrait {
* @param string[] $annotations
* A list of requires annotations from either a method or class annotation.
*
* @throws \PHPUnit_Framework_SkippedTestError
* @throws \PHPUnit\Framework\SkippedTestError
* Thrown when the requirements are not met, and this test should be
* skipped. Callers should not catch this exception.
*/
@ -83,7 +84,7 @@ trait TestRequirementsTrait {
$list = array_keys($discovery->scan('module'));
$not_available = array_diff($required_modules, $list);
if (!empty($not_available)) {
throw new \PHPUnit_Framework_SkippedTestError('Required modules: ' . implode(', ', $not_available));
throw new SkippedTestError('Required modules: ' . implode(', ', $not_available));
}
}
}

View File

@ -4,7 +4,9 @@ namespace Drupal\Tests\Traits;
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener as LegacySymfonyTestsListener;
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Test;
/**
* Adds the ability to dynamically set expected deprecation messages in tests.
@ -34,19 +36,11 @@ trait ExpectDeprecationTrait {
* The expected deprecation messages.
*/
public function expectedDeprecations(array $messages) {
if (class_exists('PHPUnit_Util_Test', FALSE)) {
$test_util = 'PHPUnit_Util_Test';
$assertion_failed_error = 'PHPUnit_Framework_AssertionFailedError';
}
else {
$test_util = 'PHPUnit\Util\Test';
$assertion_failed_error = 'PHPUnit\Framework\AssertionFailedError';
}
if ($this instanceof \PHPUnit_Framework_TestCase || $this instanceof TestCase) {
if ($this instanceof TestCase) {
// Ensure the class or method is in the legacy group.
$groups = $test_util::getGroups(get_class($this), $this->getName(FALSE));
$groups = Test::getGroups(get_class($this), $this->getName(FALSE));
if (!in_array('legacy', $groups, TRUE)) {
throw new $assertion_failed_error('Only tests with the `@group legacy` annotation can call `setExpectedDeprecation()`.');
throw new AssertionFailedError('Only tests with the `@group legacy` annotation can call `setExpectedDeprecation()`.');
}
// If setting an expected deprecation there is no need to be strict about
@ -89,7 +83,7 @@ trait ExpectDeprecationTrait {
return;
}
throw new $assertion_failed_error('Can not set an expected deprecation message because the Symfony\Bridge\PhpUnit\SymfonyTestsListener is not registered as a PHPUnit test listener.');
throw new AssertionFailedError('Can not set an expected deprecation message because the Symfony\Bridge\PhpUnit\SymfonyTestsListener is not registered as a PHPUnit test listener.');
}
/**

View File

@ -104,7 +104,7 @@ abstract class UnitTestCase extends TestCase {
* configuration object names and whose values are key => value arrays for
* the configuration object in question. Defaults to an empty array.
*
* @return \PHPUnit_Framework_MockObject_MockBuilder
* @return \PHPUnit\Framework\MockObject\MockBuilder
* A MockBuilder object for the ConfigFactory with the desired return
* values.
*/

View File

@ -8,7 +8,17 @@
*/
use Drupal\Component\Assertion\Handle;
use PHPUnit\Runner\Version;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Constraint\Count;
use PHPUnit\Framework\Error\Error;
use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
use PHPUnit\Framework\SkippedTestError;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Test;
use PHPUnit\Util\Xml;
/**
* Finds all valid extension directories recursively within a given directory.
@ -151,14 +161,6 @@ function drupal_phpunit_populate_class_loader() {
// Do class loader population.
drupal_phpunit_populate_class_loader();
// Ensure we have the correct PHPUnit version for the version of PHP.
if (class_exists('\PHPUnit_Runner_Version')) {
$phpunit_version = \PHPUnit_Runner_Version::id();
}
else {
$phpunit_version = Version::id();
}
// Set sane locale settings, to ensure consistent string, dates, times and
// numbers handling.
// @see \Drupal\Core\DrupalKernel::bootEnvironment()
@ -183,16 +185,15 @@ Handle::register();
// PHPUnit 4 to PHPUnit 6 bridge. Tests written for PHPUnit 4 need to work on
// PHPUnit 6 with a minimum of fuss.
if (version_compare($phpunit_version, '6.1', '>=')) {
class_alias('\PHPUnit\Framework\AssertionFailedError', '\PHPUnit_Framework_AssertionFailedError');
class_alias('\PHPUnit\Framework\Constraint\Count', '\PHPUnit_Framework_Constraint_Count');
class_alias('\PHPUnit\Framework\Error\Error', '\PHPUnit_Framework_Error');
class_alias('\PHPUnit\Framework\Error\Warning', '\PHPUnit_Framework_Error_Warning');
class_alias('\PHPUnit\Framework\ExpectationFailedException', '\PHPUnit_Framework_ExpectationFailedException');
class_alias('\PHPUnit\Framework\Exception', '\PHPUnit_Framework_Exception');
class_alias('\PHPUnit\Framework\MockObject\Matcher\InvokedRecorder', '\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder');
class_alias('\PHPUnit\Framework\SkippedTestError', '\PHPUnit_Framework_SkippedTestError');
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
class_alias('\PHPUnit\Util\Test', '\PHPUnit_Util_Test');
class_alias('\PHPUnit\Util\Xml', '\PHPUnit_Util_XML');
}
// @todo provided for BC; remove in Drupal 9.
class_alias(AssertionFailedError::class, '\PHPUnit_Framework_AssertionFailedError');
class_alias(Count::class, '\PHPUnit_Framework_Constraint_Count');
class_alias(Error::class, '\PHPUnit_Framework_Error');
class_alias(Warning::class, '\PHPUnit_Framework_Error_Warning');
class_alias(ExpectationFailedException::class, '\PHPUnit_Framework_ExpectationFailedException');
class_alias(Exception::class, '\PHPUnit_Framework_Exception');
class_alias(InvokedRecorder::class, '\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder');
class_alias(SkippedTestError::class, '\PHPUnit_Framework_SkippedTestError');
class_alias(TestCase::class, '\PHPUnit_Framework_TestCase');
class_alias(Test::class, '\PHPUnit_Util_Test');
class_alias(Xml::class, '\PHPUnit_Util_XML');