Commit 75f0c02a authored by alexpott's avatar alexpott
Browse files

Issue #2850797 by maxocub, dawehner, alexpott: Prepare our phpunit tests to be...

Issue #2850797 by maxocub, dawehner, alexpott: Prepare our phpunit tests to be BC compatible with phpunit 5.x/6.x
parent 3d292b3e
......@@ -41,7 +41,7 @@
"jcalderonzumba/gastonjs": "~1.0.2",
"jcalderonzumba/mink-phantomjs-driver": "~0.3.1",
"mikey179/vfsStream": "~1.2",
"phpunit/phpunit": ">=4.8.28 <5",
"phpunit/phpunit": ">=4.8.35 <5",
"symfony/browser-kit": ">=2.8.13 <3.0",
"symfony/css-selector": "~2.8"
},
......
......@@ -5,13 +5,14 @@
use Drupal\content_moderation\ContentPreprocess;
use Drupal\Core\Routing\CurrentRouteMatch;
use Drupal\node\Entity\Node;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\content_moderation\ContentPreprocess
*
* @group content_moderation
*/
class ContentPreprocessTest extends \PHPUnit_Framework_TestCase {
class ContentPreprocessTest extends UnitTestCase {
/**
* @covers ::isLatestVersionPage
......
......@@ -9,13 +9,14 @@
use Drupal\node\Entity\Node;
use Drupal\content_moderation\Access\LatestRevisionCheck;
use Drupal\content_moderation\ModerationInformation;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Routing\Route;
/**
* @coversDefaultClass \Drupal\content_moderation\Access\LatestRevisionCheck
* @group content_moderation
*/
class LatestRevisionCheckTest extends \PHPUnit_Framework_TestCase {
class LatestRevisionCheckTest extends UnitTestCase {
/**
* Test the access check of the LatestRevisionCheck service.
......
......@@ -10,13 +10,14 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\content_moderation\ModerationInformation;
use Drupal\Tests\UnitTestCase;
use Drupal\workflows\WorkflowInterface;
/**
* @coversDefaultClass \Drupal\content_moderation\ModerationInformation
* @group content_moderation
*/
class ModerationInformationTest extends \PHPUnit_Framework_TestCase {
class ModerationInformationTest extends UnitTestCase {
/**
* Builds a mock user.
......
......@@ -7,6 +7,7 @@
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\content_moderation\StateTransitionValidation;
use Drupal\Tests\UnitTestCase;
use Drupal\workflows\Entity\Workflow;
use Drupal\workflows\WorkflowTypeInterface;
use Drupal\workflows\WorkflowTypeManager;
......@@ -16,7 +17,7 @@
* @coversDefaultClass \Drupal\content_moderation\StateTransitionValidation
* @group content_moderation
*/
class StateTransitionValidationTest extends \PHPUnit_Framework_TestCase {
class StateTransitionValidationTest extends UnitTestCase {
/**
* Verifies user-aware transition validation.
......
......@@ -259,7 +259,7 @@ public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE)
/**
* Asserts that a file exists physically on disk.
*
* Overrides PHPUnit_Framework_Assert::assertFileExists() to also work with
* Overrides PHPUnit\Framework\Assert::assertFileExists() to also work with
* file entities.
*
* @param \Drupal\File\FileInterface|string $file
......@@ -286,7 +286,7 @@ public function assertFileEntryExists($file, $message = NULL) {
/**
* Asserts that a file does not exist on disk.
*
* Overrides PHPUnit_Framework_Assert::assertFileExists() to also work with
* Overrides PHPUnit\Framework\Assert::assertFileExists() to also work with
* file entities.
*
* @param \Drupal\File\FileInterface|string $file
......
......@@ -3,12 +3,13 @@
namespace Drupal\Tests\migrate\Unit\Event;
use Drupal\migrate\Event\EventBase;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\migrate\Event\EventBase
* @group migrate
*/
class EventBaseTest extends \PHPUnit_Framework_TestCase {
class EventBaseTest extends UnitTestCase {
/**
* Test getMigration method.
......
......@@ -3,12 +3,13 @@
namespace Drupal\Tests\migrate\Unit\Event;
use Drupal\migrate\Event\MigrateImportEvent;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\migrate\Event\MigrateImportEvent
* @group migrate
*/
class MigrateImportEventTest extends \PHPUnit_Framework_TestCase {
class MigrateImportEventTest extends UnitTestCase {
/**
* Test getMigration method.
......
......@@ -4,6 +4,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\serialization\RegisterSerializationClassesCompilerPass;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\Serializer\Serializer;
......@@ -11,7 +12,7 @@
* @coversDefaultClass \Drupal\serialization\RegisterSerializationClassesCompilerPass
* @group serialization
*/
class RegisterSerializationClassesCompilerPassTest extends \PHPUnit_Framework_TestCase {
class RegisterSerializationClassesCompilerPassTest extends UnitTestCase {
/**
* @covers ::process
......
......@@ -6,6 +6,7 @@
*/
use Drupal\Component\Utility\Environment;
use PHPUnit\Framework\TestCase;
/**
* Minimum value of PHP memory_limit for SimpleTest.
......@@ -18,7 +19,7 @@
function simpletest_requirements($phase) {
$requirements = [];
$has_phpunit = class_exists('\PHPUnit_Framework_TestCase');
$has_phpunit = class_exists(TestCase::class);
$has_curl = function_exists('curl_init');
$open_basedir = ini_get('open_basedir');
......
......@@ -13,6 +13,7 @@
use Drupal\Core\Test\TestDatabase;
use Drupal\simpletest\TestDiscovery;
use Drupal\Tests\Listeners\SimpletestUiPrinter;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\PhpExecutableFinder;
use Drupal\Core\Test\TestStatus;
......@@ -412,7 +413,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
// Perform the next test.
$test_class = array_shift($test_list);
if (is_subclass_of($test_class, \PHPUnit_Framework_TestCase::class)) {
if (is_subclass_of($test_class, TestCase::class)) {
$phpunit_results = simpletest_run_phpunit_tests($test_id, [$test_class]);
simpletest_process_phpunit_results($phpunit_results);
$test_results[$test_class] = simpletest_summarize_phpunit_result($phpunit_results)[$test_class];
......
......@@ -4,6 +4,7 @@
use Drupal\Component\Render\FormattableMarkup;
use Drupal\node\Entity\NodeType;
use PHPUnit\Framework\TestCase;
/**
* Provides methods to create content type from given values.
......@@ -40,7 +41,7 @@ protected function createContentType(array $values = []) {
$status = $type->save();
node_add_body_field($type);
if ($this instanceof \PHPUnit_Framework_TestCase) {
if ($this instanceof TestCase) {
$this->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', ['%type' => $type->id()]))->__toString());
}
else {
......
......@@ -2,6 +2,8 @@
namespace Drupal\Tests\simpletest\Unit;
use Drupal\Tests\UnitTestCase;
/**
* This test crashes PHP.
*
......@@ -11,7 +13,7 @@
*
* @see \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest::testSimpletestPhpUnitRunCommand()
*/
class SimpletestPhpunitRunCommandTestWillDie extends \PHPUnit_Framework_TestCase {
class SimpletestPhpunitRunCommandTestWillDie extends UnitTestCase {
/**
* Performs the status specified by SimpletestPhpunitRunCommandTestWillDie.
......
......@@ -4,15 +4,19 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\File\FileSystemInterface;
use PHPUnit\Framework\TestCase;
/**
* Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly.
*
* We don't extend Drupal\Tests\UnitTestCase here because its $root property is
* not static and we need it to be static here.
*
* @group simpletest
*
* @runTestsInSeparateProcesses
*/
class SimpletestPhpunitRunCommandTest extends \PHPUnit_Framework_TestCase {
class SimpletestPhpunitRunCommandTest extends TestCase {
/**
* Path to the app root.
......
......@@ -17,6 +17,7 @@
use Drupal\simpletest\Form\SimpletestResultsForm;
use Drupal\simpletest\TestBase;
use Drupal\simpletest\TestDiscovery;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once __DIR__ . '/../../autoload.php';
......@@ -36,7 +37,7 @@
const SIMPLETEST_SCRIPT_EXIT_FAILURE = 1;
const SIMPLETEST_SCRIPT_EXIT_EXCEPTION = 2;
if (!class_exists('\PHPUnit_Framework_TestCase')) {
if (!class_exists(TestCase::class)) {
echo "\nrun-tests.sh requires the PHPUnit testing framework. Please use 'composer install --dev' to ensure that it is present.\n\n";
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
}
......@@ -783,7 +784,7 @@ function simpletest_script_run_one_test($test_id, $test_class) {
$methods = array();
}
$test = new $class_name($test_id);
if (is_subclass_of($test_class, '\PHPUnit_Framework_TestCase')) {
if (is_subclass_of($test_class, TestCase::class)) {
$status = simpletest_script_run_phpunit($test_id, $test_class);
}
else {
......@@ -865,7 +866,7 @@ function simpletest_script_command($test_id, $test_class) {
* @see simpletest_script_run_one_test()
*/
function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
if (is_subclass_of($test_class, '\PHPUnit_Framework_TestCase')) {
if (is_subclass_of($test_class, TestCase::class)) {
// PHPUnit test, move on.
return;
}
......@@ -1020,7 +1021,7 @@ function simpletest_script_get_test_list() {
else {
foreach ($matches[1] as $class_name) {
$namespace_class = $namespace . '\\' . $class_name;
if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, '\PHPUnit_Framework_TestCase')) {
if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, TestCase::class)) {
$test_list[] = $namespace_class;
}
}
......@@ -1074,7 +1075,7 @@ function simpletest_script_get_test_list() {
else {
foreach ($matches[1] as $class_name) {
$namespace_class = $namespace . '\\' . $class_name;
if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, '\PHPUnit_Framework_TestCase')) {
if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, TestCase::class)) {
$test_list[] = $namespace_class;
}
}
......
......@@ -6,7 +6,7 @@
* Translates Simpletest assertion methods to PHPUnit.
*
* Protected methods are custom. Public static methods override methods of
* \PHPUnit_Framework_Assert.
* \PHPUnit\Framework\Assert.
*
* @deprecated Scheduled for removal in Drupal 9.0.0. Use PHPUnit's native
* assert methods instead.
......
......@@ -22,6 +22,7 @@
use Drupal\Tests\ConfigTestTrait;
use Drupal\Tests\RandomGeneratorTrait;
use Drupal\simpletest\TestServiceProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
use org\bovigo\vfs\vfsStream;
......@@ -49,7 +50,7 @@
* @todo Extend ::setRequirementsFromAnnotation() and ::checkRequirements() to
* account for '@requires module'.
*/
abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements ServiceProviderInterface {
abstract class KernelTestBase extends TestCase implements ServiceProviderInterface {
use AssertLegacyTrait;
use AssertContentTrait;
......
......@@ -27,6 +27,7 @@
use Drupal\simpletest\BlockCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
use Drupal\simpletest\UserCreationTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\CssSelector\CssSelectorConverter;
use Symfony\Component\HttpFoundation\Request;
use Psr\Http\Message\RequestInterface;
......@@ -41,7 +42,7 @@
*
* @ingroup testing
*/
abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
abstract class BrowserTestBase extends TestCase {
use FunctionalTestSetupTrait;
use TestSetupTrait;
......
......@@ -7,14 +7,14 @@
namespace Drupal\Tests\Component\Assertion;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase;
use Drupal\Component\Assertion\Inspector;
/**
* @coversDefaultClass \Drupal\Component\Assertion\Inspector
* @group Assertion
*/
class InspectorTest extends PHPUnit_Framework_TestCase {
class InspectorTest extends TestCase {
/**
* Tests asserting argument is an array or traversable object.
......
......@@ -8,6 +8,7 @@
namespace Drupal\Tests\Component\DependencyInjection;
use Drupal\Component\Utility\Crypt;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
......@@ -21,7 +22,7 @@
* @coversDefaultClass \Drupal\Component\DependencyInjection\Container
* @group DependencyInjection
*/
class ContainerTest extends \PHPUnit_Framework_TestCase {
class ContainerTest extends TestCase {
/**
* The tested container.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment