Commit 74fbb0aa authored by catch's avatar catch
Browse files

Issue #3127141 by mondrake, longwave, alexpott, Neslee Canil Pinto, Suresh...

Issue #3127141 by mondrake, longwave, alexpott, Neslee Canil Pinto, Suresh Prabhu Parkala, ravi.shankar: Use PHPUnit 9 for PHP 7.4+, while keeping support for PHPUnit 8.4 in PHP 7.3
parent 89d9f113
......@@ -21,7 +21,7 @@
"composer/composer": "^1.9.1",
"drupal/coder": "^8.3.7",
"mikey179/vfsstream": "^1.6.8",
"phpunit/phpunit": "^8.4.1",
"phpunit/phpunit": "^8.4.1 || ^9",
"phpspec/prophecy": "^1.7",
"symfony/css-selector": "^4.4",
"symfony/phpunit-bridge": "^5.1.4",
......@@ -93,7 +93,10 @@
"pre-update-cmd": "Drupal\\Composer\\Composer::ensureComposerVersion",
"pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
"drupal-phpunit-upgrade-check": "Drupal\\Core\\Composer\\Composer::upgradePHPUnit",
"drupal-phpunit-upgrade": "@composer update phpunit/phpunit symfony/phpunit-bridge phpspec/prophecy symfony/yaml --with-dependencies --no-progress",
"drupal-phpunit-upgrade": [
"@composer update phpunit/phpunit --with-dependencies --no-progress",
"@composer require phpspec/prophecy-phpunit:^2 --no-progress --no-suggest"
],
"post-update-cmd": [
"Drupal\\Composer\\Composer::generateMetapackages"
],
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "059e8aee61edb73b1526b840eb6c624c",
"content-hash": "09de613d0e44689de15282c33d3d700e",
"packages": [
{
"name": "asm89/stack-cors",
......
......@@ -16,7 +16,7 @@
"justinrainbow/json-schema": "^5.2",
"mikey179/vfsstream": "^1.6.8",
"phpspec/prophecy": "^1.7",
"phpunit/phpunit": "^8.4.1",
"phpunit/phpunit": "^8.4.1 || ^9",
"symfony/browser-kit": "^4.4",
"symfony/css-selector": "^4.4",
"symfony/dom-crawler": "^4.4 !=4.4.5",
......
......@@ -310,7 +310,7 @@ public static function upgradePHPUnit(Event $event) {
return;
}
// If the PHP version is 7.3 or above and PHPUnit is less than version 7
// If the PHP version is 7.4 or above and PHPUnit is less than version 9
// call the drupal-phpunit-upgrade script to upgrade PHPUnit.
if (!static::upgradePHPUnitCheck($phpunit_package->getVersion())) {
$event->getComposer()
......@@ -332,7 +332,7 @@ public static function upgradePHPUnit(Event $event) {
* TRUE if the PHPUnit needs to be upgraded, FALSE if not.
*/
public static function upgradePHPUnitCheck($phpunit_version) {
return !(version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, '7.3') >= 0 && version_compare($phpunit_version, '7.0') < 0);
return !(version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, '7.4') >= 0 && version_compare($phpunit_version, '9.0') < 0);
}
}
......@@ -70,8 +70,8 @@ public function testNodeTranslation() {
$normalized = $this->serializer->normalize($node, $this->format);
$this->assertContains(['lang' => 'en', 'value' => $node->getTitle()], $normalized['title'], 'Original language title has been normalized.');
$this->assertContains(['lang' => 'de', 'value' => $translation->getTitle()], $normalized['title'], 'Translation language title has been normalized.');
$this->assertContainsEquals(['lang' => 'en', 'value' => $node->getTitle()], $normalized['title'], 'Original language title has been normalized.');
$this->assertContainsEquals(['lang' => 'de', 'value' => $translation->getTitle()], $normalized['title'], 'Translation language title has been normalized.');
/** @var \Drupal\node\NodeInterface $denormalized_node */
$denormalized_node = $this->serializer->denormalize($normalized, 'Drupal\node\Entity\Node', $this->format);
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\migrate\Unit;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Tests\UnitTestCase;
use Drupal\migrate\MigrateStub;
use Drupal\migrate\Plugin\MigrateDestinationInterface;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
......@@ -10,7 +11,6 @@
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate\Row;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
/**
......@@ -20,7 +20,7 @@
*
* @coversDefaultClass \Drupal\migrate\MigrateStub
*/
class MigrateStubTest extends TestCase {
class MigrateStubTest extends UnitTestCase {
/**
* The plugin manager prophecy.
......
......@@ -126,7 +126,7 @@ public function testReferenceablesWithNoLabelKey($match, $match_operator, $limit
// entity labels.
// @see \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::getReferenceableEntities()
$item = is_string($item) ? Html::escape($item) : $item;
$this->assertContains($item, $referenceables[$this->bundle]);
$this->assertContainsEquals($item, $referenceables[$this->bundle]);
}
// Test ::countReferenceableEntities().
......
......@@ -149,7 +149,7 @@
}
if (!Composer::upgradePHPUnitCheck(Version::id())) {
simpletest_script_print_error("PHPUnit testing framework version 7 or greater is required when running on PHP 7.3 or greater. Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this.");
simpletest_script_print_error("PHPUnit testing framework version 9 or greater is required when running on PHP 7.4 or greater. Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this.");
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
}
......
......@@ -7,6 +7,7 @@
use Behat\Mink\Mink;
use Behat\Mink\Session;
use Drupal\Component\FileSystem\FileSystem as DrupalFilesystem;
use Drupal\Tests\PhpUnitCompatibilityTrait;
use Drupal\Tests\Traits\PhpUnitWarnings;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
......@@ -53,6 +54,7 @@ abstract class BuildTestBase extends TestCase {
use ExternalCommandRequirementsTrait;
use PhpUnitWarnings;
use PhpUnitCompatibilityTrait;
/**
* The working directory where this test will manipulate files.
......
......@@ -612,7 +612,7 @@ public function testUnmetDependency() {
'Configuration <em class="placeholder">unknown.config</em> depends on the <em class="placeholder">unknown</em> extension that will not be installed after import.',
];
foreach ($expected as $expected_message) {
$this->assertContains($expected_message, $error_log, $expected_message);
$this->assertContainsEquals($expected_message, $error_log, $expected_message);
}
}
......@@ -658,7 +658,7 @@ public function testUnmetDependency() {
'Configuration <em class="placeholder">config_test.dynamic.dotted.theme</em> depends on themes (<em class="placeholder">unknown, Seven</em>) that will not be installed after import.',
];
foreach ($expected as $expected_message) {
$this->assertContains($expected_message, $error_log, $expected_message);
$this->assertContainsEquals($expected_message, $error_log, $expected_message);
}
}
}
......
......@@ -42,7 +42,7 @@ public function testMunging() {
$munged_name = file_munge_filename($this->name, '', TRUE);
$messages = \Drupal::messenger()->all();
\Drupal::messenger()->deleteAll();
$this->assertContains(strtr('For security reasons, your upload has been renamed to <em class="placeholder">%filename</em>.', ['%filename' => $munged_name]), $messages['status'], 'Alert properly set when a file is renamed.');
$this->assertContainsEquals(strtr('For security reasons, your upload has been renamed to <em class="placeholder">%filename</em>.', ['%filename' => $munged_name]), $messages['status'], 'Alert properly set when a file is renamed.');
$this->assertNotEqual($munged_name, $this->name, new FormattableMarkup('The new filename (%munged) has been modified from the original (%original)', ['%munged' => $munged_name, '%original' => $this->name]));
}
......
......@@ -49,7 +49,7 @@ public function testRemoveSingleMessage() {
// Check we only have the second one.
$this->assertCount(1, $this->messenger->messagesByType(MessengerInterface::TYPE_STATUS));
$this->assertContains('Second message with <em>markup!</em> (not removed).', $this->messenger->deleteByType(MessengerInterface::TYPE_STATUS));
$this->assertContainsEquals('Second message with <em>markup!</em> (not removed).', $this->messenger->deleteByType(MessengerInterface::TYPE_STATUS));
}
......
......@@ -18,6 +18,7 @@
use Drupal\Core\Test\TestDatabase;
use Drupal\Tests\ConfigTestTrait;
use Drupal\Tests\RandomGeneratorTrait;
use Drupal\Tests\PhpUnitCompatibilityTrait;
use Drupal\Tests\TestRequirementsTrait;
use Drupal\Tests\Traits\PhpUnitWarnings;
use Drupal\TestTools\Comparator\MarkupInterfaceComparator;
......@@ -79,6 +80,7 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
use ConfigTestTrait;
use TestRequirementsTrait;
use PhpUnitWarnings;
use PhpUnitCompatibilityTrait;
/**
* {@inheritdoc}
......
<?php
namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit8;
/**
* Drupal's forward compatibility layer with multiple versions of PHPUnit.
*/
trait TestCompatibilityTrait {
}
<?php
namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit9;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* Drupal's forward compatibility layer with multiple versions of PHPUnit.
*/
trait TestCompatibilityTrait {
use ProphecyTrait;
}
......@@ -65,6 +65,7 @@ abstract class BrowserTestBase extends TestCase {
}
use XdebugRequestTrait;
use PhpUnitWarnings;
use PhpUnitCompatibilityTrait;
/**
* The database prefix of this test run.
......
......@@ -6,6 +6,7 @@
use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator;
use Drupal\Component\Plugin\Definition\PluginDefinition;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Tests\PhpUnitCompatibilityTrait;
use PHPUnit\Framework\TestCase;
/**
......@@ -14,6 +15,8 @@
*/
class AnnotationBridgeDecoratorTest extends TestCase {
use PhpUnitCompatibilityTrait;
/**
* @covers ::getDefinitions
*/
......
......@@ -8,6 +8,7 @@
namespace Drupal\Tests\Component\DependencyInjection;
use Drupal\Component\Utility\Crypt;
use Drupal\Tests\PhpUnitCompatibilityTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
......@@ -24,6 +25,8 @@
*/
class ContainerTest extends TestCase {
use PhpUnitCompatibilityTrait;
/**
* The tested container.
*
......
......@@ -8,6 +8,7 @@
namespace Drupal\Tests\Component\DependencyInjection\Dumper {
use Drupal\Component\Utility\Crypt;
use Drupal\Tests\PhpUnitCompatibilityTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
......@@ -24,6 +25,8 @@
*/
class OptimizedPhpArrayDumperTest extends TestCase {
use PhpUnitCompatibilityTrait;
/**
* The container builder instance.
*
......
......@@ -4,7 +4,6 @@
use Drupal\Component\Diff\Engine\DiffOp;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Error\Error;
/**
* Test DiffOp base class.
......@@ -25,7 +24,7 @@ class DiffOpTest extends TestCase {
* @covers ::reverse
*/
public function testReverse() {
$this->expectException(Error::class);
$this->expectError();
$op = new DiffOp();
$result = $op->reverse();
}
......
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