Commit 03fd77c8 authored by catch's avatar catch

Issue #2927806 by alexpott, mondrake, jibran, Mile23: Use PHPUnit 6 for...

Issue #2927806 by alexpott, mondrake, jibran, Mile23: Use PHPUnit 6 for testing when PHP version >= 7.2
parent 4e5b4b09
...@@ -49,11 +49,11 @@ ...@@ -49,11 +49,11 @@
}, },
"scripts": { "scripts": {
"pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump", "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
"post-autoload-dump": [ "post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
"Drupal\\Core\\Composer\\Composer::ensureHtaccess"
],
"post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup", "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
"post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup", "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
"post-install-cmd": "Drupal\\Core\\Composer\\Composer::upgradePHPUnit",
"drupal-phpunit-upgrade": "@composer update phpunit/phpunit --with-dependencies --no-progress",
"phpcs": "phpcs --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --", "phpcs": "phpcs --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --",
"phpcbf": "phpcbf --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --" "phpcbf": "phpcbf --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --"
}, },
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"jcalderonzumba/gastonjs": "^1.0.2", "jcalderonzumba/gastonjs": "^1.0.2",
"jcalderonzumba/mink-phantomjs-driver": "^0.3.1", "jcalderonzumba/mink-phantomjs-driver": "^0.3.1",
"mikey179/vfsStream": "^1.2", "mikey179/vfsStream": "^1.2",
"phpunit/phpunit": ">=4.8.35 <5", "phpunit/phpunit": "^4.8.35 || ^6.1",
"phpspec/prophecy": "^1.4", "phpspec/prophecy": "^1.4",
"symfony/css-selector": "~3.2.8", "symfony/css-selector": "~3.2.8",
"symfony/phpunit-bridge": "^3.4.0@beta" "symfony/phpunit-bridge": "^3.4.0@beta"
......
...@@ -143,6 +143,32 @@ public static function ensureHtaccess(Event $event) { ...@@ -143,6 +143,32 @@ public static function ensureHtaccess(Event $event) {
} }
} }
/**
* Fires the drupal-phpunit-upgrade script event if necessary.
*
* @param \Composer\Script\Event $event
*/
public static function upgradePHPUnit(Event $event) {
$repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
// This is, essentially, a null constraint. We only care whether the package
// is present in the vendor directory yet, but findPackage() requires it.
$constraint = new Constraint('>', '');
$phpunit_package = $repository->findPackage('phpunit/phpunit', $constraint);
if (!$phpunit_package) {
// There is nothing to do. The user is probably installing using the
// --no-dev flag.
return;
}
// If the PHP version is 7.2 or above and PHPUnit is less than version 6
// call the drupal-phpunit-upgrade script to upgrade PHPUnit.
if (version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, '7.2') >= 0 && version_compare($phpunit_package->getVersion(), '6.1') < 0) {
$event->getComposer()
->getEventDispatcher()
->dispatchScript('drupal-phpunit-upgrade');
}
}
/** /**
* Remove possibly problematic test files from vendored projects. * Remove possibly problematic test files from vendored projects.
* *
......
...@@ -49,6 +49,7 @@ public function setUpDisplayVariant($configuration = [], $definition = []) { ...@@ -49,6 +49,7 @@ public function setUpDisplayVariant($configuration = [], $definition = []) {
$container = new Container(); $container = new Container();
$cache_context_manager = $this->getMockBuilder('Drupal\Core\Cache\CacheContextsManager') $cache_context_manager = $this->getMockBuilder('Drupal\Core\Cache\CacheContextsManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(['assertValidTokens'])
->getMock(); ->getMock();
$container->set('cache_contexts_manager', $cache_context_manager); $container->set('cache_contexts_manager', $cache_context_manager);
$cache_context_manager->expects($this->any()) $cache_context_manager->expects($this->any())
...@@ -209,9 +210,6 @@ public function testBuild(array $blocks_config, $visible_block_count, array $exp ...@@ -209,9 +210,6 @@ public function testBuild(array $blocks_config, $visible_block_count, array $exp
$title_block_plugin = $this->getMock('Drupal\Core\Block\TitleBlockPluginInterface'); $title_block_plugin = $this->getMock('Drupal\Core\Block\TitleBlockPluginInterface');
foreach ($blocks_config as $block_id => $block_config) { foreach ($blocks_config as $block_id => $block_config) {
$block = $this->getMock('Drupal\block\BlockInterface'); $block = $this->getMock('Drupal\block\BlockInterface');
$block->expects($this->any())
->method('getContexts')
->willReturn([]);
$block->expects($this->atLeastOnce()) $block->expects($this->atLeastOnce())
->method('getPlugin') ->method('getPlugin')
->willReturn($block_config[1] ? $main_content_block_plugin : ($block_config[2] ? $messages_block_plugin : ($block_config[3] ? $title_block_plugin : $block_plugin))); ->willReturn($block_config[1] ? $main_content_block_plugin : ($block_config[2] ? $messages_block_plugin : ($block_config[3] ? $title_block_plugin : $block_plugin)));
......
...@@ -269,7 +269,7 @@ public function getLinkCombinations() { ...@@ -269,7 +269,7 @@ public function getLinkCombinations() {
*/ */
protected function getMockNode($has_field, $comment_status, $form_location, $comment_count) { protected function getMockNode($has_field, $comment_status, $form_location, $comment_count) {
$node = $this->getMock('\Drupal\node\NodeInterface'); $node = $this->getMock('\Drupal\node\NodeInterface');
$node->expects($this->once()) $node->expects($this->any())
->method('hasField') ->method('hasField')
->willReturn($has_field); ->willReturn($has_field);
......
...@@ -367,7 +367,7 @@ protected function getAuthenticatedMockMessage($copy_sender = FALSE) { ...@@ -367,7 +367,7 @@ protected function getAuthenticatedMockMessage($copy_sender = FALSE) {
$recipient->expects($this->once()) $recipient->expects($this->once())
->method('getEmail') ->method('getEmail')
->willReturn('user2@drupal.org'); ->willReturn('user2@drupal.org');
$recipient->expects($this->once()) $recipient->expects($this->any())
->method('getDisplayName') ->method('getDisplayName')
->willReturn('user2'); ->willReturn('user2');
$recipient->expects($this->once()) $recipient->expects($this->once())
......
...@@ -217,7 +217,7 @@ public function testInvalidStateMultilingual() { ...@@ -217,7 +217,7 @@ public function testInvalidStateMultilingual() {
/** /**
* Tests that content without prior moderation information can be moderated. * Tests that content without prior moderation information can be moderated.
*/ */
public function testLegacyContent() { public function testExistingContentWithNoModeration() {
$node_type = NodeType::create([ $node_type = NodeType::create([
'type' => 'example', 'type' => 'example',
]); ]);
...@@ -251,7 +251,7 @@ public function testLegacyContent() { ...@@ -251,7 +251,7 @@ public function testLegacyContent() {
/** /**
* Tests that content without prior moderation information can be translated. * Tests that content without prior moderation information can be translated.
*/ */
public function testLegacyMultilingualContent() { public function testExistingMultilingualContentWithNoModeration() {
// Enable French. // Enable French.
ConfigurableLanguage::createFromLangcode('fr')->save(); ConfigurableLanguage::createFromLangcode('fr')->save();
......
...@@ -20,6 +20,7 @@ class CckFileTest extends MigrateDrupalTestBase { ...@@ -20,6 +20,7 @@ class CckFileTest extends MigrateDrupalTestBase {
* Tests configurability of file migration name. * Tests configurability of file migration name.
* *
* @covers ::__construct * @covers ::__construct
* @expectedDeprecation CckFile is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\process\d6\FieldFile instead.
*/ */
public function testConfigurableFileMigration() { public function testConfigurableFileMigration() {
$migration = Migration::create($this->container, [], 'custom_migration', []); $migration = Migration::create($this->container, [], 'custom_migration', []);
......
...@@ -17,6 +17,8 @@ class CckFileTest extends UnitTestCase { ...@@ -17,6 +17,8 @@ class CckFileTest extends UnitTestCase {
/** /**
* Tests that alt and title attributes are included in transformed values. * Tests that alt and title attributes are included in transformed values.
*
* @expectedDeprecation CckFile is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\process\d6\FieldFile instead.
*/ */
public function testTransformAltTitle() { public function testTransformAltTitle() {
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal(); $executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
......
...@@ -53,6 +53,8 @@ protected function setUp() { ...@@ -53,6 +53,8 @@ protected function setUp() {
/** /**
* @covers ::processCckFieldValues * @covers ::processCckFieldValues
* @expectedDeprecation CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.
* @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
*/ */
public function testProcessCckFieldValues() { public function testProcessCckFieldValues() {
$this->plugin->processFieldInstance($this->migration); $this->plugin->processFieldInstance($this->migration);
......
...@@ -46,6 +46,8 @@ protected function setUp() { ...@@ -46,6 +46,8 @@ protected function setUp() {
/** /**
* @covers ::processCckFieldValues * @covers ::processCckFieldValues
* @expectedDeprecation CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.
* @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
*/ */
public function testProcessCckFieldValues() { public function testProcessCckFieldValues() {
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []); $this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row; use Drupal\migrate\Row;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
/** /**
* Tests the download process plugin. * Tests the download process plugin.
...@@ -100,14 +99,8 @@ public function testWriteProtectedDestination() { ...@@ -100,14 +99,8 @@ public function testWriteProtectedDestination() {
* The local URI of the downloaded file. * The local URI of the downloaded file.
*/ */
protected function doTransform($destination_uri, $configuration = []) { protected function doTransform($destination_uri, $configuration = []) {
// The HTTP client will return a file with contents 'It worked!'
$body = fopen('data://text/plain;base64,SXQgd29ya2VkIQ==', 'r');
// Prepare a mock HTTP client. // Prepare a mock HTTP client.
$this->container->set('http_client', $this->getMock(Client::class)); $this->container->set('http_client', $this->getMock(Client::class));
$this->container->get('http_client')
->method('get')
->willReturn(new Response(200, [], $body));
// Instantiate the plugin statically so it can pull dependencies out of // Instantiate the plugin statically so it can pull dependencies out of
// the container. // the container.
......
...@@ -78,11 +78,6 @@ protected function getMigration() { ...@@ -78,11 +78,6 @@ protected function getMigration() {
$configuration = &$this->migrationConfiguration; $configuration = &$this->migrationConfiguration;
$migration->method('getHighWaterProperty')
->willReturnCallback(function () use ($configuration) {
return isset($configuration['high_water_property']) ? $configuration['high_water_property'] : '';
});
$migration->method('set') $migration->method('set')
->willReturnCallback(function ($argument, $value) use (&$configuration) { ->willReturnCallback(function ($argument, $value) use (&$configuration) {
$configuration[$argument] = $value; $configuration[$argument] = $value;
......
...@@ -134,8 +134,6 @@ protected function setUp() { ...@@ -134,8 +134,6 @@ protected function setUp() {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE); $cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
$cache_contexts_manager->expects($this->any())
->method('validate_tokens');
$container = new Container(); $container = new Container();
$container->set('cache_contexts_manager', $cache_contexts_manager); $container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container); \Drupal::setContainer($container);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* @group taxonomy * @group taxonomy
*/ */
class LegacyTest extends TaxonomyTestBase { class EarlyDateTest extends TaxonomyTestBase {
/** /**
* Modules to enable. * Modules to enable.
...@@ -51,7 +51,7 @@ protected function setUp() { ...@@ -51,7 +51,7 @@ protected function setUp() {
/** /**
* Test taxonomy functionality with nodes prior to 1970. * Test taxonomy functionality with nodes prior to 1970.
*/ */
public function testTaxonomyLegacyNode() { public function testTaxonomyEarlyDateNode() {
// Posts an article with a taxonomy term and a date prior to 1970. // Posts an article with a taxonomy term and a date prior to 1970.
$date = new DrupalDateTime('1969-01-01 00:00:00'); $date = new DrupalDateTime('1969-01-01 00:00:00');
$edit = []; $edit = [];
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* @group views * @group views
*/ */
class LegacyBulkFormUpdateTest extends UpdatePathTestBase { class BulkFormUpdateTest extends UpdatePathTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
......
...@@ -70,7 +70,7 @@ protected function setUp() { ...@@ -70,7 +70,7 @@ protected function setUp() {
$this->executable = $this->getMockBuilder('Drupal\views\ViewExecutable') $this->executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage']) ->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage', 'getShowAdminLinks'])
->getMock(); ->getMock();
$this->executable->expects($this->any()) $this->executable->expects($this->any())
->method('setDisplay') ->method('setDisplay')
......
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
<phpunit bootstrap="tests/bootstrap.php" colors="true" <phpunit bootstrap="tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true" beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true" beStrictAboutChangesToGlobalState="true">
checkForUnintentionallyCoveredCode="false">
<!-- TODO set printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" once <!-- TODO set printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" once
https://youtrack.jetbrains.com/issue/WI-24808 is resolved. Drupal provides a https://youtrack.jetbrains.com/issue/WI-24808 is resolved. Drupal provides a
result printer that links to the html output results for functional tests. result printer that links to the html output results for functional tests.
...@@ -30,7 +29,7 @@ ...@@ -30,7 +29,7 @@
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output --> <!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/> <env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>
<!-- To disable deprecation testing uncomment the next line. --> <!-- To disable deprecation testing uncomment the next line. -->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> --> <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak_vendors"/>
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' --> <!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
<!-- Example for changing the driver args to phantomjs tests MINK_DRIVER_ARGS_PHANTOMJS value: '["http://127.0.0.1:8510"]' --> <!-- Example for changing the driver args to phantomjs tests MINK_DRIVER_ARGS_PHANTOMJS value: '["http://127.0.0.1:8510"]' -->
</php> </php>
......
...@@ -793,7 +793,11 @@ function simpletest_script_run_one_test($test_id, $test_class) { ...@@ -793,7 +793,11 @@ function simpletest_script_run_one_test($test_id, $test_class) {
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled'); putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
} }
else { else {
putenv('SYMFONY_DEPRECATIONS_HELPER=strict'); // Prevent deprecations caused by vendor code calling deprecated code.
// This also prevents mock objects in PHPUnit 6 triggering silenced
// deprecations from breaking the test suite. We should consider changing
// this to 'strict' once PHPUnit 4 is no longer used.
putenv('SYMFONY_DEPRECATIONS_HELPER=weak_vendors');
} }
if (is_subclass_of($test_class, TestCase::class)) { if (is_subclass_of($test_class, TestCase::class)) {
$status = simpletest_script_run_phpunit($test_id, $test_class); $status = simpletest_script_run_phpunit($test_id, $test_class);
......
...@@ -188,7 +188,7 @@ public function testInvalidLinkNotExistsExact() { ...@@ -188,7 +188,7 @@ public function testInvalidLinkNotExistsExact() {
/** /**
* Tests legacy text asserts. * Tests legacy text asserts.
*/ */
public function testLegacyTextAsserts() { public function testTextAsserts() {
$this->drupalGet('test-encoded'); $this->drupalGet('test-encoded');
$dangerous = 'Bad html <script>alert(123);</script>'; $dangerous = 'Bad html <script>alert(123);</script>';
$sanitized = Html::escape($dangerous); $sanitized = Html::escape($dangerous);
...@@ -202,7 +202,7 @@ public function testLegacyTextAsserts() { ...@@ -202,7 +202,7 @@ public function testLegacyTextAsserts() {
/** /**
* Tests legacy field asserts which use xpath directly. * Tests legacy field asserts which use xpath directly.
*/ */
public function testLegacyXpathAsserts() { public function testXpathAsserts() {
$this->drupalGet('test-field-xpath'); $this->drupalGet('test-field-xpath');
$this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL); $this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL);
$this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one'); $this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one');
...@@ -245,7 +245,7 @@ public function testLegacyXpathAsserts() { ...@@ -245,7 +245,7 @@ public function testLegacyXpathAsserts() {
/** /**
* Tests legacy field asserts using textfields. * Tests legacy field asserts using textfields.
*/ */
public function testLegacyFieldAssertsForTextfields() { public function testFieldAssertsForTextfields() {
$this->drupalGet('test-field-xpath'); $this->drupalGet('test-field-xpath');
// *** 1. assertNoField(). // *** 1. assertNoField().
...@@ -387,7 +387,7 @@ public function testLegacyFieldAssertsForTextfields() { ...@@ -387,7 +387,7 @@ public function testLegacyFieldAssertsForTextfields() {
/** /**
* Tests legacy field asserts for options field type. * Tests legacy field asserts for options field type.
*/ */
public function testLegacyFieldAssertsForOptions() { public function testFieldAssertsForOptions() {
$this->drupalGet('test-field-xpath'); $this->drupalGet('test-field-xpath');
// Option field type. // Option field type.
...@@ -443,7 +443,7 @@ public function testLegacyFieldAssertsForOptions() { ...@@ -443,7 +443,7 @@ public function testLegacyFieldAssertsForOptions() {
/** /**
* Tests legacy field asserts for button field type. * Tests legacy field asserts for button field type.
*/ */
public function testLegacyFieldAssertsForButton() { public function testFieldAssertsForButton() {
$this->drupalGet('test-field-xpath'); $this->drupalGet('test-field-xpath');
$this->assertFieldById('edit-save', NULL); $this->assertFieldById('edit-save', NULL);
...@@ -485,7 +485,7 @@ public function testLegacyFieldAssertsForButton() { ...@@ -485,7 +485,7 @@ public function testLegacyFieldAssertsForButton() {
/** /**
* Tests legacy field asserts for checkbox field type. * Tests legacy field asserts for checkbox field type.
*/ */
public function testLegacyFieldAssertsForCheckbox() { public function testFieldAssertsForCheckbox() {
$this->drupalGet('test-field-xpath'); $this->drupalGet('test-field-xpath');
// Part 1 - Test by name. // Part 1 - Test by name.
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* @group Messenger * @group Messenger
* @coversDefaultClass \Drupal\Core\Messenger\LegacyMessenger * @coversDefaultClass \Drupal\Core\Messenger\LegacyMessenger
*/ */
class LegacyMessengerTest extends KernelTestBase { class MessengerTest extends KernelTestBase {
/** /**
* Retrieves the Messenger service from LegacyMessenger. * Retrieves the Messenger service from LegacyMessenger.
......
...@@ -497,6 +497,11 @@ protected function setUp() { ...@@ -497,6 +497,11 @@ protected function setUp() {
if ($disable_gc) { if ($disable_gc) {
gc_enable(); gc_enable();
} }
// Ensure that the test is not marked as risky because of no assertions. In
// PHPUnit 6 tests that only make assertions using $this->assertSession()
// can be marked as risky.
$this->addToAssertionCount(1);
} }
/** /**
......
...@@ -87,7 +87,13 @@ public function testDateDiff($input1, $input2, $absolute, \DateInterval $expecte ...@@ -87,7 +87,13 @@ public function testDateDiff($input1, $input2, $absolute, \DateInterval $expecte
* @dataProvider providerTestInvalidDateDiff * @dataProvider providerTestInvalidDateDiff
*/ */
public function testInvalidDateDiff($input1, $input2, $absolute) { public function testInvalidDateDiff($input1, $input2, $absolute) {
$this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); if (method_exists($this, 'expectException')) {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
}
else {
$this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
}
$interval = $input1->diff($input2, $absolute); $interval = $input1->diff($input2, $absolute);
} }
...@@ -104,7 +110,12 @@ public function testInvalidDateDiff($input1, $input2, $absolute) { ...@@ -104,7 +110,12 @@ public function testInvalidDateDiff($input1, $input2, $absolute) {
* @dataProvider providerTestInvalidDateArrays * @dataProvider providerTestInvalidDateArrays
*/ */
public function testInvalidDateArrays($input, $timezone, $class) { public function testInvalidDateArrays($input, $timezone, $class) {
$this->setExpectedException($class); if (method_exists($this, 'expectException')) {
$this->expectException($class);
}
else {
$this->setExpectedException($class);
}
$this->assertInstanceOf( $this->assertInstanceOf(
'\Drupal\Component\DateTimePlus', '\Drupal\Component\DateTimePlus',
DateTimePlus::createFromArray($input, $timezone) DateTimePlus::createFromArray($input, $timezone)
...@@ -242,7 +253,12 @@ public function testDateFormat($input, $timezone, $format, $format_date, $expect ...@@ -242,7 +253,12 @@ public function testDateFormat($input, $timezone, $format, $format_date, $expect
* @dataProvider providerTestInvalidDates * @dataProvider providerTestInvalidDates
*/ */
public function testInvalidDates($input, $timezone, $format, $message, $class) { public function testInvalidDates($input, $timezone, $format, $message, $class) {
$this->setExpectedException($class); if (method_exists($this, 'expectException')) {
$this->expectException($class);
}
else {
$this->setExpectedException($class);
}
DateTimePlus::createFromFormat($format, $input, $timezone); DateTimePlus::createFromFormat($format, $input, $timezone);
} }
...@@ -800,7 +816,12 @@ public function testValidateFormat() { ...@@ -800,7 +816,12 @@ public function testValidateFormat() {
// Parse the same date with ['validate_format' => TRUE] and make sure we // Parse the same date with ['validate_format' => TRUE] and make sure we
// get the expected exception. // get the expected exception.
$this->setExpectedException(\UnexpectedValueException::class); if (method_exists($this, 'expectException')) {
$this->expectException(\UnexpectedValueException::class);
}
else {
$this->setExpectedException(\UnexpectedValueException::class);
}
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]); $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]);
} }
...@@ -859,7 +880,13 @@ public function testChainableNonChainable() { ...@@ -859,7 +880,13 @@ public function testChainableNonChainable() {
* @covers ::__call * @covers ::__call
*/ */
public function testChainableNonCallable() { public function testChainableNonCallable() {
$this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); if (method_exists($this, 'expectException')) {
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
}
else {
$this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
}
$date = new DateTimePlus('now', 'Australia/Sydney'); $date = new DateTimePlus('now', 'Australia/Sydney');
$date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent(); $date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent();
} }
......
...@@ -37,8 +37,7 @@ class TimeTest extends TestCase { ...@@ -37,8 +37,7 @@ class TimeTest extends TestCase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); $this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$this->time = new Time($this->requestStack); $this->time = new Time($this->requestStack);
} }
......
...@@ -70,7 +70,12 @@ protected function setUp() { ...@@ -70,7 +70,12 @@ protected function setUp() {
public function testConstruct() { public function testConstruct() {
$container_definition = $this->getMockContainerDefinition(); $container_definition = $this->getMockContainerDefinition();
$container_definition['machine_format'] = !$this->machineFormat; $container_definition['machine_format'] = !$this->machineFormat;
$this->setExpectedException(InvalidArgumentException::class); if (method_exists($this, 'expectException')) {
$this->expectException(InvalidArgumentException::class);
}
else {
$this->setExpectedException(InvalidArgumentException::class);
}
$container = new $this->containerClass($container_definition); $container = new $this->containerClass($container_definition);
} }
...@@ -93,7 +98,12 @@ public function testGetParameter() { ...@@ -93,7 +98,12 @@ public function testGetParameter() {
* @covers ::getAlternatives * @covers ::getAlternatives
*/