diff --git a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php index 25f11b8..8fa2293 100644 --- a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php +++ b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php @@ -30,10 +30,10 @@ class BigPipeResponseAttachmentsProcessorTest extends UnitTestCase { * @dataProvider nonHtmlResponseProvider */ public function testNonHtmlResponse($response_class) { - $this->setExpectedException(\AssertionError::class); $big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($this->prophesize(AttachmentsResponseProcessorInterface::class)); $non_html_response = new $response_class(); + $this->setExpectedException(\AssertionError::class); $big_pipe_response_attachments_processor->processAttachments($non_html_response); } diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php index dbca7f8..9ae8bc4 100644 --- a/core/modules/contact/tests/src/Unit/MailHandlerTest.php +++ b/core/modules/contact/tests/src/Unit/MailHandlerTest.php @@ -98,7 +98,6 @@ class MailHandlerTest extends UnitTestCase { * @covers ::sendMailMessages */ public function testInvalidRecipient() { - $this->setExpectedException(MailHandlerException::class, 'Unable to determine message recipient'); $message = $this->getMock('\Drupal\contact\MessageInterface'); $message->expects($this->once()) ->method('isPersonal') @@ -120,6 +119,7 @@ class MailHandlerTest extends UnitTestCase { $sender->expects($this->once()) ->method('isAnonymous') ->willReturn(FALSE); + $this->setExpectedException(MailHandlerException::class, 'Unable to determine message recipient'); $this->contactMailHandler->sendMailMessages($message, $sender); } diff --git a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php index 086450d..8b8587a 100644 --- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @@ -162,7 +162,6 @@ class FieldConfigEntityUnitTest extends UnitTestCase { * Test that invalid bundles are handled. */ public function testCalculateDependenciesIncorrectBundle() { - $this->setExpectedException(\LogicException::class, 'Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.'); $storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface'); $storage->expects($this->any()) ->method('load') @@ -207,6 +206,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { 'bundle' => 'test_bundle_not_exists', 'field_type' => 'test_field', ), $this->entityTypeId); + $this->setExpectedException(\LogicException::class, 'Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.'); $field->calculateDependencies(); } diff --git a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php index 7ff43e6..fe84287 100644 --- a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php +++ b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php @@ -20,10 +20,10 @@ class FieldItemNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenorma * @dataProvider providerNormalizerDenormalizeExceptions */ public function testFieldItemNormalizerDenormalizeExceptions($context) { - $this->setExpectedException(InvalidArgumentException::class); $field_item_normalizer = new FieldItemNormalizer(); $data = array(); $class = array(); + $this->setExpectedException(InvalidArgumentException::class); $field_item_normalizer->denormalize($data, $class, NULL, $context); } diff --git a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php index fa2bc53..6ef1215 100644 --- a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php +++ b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php @@ -20,10 +20,10 @@ class FieldNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalize * @dataProvider providerNormalizerDenormalizeExceptions */ public function testFieldNormalizerDenormalizeExceptions($context) { - $this->setExpectedException(InvalidArgumentException::class); $field_item_normalizer = new FieldNormalizer(); $data = array(); $class = array(); + $this->setExpectedException(InvalidArgumentException::class); $field_item_normalizer->denormalize($data, $class, NULL, $context); } diff --git a/core/modules/locale/tests/src/Unit/StringBaseTest.php b/core/modules/locale/tests/src/Unit/StringBaseTest.php index 37e43dc..96bb41b 100644 --- a/core/modules/locale/tests/src/Unit/StringBaseTest.php +++ b/core/modules/locale/tests/src/Unit/StringBaseTest.php @@ -16,8 +16,8 @@ class StringBaseTest extends UnitTestCase { * @covers ::save */ public function testSaveWithoutStorage() { - $this->setExpectedException(StringStorageException::class, 'The string cannot be saved because its not bound to a storage: test'); $string = new SourceString(['source' => 'test']); + $this->setExpectedException(StringStorageException::class, 'The string cannot be saved because its not bound to a storage: test'); $string->save(); } @@ -26,8 +26,8 @@ class StringBaseTest extends UnitTestCase { * @covers ::delete */ public function testDeleteWithoutStorage() { - $this->setExpectedException(StringStorageException::class, 'The string cannot be deleted because its not bound to a storage: test'); $string = new SourceString(['lid' => 1, 'source' => 'test']); + $this->setExpectedException(StringStorageException::class, 'The string cannot be deleted because its not bound to a storage: test'); $string->delete(); } diff --git a/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php b/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php index 503d719..7dbdf56 100644 --- a/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php @@ -138,8 +138,8 @@ class CopyFileTest extends FileTestBase { * Test that non-existent files throw an exception. */ public function testNonExistentSourceFile() { - $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist"); $source = '/non/existent/file'; + $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist"); $this->doImport($source, 'public://wontmatter.jpg'); } diff --git a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php index d5d8999..7fb2097 100644 --- a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php @@ -113,8 +113,8 @@ class FileCopyTest extends FileTestBase { * Test that non-existent files throw an exception. */ public function testNonExistentSourceFile() { - $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist"); $source = '/non/existent/file'; + $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist"); $this->doTransform($source, 'public://wontmatter.jpg'); } diff --git a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php index 68a8f6d..35063fe 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php @@ -152,8 +152,8 @@ class MigrateSourceTest extends MigrateTestCase { * @covers ::__construct */ public function testHighwaterTrackChangesIncompatible() { - $this->setExpectedException(MigrateException::class); $source_config = ['track_changes' => TRUE, 'high_water_property' => ['name' => 'something']]; + $this->setExpectedException(MigrateException::class); $this->getSource($source_config); } diff --git a/core/modules/migrate/tests/src/Unit/MigrationTest.php b/core/modules/migrate/tests/src/Unit/MigrationTest.php index 34246a0..649104b 100644 --- a/core/modules/migrate/tests/src/Unit/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrationTest.php @@ -29,7 +29,6 @@ class MigrationTest extends UnitTestCase { * @covers ::checkRequirements */ public function testRequirementsForSourcePlugin() { - $this->setExpectedException(RequirementsException::class, 'Missing source requirement'); $migration = new TestMigration(); $source_plugin = $this->getMock('Drupal\Tests\migrate\Unit\RequirementsAwareSourceInterface'); @@ -41,6 +40,7 @@ class MigrationTest extends UnitTestCase { $migration->setSourcePlugin($source_plugin); $migration->setDestinationPlugin($destination_plugin); + $this->setExpectedException(RequirementsException::class, 'Missing source requirement'); $migration->checkRequirements(); } @@ -50,7 +50,6 @@ class MigrationTest extends UnitTestCase { * @covers ::checkRequirements */ public function testRequirementsForDestinationPlugin() { - $this->setExpectedException(RequirementsException::class, 'Missing destination requirement'); $migration = new TestMigration(); $source_plugin = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface'); @@ -62,6 +61,7 @@ class MigrationTest extends UnitTestCase { $migration->setSourcePlugin($source_plugin); $migration->setDestinationPlugin($destination_plugin); + $this->setExpectedException(RequirementsException::class, 'Missing destination requirement'); $migration->checkRequirements(); } @@ -71,7 +71,6 @@ class MigrationTest extends UnitTestCase { * @covers ::checkRequirements */ public function testRequirementsForMigrations() { - $this->setExpectedException(RequirementsException::class, 'Missing migrations test_a, test_c'); $migration = new TestMigration(); // Setup source and destination plugins without any requirements. @@ -106,6 +105,7 @@ class MigrationTest extends UnitTestCase { ->with(['test_a', 'test_b', 'test_c', 'test_d']) ->willReturn(['test_b' => $migration_b, 'test_c' => $migration_c, 'test_d' => $migration_d]); + $this->setExpectedException(RequirementsException::class, 'Missing migrations test_a, test_c'); $migration->checkRequirements(); } diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php index 6fdc4e3..e6bb37b 100644 --- a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php +++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php @@ -87,7 +87,6 @@ class EntityContentBaseTest extends UnitTestCase { * @covers ::import */ public function testImportEntityLoadFailure() { - $this->setExpectedException(MigrateException::class, 'Unable to get entity'); $bundles = []; $destination = new EntityTestDestination([], '', [], $this->migration->reveal(), @@ -96,6 +95,7 @@ class EntityContentBaseTest extends UnitTestCase { $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal()); $destination->setEntity(FALSE); + $this->setExpectedException(MigrateException::class, 'Unable to get entity'); $destination->import(new Row()); } @@ -104,7 +104,6 @@ class EntityContentBaseTest extends UnitTestCase { */ public function testUntranslatable() { // An entity type without a language. - $this->setExpectedException(MigrateException::class, 'This entity type does not support translation'); $entity_type = $this->prophesize(ContentEntityType::class); $entity_type->getKey('langcode')->willReturn(''); $entity_type->getKey('id')->willReturn('id'); @@ -123,6 +122,7 @@ class EntityContentBaseTest extends UnitTestCase { $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() ); + $this->setExpectedException(MigrateException::class, 'This entity type does not support translation'); $destination->getIds(); } diff --git a/core/modules/migrate/tests/src/Unit/RowTest.php b/core/modules/migrate/tests/src/Unit/RowTest.php index 9e7dcf5..250c7b2 100644 --- a/core/modules/migrate/tests/src/Unit/RowTest.php +++ b/core/modules/migrate/tests/src/Unit/RowTest.php @@ -75,10 +75,10 @@ class RowTest extends UnitTestCase { * Tests object creation: invalid values. */ public function testRowWithInvalidData() { - $this->setExpectedException(\Exception::class); $invalid_values = array( 'title' => 'node X', ); + $this->setExpectedException(\Exception::class); $row = new Row($invalid_values, $this->testSourceIds); } @@ -86,9 +86,9 @@ class RowTest extends UnitTestCase { * Tests source immutability after freeze. */ public function testSourceFreeze() { - $this->setExpectedException(\Exception::class); $row = new Row($this->testValues, $this->testSourceIds); $row->rehash(); + $this->setExpectedException(\Exception::class); $this->assertSame($this->testHash, $row->getHash(), 'Correct hash.'); $row->setSourceProperty('title', 'new title'); $row->rehash(); @@ -101,9 +101,9 @@ class RowTest extends UnitTestCase { * Tests setting on a frozen row. */ public function testSetFrozenRow() { - $this->setExpectedException(\Exception::class, "The source is frozen and can't be changed any more"); $row = new Row($this->testValues, $this->testSourceIds); $row->freezeSource(); + $this->setExpectedException(\Exception::class, "The source is frozen and can't be changed any more"); $row->setSourceProperty('title', 'new title'); } diff --git a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php index df2a652..0cd0db2 100644 --- a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php @@ -64,8 +64,8 @@ class ExplodeTest extends MigrateProcessTestCase { * Test explode fails with empty delimiter. */ public function testExplodeWithEmptyDelimiter() { - $this->setExpectedException(MigrateException::class, 'delimiter is empty'); $plugin = new Explode(['delimiter' => ''], 'map', []); + $this->setExpectedException(MigrateException::class, 'delimiter is empty'); $plugin->transform('foo,bar', $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php index 996ff34..3dcc94f 100644 --- a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php @@ -92,7 +92,6 @@ class MigrationTest extends MigrateProcessTestCase { * Tests that processing is skipped when the input value is empty. */ public function testSkipOnEmpty() { - $this->setExpectedException(MigrateSkipProcessException::class); $migration_plugin = $this->prophesize(MigrationInterface::class); $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); $process_plugin_manager = $this->prophesize(MigratePluginManager::class); @@ -102,6 +101,7 @@ class MigrationTest extends MigrateProcessTestCase { ]; $migration_plugin->id()->willReturn(uniqid()); $migration = new Migration($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal()); + $this->setExpectedException(MigrateSkipProcessException::class); $migration->transform(0, $this->migrateExecutable, $this->row, 'foo'); } diff --git a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php index 8514fd9..66b27cc 100644 --- a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php @@ -17,8 +17,8 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { * @covers ::process */ public function testProcessSkipsOnEmpty() { - $this->setExpectedException(MigrateSkipProcessException::class); $configuration['method'] = 'process'; + $this->setExpectedException(MigrateSkipProcessException::class); (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -37,8 +37,8 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { * @covers ::row */ public function testRowSkipsOnEmpty() { - $this->setExpectedException(MigrateSkipRowException::class); $configuration['method'] = 'row'; + $this->setExpectedException(MigrateSkipRowException::class); (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php index 15cd4a3..f8ba1dd 100644 --- a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php +++ b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php @@ -80,11 +80,11 @@ class StaticMapTest extends MigrateProcessTestCase { * Tests when the source is invalid and bypass is enabled. */ public function testMapWithInvalidSourceAndBypass() { - $this->setExpectedException(MigrateException::class, 'Setting both default_value and bypass is invalid.'); $configuration['map']['foo']['bar'] = 'baz'; $configuration['default_value'] = 'test'; $configuration['bypass'] = TRUE; $this->plugin = new StaticMap($configuration, 'map', array()); + $this->setExpectedException(MigrateException::class, 'Setting both default_value and bypass is invalid.'); $this->plugin->transform(array('bar'), $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php index 95993b7..6a73905 100644 --- a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php @@ -58,9 +58,9 @@ class SubstrTest extends MigrateProcessTestCase { * Tests invalid input type. */ public function testSubstrFail() { - $this->setExpectedException(MigrateException::class, 'The input value must be a string.'); $configuration = []; $this->plugin = new Substr($configuration, 'map', []); + $this->setExpectedException(MigrateException::class, 'The input value must be a string.'); $this->plugin->transform(['Captain Janeway'], $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -68,9 +68,9 @@ class SubstrTest extends MigrateProcessTestCase { * Tests that the start parameter is an integer. */ public function testStartIsString() { - $this->setExpectedException(MigrateException::class, 'The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.'); $configuration['start'] = '2'; $this->plugin = new Substr($configuration, 'map', []); + $this->setExpectedException(MigrateException::class, 'The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.'); $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -78,9 +78,9 @@ class SubstrTest extends MigrateProcessTestCase { * Tests that the length parameter is an integer. */ public function testLengthIsString() { - $this->setExpectedException(MigrateException::class, 'The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.'); $configuration['length'] = '1'; $this->plugin = new Substr($configuration, 'map', []); + $this->setExpectedException(MigrateException::class, 'The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.'); $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php index 8032679..7aee9f4 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php @@ -181,7 +181,6 @@ class EntityNormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeWithInvalidBundle() { - $this->setExpectedException(UnexpectedValueException::class); $test_data = [ 'key_1' => 'value_1', 'key_2' => 'value_2', @@ -242,6 +241,7 @@ class EntityNormalizerTest extends UnitTestCase { ->will($this->returnValue($entity_type_storage)); + $this->setExpectedException(UnexpectedValueException::class); $this->entityNormalizer->denormalize($test_data, 'Drupal\Core\Entity\ContentEntityBase', NULL, ['entity_type' => 'test']); } diff --git a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php index 3047045..f36243e 100644 --- a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php +++ b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php @@ -238,13 +238,13 @@ class TestInfoParsingTest extends UnitTestCase { * @covers ::getTestInfo */ public function testTestInfoParserMissingGroup() { - $this->setExpectedException(MissingGroupException::class, 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest'); $classname = 'Drupal\KernelTests\field\BulkDeleteTest'; $doc_comment = <<setExpectedException(MissingGroupException::class, 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest'); TestDiscovery::getTestInfo($classname, $doc_comment); } diff --git a/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php b/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php index 8faaae1..fc044d5 100644 --- a/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php +++ b/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php @@ -90,7 +90,6 @@ class AcceptHeaderMatcherTest extends UnitTestCase { */ public function testNoRouteFound() { // Remove the sample routes that would match any method. - $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified formats application/json text/xml.'); $routes = $this->fixtures->sampleRouteCollection(); $routes->remove('route_a'); $routes->remove('route_b'); @@ -102,6 +101,7 @@ class AcceptHeaderMatcherTest extends UnitTestCase { $request->setRequestFormat('json'); $this->matcher->filter($routes, $request); $this->matcher->filter($routes, $request); + $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified formats application/json text/xml.'); $this->fail('No exception was thrown.'); } diff --git a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php index b08f273..cb7f5eb 100644 --- a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php +++ b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php @@ -45,12 +45,12 @@ class DbCommandBaseTest extends KernelTestBase { * Invalid database names will throw a useful exception. */ public function testSpecifyDatabaseDoesNotExist() { - $this->setExpectedException(ConnectionNotDefinedException::class); $command = new DbCommandBaseTester(); $command_tester = new CommandTester($command); $command_tester->execute([ '--database' => 'dne' ]); + $this->setExpectedException(ConnectionNotDefinedException::class); $command->getDatabaseConnection($command_tester->getInput()); } diff --git a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php index 017858f..b528b48 100644 --- a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php @@ -124,7 +124,6 @@ class PrivateTempStoreTest extends UnitTestCase { * @covers ::set */ public function testSetWithNoLockAvailable() { - $this->setExpectedException(TempStoreException::class); $this->lock->expects($this->at(0)) ->method('acquire') ->with('1:test') @@ -140,6 +139,7 @@ class PrivateTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); + $this->setExpectedException(TempStoreException::class); $this->tempStore->set('test', 'value'); } @@ -223,7 +223,6 @@ class PrivateTempStoreTest extends UnitTestCase { * @covers ::delete */ public function testDeleteWithNoLockAvailable() { - $this->setExpectedException(TempStoreException::class); $this->keyValue->expects($this->once()) ->method('get') ->with('1:test') @@ -243,6 +242,7 @@ class PrivateTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); + $this->setExpectedException(TempStoreException::class); $this->tempStore->delete('test'); } diff --git a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php index 32cb482..49e00b7 100644 --- a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php @@ -135,7 +135,6 @@ class SharedTempStoreTest extends UnitTestCase { * @covers ::set */ public function testSetWithNoLockAvailable() { - $this->setExpectedException(TempStoreException::class); $this->lock->expects($this->at(0)) ->method('acquire') ->with('test') @@ -151,6 +150,7 @@ class SharedTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); + $this->setExpectedException(TempStoreException::class); $this->tempStore->set('test', 'value'); } @@ -299,7 +299,6 @@ class SharedTempStoreTest extends UnitTestCase { * @covers ::delete */ public function testDeleteWithNoLockAvailable() { - $this->setExpectedException(TempStoreException::class); $this->lock->expects($this->at(0)) ->method('acquire') ->with('test') @@ -315,6 +314,7 @@ class SharedTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); + $this->setExpectedException(TempStoreException::class); $this->tempStore->delete('test'); } diff --git a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php index 3f8d9ad..b7d228d 100644 --- a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php +++ b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php @@ -117,8 +117,8 @@ class ViewAjaxControllerTest extends UnitTestCase { * Tests missing view_name and view_display_id */ public function testMissingViewName() { - $this->setExpectedException(NotFoundHttpException::class); $request = new Request(); + $this->setExpectedException(NotFoundHttpException::class); $this->viewAjaxController->ajaxView($request); } @@ -126,7 +126,6 @@ class ViewAjaxControllerTest extends UnitTestCase { * Tests with view_name and view_display_id but not existing view. */ public function testMissingView() { - $this->setExpectedException(NotFoundHttpException::class); $request = new Request(); $request->request->set('view_name', 'test_view'); $request->request->set('view_display_id', 'page_1'); @@ -136,6 +135,7 @@ class ViewAjaxControllerTest extends UnitTestCase { ->with('test_view') ->will($this->returnValue(FALSE)); + $this->setExpectedException(NotFoundHttpException::class); $this->viewAjaxController->ajaxView($request); } @@ -143,7 +143,6 @@ class ViewAjaxControllerTest extends UnitTestCase { * Tests a view without having access to it. */ public function testAccessDeniedView() { - $this->setExpectedException(AccessDeniedHttpException::class); $request = new Request(); $request->request->set('view_name', 'test_view'); $request->request->set('view_display_id', 'page_1'); @@ -169,6 +168,7 @@ class ViewAjaxControllerTest extends UnitTestCase { ->with($view) ->will($this->returnValue($executable)); + $this->setExpectedException(AccessDeniedHttpException::class); $this->viewAjaxController->ajaxView($request); } diff --git a/core/modules/views/tests/src/Unit/ViewExecutableTest.php b/core/modules/views/tests/src/Unit/ViewExecutableTest.php index e787ab9..405f9e2 100644 --- a/core/modules/views/tests/src/Unit/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Unit/ViewExecutableTest.php @@ -185,13 +185,13 @@ class ViewExecutableTest extends UnitTestCase { * @covers ::getUrl */ public function testGetUrlWithoutRouterDisplay() { - $this->setExpectedException(\InvalidArgumentException::class); $this->displayHandler = $this->getMock('Drupal\views\Plugin\views\display\DisplayPluginInterface'); $this->displayHandlers->expects($this->any()) ->method('get') ->willReturn($this->displayHandler); $this->executable->display_handler = $this->displayHandler; + $this->setExpectedException(\InvalidArgumentException::class); $this->executable->getUrl(); } diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index e647dc0..759eea4 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -66,9 +66,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::__construct */ public function testConstruct() { - $this->setExpectedException(InvalidArgumentException::class); $container_definition = $this->getMockContainerDefinition(); $container_definition['machine_format'] = !$this->machineFormat; + $this->setExpectedException(InvalidArgumentException::class); $container = new $this->containerClass($container_definition); } @@ -134,8 +134,8 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::setParameter */ public function testSetParameterWithFrozenContainer() { - $this->setExpectedException(LogicException::class); $this->container = new $this->containerClass($this->containerDefinition); + $this->setExpectedException(LogicException::class); $this->container->setParameter('some_config', 'new_value'); } @@ -297,12 +297,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::resolveServicesAndParameters */ public function testGetForParameterDependencyWithExceptionOnSecondCall() { - $this->setExpectedException(InvalidArgumentException::class); $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); $this->assertNull($service, 'Service is NULL.'); // Reset the service. $this->container->set('service_parameter_not_exists', NULL); + $this->setExpectedException(InvalidArgumentException::class); $this->container->get('service_parameter_not_exists'); } @@ -384,8 +384,8 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::getAlternatives */ public function testGetForNonExistantServiceWithExceptionOnSecondCall() { - $this->setExpectedException(ServiceNotFoundException::class); $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.'); + $this->setExpectedException(ServiceNotFoundException::class); $this->container->get('service_not_exists'); } @@ -664,12 +664,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @dataProvider scopeExceptionTestProvider */ public function testScopeFunctionsWithException($method, $argument) { - $this->setExpectedException(\BadMethodCallException::class); $callable = array( $this->container, $method, ); + $this->setExpectedException(\BadMethodCallException::class); $callable($argument); } diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 17d11bc..9463b50 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -485,12 +485,12 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; * @covers ::getServiceDefinition */ public function testGetServiceDefinitionWithInvalidScope() { - $this->setExpectedException(InvalidArgumentException::class); $bar_definition = new Definition('\stdClass'); $bar_definition->setScope('foo_scope'); $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); + $this->setExpectedException(InvalidArgumentException::class); $this->dumper->getArray(); } @@ -557,12 +557,12 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; * @covers ::getServiceDefinition */ public function testGetServiceDefinitionForDecoratedService() { - $this->setExpectedException(InvalidArgumentException::class); $bar_definition = new Definition('\stdClass'); $bar_definition->setDecoratedService(new Reference('foo')); $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); + $this->setExpectedException(InvalidArgumentException::class); $this->dumper->getArray(); } @@ -572,7 +572,6 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; * @covers ::dumpValue */ public function testGetServiceDefinitionForExpression() { - $this->setExpectedException(RuntimeException::class); $expression = new Expression(); $bar_definition = new Definition('\stdClass'); @@ -580,6 +579,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); + $this->setExpectedException(RuntimeException::class); $this->dumper->getArray(); } @@ -589,7 +589,6 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; * @covers ::dumpValue */ public function testGetServiceDefinitionForObject() { - $this->setExpectedException(RuntimeException::class); $service = new \stdClass(); $bar_definition = new Definition('\stdClass'); @@ -597,6 +596,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); + $this->setExpectedException(RuntimeException::class); $this->dumper->getArray(); } @@ -606,7 +606,6 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; * @covers ::dumpValue */ public function testGetServiceDefinitionForResource() { - $this->setExpectedException(RuntimeException::class); $resource = fopen('php://memory', 'r'); $bar_definition = new Definition('\stdClass'); @@ -614,6 +613,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); + $this->setExpectedException(RuntimeException::class); $this->dumper->getArray(); } diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php index 25461e0..506a14c 100644 --- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php @@ -57,8 +57,8 @@ class FileCacheFactoryTest extends UnitTestCase { * @covers ::get */ public function testGetNoPrefix() { - $this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing'); FileCacheFactory::setPrefix(NULL); + $this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing'); FileCacheFactory::get('test_foo_settings', []); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php index 17dcccb..28a48f6 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php @@ -60,8 +60,8 @@ class DefaultFactoryTest extends UnitTestCase { * @covers ::getPluginClass */ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() { - $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); $plugin_definition = $this->getMock(PluginDefinitionInterface::class); + $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); DefaultFactory::getPluginClass('cherry', $plugin_definition); } @@ -81,12 +81,12 @@ class DefaultFactoryTest extends UnitTestCase { * @covers ::getPluginClass */ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() { - $this->setExpectedException(PluginException::class); $plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit'; $plugin_definition = $this->getMock(PluginDefinitionInterface::class); $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); + $this->setExpectedException(PluginException::class); DefaultFactory::getPluginClass('kiwifruit', $plugin_definition); } @@ -124,8 +124,8 @@ class DefaultFactoryTest extends UnitTestCase { * @covers ::getPluginClass */ public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() { - $this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.'); $plugin_class = Kale::class; + $this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.'); DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::class); } @@ -135,12 +135,12 @@ class DefaultFactoryTest extends UnitTestCase { * @covers ::getPluginClass */ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() { - $this->setExpectedException(PluginException::class); $plugin_class = Kale::class; $plugin_definition = $this->getMock(PluginDefinitionInterface::class); $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); + $this->setExpectedException(PluginException::class); DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php index 70c0ffb..34ee86a 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php @@ -64,12 +64,12 @@ class DiscoveryTraitTest extends UnitTestCase { */ public function testDoGetDefinitionException($expected, $definitions, $plugin_id) { // Mock the trait. - $this->setExpectedException(PluginNotFoundException::class); $trait = $this->getMockForTrait('Drupal\Component\Plugin\Discovery\DiscoveryTrait'); // Un-protect the method using reflection. $method_ref = new \ReflectionMethod($trait, 'doGetDefinition'); $method_ref->setAccessible(TRUE); // Call doGetDefinition, with $exception_on_invalid always TRUE. + $this->setExpectedException(PluginNotFoundException::class); $this->assertSame( $expected, $method_ref->invoke($trait, $definitions, $plugin_id, TRUE) @@ -104,12 +104,12 @@ class DiscoveryTraitTest extends UnitTestCase { // Since getDefinition is a wrapper around doGetDefinition(), we can re-use // its data provider. We just have to tell abstract method getDefinitions() // to use the $definitions array. - $this->setExpectedException(PluginNotFoundException::class); $trait = $this->getMockForTrait('Drupal\Component\Plugin\Discovery\DiscoveryTrait'); $trait->expects($this->once()) ->method('getDefinitions') ->willReturn($definitions); // Call getDefinition(), with $exception_on_invalid always TRUE. + $this->setExpectedException(PluginNotFoundException::class); $this->assertSame( $expected, $trait->getDefinition($plugin_id, TRUE) diff --git a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php index b4c610a..4dbc8a7 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php @@ -123,12 +123,12 @@ class ArgumentsResolverTest extends UnitTestCase { * Without the typehint, the wildcard object will not be passed to the callable. */ public function testGetWildcardArgumentNoTypehint() { - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); $a = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1'); $wildcards = [$a]; $resolver = new ArgumentsResolver([], [], $wildcards); $callable = function($route) {}; + $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); $arguments = $resolver->getArguments($callable); $this->assertNull($arguments); } @@ -152,12 +152,12 @@ class ArgumentsResolverTest extends UnitTestCase { * Tests handleUnresolvedArgument() for a scalar argument. */ public function testHandleNotUpcastedArgument() { - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); $objects = ['foo' => 'bar']; $scalars = ['foo' => 'baz']; $resolver = new ArgumentsResolver($scalars, $objects, []); $callable = function(\stdClass $foo) {}; + $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); $arguments = $resolver->getArguments($callable); $this->assertNull($arguments); } @@ -168,8 +168,8 @@ class ArgumentsResolverTest extends UnitTestCase { * @dataProvider providerTestHandleUnresolvedArgument */ public function testHandleUnresolvedArgument($callable) { - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); $resolver = new ArgumentsResolver([], [], []); + $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); $arguments = $resolver->getArguments($callable); $this->assertNull($arguments); } diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php index 6a98d2a..321565e 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -61,8 +61,8 @@ class RandomTest extends UnitTestCase { public function testRandomNameException() { // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. - $this->setExpectedException(\RuntimeException::class); $random = new Random(); + $this->setExpectedException(\RuntimeException::class); for ($i = 0; $i <= 100; $i++) { $str = $random->name(1, TRUE); $names[$str] = TRUE; @@ -77,8 +77,8 @@ class RandomTest extends UnitTestCase { public function testRandomStringException() { // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. - $this->setExpectedException(\RuntimeException::class); $random = new Random(); + $this->setExpectedException(\RuntimeException::class); for ($i = 0; $i <= 100; $i++) { $str = $random->string(1, TRUE); $names[$str] = TRUE; diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index 5532f61..fdbe09b 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -477,7 +477,6 @@ class AccessManagerTest extends UnitTestCase { * @dataProvider providerCheckException */ public function testCheckException($return_value) { - $this->setExpectedException(AccessException::class); $route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface'); // Setup a test route for each access configuration. @@ -515,6 +514,7 @@ class AccessManagerTest extends UnitTestCase { $this->checkProvider->setContainer($container); $this->checkProvider->addCheckService('test_incorrect_value', 'access'); + $this->setExpectedException(AccessException::class); $access_manager->checkNamedRoute('test_incorrect_value', array(), $this->account); } diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php index 5b98a68..61bbec5 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php @@ -173,9 +173,9 @@ class CsrfTokenGeneratorTest extends UnitTestCase { * @dataProvider providerTestInvalidParameterTypes */ public function testInvalidParameterTypes($token, $value = '') { - $this->setExpectedException(\InvalidArgumentException::class); $this->setupDefaultExpectations(); + $this->setExpectedException(\InvalidArgumentException::class); $this->generator->validate($token, $value); } @@ -201,9 +201,9 @@ class CsrfTokenGeneratorTest extends UnitTestCase { */ public function testGetWithNoHashSalt() { // Update settings with no hash salt. - $this->setExpectedException(\RuntimeException::class); new Settings(array()); $generator = new CsrfTokenGenerator($this->privateKey, $this->sessionMetadata); + $this->setExpectedException(\RuntimeException::class); $generator->get(); } diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index e882fff..a02cfa7 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -149,7 +149,6 @@ class LibraryDiscoveryParserTest extends UnitTestCase { * @covers ::buildByExtension */ public function testInvalidLibrariesFile() { - $this->setExpectedException(InvalidLibraryFileException::class); $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('invalid_file') @@ -159,6 +158,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'invalid_file', $path); + $this->setExpectedException(InvalidLibraryFileException::class); $this->libraryDiscoveryParser->buildByExtension('invalid_file'); } @@ -168,7 +168,6 @@ class LibraryDiscoveryParserTest extends UnitTestCase { * @covers ::buildByExtension */ public function testBuildByExtensionWithMissingInformation() { - $this->setExpectedException(IncompleteLibraryDefinitionException::class, "Incomplete library definition for definition 'example' in extension 'example_module_missing_information'"); $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('example_module_missing_information') @@ -178,6 +177,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'example_module_missing_information', $path); + $this->setExpectedException(IncompleteLibraryDefinitionException::class, "Incomplete library definition for definition 'example' in extension 'example_module_missing_information'"); $this->libraryDiscoveryParser->buildByExtension('example_module_missing_information'); } @@ -279,7 +279,6 @@ class LibraryDiscoveryParserTest extends UnitTestCase { * @covers ::buildByExtension */ public function testJsWithPositiveWeight() { - $this->setExpectedException(\UnexpectedValueException::class); $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('js_positive_weight') @@ -289,6 +288,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'js_positive_weight', $path); + $this->setExpectedException(\UnexpectedValueException::class); $this->libraryDiscoveryParser->buildByExtension('js_positive_weight'); } @@ -405,7 +405,6 @@ class LibraryDiscoveryParserTest extends UnitTestCase { * @covers ::buildByExtension */ public function testLibraryThirdPartyWithMissingLicense() { - $this->setExpectedException(LibraryDefinitionMissingLicenseException::class, "Missing license information in library definition for definition 'no-license-info-but-remote' extension 'licenses_missing_information': it has a remote, but no license."); $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('licenses_missing_information') @@ -415,6 +414,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'licenses_missing_information', $path); + $this->setExpectedException(LibraryDefinitionMissingLicenseException::class, "Missing license information in library definition for definition 'no-license-info-but-remote' extension 'licenses_missing_information': it has a remote, but no license."); $this->libraryDiscoveryParser->buildByExtension('licenses_missing_information'); } diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php index 37e2c38..16ee3f4 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php @@ -185,7 +185,6 @@ class BreadcrumbManagerTest extends UnitTestCase { * Tests a breadcrumb builder with a bad return value. */ public function testBuildWithInvalidBreadcrumbResult() { - $this->setExpectedException(\UnexpectedValueException::class); $builder = $this->getMock('Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface'); $builder->expects($this->once()) ->method('applies') @@ -195,6 +194,7 @@ class BreadcrumbManagerTest extends UnitTestCase { ->will($this->returnValue('invalid_result')); $this->breadcrumbManager->addBuilder($builder, 0); + $this->setExpectedException(\UnexpectedValueException::class); $this->breadcrumbManager->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface')); } diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php index 28282ac..407dd27 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php @@ -17,8 +17,8 @@ class BreadcrumbTest extends UnitTestCase { * @covers ::setLinks */ public function testSetLinks() { - $this->setExpectedException(\LogicException::class, 'Once breadcrumb links are set, only additional breadcrumb links can be added.'); $breadcrumb = new Breadcrumb(); + $this->setExpectedException(\LogicException::class, 'Once breadcrumb links are set, only additional breadcrumb links can be added.'); $breadcrumb->setLinks([new Link('Home', Url::fromRoute(''))]); $breadcrumb->setLinks([new Link('None', Url::fromRoute(''))]); } diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php index a456942..463bd0e 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php @@ -16,8 +16,8 @@ class CacheTagsInvalidatorTest extends UnitTestCase { * @covers ::invalidateTags */ public function testInvalidateTagsWithInvalidTags() { - $this->setExpectedException(\AssertionError::class); $cache_tags_invalidator = new CacheTagsInvalidator(); + $this->setExpectedException(\AssertionError::class); $cache_tags_invalidator->invalidateTags(['node' => [2, 3, 5, 8, 13]]); } diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php index 1f42d76..e2e1c42 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -107,10 +107,10 @@ class CacheContextsManagerTest extends UnitTestCase { * @covers ::convertTokensToKeys */ public function testInvalidContext() { - $this->setExpectedException(\AssertionError::class); $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); + $this->setExpectedException(\AssertionError::class); $cache_contexts_manager->convertTokensToKeys(["non-cache-context"]); } @@ -120,10 +120,10 @@ class CacheContextsManagerTest extends UnitTestCase { * @dataProvider providerTestInvalidCalculatedContext */ public function testInvalidCalculatedContext($context_token) { - $this->setExpectedException(\Exception::class); $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); + $this->setExpectedException(\Exception::class); $cache_contexts_manager->convertTokensToKeys([$context_token]); } diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index f5fb20b..a4e6e92 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -242,10 +242,10 @@ class ConfigTest extends UnitTestCase { */ public function testSetIllegalOffsetValue() { // Set a single value. - $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class); $this->config->set('testData', 1); // Attempt to treat the single value as a nested item. + $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class); $this->config->set('testData.illegalOffset', 1); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index bad8048..c078398 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -570,10 +570,10 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { * @covers ::toArray */ public function testToArrayFallback() { - $this->setExpectedException(SchemaIncompleteException::class); $this->entityType->expects($this->any()) ->method('getPropertiesToExport') ->willReturn([]); + $this->setExpectedException(SchemaIncompleteException::class); $this->entity->toArray(); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 4f8392e..216d646 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -475,11 +475,11 @@ class ConfigEntityStorageTest extends UnitTestCase { * @covers ::save */ public function testSaveInvalid() { - $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); $entity = $this->getMockEntity(); + $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); $this->entityStorage->save($entity); } @@ -488,7 +488,6 @@ class ConfigEntityStorageTest extends UnitTestCase { * @covers ::doSave */ public function testSaveDuplicate() { - $this->setExpectedException(EntityStorageException::class); $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') ->disableOriginalConstructor() ->getMock(); @@ -511,6 +510,7 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity = $this->getMockEntity(array('id' => 'foo')); $entity->enforceIsNew(); + $this->setExpectedException(EntityStorageException::class); $this->entityStorage->save($entity); } @@ -519,7 +519,6 @@ class ConfigEntityStorageTest extends UnitTestCase { * @covers ::doSave */ public function testSaveMismatch() { - $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this UUID is already used for'); $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') ->disableOriginalConstructor() ->getMock(); @@ -545,6 +544,7 @@ class ConfigEntityStorageTest extends UnitTestCase { ->will($this->returnValue(array('baz'))); $entity = $this->getMockEntity(array('id' => 'foo')); + $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this UUID is already used for'); $this->entityStorage->save($entity); } @@ -600,7 +600,6 @@ class ConfigEntityStorageTest extends UnitTestCase { * @covers ::doSave */ public function testSaveChangedUuid() { - $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this entity already exists with UUID'); $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') ->disableOriginalConstructor() ->getMock(); @@ -661,6 +660,7 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity = $this->getMockEntity(array('id' => 'foo')); $entity->set('uuid', 'baz'); + $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this entity already exists with UUID'); $this->entityStorage->save($entity); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php index c93b7f5..0c5ccab 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -93,8 +93,8 @@ class ConfigEntityTypeTest extends UnitTestCase { * @covers ::setStorageClass */ public function testSetStorageClass() { - $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); $config_entity = $this->setUpConfigEntityType([]); + $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); $config_entity->setStorageClass('\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php index 214191a..7c4cb3f 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php @@ -98,7 +98,6 @@ class QueryFactoryTest extends UnitTestCase { /** */ public function testGetKeysWildCardEnd() { - $this->setExpectedException(\LogicException::class, 'test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup'); $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'); $key_value_factory = $this->getMock('Drupal\Core\KeyValueStore\KeyValueFactoryInterface'); $config_manager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface'); @@ -110,6 +109,7 @@ class QueryFactoryTest extends UnitTestCase { $method = new \ReflectionMethod($query_factory, 'getKeys'); $method->setAccessible(TRUE); + $this->setExpectedException(\LogicException::class, 'test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup'); $method->invoke($query_factory, $this->getConfigObject('test'), 'test.*', 'get', $config_entity_type); } diff --git a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php index 2fa4197..13b6293 100644 --- a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php @@ -143,7 +143,6 @@ class ConditionTest extends UnitTestCase { * @dataProvider providerTestCompileWithSqlInjectionForOperator */ public function testCompileWithSqlInjectionForOperator($operator) { - $this->setExpectedException(\PHPUnit_Framework_Error::class); $connection = $this->prophesize(Connection::class); $connection->escapeField(Argument::any())->will(function ($args) { return preg_replace('/[^A-Za-z0-9_.]+/', '', $args[0]); @@ -162,6 +161,7 @@ class ConditionTest extends UnitTestCase { $condition = new Condition('AND'); $condition->condition('name', 'value', $operator); + $this->setExpectedException(\PHPUnit_Framework_Error::class); $condition->compile($connection, $query_placeholder); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php index 4b98746..aea2524 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php @@ -67,11 +67,11 @@ class ProxyServicesPassTest extends UnitTestCase { * @covers ::process */ public function testContainerWithLazyServicesWithoutProxyClass() { - $this->setExpectedException(InvalidArgumentException::class); $container = new ContainerBuilder(); $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist') ->setLazy(TRUE); + $this->setExpectedException(InvalidArgumentException::class); $this->proxyServicesPass->process($container); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php index 290c2c7..8f81371 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -48,7 +48,6 @@ class TaggedHandlersPassTest extends UnitTestCase { * @covers ::process */ public function testProcessRequiredHandlers() { - $this->setExpectedException(LogicException::class, "At least one service tagged with 'consumer_id' is required."); $container = $this->buildContainer(); $container ->register('consumer_id', __NAMESPACE__ . '\ValidConsumer') @@ -57,6 +56,7 @@ class TaggedHandlersPassTest extends UnitTestCase { )); $handler_pass = new TaggedHandlersPass(); + $this->setExpectedException(LogicException::class, "At least one service tagged with 'consumer_id' is required."); $handler_pass->process($container); } @@ -66,13 +66,13 @@ class TaggedHandlersPassTest extends UnitTestCase { * @covers ::process */ public function testProcessMissingInterface() { - $this->setExpectedException(LogicException::class, "Service consumer 'consumer_id' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface."); $container = $this->buildContainer(); $container ->register('consumer_id', __NAMESPACE__ . '\InvalidConsumer') ->addTag('service_collector'); $handler_pass = new TaggedHandlersPass(); + $this->setExpectedException(LogicException::class, "Service consumer 'consumer_id' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface."); $handler_pass->process($container); } @@ -206,7 +206,6 @@ class TaggedHandlersPassTest extends UnitTestCase { * @covers ::process */ public function testProcessInterfaceMismatch() { - $this->setExpectedException(LogicException::class); $container = $this->buildContainer(); $container @@ -222,6 +221,7 @@ class TaggedHandlersPassTest extends UnitTestCase { )); $handler_pass = new TaggedHandlersPass(); + $this->setExpectedException(LogicException::class); $handler_pass->process($container); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php index 3cf624d..4020b88 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php @@ -37,9 +37,9 @@ class ContainerBuilderTest extends UnitTestCase { * @covers ::set */ public function testSetException() { - $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); $container = new ContainerBuilder(); $class = new BarClass(); + $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); $container->set('Bar', $class); $this->assertNotEquals('bar', $class->_serviceId); } @@ -48,8 +48,8 @@ class ContainerBuilderTest extends UnitTestCase { * @covers ::setParameter */ public function testSetParameterException() { - $this->setExpectedException(\InvalidArgumentException::class, 'Parameter names must be lowercase: Buzz'); $container = new ContainerBuilder(); + $this->setExpectedException(\InvalidArgumentException::class, 'Parameter names must be lowercase: Buzz'); $container->setParameter('Buzz', 'buzz'); } @@ -57,8 +57,8 @@ class ContainerBuilderTest extends UnitTestCase { * @covers ::register */ public function testRegisterException() { - $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); $container = new ContainerBuilder(); + $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); $container->register('Bar'); } @@ -66,8 +66,8 @@ class ContainerBuilderTest extends UnitTestCase { * Tests serialization. */ public function testSerialize() { - $this->setExpectedException(\AssertionError::class); $container = new ContainerBuilder(); + $this->setExpectedException(\AssertionError::class); serialize($container); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php index 29eb245..46f00bd 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php @@ -16,8 +16,8 @@ class ContainerTest extends UnitTestCase { * Tests serialization. */ public function testSerialize() { - $this->setExpectedException(\AssertionError::class); $container = new Container(); + $this->setExpectedException(\AssertionError::class); serialize($container); } diff --git a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php index 7bedbb3..59ab14c 100644 --- a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php @@ -300,9 +300,9 @@ class BaseFieldDefinitionTest extends UnitTestCase { * @covers ::setDefaultValueCallback */ public function testInvalidDefaultValueCallback() { - $this->setExpectedException(\InvalidArgumentException::class); $definition = BaseFieldDefinition::create($this->fieldType); // setDefaultValueCallback returns $this. + $this->setExpectedException(\InvalidArgumentException::class); $this->assertSame($definition, $definition->setDefaultValueCallback([get_class($this), 'mockDefaultValueCallback']) ); diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index 0c53d40..ee0fc95 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -354,7 +354,6 @@ class ContentEntityBaseUnitTest extends UnitTestCase { * @covers ::preSave */ public function testRequiredValidation() { - $this->setExpectedException(\LogicException::class, 'Entity validation was skipped.'); $validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface'); /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */ $empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList') @@ -397,6 +396,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase { // that trying to save a non-validated entity when validation is required // results in an exception. $this->assertTrue($this->entity->isValidationRequired()); + $this->setExpectedException(\LogicException::class, 'Entity validation was skipped.'); $this->entity->save(); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php index aa6dd78..8c99a6b 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php @@ -313,7 +313,6 @@ class EntityFieldManagerTest extends UnitTestCase { * @dataProvider providerTestGetBaseFieldDefinitionsTranslatableEntityTypeLangcode */ public function testGetBaseFieldDefinitionsTranslatableEntityTypeLangcode($provide_key, $provide_field, $translatable) { - $this->setExpectedException(\LogicException::class, 'The Test entity type cannot be translatable as it does not define a translatable "langcode" field.'); $keys = $provide_key ? ['langcode' => 'langcode'] : []; $this->setUpEntityWithFieldDefinition(FALSE, 'id', $keys); @@ -331,6 +330,7 @@ class EntityFieldManagerTest extends UnitTestCase { $this->entityType->isTranslatable()->willReturn(TRUE); $this->entityType->getLabel()->willReturn('Test'); + $this->setExpectedException(\LogicException::class, 'The Test entity type cannot be translatable as it does not define a translatable "langcode" field.'); $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type'); } @@ -452,12 +452,12 @@ class EntityFieldManagerTest extends UnitTestCase { * @covers ::buildBaseFieldDefinitions */ public function testGetBaseFieldDefinitionsInvalidDefinition() { - $this->setExpectedException(\LogicException::class); $this->setUpEntityWithFieldDefinition(FALSE, 'langcode', ['langcode' => 'langcode']); $this->entityType->isTranslatable()->willReturn(TRUE); $this->entityType->getLabel()->willReturn('the_label'); + $this->setExpectedException(\LogicException::class); $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php index 896ea9b..f35beaf 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php @@ -252,11 +252,11 @@ class EntityTypeManagerTest extends UnitTestCase { * @covers ::getFormObject */ public function testGetFormObjectInvalidOperation() { - $this->setExpectedException(InvalidPluginDefinitionException::class); $entity = $this->prophesize(EntityTypeInterface::class); $entity->getFormClass('edit')->willReturn(''); $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]); + $this->setExpectedException(InvalidPluginDefinitionException::class); $this->entityTypeManager->getFormObject('test_entity_type', 'edit'); } @@ -286,10 +286,10 @@ class EntityTypeManagerTest extends UnitTestCase { * @covers ::getHandler */ public function testGetHandlerMissingHandler() { - $this->setExpectedException(InvalidPluginDefinitionException::class); $entity = $this->prophesize(EntityTypeInterface::class); $entity->getHandlerClass('storage')->willReturn(''); $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]); + $this->setExpectedException(InvalidPluginDefinitionException::class); $this->entityTypeManager->getHandler('test_entity_type', 'storage'); } @@ -316,13 +316,13 @@ class EntityTypeManagerTest extends UnitTestCase { * @covers ::processDefinition */ public function testProcessDefinition() { - $this->setExpectedException(InvalidLinkTemplateException::class, "Link template 'canonical' for entity type 'apple' must start with a leading slash, the current link template is 'path/to/apple'"); $apple = $this->prophesize(EntityTypeInterface::class); $this->setUpEntityTypeDefinitions(['apple' => $apple]); $apple->getLinkTemplates()->willReturn(['canonical' => 'path/to/apple']); $definition = $apple->reveal(); + $this->setExpectedException(InvalidLinkTemplateException::class, "Link template 'canonical' for entity type 'apple' must start with a leading slash, the current link template is 'path/to/apple'"); $this->entityTypeManager->processDefinition($definition, 'apple'); } @@ -370,9 +370,9 @@ class EntityTypeManagerTest extends UnitTestCase { * @covers ::getDefinition */ public function testGetDefinitionInvalidException() { - $this->setExpectedException(PluginNotFoundException::class, 'The "pear" entity type does not exist.'); $this->setUpEntityTypeDefinitions(); + $this->setExpectedException(PluginNotFoundException::class, 'The "pear" entity type does not exist.'); $this->entityTypeManager->getDefinition('pear', TRUE); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php index a0c355e..5b37291 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php @@ -134,7 +134,6 @@ class EntityTypeRepositoryTest extends UnitTestCase { * @covers ::getEntityTypeFromClass */ public function testGetEntityTypeFromClassNoMatch() { - $this->setExpectedException(NoCorrespondingEntityClassException::class, 'The \Drupal\pear\Entity\Pear class does not correspond to an entity type.'); $apple = $this->prophesize(EntityTypeInterface::class); $banana = $this->prophesize(EntityTypeInterface::class); @@ -146,6 +145,7 @@ class EntityTypeRepositoryTest extends UnitTestCase { $apple->getOriginalClass()->willReturn('\Drupal\apple\Entity\Apple'); $banana->getOriginalClass()->willReturn('\Drupal\banana\Entity\Banana'); + $this->setExpectedException(NoCorrespondingEntityClassException::class, 'The \Drupal\pear\Entity\Pear class does not correspond to an entity type.'); $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\pear\Entity\Pear'); } @@ -153,7 +153,6 @@ class EntityTypeRepositoryTest extends UnitTestCase { * @covers ::getEntityTypeFromClass */ public function testGetEntityTypeFromClassAmbiguous() { - $this->setExpectedException(AmbiguousEntityClassException::class, 'Multiple entity types found for \Drupal\apple\Entity\Apple.'); $boskoop = $this->prophesize(EntityTypeInterface::class); $boskoop->getOriginalClass()->willReturn('\Drupal\apple\Entity\Apple'); $boskoop->id()->willReturn('boskop'); @@ -167,6 +166,7 @@ class EntityTypeRepositoryTest extends UnitTestCase { 'gala' => $gala, ]); + $this->setExpectedException(AmbiguousEntityClassException::class, 'Multiple entity types found for \Drupal\apple\Entity\Apple.'); $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\apple\Entity\Apple'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index cbbc3a4..f7caddb 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -392,8 +392,8 @@ class EntityTypeTest extends UnitTestCase { * @covers ::setLinkTemplate */ public function testSetLinkTemplateWithInvalidPath() { - $this->setExpectedException(\InvalidArgumentException::class); $entity_type = $this->setUpEntityType(['id' => $this->randomMachineName()]); + $this->setExpectedException(\InvalidArgumentException::class); $entity_type->setLinkTemplate('test', 'invalid-path'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index d4a9b93..46251c6 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -443,10 +443,10 @@ class KeyValueEntityStorageTest extends UnitTestCase { * @covers ::doSave */ public function testSaveInvalid() { - $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); $this->setUpKeyValueEntityStorage(); $entity = $this->getMockEntity('Drupal\Core\Config\Entity\ConfigEntityBase'); + $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); $this->entityStorage->save($entity); $this->keyValueStore->expects($this->never()) ->method('has'); @@ -461,7 +461,6 @@ class KeyValueEntityStorageTest extends UnitTestCase { * @covers ::doSave */ public function testSaveDuplicate() { - $this->setExpectedException(EntityStorageException::class, "'test_entity_type' entity with ID 'foo' already exists"); $this->setUpKeyValueEntityStorage(); $entity = $this->getMockEntity('Drupal\Core\Entity\Entity', array(array('id' => 'foo'))); @@ -473,6 +472,7 @@ class KeyValueEntityStorageTest extends UnitTestCase { ->method('set'); $this->keyValueStore->expects($this->never()) ->method('delete'); + $this->setExpectedException(EntityStorageException::class, "'test_entity_type' entity with ID 'foo' already exists"); $this->entityStorage->save($entity); } diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php index 24fdb34..39c9a05 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php @@ -300,7 +300,6 @@ class DefaultTableMappingTest extends UnitTestCase { * @dataProvider providerTestGetFieldColumnName */ public function testGetFieldColumnNameInvalid($base_field, $columns, $column) { - $this->setExpectedException(SqlContentEntityStorageException::class, "Column information not available for the 'test' field."); $definitions['test'] = $this->setUpDefinition('test', $columns, $base_field); // Mark field storage definition as custom storage. @@ -309,6 +308,7 @@ class DefaultTableMappingTest extends UnitTestCase { ->willReturn(TRUE); $table_mapping = new DefaultTableMapping($this->entityType, $definitions); + $this->setExpectedException(SqlContentEntityStorageException::class, "Column information not available for the 'test' field."); $table_mapping->getFieldColumnName($definitions['test'], $column); } @@ -442,8 +442,8 @@ class DefaultTableMappingTest extends UnitTestCase { * @covers ::getFieldTableName */ public function testGetFieldTableNameInvalid() { - $this->setExpectedException(SqlContentEntityStorageException::class, "Table information not available for the 'invalid_field_name' field."); $table_mapping = new DefaultTableMapping($this->entityType, []); + $this->setExpectedException(SqlContentEntityStorageException::class, "Table information not available for the 'invalid_field_name' field."); $table_mapping->getFieldTableName('invalid_field_name'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php index 51771ea..dea1567 100644 --- a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php @@ -286,8 +286,8 @@ class EntityAdapterUnitTest extends UnitTestCase { * @covers ::get */ public function testGetWithoutData() { - $this->setExpectedException(MissingDataException::class); $this->entityAdapter->setValue(NULL); + $this->setExpectedException(MissingDataException::class); $this->entityAdapter->get('id'); } @@ -308,9 +308,9 @@ class EntityAdapterUnitTest extends UnitTestCase { * @covers ::set */ public function testSetWithoutData() { - $this->setExpectedException(MissingDataException::class); $this->entityAdapter->setValue(NULL); $id_items = [ array('value' => $this->id + 1) ]; + $this->setExpectedException(MissingDataException::class); $this->entityAdapter->set('id', $id_items); } @@ -338,8 +338,8 @@ class EntityAdapterUnitTest extends UnitTestCase { * @covers ::toArray */ public function testToArrayWithoutData() { - $this->setExpectedException(MissingDataException::class); $this->entityAdapter->setValue(NULL); + $this->setExpectedException(MissingDataException::class); $this->entityAdapter->toArray(); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php index 7d3c3d1..ba1aa3a 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php @@ -117,7 +117,6 @@ class RedirectResponseSubscriberTest extends UnitTestCase { * @dataProvider providerTestDestinationRedirectToExternalUrl */ public function testDestinationRedirectToExternalUrl($request, $expected) { - $this->setExpectedException(\PHPUnit_Framework_Error::class); $dispatcher = new EventDispatcher(); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $response = new RedirectResponse('http://other-example.com'); @@ -125,6 +124,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase { $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'checkRedirectUrl')); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); + $this->setExpectedException(\PHPUnit_Framework_Error::class); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); $this->assertEquals(400, $event->getResponse()->getStatusCode()); @@ -167,7 +167,6 @@ class RedirectResponseSubscriberTest extends UnitTestCase { * @dataProvider providerTestDestinationRedirectWithInvalidUrl */ public function testDestinationRedirectWithInvalidUrl(Request $request) { - $this->setExpectedException(\PHPUnit_Framework_Error::class); $dispatcher = new EventDispatcher(); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $response = new RedirectResponse('http://example.com/drupal'); @@ -175,6 +174,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase { $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'checkRedirectUrl')); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); + $this->setExpectedException(\PHPUnit_Framework_Error::class); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); $this->assertEquals(400, $event->getResponse()->getStatusCode()); diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index e3ef0a0..01a6f36 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -92,12 +92,12 @@ class SpecialAttributesRouteSubscriberTest extends UnitTestCase { * @covers ::onAlterRoutes */ public function testOnRouteBuildingInvalidVariables(Route $route) { - $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'uses reserved variable names'); $route_collection = $this->getMock('Symfony\Component\Routing\RouteCollection', NULL); $route_collection->add('test', $route); $event = new RouteBuildEvent($route_collection, 'test'); $subscriber = new SpecialAttributesRouteSubscriber(); + $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'uses reserved variable names'); $subscriber->onAlterRoutes($event); } diff --git a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php index 0cd0699..14e03cb 100644 --- a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php @@ -43,12 +43,12 @@ class ConfigFormBaseTraitTest extends UnitTestCase { * @covers ::config */ public function testConfigFactoryException() { - $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait'); $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait'); $config_method = new \ReflectionMethod($trait, 'config'); $config_method->setAccessible(TRUE); // There is no config factory available this should result in an exception. + $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait'); $config_method->invoke($trait, 'editable.config'); } @@ -56,13 +56,13 @@ class ConfigFormBaseTraitTest extends UnitTestCase { * @covers ::config */ public function testConfigFactoryExceptionInvalidProperty() { - $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait'); $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait'); $trait->configFactory = TRUE; $config_method = new \ReflectionMethod($trait, 'config'); $config_method->setAccessible(TRUE); // There is no config factory available this should result in an exception. + $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait'); $config_method->invoke($trait, 'editable.config'); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php index 0737ec6..ce62735 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php @@ -46,7 +46,6 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { * @covers ::buildResponse */ public function testBuildResponseNoTriggeringElement() { - $this->setExpectedException(HttpException::class); $this->renderer->expects($this->never()) ->method('renderResponse'); @@ -56,6 +55,7 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { $commands = []; $expected = []; + $this->setExpectedException(HttpException::class); $this->assertSame($expected, $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands)); } @@ -63,7 +63,6 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { * @covers ::buildResponse */ public function testBuildResponseNoCallable() { - $this->setExpectedException(HttpException::class); $this->renderer->expects($this->never()) ->method('renderResponse'); @@ -75,6 +74,7 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { $commands = []; $expected = []; + $this->setExpectedException(HttpException::class); $this->assertSame($expected, $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands)); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index 4941268..e06e125 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -55,11 +55,11 @@ class FormBuilderTest extends FormTestBase { * Tests the getFormId() method with a string based form ID. */ public function testGetFormIdWithString() { - $this->setExpectedException(\InvalidArgumentException::class, 'The form argument foo is not a valid form.'); $form_arg = 'foo'; $clean_form_state = new FormState(); $form_state = new FormState(); + $this->setExpectedException(\InvalidArgumentException::class, 'The form argument foo is not a valid form.'); $form_id = $this->formBuilder->getFormId($form_arg, $form_state); $this->assertSame($form_arg, $form_id); @@ -219,10 +219,10 @@ class FormBuilderTest extends FormTestBase { * Tests the getForm() method with a string based form ID. */ public function testGetFormWithString() { - $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.'); $form_id = 'test_form_id'; $expected_form = $form_id(); + $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.'); $form = $this->formBuilder->getForm($form_id); $this->assertFormElement($expected_form, $form, 'test'); $this->assertSame('test-form-id', $form['#id']); @@ -261,10 +261,10 @@ class FormBuilderTest extends FormTestBase { * Tests the buildForm() method with a string based form ID. */ public function testBuildFormWithString() { - $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.'); $form_id = 'test_form_id'; $expected_form = $form_id(); + $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.'); $form = $this->formBuilder->getForm($form_id); $this->assertFormElement($expected_form, $form, 'test'); $this->assertArrayHasKey('#id', $form); @@ -544,7 +544,6 @@ class FormBuilderTest extends FormTestBase { * @covers ::buildForm */ public function testExceededFileSize() { - $this->setExpectedException(BrokenPostRequestException::class); $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]); $request_stack = new RequestStack(); $request_stack->push($request); @@ -559,6 +558,7 @@ class FormBuilderTest extends FormTestBase { $form_arg = $this->getMockForm('test_form_id'); $form_state = new FormState(); + $this->setExpectedException(BrokenPostRequestException::class); $this->formBuilder->buildForm($form_arg, $form_state); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php index 4f794a7..dd4c340 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php @@ -134,9 +134,9 @@ class FormStateTest extends UnitTestCase { * @covers ::setErrorByName */ public function testFormErrorsDuringSubmission() { - $this->setExpectedException(\LogicException::class, 'Form errors cannot be set after form validation has finished.'); $form_state = new FormState(); $form_state->setValidationComplete(); + $this->setExpectedException(\LogicException::class, 'Form errors cannot be set after form validation has finished.'); $form_state->setErrorByName('test', 'message'); } @@ -315,9 +315,9 @@ class FormStateTest extends UnitTestCase { * @covers ::setCached */ public function testSetCachedGet() { - $this->setExpectedException(\LogicException::class, 'Form state caching on GET requests is not allowed.'); $form_state = new FormState(); $form_state->setRequestMethod('GET'); + $this->setExpectedException(\LogicException::class, 'Form state caching on GET requests is not allowed.'); $form_state->setCached(); } diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index 2c1aeab..f22db96 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -206,12 +206,12 @@ class ContextualLinkManagerTest extends UnitTestCase { * @see \Drupal\Core\Menu\ContextualLinkManager::processDefinition() */ public function testProcessDefinitionWithoutRoute() { - $this->setExpectedException(PluginException::class); $definition = array( 'class' => '\Drupal\Core\Menu\ContextualLinkDefault', 'group' => 'example', 'id' => 'test_plugin', ); + $this->setExpectedException(PluginException::class); $this->contextualLinkManager->processDefinition($definition, 'test_plugin'); } @@ -221,12 +221,12 @@ class ContextualLinkManagerTest extends UnitTestCase { * @see \Drupal\Core\Menu\ContextualLinkManager::processDefinition() */ public function testProcessDefinitionWithoutGroup() { - $this->setExpectedException(PluginException::class); $definition = array( 'class' => '\Drupal\Core\Menu\ContextualLinkDefault', 'route_name' => 'example', 'id' => 'test_plugin', ); + $this->setExpectedException(PluginException::class); $this->contextualLinkManager->processDefinition($definition, 'test_plugin'); } diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php index fd520b4..67e99de 100644 --- a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php +++ b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php @@ -67,7 +67,6 @@ class ChainRequestPolicyTest extends UnitTestCase { * @covers ::check */ public function testChainExceptionOnInvalidReturnValue($return_value) { - $this->setExpectedException(\UnexpectedValueException::class); $rule = $this->getMock('Drupal\Core\PageCache\RequestPolicyInterface'); $rule->expects($this->once()) ->method('check') @@ -76,6 +75,7 @@ class ChainRequestPolicyTest extends UnitTestCase { $this->policy->addPolicy($rule); + $this->setExpectedException(\UnexpectedValueException::class); $this->policy->check($this->request); } diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php index 46482c5..902d646 100644 --- a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php +++ b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php @@ -76,7 +76,6 @@ class ChainResponsePolicyTest extends UnitTestCase { * @covers ::check */ public function testChainExceptionOnInvalidReturnValue($return_value) { - $this->setExpectedException(\UnexpectedValueException::class); $rule = $this->getMock('Drupal\Core\PageCache\ResponsePolicyInterface'); $rule->expects($this->once()) ->method('check') @@ -85,6 +84,7 @@ class ChainResponsePolicyTest extends UnitTestCase { $this->policy->addPolicy($rule); + $this->setExpectedException(\UnexpectedValueException::class); $actual_result = $this->policy->check($this->response, $this->request); $this->assertSame(NULL, $actual_result); } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php index dd7c7ca..67decbe 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php @@ -113,12 +113,12 @@ class EntityConverterTest extends UnitTestCase { * Tests the convert() method with an invalid entity type. */ public function testConvertWithInvalidEntityType() { - $this->setExpectedException(InvalidPluginDefinitionException::class); $this->entityManager->expects($this->once()) ->method('getStorage') ->with('invalid_id') ->willThrowException(new InvalidPluginDefinitionException('invalid_id')); + $this->setExpectedException(InvalidPluginDefinitionException::class); $this->entityConverter->convert('id', ['type' => 'entity:invalid_id'], 'foo', ['foo' => 'id']); } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php index 6c1c732..c7c3198 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php @@ -222,7 +222,6 @@ class ParamConverterManagerTest extends UnitTestCase { * @covers ::convert */ public function testConvertMissingParam() { - $this->setExpectedException(ParamNotConvertedException::class, 'The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")'); $route = new Route('/test/{id}'); $parameters = array( 'id' => array( @@ -244,6 +243,7 @@ class ParamConverterManagerTest extends UnitTestCase { ->will($this->returnValue(NULL)); $this->manager->addConverter($converter, 'test_convert'); + $this->setExpectedException(ParamNotConvertedException::class, 'The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")'); $this->manager->convert($defaults); } diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php index 2ea6457..586259d 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php @@ -50,7 +50,6 @@ class PathProcessorFrontTest extends UnitTestCase { * @covers ::processInbound */ public function testProcessInboundBadConfig() { - $this->setExpectedException(NotFoundHttpException::class); $config_factory = $this->prophesize(ConfigFactoryInterface::class); $config = $this->prophesize(ImmutableConfig::class); $config_factory->get('system.site') @@ -58,6 +57,7 @@ class PathProcessorFrontTest extends UnitTestCase { $config->get('page.front') ->willReturn(''); $processor = new PathProcessorFront($config_factory->reveal()); + $this->setExpectedException(NotFoundHttpException::class); $processor->processInbound('/', new Request()); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php index 4e99e01..e8bf11d 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php @@ -115,7 +115,6 @@ class ContextDefinitionTest extends UnitTestCase { public function testGetDataDefinitionInvalidType($is_multiple) { // Since we're trying to make getDataDefinition() throw an exception in // isolation, we use a data type which is not valid. - $this->setExpectedException(\Exception::class); $data_type = 'not_valid'; $mock_data_definition = $this->getMockBuilder('\Drupal\Core\TypedData\ListDataDefinitionInterface') ->getMockForAbstractClass(); @@ -155,6 +154,7 @@ class ContextDefinitionTest extends UnitTestCase { ->method('getDataType') ->willReturn($data_type); + $this->setExpectedException(\Exception::class); $this->assertSame( $mock_data_definition, $mock_context_definition->getDataDefinition() diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php index 81637e5..6fe21c1 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php @@ -68,8 +68,8 @@ class LazyContextRepositoryTest extends UnitTestCase { * @covers ::getRuntimeContexts */ public function testInvalidContextId() { - $this->setExpectedException(\InvalidArgumentException::class, 'You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); $lazy_context_repository = new LazyContextRepository($this->container, ['test_provider']); + $this->setExpectedException(\InvalidArgumentException::class, 'You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); $lazy_context_repository->getRuntimeContexts(['test_context', '@test_provider:test_context1']); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php index 58f9abd..f0e1e66 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php @@ -282,7 +282,6 @@ class ContextHandlerTest extends UnitTestCase { * @covers ::applyContextMapping */ public function testApplyContextMappingMissingRequired() { - $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.'); $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); $context->expects($this->never()) ->method('getContextValue'); @@ -310,6 +309,7 @@ class ContextHandlerTest extends UnitTestCase { $plugin->expects($this->never()) ->method('getContext'); + $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.'); $this->contextHandler->applyContextMapping($plugin, $contexts); } @@ -351,7 +351,6 @@ class ContextHandlerTest extends UnitTestCase { * @covers ::applyContextMapping */ public function testApplyContextMappingNoValueRequired() { - $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.'); $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); $context->expects($this->never()) ->method('getContextValue'); @@ -378,6 +377,7 @@ class ContextHandlerTest extends UnitTestCase { $plugin->expects($this->never()) ->method('setContextValue'); + $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.'); $this->contextHandler->applyContextMapping($plugin, $contexts); } @@ -463,7 +463,6 @@ class ContextHandlerTest extends UnitTestCase { * @covers ::applyContextMapping */ public function testApplyContextMappingConfigurableAssignedMiss() { - $this->setExpectedException(ContextException::class, 'Assigned contexts were not satisfied: miss'); $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); $context->expects($this->never()) ->method('getContextValue'); @@ -484,6 +483,7 @@ class ContextHandlerTest extends UnitTestCase { $plugin->expects($this->never()) ->method('setContextValue'); + $this->setExpectedException(ContextException::class, 'Assigned contexts were not satisfied: miss'); $this->contextHandler->applyContextMapping($plugin, $contexts, ['miss' => 'name']); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php index 8995229..852ea8a 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php @@ -46,8 +46,8 @@ class DefaultLazyPluginCollectionTest extends LazyPluginCollectionTestBase { * @covers ::get */ public function testGetNotExistingPlugin() { - $this->setExpectedException(PluginNotFoundException::class, "Plugin ID 'pear' was not found."); $this->setupPluginCollection(); + $this->setExpectedException(PluginNotFoundException::class, "Plugin ID 'pear' was not found."); $this->defaultPluginCollection->get('pear'); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 9771c98..0fa8d58 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -273,7 +273,6 @@ class DefaultPluginManagerTest extends UnitTestCase { * @covers ::createInstance */ public function testCreateInstanceWithInvalidInterfaces() { - $this->setExpectedException(PluginException::class, 'Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $module_handler->expects($this->any()) @@ -292,6 +291,7 @@ class DefaultPluginManagerTest extends UnitTestCase { $this->expectedDefinitions['banana']['provider'] = 'plugin_test'; $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); + $this->setExpectedException(PluginException::class, 'Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); $plugin_manager->createInstance('kale'); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php index 51bc71c..0483064 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php @@ -89,7 +89,6 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\ */ public function testNonExistentDerivativeFetcher() { - $this->setExpectedException(InvalidDeriverException::class, 'Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); $definitions = array(); // Do this with a class that doesn't exist. $definitions['non_existent_discovery'] = array( @@ -101,6 +100,7 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { ->will($this->returnValue($definitions)); $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); + $this->setExpectedException(InvalidDeriverException::class, 'Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); $discovery->getDefinitions(); } @@ -110,7 +110,6 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\ */ public function testInvalidDerivativeFetcher() { - $this->setExpectedException(InvalidDeriverException::class, 'Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.'); $definitions = array(); // Do this with a class that doesn't implement the interface. $definitions['invalid_discovery'] = array( @@ -122,6 +121,7 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { ->will($this->returnValue($definitions)); $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); + $this->setExpectedException(InvalidDeriverException::class, 'Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.'); $discovery->getDefinitions(); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php index 9f26087..193b5ec 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php @@ -121,11 +121,11 @@ class HookDiscoveryTest extends UnitTestCase { * @see \Drupal\Core\Plugin\Discovery::getDefinition() */ public function testGetDefinitionWithUnknownID() { - $this->setExpectedException(PluginNotFoundException::class); $this->moduleHandler->expects($this->once()) ->method('getImplementations') ->will($this->returnValue(array())); + $this->setExpectedException(PluginNotFoundException::class); $this->hookDiscovery->getDefinition('test_non_existant', TRUE); } diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php index 23ebac9..f92bdbd 100644 --- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php +++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php @@ -103,10 +103,10 @@ class ElementTest extends UnitTestCase { * Tests the children() method with an invalid key. */ public function testInvalidChildren() { - $this->setExpectedException(\PHPUnit_Framework_Error::class, '"foo" is an invalid render array key'); $element = array( 'foo' => 'bar', ); + $this->setExpectedException(\PHPUnit_Framework_Error::class, '"foo" is an invalid render array key'); Element::children($element); } diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php index 207a4cf..776b794 100644 --- a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php @@ -123,12 +123,12 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { */ public function testProcessPlaceholdersNoStrategies() { // Placeholders but no strategies defined. - $this->setExpectedException(\AssertionError::class, 'At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.'); $placeholders = [ 'assert-me' => ['#markup' => 'I-am-a-llama-that-will-lead-to-an-assertion-by-the-chained-placeholder-strategy.'], ]; $chained_placeholder_strategy = new ChainedPlaceholderStrategy(); + $this->setExpectedException(\AssertionError::class, 'At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.'); $chained_placeholder_strategy->processPlaceholders($placeholders); } @@ -137,7 +137,6 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { */ public function testProcessPlaceholdersWithRoguePlaceholderStrategy() { // Placeholders but no strategies defined. - $this->setExpectedException(\AssertionError::class, 'Processed placeholders must be a subset of all placeholders.'); $placeholders = [ 'assert-me' => ['#markup' => 'llama'], ]; @@ -153,6 +152,7 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { $chained_placeholder_strategy = new ChainedPlaceholderStrategy(); $chained_placeholder_strategy->addPlaceholderStrategy($rogue_strategy); + $this->setExpectedException(\AssertionError::class, 'Processed placeholders must be a subset of all placeholders.'); $chained_placeholder_strategy->processPlaceholders($placeholders); } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php index e32d530..10080f4 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php @@ -572,7 +572,6 @@ class RendererBubblingTest extends RendererTestBase { * Tests that an element's cache keys cannot be changed during its rendering. */ public function testOverWriteCacheKeys() { - $this->setExpectedException(\LogicException::class, 'Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.'); $this->setUpRequest(); $this->setupMemoryCache(); @@ -583,6 +582,7 @@ class RendererBubblingTest extends RendererTestBase { ], '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingCacheOverwritePrerender'], ]; + $this->setExpectedException(\LogicException::class, 'Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.'); $this->renderer->renderRoot($data); } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php index 15cf595..a4f9694 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php @@ -848,10 +848,10 @@ class RendererPlaceholdersTest extends RendererTestBase { * @covers ::doRender */ public function testInvalidLazyBuilder() { - $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value.'); $element = []; $element['#lazy_builder'] = '\Drupal\Tests\Core\Render\PlaceholdersTest::callback'; + $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value.'); $this->renderer->renderRoot($element); } @@ -860,10 +860,10 @@ class RendererPlaceholdersTest extends RendererTestBase { * @covers ::doRender */ public function testInvalidLazyBuilderArguments() { - $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback.'); $element = []; $element['#lazy_builder'] = ['\Drupal\Tests\Core\Render\PlaceholdersTest::callback', 'arg1', 'arg2']; + $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback.'); $this->renderer->renderRoot($element); } @@ -893,7 +893,6 @@ class RendererPlaceholdersTest extends RendererTestBase { * @covers ::doRender */ public function testNonScalarLazybuilderCallbackContext() { - $this->setExpectedException(\DomainException::class, "A #lazy_builder callback's context may only contain scalar values or NULL."); $element = []; $element['#lazy_builder'] = ['\Drupal\Tests\Core\Render\PlaceholdersTest::callback', [ 'string' => 'foo', @@ -905,6 +904,7 @@ class RendererPlaceholdersTest extends RendererTestBase { 'array' => ['hi!'], ]]; + $this->setExpectedException(\DomainException::class, "A #lazy_builder callback's context may only contain scalar values or NULL."); $this->renderer->renderRoot($element); } @@ -913,12 +913,12 @@ class RendererPlaceholdersTest extends RendererTestBase { * @covers ::doRender */ public function testChildrenPlusBuilder() { - $this->setExpectedException(\DomainException::class, 'When a #lazy_builder callback is specified, no children can exist; all children must be generated by the #lazy_builder callback. You specified the following children: child_a, child_b.'); $element = []; $element['#lazy_builder'] = ['Drupal\Tests\Core\Render\RecursivePlaceholdersTest::callback', []]; $element['child_a']['#markup'] = 'Oh hai!'; $element['child_b']['#markup'] = 'kthxbai'; + $this->setExpectedException(\DomainException::class, 'When a #lazy_builder callback is specified, no children can exist; all children must be generated by the #lazy_builder callback. You specified the following children: child_a, child_b.'); $this->renderer->renderRoot($element); } @@ -927,12 +927,12 @@ class RendererPlaceholdersTest extends RendererTestBase { * @covers ::doRender */ public function testPropertiesPlusBuilder() { - $this->setExpectedException(\DomainException::class, 'When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #llama, #piglet.'); $element = []; $element['#lazy_builder'] = ['Drupal\Tests\Core\Render\RecursivePlaceholdersTest::callback', []]; $element['#llama'] = '#awesome'; $element['#piglet'] = '#cute'; + $this->setExpectedException(\DomainException::class, 'When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #llama, #piglet.'); $this->renderer->renderRoot($element); } @@ -941,10 +941,10 @@ class RendererPlaceholdersTest extends RendererTestBase { * @covers ::doRender */ public function testCreatePlaceholderPropertyWithoutLazyBuilder() { - $this->setExpectedException(\LogicException::class, 'When #create_placeholder is set, a #lazy_builder callback must be present as well.'); $element = []; $element['#create_placeholder'] = TRUE; + $this->setExpectedException(\LogicException::class, 'When #create_placeholder is set, a #lazy_builder callback must be present as well.'); $this->renderer->renderRoot($element); } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php index 12d05a2..96b89b9 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php @@ -33,14 +33,14 @@ class RendererRecursionTest extends RendererTestBase { * @covers ::doRender */ public function testRenderRecursionWithNestedRenderRoot() { - $this->setExpectedException(\LogicException::class); list($complex_child_markup, $parent_markup, $complex_child_template) = $this->setUpRenderRecursionComplexElements(); $renderer = $this->renderer; $this->setUpRequest(); $complex_child = $complex_child_template; $callable = function () use ($renderer, $complex_child) { - $renderer->renderRoot($complex_child); + $this->setExpectedException(\LogicException::class); + $renderer->renderRoot($complex_child); }; $page = [ diff --git a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php index 419bde8..c5cafe6 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php @@ -89,7 +89,6 @@ class AccessAwareRouterTest extends UnitTestCase { * Tests the matchRequest() function for access denied. */ public function testMatchRequestDenied() { - $this->setExpectedException(AccessDeniedHttpException::class); $this->setupRouter(); $request = new Request(); $access_result = AccessResult::forbidden(); @@ -97,6 +96,7 @@ class AccessAwareRouterTest extends UnitTestCase { ->method('checkRequest') ->with($request) ->willReturn($access_result); + $this->setExpectedException(AccessDeniedHttpException::class); $parameters = $this->router->matchRequest($request); $expected = [ AccessAwareRouterInterface::ACCESS_RESULT => $access_result, diff --git a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php index 83a779f..1aa56cf 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php @@ -64,7 +64,6 @@ class RequestFormatRouteFilterTest extends UnitTestCase { * @covers ::filter */ public function testNoRouteFound() { - $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified format xml.'); $collection = new RouteCollection(); $route_with_format = $route = new Route('/test'); $route_with_format->setRequirement('_format', 'json'); @@ -74,6 +73,7 @@ class RequestFormatRouteFilterTest extends UnitTestCase { $request = Request::create('test?_format=xml', 'GET'); $request->setRequestFormat('xml'); $route_filter = new RequestFormatRouteFilter(); + $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified format xml.'); $route_filter->filter($collection, $request); } diff --git a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php index 7650d41..ded951b 100644 --- a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php @@ -31,7 +31,6 @@ class TrustedRedirectResponseTest extends UnitTestCase { * @covers ::setTargetUrl */ public function testSetTargetUrlWithUntrustedUrl() { - $this->setExpectedException(\InvalidArgumentException::class); $request_context = new RequestContext(); $request_context->setCompleteBaseUrl('https://www.drupal.org'); $container = new ContainerBuilder(); @@ -40,6 +39,7 @@ class TrustedRedirectResponseTest extends UnitTestCase { $redirect_response = new TrustedRedirectResponse('/example'); + $this->setExpectedException(\InvalidArgumentException::class); $redirect_response->setTargetUrl('http://evil-url.com/example'); } diff --git a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php index c2d5f63..ca0c6ba 100644 --- a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php +++ b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php @@ -83,8 +83,8 @@ class SettingsTest extends UnitTestCase { */ public function testGetHashSaltEmpty(array $config) { // Re-create settings with no 'hash_salt' key. - $this->setExpectedException(\RuntimeException::class); $settings = new Settings($config); + $this->setExpectedException(\RuntimeException::class); $settings->getHashSalt(); } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php index 23002c3..974b374 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php @@ -85,8 +85,8 @@ class TranslatableMarkupTest extends UnitTestCase { * @covers ::__construct */ public function testIsStringAssertion() { - $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); $translation = $this->getStringTranslationStub(); + $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); new TranslatableMarkup(new TranslatableMarkup('foo', [], [], $translation)); } @@ -94,8 +94,8 @@ class TranslatableMarkupTest extends UnitTestCase { * @covers ::__construct */ public function testIsStringAssertionWithFormattableMarkup() { - $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); $translation = $this->getStringTranslationStub(); + $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); $formattable_string = new FormattableMarkup('@bar', ['@bar' => 'foo']); new TranslatableMarkup($formattable_string); } diff --git a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php index 4509ca1..e599463 100644 --- a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php +++ b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php @@ -47,8 +47,8 @@ class TwigSandboxTest extends UnitTestCase { * @dataProvider getTwigEntityDangerousMethods */ public function testEntityDangerousMethods($template) { - $this->setExpectedException(\Twig_Sandbox_SecurityError::class); $entity = $this->getMock('Drupal\Core\Entity\EntityInterface'); + $this->setExpectedException(\Twig_Sandbox_SecurityError::class); $this->twig->render($template, ['entity' => $entity]); } diff --git a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php index 93dba9d..08b8117 100644 --- a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php @@ -228,7 +228,6 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * @covers ::validateProperty */ public function testValidatePropertyWithCustomGroup() { - $this->setExpectedException(\LogicException::class); $tree = [ 'value' => [], 'properties' => [ @@ -236,6 +235,7 @@ class RecursiveContextualValidatorTest extends UnitTestCase { ], ]; $typed_data = $this->setupTypedData($tree, 'test_name'); + $this->setExpectedException(\LogicException::class); $this->recursiveValidator->validateProperty($typed_data, 'key1', 'test group'); } diff --git a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php index d786751..7afd0bb 100644 --- a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php +++ b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php @@ -135,7 +135,6 @@ class UnroutedUrlTest extends UnitTestCase { * @covers ::createFromRequest */ public function testCreateFromRequest() { - $this->setExpectedException(ResourceNotFoundException::class); $request = Request::create('/test-path'); $this->router->expects($this->once()) @@ -143,6 +142,7 @@ class UnroutedUrlTest extends UnitTestCase { ->with($request) ->will($this->throwException(new ResourceNotFoundException())); + $this->setExpectedException(ResourceNotFoundException::class); $this->assertNull(Url::createFromRequest($request)); } @@ -181,8 +181,8 @@ class UnroutedUrlTest extends UnitTestCase { * @covers ::getRouteName */ public function testGetRouteName($uri) { - $this->setExpectedException(\UnexpectedValueException::class); $url = Url::fromUri($uri); + $this->setExpectedException(\UnexpectedValueException::class); $url->getRouteName(); } @@ -195,8 +195,8 @@ class UnroutedUrlTest extends UnitTestCase { * @covers ::getRouteParameters */ public function testGetRouteParameters($uri) { - $this->setExpectedException(\UnexpectedValueException::class); $url = Url::fromUri($uri); + $this->setExpectedException(\UnexpectedValueException::class); $url->getRouteParameters(); } @@ -209,8 +209,8 @@ class UnroutedUrlTest extends UnitTestCase { * @covers ::getInternalPath */ public function testGetInternalPath($uri) { - $this->setExpectedException(\Exception::class); $url = Url::fromUri($uri); + $this->setExpectedException(\Exception::class); $this->assertNull($url->getInternalPath()); } diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index a235229..fb98937 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -282,7 +282,6 @@ class UrlTest extends UnitTestCase { * @covers ::createFromRequest */ public function testUrlFromRequestInvalid() { - $this->setExpectedException(ResourceNotFoundException::class); $request = Request::create('/test-path'); $this->router->expects($this->once()) @@ -290,6 +289,7 @@ class UrlTest extends UnitTestCase { ->with($request) ->will($this->throwException(new ResourceNotFoundException())); + $this->setExpectedException(ResourceNotFoundException::class); $this->assertNull(Url::createFromRequest($request)); } @@ -418,8 +418,8 @@ class UrlTest extends UnitTestCase { * @covers ::getRouteName */ public function testGetRouteNameWithExternalUrl() { - $this->setExpectedException(\UnexpectedValueException::class); $url = Url::fromUri('http://example.com'); + $this->setExpectedException(\UnexpectedValueException::class); $url->getRouteName(); } @@ -445,8 +445,8 @@ class UrlTest extends UnitTestCase { * @covers ::getRouteParameters */ public function testGetRouteParametersWithExternalUrl() { - $this->setExpectedException(\UnexpectedValueException::class); $url = Url::fromUri('http://example.com'); + $this->setExpectedException(\UnexpectedValueException::class); $url->getRouteParameters(); } @@ -606,12 +606,12 @@ class UrlTest extends UnitTestCase { */ public function testInvalidEntityUriParameter() { // Make the mocked URL generator behave like the actual one. - $this->setExpectedException(InvalidParameterException::class); $this->urlGenerator->expects($this->once()) ->method('generateFromRoute') ->with('entity.test_entity.canonical', ['test_entity' => '1/blah']) ->willThrowException(new InvalidParameterException('Parameter "test_entity" for route "/test_entity/{test_entity}" must match "[^/]++" ("1/blah" given) to generate a corresponding URL..')); + $this->setExpectedException(InvalidParameterException::class); Url::fromUri('entity:test_entity/1/blah')->toString(); }