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 @@
},
"scripts": {
"pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
"post-autoload-dump": [
"Drupal\\Core\\Composer\\Composer::ensureHtaccess"
],
"post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
"post-package-install": "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 --",
"phpcbf": "phpcbf --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --"
},
......
......@@ -44,7 +44,7 @@
"jcalderonzumba/gastonjs": "^1.0.2",
"jcalderonzumba/mink-phantomjs-driver": "^0.3.1",
"mikey179/vfsStream": "^1.2",
"phpunit/phpunit": ">=4.8.35 <5",
"phpunit/phpunit": "^4.8.35 || ^6.1",
"phpspec/prophecy": "^1.4",
"symfony/css-selector": "~3.2.8",
"symfony/phpunit-bridge": "^3.4.0@beta"
......
......@@ -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.
*
......
......@@ -49,6 +49,7 @@ public function setUpDisplayVariant($configuration = [], $definition = []) {
$container = new Container();
$cache_context_manager = $this->getMockBuilder('Drupal\Core\Cache\CacheContextsManager')
->disableOriginalConstructor()
->setMethods(['assertValidTokens'])
->getMock();
$container->set('cache_contexts_manager', $cache_context_manager);
$cache_context_manager->expects($this->any())
......@@ -209,9 +210,6 @@ public function testBuild(array $blocks_config, $visible_block_count, array $exp
$title_block_plugin = $this->getMock('Drupal\Core\Block\TitleBlockPluginInterface');
foreach ($blocks_config as $block_id => $block_config) {
$block = $this->getMock('Drupal\block\BlockInterface');
$block->expects($this->any())
->method('getContexts')
->willReturn([]);
$block->expects($this->atLeastOnce())
->method('getPlugin')
->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() {
*/
protected function getMockNode($has_field, $comment_status, $form_location, $comment_count) {
$node = $this->getMock('\Drupal\node\NodeInterface');
$node->expects($this->once())
$node->expects($this->any())
->method('hasField')
->willReturn($has_field);
......
......@@ -367,7 +367,7 @@ protected function getAuthenticatedMockMessage($copy_sender = FALSE) {
$recipient->expects($this->once())
->method('getEmail')
->willReturn('user2@drupal.org');
$recipient->expects($this->once())
$recipient->expects($this->any())
->method('getDisplayName')
->willReturn('user2');
$recipient->expects($this->once())
......
......@@ -217,7 +217,7 @@ public function testInvalidStateMultilingual() {
/**
* Tests that content without prior moderation information can be moderated.
*/
public function testLegacyContent() {
public function testExistingContentWithNoModeration() {
$node_type = NodeType::create([
'type' => 'example',
]);
......@@ -251,7 +251,7 @@ public function testLegacyContent() {
/**
* Tests that content without prior moderation information can be translated.
*/
public function testLegacyMultilingualContent() {
public function testExistingMultilingualContentWithNoModeration() {
// Enable French.
ConfigurableLanguage::createFromLangcode('fr')->save();
......
......@@ -20,6 +20,7 @@ class CckFileTest extends MigrateDrupalTestBase {
* Tests configurability of file migration name.
*
* @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() {
$migration = Migration::create($this->container, [], 'custom_migration', []);
......
......@@ -17,6 +17,8 @@ class CckFileTest extends UnitTestCase {
/**
* 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() {
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
......
......@@ -53,6 +53,8 @@ protected function setUp() {
/**
* @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() {
$this->plugin->processFieldInstance($this->migration);
......
......@@ -46,6 +46,8 @@ protected function setUp() {
/**
* @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() {
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
......
......@@ -9,7 +9,6 @@
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
/**
* Tests the download process plugin.
......@@ -100,14 +99,8 @@ public function testWriteProtectedDestination() {
* The local URI of the downloaded file.
*/
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.
$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
// the container.
......
......@@ -78,11 +78,6 @@ protected function getMigration() {
$configuration = &$this->migrationConfiguration;
$migration->method('getHighWaterProperty')
->willReturnCallback(function () use ($configuration) {
return isset($configuration['high_water_property']) ? $configuration['high_water_property'] : '';
});
$migration->method('set')
->willReturnCallback(function ($argument, $value) use (&$configuration) {
$configuration[$argument] = $value;
......
......@@ -134,8 +134,6 @@ protected function setUp() {
->disableOriginalConstructor()
->getMock();
$cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
$cache_contexts_manager->expects($this->any())
->method('validate_tokens');
$container = new Container();
$container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
......
......@@ -11,7 +11,7 @@
*
* @group taxonomy
*/
class LegacyTest extends TaxonomyTestBase {
class EarlyDateTest extends TaxonomyTestBase {
/**
* Modules to enable.
......@@ -51,7 +51,7 @@ protected function setUp() {
/**
* 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.
$date = new DrupalDateTime('1969-01-01 00:00:00');
$edit = [];
......
......@@ -10,7 +10,7 @@
*
* @group views
*/
class LegacyBulkFormUpdateTest extends UpdatePathTestBase {
class BulkFormUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
......
......@@ -70,7 +70,7 @@ protected function setUp() {
$this->executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
->disableOriginalConstructor()
->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage'])
->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage', 'getShowAdminLinks'])
->getMock();
$this->executable->expects($this->any())
->method('setDisplay')
......
......@@ -8,8 +8,7 @@
<phpunit bootstrap="tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
checkForUnintentionallyCoveredCode="false">
beStrictAboutChangesToGlobalState="true">
<!-- TODO set printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" once
https://youtrack.jetbrains.com/issue/WI-24808 is resolved. Drupal provides a
result printer that links to the html output results for functional tests.
......@@ -30,7 +29,7 @@
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>
<!-- 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 phantomjs tests MINK_DRIVER_ARGS_PHANTOMJS value: '["http://127.0.0.1:8510"]' -->
</php>
......
......@@ -793,7 +793,11 @@ function simpletest_script_run_one_test($test_id, $test_class) {
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
}
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)) {
$status = simpletest_script_run_phpunit($test_id, $test_class);
......
......@@ -188,7 +188,7 @@ public function testInvalidLinkNotExistsExact() {
/**
* Tests legacy text asserts.
*/
public function testLegacyTextAsserts() {
public function testTextAsserts() {
$this->drupalGet('test-encoded');
$dangerous = 'Bad html <script>alert(123);</script>';
$sanitized = Html::escape($dangerous);
......@@ -202,7 +202,7 @@ public function testLegacyTextAsserts() {
/**
* Tests legacy field asserts which use xpath directly.
*/
public function testLegacyXpathAsserts() {
public function testXpathAsserts() {
$this->drupalGet('test-field-xpath');
$this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL);
$this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one');
......@@ -245,7 +245,7 @@ public function testLegacyXpathAsserts() {
/**
* Tests legacy field asserts using textfields.
*/
public function testLegacyFieldAssertsForTextfields() {
public function testFieldAssertsForTextfields() {
$this->drupalGet('test-field-xpath');
// *** 1. assertNoField().
......@@ -387,7 +387,7 @@ public function testLegacyFieldAssertsForTextfields() {
/**
* Tests legacy field asserts for options field type.
*/
public function testLegacyFieldAssertsForOptions() {
public function testFieldAssertsForOptions() {
$this->drupalGet('test-field-xpath');
// Option field type.
......@@ -443,7 +443,7 @@ public function testLegacyFieldAssertsForOptions() {
/**
* Tests legacy field asserts for button field type.
*/
public function testLegacyFieldAssertsForButton() {
public function testFieldAssertsForButton() {
$this->drupalGet('test-field-xpath');
$this->assertFieldById('edit-save', NULL);
......@@ -485,7 +485,7 @@ public function testLegacyFieldAssertsForButton() {
/**
* Tests legacy field asserts for checkbox field type.
*/
public function testLegacyFieldAssertsForCheckbox() {
public function testFieldAssertsForCheckbox() {
$this->drupalGet('test-field-xpath');
// Part 1 - Test by name.
......
......@@ -11,7 +11,7 @@
* @group Messenger
* @coversDefaultClass \Drupal\Core\Messenger\LegacyMessenger
*/
class LegacyMessengerTest extends KernelTestBase {
class MessengerTest extends KernelTestBase {
/**
* Retrieves the Messenger service from LegacyMessenger.
......
......@@ -497,6 +497,11 @@ protected function setUp() {
if ($disable_gc) {
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
* @dataProvider providerTestInvalidDateDiff
*/
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);
}
......@@ -104,7 +110,12 @@ public function testInvalidDateDiff($input1, $input2, $absolute) {
* @dataProvider providerTestInvalidDateArrays
*/
public function testInvalidDateArrays($input, $timezone, $class) {
$this->setExpectedException($class);
if (method_exists($this, 'expectException')) {
$this->expectException($class);
}
else {
$this->setExpectedException($class);
}
$this->assertInstanceOf(
'\Drupal\Component\DateTimePlus',
DateTimePlus::createFromArray($input, $timezone)
......@@ -242,7 +253,12 @@ public function testDateFormat($input, $timezone, $format, $format_date, $expect
* @dataProvider providerTestInvalidDates
*/
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);
}
......@@ -800,7 +816,12 @@ public function testValidateFormat() {
// Parse the same date with ['validate_format' => TRUE] and make sure we
// 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]);
}
......@@ -859,7 +880,13 @@ public function testChainableNonChainable() {
* @covers ::__call
*/
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->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent();
}
......
......@@ -37,8 +37,7 @@ class TimeTest extends TestCase {
protected function 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);
}
......
......@@ -70,7 +70,12 @@ protected function setUp() {
public function testConstruct() {
$container_definition = $this->getMockContainerDefinition();
$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);
}
......@@ -93,7 +98,12 @@ public function testGetParameter() {
* @covers ::getAlternatives
*/
public function testGetParameterIfNotFound() {
$this->setExpectedException(ParameterNotFoundException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(ParameterNotFoundException::class);
}
else {
$this->setExpectedException(ParameterNotFoundException::class);
}
$this->container->getParameter('parameter_that_does_not_exist');
}
......@@ -103,7 +113,12 @@ public function testGetParameterIfNotFound() {
* @covers ::getParameter
*/
public function testGetParameterIfNotFoundBecauseNull() {
$this->setExpectedException(ParameterNotFoundException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(ParameterNotFoundException::class);
}
else {
$this->setExpectedException(ParameterNotFoundException::class);
}
$this->container->getParameter(NULL);
}
......@@ -137,7 +152,12 @@ public function testSetParameterWithUnfrozenContainer() {
*/
public function testSetParameterWithFrozenContainer() {
$this->container = new $this->containerClass($this->containerDefinition);
$this->setExpectedException(LogicException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(LogicException::class);
}
else {
$this->setExpectedException(LogicException::class);
}
$this->container->setParameter('some_config', 'new_value');
}
......@@ -242,7 +262,12 @@ public function testHasForAliasedService() {
* @covers ::createService
*/
public function testGetForCircularServices() {
$this->setExpectedException(ServiceCircularReferenceException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(ServiceCircularReferenceException::class);
}
else {
$this->setExpectedException(ServiceCircularReferenceException::class);
}
$this->container->get('circular_dependency');
}
......@@ -255,7 +280,12 @@ public function testGetForCircularServices() {
* @covers ::getServiceAlternatives
*/
public function testGetForNonExistantService() {
$this->setExpectedException(ServiceNotFoundException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(ServiceNotFoundException::class);
}
else {
$this->setExpectedException(ServiceNotFoundException::class);
}
$this->container->get('service_not_exists');
}
......@@ -304,7 +334,12 @@ public function testGetForParameterDependencyWithExceptionOnSecondCall() {
// Reset the service.
$this->container->set('service_parameter_not_exists', NULL);
$this->setExpectedException(InvalidArgumentException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(InvalidArgumentException::class);
}
else {
$this->setExpectedException(InvalidArgumentException::class);
}
$this->container->get('service_parameter_not_exists');
}
......@@ -316,7 +351,12 @@ public function testGetForParameterDependencyWithExceptionOnSecondCall() {
* @covers ::resolveServicesAndParameters
*/
public function testGetForNonExistantParameterDependencyWithException() {
$this->setExpectedException(InvalidArgumentException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(InvalidArgumentException::class);
}
else {
$this->setExpectedException(InvalidArgumentException::class);
}
$this->container->get('service_parameter_not_exists');
}
......@@ -341,7 +381,12 @@ public function testGetForNonExistantServiceDependency() {
* @covers ::getAlternatives
*/
public function testGetForNonExistantServiceDependencyWithException() {
$this->setExpectedException(ServiceNotFoundException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(ServiceNotFoundException::class);
}
else {
$this->setExpectedException(ServiceNotFoundException::class);
}
$this->container->get('service_dependency_not_exists');
}
......@@ -361,7 +406,12 @@ public function testGetForNonExistantServiceWhenUsingNull() {
* @covers ::createService
*/
public function testGetForNonExistantNULLService() {
$this->setExpectedException(ServiceNotFoundException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(ServiceNotFoundException::class);
}
else {
$this->setExpectedException(ServiceNotFoundException::class);
}
$this->container->get(NULL);
}
......@@ -387,7 +437,12 @@ public function testGetForNonExistantServiceMultipleTimes() {
*/
public function testGetForNonExistantServiceWithExceptionOnSecondCall() {
$this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.');
$this->setExpectedException(ServiceNotFoundException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(ServiceNotFoundException::class);
}
else {
$this->setExpectedException(ServiceNotFoundException::class);
}
$this->container->get('service_not_exists');
}
......@@ -423,7 +478,12 @@ public function testGetForSyntheticService() {
* @covers ::createService
*/
public function testGetForSyntheticServiceWithException() {
$this->setExpectedException(RuntimeException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(RuntimeException::class);
}
else {
$this->setExpectedException(RuntimeException::class);
}
$this->container->get('synthetic');
}
......@@ -462,7 +522,12 @@ public function testGetForInstantiationWithVariousArgumentLengths() {
* @covers ::createService
*/
public function testGetForWrongFactory() {
$this->setExpectedException(RuntimeException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(RuntimeException::class);
}
else {
$this->setExpectedException(RuntimeException::class);
}
$this->container->get('wrong_factory');
}
......@@ -500,7 +565,12 @@ public function testGetForFactoryClass() {
* @covers ::createService
*/
public function testGetForConfiguratorWithException() {
$this->setExpectedException(InvalidArgumentException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(InvalidArgumentException::class);
}
else {
$this->setExpectedException(InvalidArgumentException::class);
}
$this->container->get('configurable_service_exception');
}
......@@ -598,7 +668,12 @@ public function testResolveServicesAndParametersForOptionalServiceDependencies()
* @covers ::resolveServicesAndParameters
*/
public function testResolveServicesAndParametersForInvalidArgument() {
$this->setExpectedException(InvalidArgumentException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(InvalidArgumentException::class);
}
else {
$this->setExpectedException(InvalidArgumentException::class);
}
$this->container->get('invalid_argument_service');
}
......@@ -612,7 +687,12 @@ public function testResolveServicesAndParametersForInvalidArgument() {
public function testResolveServicesAndParametersForInvalidArguments() {
// In case the machine-optimized format is not used, we need to simulate the
// test failure.
$this->setExpectedException(InvalidArgumentException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(InvalidArgumentException::class);
}
else {
$this->setExpectedException(InvalidArgumentException::class);
}
if (!$this->machineFormat) {
throw new InvalidArgumentException('Simulating the test failure.');
}
......
......@@ -545,7 +545,12 @@ public function testGetServiceDefinitionForDecoratedService() {
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(InvalidArgumentException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(InvalidArgumentException::class);
}
else {
$this->setExpectedException(InvalidArgumentException::class);
}
$this->dumper->getArray();
}
......@@ -562,7 +567,12 @@ public function testGetServiceDefinitionForExpression() {
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(RuntimeException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(RuntimeException::class);
}
else {
$this->setExpectedException(RuntimeException::class);
}
$this->dumper->getArray();
}
......@@ -579,7 +589,12 @@ public function testGetServiceDefinitionForObject() {
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(RuntimeException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(RuntimeException::class);
}
else {