reverted: --- b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php +++ a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php @@ -28,12 +28,13 @@ * @covers ::processAttachments * * @dataProvider nonHtmlResponseProvider + * + * @expectedException \AssertionError */ public function testNonHtmlResponse($response_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); } reverted: --- b/core/modules/contact/tests/src/Unit/MailHandlerTest.php +++ a/core/modules/contact/tests/src/Unit/MailHandlerTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\contact\Unit; use Drupal\contact\MailHandler; -use Drupal\contact\MailHandlerException; use Drupal\contact\MessageInterface; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; @@ -95,6 +94,9 @@ /** * Tests the children() method with an invalid key. * + * @expectedException \Drupal\contact\MailHandlerException + * @expectedExceptionMessage Unable to determine message recipient + * * @covers ::sendMailMessages */ public function testInvalidRecipient() { @@ -119,7 +121,6 @@ $sender->expects($this->once()) ->method('isAnonymous') ->willReturn(FALSE); - $this->setExpectedException(MailHandlerException::class, 'Unable to determine message recipient'); $this->contactMailHandler->sendMailMessages($message, $sender); } reverted: --- b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php +++ a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @@ -160,6 +160,9 @@ /** * Test that invalid bundles are handled. + * + * @expectedException \LogicException + * @expectedExceptionMessage Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists. */ public function testCalculateDependenciesIncorrectBundle() { $storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface'); @@ -206,7 +209,6 @@ '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(); } reverted: --- b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php +++ a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\hal\Unit; use Drupal\hal\Normalizer\FieldItemNormalizer; -use Symfony\Component\Serializer\Exception\InvalidArgumentException; /** * @coversDefaultClass \Drupal\hal\Normalizer\FieldItemNormalizer @@ -18,12 +17,12 @@ * Context for FieldItemNormalizer::denormalize(). * * @dataProvider providerNormalizerDenormalizeExceptions + * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testFieldItemNormalizerDenormalizeExceptions($context) { $field_item_normalizer = new FieldItemNormalizer(); $data = []; $class = []; - $this->setExpectedException(InvalidArgumentException::class); $field_item_normalizer->denormalize($data, $class, NULL, $context); } reverted: --- b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php +++ a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\hal\Unit; use Drupal\hal\Normalizer\FieldNormalizer; -use Symfony\Component\Serializer\Exception\InvalidArgumentException; /** * @coversDefaultClass \Drupal\hal\Normalizer\FieldNormalizer @@ -18,12 +17,12 @@ * Context for FieldNormalizer::denormalize(). * * @dataProvider providerNormalizerDenormalizeExceptions + * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testFieldNormalizerDenormalizeExceptions($context) { $field_item_normalizer = new FieldNormalizer(); $data = []; $class = []; - $this->setExpectedException(InvalidArgumentException::class); $field_item_normalizer->denormalize($data, $class, NULL, $context); } reverted: --- b/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php +++ a/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php @@ -4,7 +4,6 @@ use Drupal\language\Plugin\migrate\process\LanguageNegotiation; use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; -use Drupal\migrate\MigrateException; /** * @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageNegotiation @@ -76,10 +75,12 @@ /** * Tests string input. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage The input should be an array */ public function testStringInput() { $this->plugin = new LanguageNegotiation([], 'map', []); - $this->setExpectedException(MigrateException::class, 'The input should be an array'); $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); } reverted: --- b/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php +++ a/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php @@ -4,7 +4,6 @@ use Drupal\language\Plugin\migrate\process\LanguageTypes; use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; -use Drupal\migrate\MigrateException; /** * @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageTypes @@ -50,10 +49,12 @@ /** * Tests string input. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage The input should be an array */ public function testStringInput() { $this->plugin = new LanguageTypes([], 'map', []); - $this->setExpectedException(MigrateException::class, 'The input should be an array'); $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); } reverted: --- b/core/modules/locale/tests/src/Unit/StringBaseTest.php +++ a/core/modules/locale/tests/src/Unit/StringBaseTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\locale\Unit; use Drupal\locale\SourceString; -use Drupal\locale\StringStorageException; use Drupal\Tests\UnitTestCase; /** @@ -14,20 +13,22 @@ /** * @covers ::save + * @expectedException \Drupal\locale\StringStorageException + * @expectedExceptionMessage The string cannot be saved because its not bound to a storage: test */ public function testSaveWithoutStorage() { $string = new SourceString(['source' => 'test']); - $this->setExpectedException(StringStorageException::class, 'The string cannot be saved because its not bound to a storage: test'); $string->save(); } /** * @covers ::delete + * @expectedException \Drupal\locale\StringStorageException + * @expectedExceptionMessage The string cannot be deleted because its not bound to a storage: test */ public function testDeleteWithoutStorage() { $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(); } reverted: --- b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php +++ a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php @@ -139,10 +139,13 @@ /** * Test that non-existent files throw an exception. + * + * @expectedException \Drupal\migrate\MigrateException + * + * @expectedExceptionMessage File '/non/existent/file' does not exist */ public function testNonExistentSourceFile() { $source = '/non/existent/file'; - $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist"); $this->doTransform($source, 'public://wontmatter.jpg'); } reverted: --- b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php +++ a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php @@ -12,7 +12,6 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; -use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Plugin\migrate\source\SourcePluginBase; @@ -150,10 +149,10 @@ /** * @covers ::__construct + * @expectedException \Drupal\migrate\MigrateException */ public function testHighwaterTrackChangesIncompatible() { $source_config = ['track_changes' => TRUE, 'high_water_property' => ['name' => 'something']]; - $this->setExpectedException(MigrateException::class); $this->getSource($source_config); } reverted: --- b/core/modules/migrate/tests/src/Unit/MigrationTest.php +++ a/core/modules/migrate/tests/src/Unit/MigrationTest.php @@ -27,6 +27,9 @@ * Tests checking requirements for source plugins. * * @covers ::checkRequirements + * + * @expectedException \Drupal\migrate\Exception\RequirementsException + * @expectedExceptionMessage Missing source requirement */ public function testRequirementsForSourcePlugin() { $migration = new TestMigration(); @@ -40,7 +43,6 @@ $migration->setSourcePlugin($source_plugin); $migration->setDestinationPlugin($destination_plugin); - $this->setExpectedException(RequirementsException::class, 'Missing source requirement'); $migration->checkRequirements(); } @@ -48,6 +50,9 @@ * Tests checking requirements for destination plugins. * * @covers ::checkRequirements + * + * @expectedException \Drupal\migrate\Exception\RequirementsException + * @expectedExceptionMessage Missing destination requirement */ public function testRequirementsForDestinationPlugin() { $migration = new TestMigration(); @@ -61,7 +66,6 @@ $migration->setSourcePlugin($source_plugin); $migration->setDestinationPlugin($destination_plugin); - $this->setExpectedException(RequirementsException::class, 'Missing destination requirement'); $migration->checkRequirements(); } @@ -69,6 +73,9 @@ * Tests checking requirements for destination plugins. * * @covers ::checkRequirements + * + * @expectedException \Drupal\migrate\Exception\RequirementsException + * @expectedExceptionMessage Missing migrations test_a, test_c */ public function testRequirementsForMigrations() { $migration = new TestMigration(); @@ -105,7 +112,6 @@ ->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(); } reverted: --- b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php +++ a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php @@ -13,7 +13,6 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\FieldTypePluginManagerInterface; -use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; use Drupal\migrate\Plugin\MigrateIdMapInterface; @@ -85,6 +84,8 @@ * Test row skipping when we can't get an entity to save. * * @covers ::import + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage Unable to get entity */ public function testImportEntityLoadFailure() { $bundles = []; @@ -95,12 +96,14 @@ $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal()); $destination->setEntity(FALSE); - $this->setExpectedException(MigrateException::class, 'Unable to get entity'); $destination->import(new Row()); } /** * Test that translation destination fails for untranslatable entities. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage This entity type does not support translation */ public function testUntranslatable() { // An entity type without a language. @@ -122,7 +125,6 @@ $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() ); - $this->setExpectedException(MigrateException::class, 'This entity type does not support translation'); $destination->getIds(); } reverted: --- b/core/modules/migrate/tests/src/Unit/RowTest.php +++ a/core/modules/migrate/tests/src/Unit/RowTest.php @@ -73,17 +73,20 @@ /** * Tests object creation: invalid values. + * + * @expectedException \Exception */ public function testRowWithInvalidData() { $invalid_values = [ 'title' => 'node X', ]; - $this->setExpectedException(\Exception::class); $row = new Row($invalid_values, $this->testSourceIds); } /** * Tests source immutability after freeze. + * + * @expectedException \Exception */ public function testSourceFreeze() { $row = new Row($this->testValues, $this->testSourceIds); @@ -93,17 +96,18 @@ $row->rehash(); $this->assertSame($this->testHashMod, $row->getHash(), 'Hash changed correctly.'); $row->freezeSource(); - $this->setExpectedException(\Exception::class); $row->setSourceProperty('title', 'new title'); } /** * Tests setting on a frozen row. + * + * @expectedException \Exception + * @expectedExceptionMessage The source is frozen and can't be changed any more */ public function testSetFrozenRow() { $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'); } reverted: --- b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php +++ a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\migrate\Unit\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\Concat; /** @@ -35,9 +34,10 @@ /** * Test concat fails properly on non-arrays. + * + * @expectedException \Drupal\migrate\MigrateException */ public function testConcatWithNonArray() { - $this->setExpectedException(MigrateException::class); $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); } reverted: --- b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php +++ a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\migrate\Unit\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\Explode; use Drupal\migrate\Plugin\migrate\process\Concat; @@ -54,18 +53,24 @@ /** * Test explode fails properly on non-strings. + * + * @expectedException \Drupal\migrate\MigrateException + * + * @expectedExceptionMessage is not a string */ public function testExplodeWithNonString() { - $this->setExpectedException(MigrateException::class, 'is not a string'); $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } /** * Test explode fails with empty delimiter. + * + * @expectedException \Drupal\migrate\MigrateException + * + * @expectedExceptionMessage delimiter is empty */ public function testExplodeWithEmptyDelimiter() { $plugin = new Explode(['delimiter' => ''], 'map', []); - $this->setExpectedException(MigrateException::class, 'delimiter is empty'); $plugin->transform('foo,bar', $this->migrateExecutable, $this->row, 'destinationproperty'); } reverted: --- b/core/modules/migrate/tests/src/Unit/process/ExtractTest.php +++ a/core/modules/migrate/tests/src/Unit/process/ExtractTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\migrate\Unit\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\Extract; /** @@ -30,17 +29,21 @@ /** * Tests invalid input. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage Input should be an array. */ public function testExtractFromString() { - $this->setExpectedException(MigrateException::class, 'Input should be an array.'); $this->plugin->transform('bar', $this->migrateExecutable, $this->row, 'destinationproperty'); } /** * Tests unsuccessful extraction. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage Array index missing, extraction failed. */ public function testExtractFail() { - $this->setExpectedException(MigrateException::class, 'Array index missing, extraction failed.'); $this->plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } reverted: --- b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php +++ a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\migrate\Unit\process; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\migrate\process\Migration; use Drupal\migrate\Plugin\MigrateDestinationInterface; @@ -90,6 +89,8 @@ /** * Tests that processing is skipped when the input value is empty. + * + * @expectedException \Drupal\migrate\MigrateSkipProcessException */ public function testSkipOnEmpty() { $migration_plugin = $this->prophesize(MigrationInterface::class); @@ -101,7 +102,6 @@ ]; $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'); } reverted: --- b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php +++ a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php @@ -1,8 +1,6 @@ setExpectedException(MigrateSkipProcessException::class); (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -35,10 +33,10 @@ /** * @covers ::row + * @expectedException \Drupal\migrate\MigrateSkipRowException */ public function testRowSkipsOnEmpty() { $configuration['method'] = 'row'; - $this->setExpectedException(MigrateSkipRowException::class); (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } reverted: --- b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php +++ a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php @@ -2,8 +2,6 @@ namespace Drupal\Tests\migrate\Unit\process; -use Drupal\migrate\MigrateException; -use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Plugin\migrate\process\StaticMap; /** @@ -40,17 +38,19 @@ /** * Tests when the source is empty. + * + * @expectedException \Drupal\migrate\MigrateException */ public function testMapwithEmptySource() { - $this->setExpectedException(MigrateException::class); $this->plugin->transform([], $this->migrateExecutable, $this->row, 'destinationproperty'); } /** * Tests when the source is invalid. + * + * @expectedException \Drupal\migrate\MigrateSkipRowException */ public function testMapwithInvalidSource() { - $this->setExpectedException(MigrateSkipRowException::class); $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -78,13 +78,15 @@ /** * Tests when the source is invalid and bypass is enabled. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage Setting both default_value and bypass is invalid. */ public function testMapWithInvalidSourceAndBypass() { $configuration['map']['foo']['bar'] = 'baz'; $configuration['default_value'] = 'test'; $configuration['bypass'] = TRUE; $this->plugin = new StaticMap($configuration, 'map', []); - $this->setExpectedException(MigrateException::class, 'Setting both default_value and bypass is invalid.'); $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty'); } reverted: --- b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php +++ a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\migrate\Unit\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\Substr; /** @@ -56,31 +55,37 @@ /** * Tests invalid input type. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage The input value must be a string. */ public function testSubstrFail() { $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'); } /** * Tests that the start parameter is an integer. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage The start position configuration value should be an integer. Omit this key to capture from the beginning of the string. */ public function testStartIsString() { $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'); } /** * Tests that the length parameter is an integer. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string. */ public function testLengthIsString() { $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'); } reverted: --- b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php +++ a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php @@ -6,7 +6,6 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\serialization\Normalizer\EntityNormalizer; use Drupal\Tests\UnitTestCase; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** * @coversDefaultClass \Drupal\serialization\Normalizer\EntityNormalizer @@ -85,9 +84,10 @@ * Tests the denormalize() method with no entity type provided in context. * * @covers ::denormalize + * + * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException */ public function testDenormalizeWithNoEntityType() { - $this->setExpectedException(UnexpectedValueException::class); $this->entityNormalizer->denormalize([], 'Drupal\Core\Entity\ContentEntityBase'); } @@ -215,6 +215,8 @@ /** * Tests the denormalize method with a bundle property. * + * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException + * * @covers ::denormalize */ public function testDenormalizeWithInvalidBundle() { @@ -286,8 +288,7 @@ ->with('test_bundle') ->will($this->returnValue($entity_type_storage)); + $this->assertNotNull($this->entityNormalizer->denormalize($test_data, 'Drupal\Core\Entity\ContentEntityBase', NULL, ['entity_type' => 'test'])); - $this->setExpectedException(UnexpectedValueException::class); - $this->entityNormalizer->denormalize($test_data, 'Drupal\Core\Entity\ContentEntityBase', NULL, ['entity_type' => 'test']); } /** reverted: --- b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php +++ a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php @@ -10,7 +10,6 @@ use Composer\Autoload\ClassLoader; use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\simpletest\Exception\MissingGroupException; use Drupal\simpletest\TestDiscovery; use Drupal\Tests\UnitTestCase; use org\bovigo\vfs\vfsStream; @@ -236,6 +235,8 @@ /** * @covers ::getTestInfo + * @expectedException \Drupal\simpletest\Exception\MissingGroupException + * @expectedExceptionMessage Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest */ public function testTestInfoParserMissingGroup() { $classname = 'Drupal\KernelTests\field\BulkDeleteTest'; @@ -244,7 +245,6 @@ * Bulk delete storages and fields, and clean up afterwards. */ EOT; - $this->setExpectedException(MissingGroupException::class, 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest'); TestDiscovery::getTestInfo($classname, $doc_comment); } reverted: --- b/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php +++ a/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php @@ -6,7 +6,6 @@ use Drupal\Tests\Core\Routing\RoutingFixtures; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; /** * Confirm that the mime types partial matcher is functioning properly. @@ -87,6 +86,9 @@ /** * Confirms that the AcceptHeaderMatcher throws an exception for no-route. + * + * @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException + * @expectedExceptionMessage No route found for the specified formats application/json text/xml. */ public function testNoRouteFound() { // Remove the sample routes that would match any method. @@ -101,7 +103,6 @@ $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.'); } reverted: --- b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php +++ a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php @@ -8,7 +8,6 @@ namespace Drupal\Tests\system\Kernel\Scripts; use Drupal\Core\Command\DbCommandBase; -use Drupal\Core\Database\ConnectionNotDefinedException; use Drupal\Core\Database\Database; use Drupal\KernelTests\KernelTestBase; use Symfony\Component\Console\Input\InputInterface; @@ -43,6 +42,8 @@ /** * Invalid database names will throw a useful exception. + * + * @expectedException \Drupal\Core\Database\ConnectionNotDefinedException */ public function testSpecifyDatabaseDoesNotExist() { $command = new DbCommandBaseTester(); @@ -50,7 +51,6 @@ $command_tester->execute([ '--database' => 'dne' ]); - $this->setExpectedException(ConnectionNotDefinedException::class); $command->getDatabaseConnection($command_tester->getInput()); } reverted: --- b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php +++ a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php @@ -4,7 +4,6 @@ use Drupal\Tests\UnitTestCase; use Drupal\user\PrivateTempStore; -use Drupal\user\TempStoreException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -122,6 +121,7 @@ * Tests the set() method with no lock available. * * @covers ::set + * @expectedException \Drupal\user\TempStoreException */ public function testSetWithNoLockAvailable() { $this->lock->expects($this->at(0)) @@ -139,7 +139,6 @@ $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); $this->tempStore->set('test', 'value'); } @@ -221,6 +220,7 @@ * Tests the delete() method with no lock available. * * @covers ::delete + * @expectedException \Drupal\user\TempStoreException */ public function testDeleteWithNoLockAvailable() { $this->keyValue->expects($this->once()) @@ -242,7 +242,6 @@ $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); $this->tempStore->delete('test'); } reverted: --- b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php +++ a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php @@ -4,7 +4,6 @@ use Drupal\Tests\UnitTestCase; use Drupal\user\SharedTempStore; -use Drupal\user\TempStoreException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -133,6 +132,7 @@ * Tests the set() method with no lock available. * * @covers ::set + * @expectedException \Drupal\user\TempStoreException */ public function testSetWithNoLockAvailable() { $this->lock->expects($this->at(0)) @@ -150,7 +150,6 @@ $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); $this->tempStore->set('test', 'value'); } @@ -297,6 +296,7 @@ * Tests the delete() method with no lock available. * * @covers ::delete + * @expectedException \Drupal\user\TempStoreException */ public function testDeleteWithNoLockAvailable() { $this->lock->expects($this->at(0)) @@ -314,7 +314,6 @@ $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); $this->tempStore->delete('test'); } reverted: --- b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php +++ a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php @@ -9,8 +9,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * @coversDefaultClass \Drupal\views\Controller\ViewAjaxController @@ -115,15 +113,18 @@ /** * Tests missing view_name and view_display_id + * + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testMissingViewName() { $request = new Request(); - $this->setExpectedException(NotFoundHttpException::class); $this->viewAjaxController->ajaxView($request); } /** * Tests with view_name and view_display_id but not existing view. + * + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testMissingView() { $request = new Request(); @@ -135,12 +136,13 @@ ->with('test_view') ->will($this->returnValue(FALSE)); - $this->setExpectedException(NotFoundHttpException::class); $this->viewAjaxController->ajaxView($request); } /** * Tests a view without having access to it. + * + * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function testAccessDeniedView() { $request = new Request(); @@ -168,7 +170,6 @@ ->with($view) ->will($this->returnValue($executable)); - $this->setExpectedException(AccessDeniedHttpException::class); $this->viewAjaxController->ajaxView($request); } reverted: --- b/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php +++ a/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php @@ -30,9 +30,9 @@ /** * @covers ::buildBasicRenderable + * @expectedException \BadFunctionCallException */ public function testBuildBasicRenderableWithMissingRoute() { - $this->setExpectedException(\BadFunctionCallException::class); Page::buildBasicRenderable('test_view', 'page_1', []); } reverted: --- b/core/modules/views/tests/src/Unit/ViewExecutableTest.php +++ a/core/modules/views/tests/src/Unit/ViewExecutableTest.php @@ -182,6 +182,8 @@ } /** + * @expectedException \InvalidArgumentException + * * @covers ::getUrl */ public function testGetUrlWithoutRouterDisplay() { @@ -191,7 +193,6 @@ ->willReturn($this->displayHandler); $this->executable->display_handler = $this->displayHandler; - $this->setExpectedException(\InvalidArgumentException::class); $this->executable->getUrl(); } reverted: --- b/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php +++ a/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php @@ -4,7 +4,6 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\workflows\Entity\Workflow; -use Drupal\workflows\Exception\RequiredStateMissingException; /** * Tests Workflow type's required states and configuration initialization. @@ -43,6 +42,8 @@ /** * @covers \Drupal\workflows\Entity\Workflow::preSave + * @expectedException \Drupal\workflows\Exception\RequiredStateMissingException + * @expectedExceptionMessage Required State Type Test' requires states with the ID 'fresh' in workflow 'test' */ public function testDeleteRequiredStateAPI() { $workflow = new Workflow([ @@ -52,19 +53,19 @@ $workflow = $workflow->getTypePlugin()->initializeWorkflow($workflow); $workflow->save(); // Ensure that required states can't be deleted. - $this->setExpectedException(RequiredStateMissingException::class, "Required State Type Test' requires states with the ID 'fresh' in workflow 'test'"); $workflow->deleteState('fresh')->save(); } /** * @covers \Drupal\workflows\Entity\Workflow::preSave + * @expectedException \Drupal\workflows\Exception\RequiredStateMissingException + * @expectedExceptionMessage Required State Type Test' requires states with the ID 'fresh', 'rotten' in workflow 'test' */ public function testNoStatesRequiredStateAPI() { $workflow = new Workflow([ 'id' => 'test', 'type' => 'workflow_type_required_state_test', ], 'workflow'); - $this->setExpectedException(RequiredStateMissingException::class, "Required State Type Test' requires states with the ID 'fresh', 'rotten' in workflow 'test'"); $workflow->save(); } reverted: --- b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php +++ a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php @@ -107,10 +107,10 @@ /** * @dataProvider providerTestSafeMarkupUriWithException + * @expectedException \InvalidArgumentException */ public function testSafeMarkupUriWithExceptionUri($string, $uri) { // Should throw an \InvalidArgumentException, due to Uri::toString(). - $this->setExpectedException(\InvalidArgumentException::class); $args = self::getSafeMarkupUriArgs($uri); SafeMarkup::format($string, $args); reverted: --- b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php +++ a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php @@ -82,9 +82,10 @@ /** * Ensures invalid content is handled correctly. + * + * @expectedException \Exception */ public function testThemeEscapeAndRenderNotPrintable() { - $this->setExpectedException(\Exception::class); theme_render_and_autoescape(new NonPrintable()); } reverted: --- b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -10,11 +10,6 @@ use Drupal\Component\Utility\Crypt; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; -use Symfony\Component\DependencyInjection\Exception\LogicException; -use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; -use Symfony\Component\DependencyInjection\Exception\RuntimeException; -use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; -use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Prophecy\Argument; /** @@ -65,11 +60,12 @@ * Tests that passing a non-supported format throws an InvalidArgumentException. * * @covers ::__construct + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testConstruct() { $container_definition = $this->getMockContainerDefinition(); $container_definition['machine_format'] = !$this->machineFormat; - $this->setExpectedException(InvalidArgumentException::class); $container = new $this->containerClass($container_definition); } @@ -90,9 +86,10 @@ * @covers ::getParameter * @covers ::getParameterAlternatives * @covers ::getAlternatives + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ public function testGetParameterIfNotFound() { - $this->setExpectedException(ParameterNotFoundException::class); $this->container->getParameter('parameter_that_does_not_exist'); } @@ -100,9 +97,10 @@ * Tests that Container::getParameter() works properly for NULL parameters. * * @covers ::getParameter + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ public function testGetParameterIfNotFoundBecauseNull() { - $this->setExpectedException(ParameterNotFoundException::class); $this->container->getParameter(NULL); } @@ -133,10 +131,11 @@ * Tests that Container::setParameter() in a frozen case works properly. * * @covers ::setParameter + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException */ public function testSetParameterWithFrozenContainer() { $this->container = new $this->containerClass($this->containerDefinition); - $this->setExpectedException(LogicException::class); $this->container->setParameter('some_config', 'new_value'); } @@ -237,11 +236,11 @@ /** * Tests that Container::get() for circular dependencies works properly. + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException * @covers ::get * @covers ::createService */ public function testGetForCircularServices() { - $this->setExpectedException(ServiceCircularReferenceException::class); $this->container->get('circular_dependency'); } @@ -252,9 +251,10 @@ * @covers ::createService * @covers ::getAlternatives * @covers ::getServiceAlternatives + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantService() { - $this->setExpectedException(ServiceNotFoundException::class); $this->container->get('service_not_exists'); } @@ -296,6 +296,8 @@ * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetForParameterDependencyWithExceptionOnSecondCall() { $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); @@ -303,7 +305,6 @@ // Reset the service. $this->container->set('service_parameter_not_exists', NULL); - $this->setExpectedException(InvalidArgumentException::class); $this->container->get('service_parameter_not_exists'); } @@ -313,9 +314,10 @@ * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetForNonExistantParameterDependencyWithException() { - $this->setExpectedException(InvalidArgumentException::class); $this->container->get('service_parameter_not_exists'); } @@ -338,9 +340,10 @@ * @covers ::createService * @covers ::resolveServicesAndParameters * @covers ::getAlternatives + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantServiceDependencyWithException() { - $this->setExpectedException(ServiceNotFoundException::class); $this->container->get('service_dependency_not_exists'); } @@ -358,9 +361,10 @@ * Tests that Container::get() for NULL service works properly. * @covers ::get * @covers ::createService + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantNULLService() { - $this->setExpectedException(ServiceNotFoundException::class); $this->container->get(NULL); } @@ -383,10 +387,11 @@ * @covers ::get * @covers ::createService * @covers ::getAlternatives + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantServiceWithExceptionOnSecondCall() { $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.'); - $this->setExpectedException(ServiceNotFoundException::class); $this->container->get('service_not_exists'); } @@ -420,9 +425,10 @@ * * @covers ::get * @covers ::createService + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetForSyntheticServiceWithException() { - $this->setExpectedException(RuntimeException::class); $this->container->get('synthetic'); } @@ -459,9 +465,10 @@ * * @covers ::get * @covers ::createService + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetForWrongFactory() { - $this->setExpectedException(RuntimeException::class); $this->container->get('wrong_factory'); } @@ -497,9 +504,10 @@ * * @covers ::get * @covers ::createService + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetForConfiguratorWithException() { - $this->setExpectedException(InvalidArgumentException::class); $this->container->get('configurable_service_exception'); } @@ -595,9 +603,10 @@ * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testResolveServicesAndParametersForInvalidArgument() { - $this->setExpectedException(InvalidArgumentException::class); $this->container->get('invalid_argument_service'); } @@ -607,11 +616,12 @@ * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testResolveServicesAndParametersForInvalidArguments() { // In case the machine-optimized format is not used, we need to simulate the // test failure. - $this->setExpectedException(InvalidArgumentException::class); if (!$this->machineFormat) { throw new InvalidArgumentException('Simulating the test failure.'); } @@ -662,6 +672,8 @@ * @covers ::hasScope * @covers ::isScopeActive * + * @expectedException \BadMethodCallException + * * @dataProvider scopeExceptionTestProvider */ public function testScopeFunctionsWithException($method, $argument) { @@ -670,7 +682,6 @@ $method, ]; - $this->setExpectedException(\BadMethodCallException::class); $callable($argument); } reverted: --- b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -14,8 +14,6 @@ use Symfony\Component\ExpressionLanguage\Expression; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\ContainerInterface; - use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; - use Symfony\Component\DependencyInjection\Exception\RuntimeException; /** * @coversDefaultClass \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper @@ -484,6 +482,8 @@ * Tests that the correct InvalidArgumentException is thrown for getScope(). * * @covers ::getServiceDefinition + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetServiceDefinitionWithInvalidScope() { $bar_definition = new Definition('\stdClass'); @@ -491,7 +491,6 @@ $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(InvalidArgumentException::class); $this->dumper->getArray(); } @@ -556,6 +555,8 @@ * getDecoratedService(). * * @covers ::getServiceDefinition + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetServiceDefinitionForDecoratedService() { $bar_definition = new Definition('\stdClass'); @@ -563,7 +564,6 @@ $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(InvalidArgumentException::class); $this->dumper->getArray(); } @@ -571,6 +571,8 @@ * Tests that the correct RuntimeException is thrown for expressions. * * @covers ::dumpValue + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetServiceDefinitionForExpression() { $expression = new Expression(); @@ -580,7 +582,6 @@ $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(RuntimeException::class); $this->dumper->getArray(); } @@ -588,6 +589,8 @@ * Tests that the correct RuntimeException is thrown for dumping an object. * * @covers ::dumpValue + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetServiceDefinitionForObject() { $service = new \stdClass(); @@ -597,7 +600,6 @@ $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(RuntimeException::class); $this->dumper->getArray(); } @@ -605,6 +607,8 @@ * Tests that the correct RuntimeException is thrown for dumping a resource. * * @covers ::dumpValue + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetServiceDefinitionForResource() { $resource = fopen('php://memory', 'r'); @@ -614,7 +618,6 @@ $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(RuntimeException::class); $this->dumper->getArray(); } reverted: --- b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php +++ a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php @@ -55,10 +55,12 @@ /** * @covers ::get + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Required prefix configuration is missing */ public function testGetNoPrefix() { FileCacheFactory::setPrefix(NULL); - $this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing'); FileCacheFactory::get('test_foo_settings', []); } reverted: --- b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +++ a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\Component\Plugin; use Drupal\Component\Plugin\Definition\PluginDefinitionInterface; -use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry; use Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface; @@ -48,9 +47,11 @@ * Tests getPluginClass() with a missing class definition. * * @covers ::getPluginClass + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException + * @expectedExceptionMessage The plugin (cherry) did not specify an instance class. */ public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() { - $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); DefaultFactory::getPluginClass('cherry', []); } @@ -58,10 +59,12 @@ * Tests getPluginClass() with a missing class definition. * * @covers ::getPluginClass + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException + * @expectedExceptionMessage The plugin (cherry) did not specify an instance class. */ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() { $plugin_definition = $this->getMock(PluginDefinitionInterface::class); - $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); DefaultFactory::getPluginClass('cherry', $plugin_definition); } @@ -69,9 +72,11 @@ * Tests getPluginClass() with a not existing class definition. * * @covers ::getPluginClass + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException + * @expectedExceptionMessage Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist. */ public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() { - $this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.'); DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']); } @@ -79,6 +84,8 @@ * Tests getPluginClass() with a not existing class definition. * * @covers ::getPluginClass + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException */ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() { $plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit'; @@ -86,7 +93,6 @@ $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); - $this->setExpectedException(PluginException::class); DefaultFactory::getPluginClass('kiwifruit', $plugin_definition); } @@ -122,10 +128,12 @@ * Tests getPluginClass() with a required interface but no implementation. * * @covers ::getPluginClass + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException + * @expectedExceptionMessage Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface. */ public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() { $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); } @@ -133,6 +141,8 @@ * Tests getPluginClass() with a required interface but no implementation. * * @covers ::getPluginClass + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException */ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() { $plugin_class = Kale::class; @@ -140,7 +150,6 @@ $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); - $this->setExpectedException(PluginException::class); DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class); } reverted: --- b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php +++ a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\Component\Plugin\Discovery; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Tests\UnitTestCase; /** @@ -59,6 +58,7 @@ /** * @covers ::doGetDefinition + * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException * @dataProvider providerDoGetDefinitionException * @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException */ @@ -69,8 +69,10 @@ $method_ref = new \ReflectionMethod($trait, 'doGetDefinition'); $method_ref->setAccessible(TRUE); // Call doGetDefinition, with $exception_on_invalid always TRUE. + $this->assertSame( + $expected, + $method_ref->invoke($trait, $definitions, $plugin_id, TRUE) + ); - $this->setExpectedException(PluginNotFoundException::class); - $method_ref->invoke($trait, $definitions, $plugin_id, TRUE); } /** @@ -94,6 +96,7 @@ /** * @covers ::getDefinition + * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException * @dataProvider providerDoGetDefinitionException * @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException */ @@ -106,8 +109,10 @@ ->method('getDefinitions') ->willReturn($definitions); // Call getDefinition(), with $exception_on_invalid always TRUE. + $this->assertSame( + $expected, + $trait->getDefinition($plugin_id, TRUE) + ); - $this->setExpectedException(PluginNotFoundException::class); - $trait->getDefinition($plugin_id, TRUE); } /** reverted: --- b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php +++ a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\Component\Serialization; -use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Serialization\YamlPecl; /** @@ -75,9 +74,9 @@ * Tests that invalid YAML throws an exception. * * @covers ::errorHandler + * @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException */ public function testError() { - $this->setExpectedException(InvalidDataTypeException::class); YamlPecl::decode('foo: [ads'); } reverted: --- b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php +++ a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\Component\Serialization; -use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Serialization\YamlSymfony; /** @@ -57,9 +56,9 @@ * Tests that invalid YAML throws an exception. * * @covers ::decode + * @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException */ public function testError() { - $this->setExpectedException(InvalidDataTypeException::class); YamlSymfony::decode('foo: [ads'); } reverted: --- b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php +++ a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php @@ -121,6 +121,9 @@ * Tests getArgument() with a wildcard parameter with no typehint. * * Without the typehint, the wildcard object will not be passed to the callable. + * + * @expectedException \RuntimeException + * @expectedExceptionMessage requires a value for the "$route" argument. */ public function testGetWildcardArgumentNoTypehint() { $a = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1'); @@ -128,8 +131,8 @@ $resolver = new ArgumentsResolver([], [], $wildcards); $callable = function($route) {}; + $arguments = $resolver->getArguments($callable); + $this->assertNull($arguments); - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); - $resolver->getArguments($callable); } /** @@ -149,6 +152,9 @@ /** * Tests handleUnresolvedArgument() for a scalar argument. + * + * @expectedException \RuntimeException + * @expectedExceptionMessage requires a value for the "$foo" argument. */ public function testHandleNotUpcastedArgument() { $objects = ['foo' => 'bar']; @@ -156,19 +162,22 @@ $resolver = new ArgumentsResolver($scalars, $objects, []); $callable = function(\stdClass $foo) {}; + $arguments = $resolver->getArguments($callable); + $this->assertNull($arguments); - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); - $resolver->getArguments($callable); } /** * Tests handleUnresolvedArgument() for missing arguments. * + * @expectedException \RuntimeException + * @expectedExceptionMessage requires a value for the "$foo" argument. + * * @dataProvider providerTestHandleUnresolvedArgument */ public function testHandleUnresolvedArgument($callable) { $resolver = new ArgumentsResolver([], [], []); + $arguments = $resolver->getArguments($callable); + $this->assertNull($arguments); - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); - $resolver->getArguments($callable); } /** reverted: --- b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php +++ a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php @@ -69,6 +69,7 @@ * Tests the hmacBase64 method with invalid parameters. * * @dataProvider providerTestHmacBase64Invalid + * @expectedException InvalidArgumentException * @covers ::hmacBase64 * * @param string $data @@ -77,7 +78,6 @@ * Key to use in hashing process. */ public function testHmacBase64Invalid($data, $key) { - $this->setExpectedException(\InvalidArgumentException::class); Crypt::hmacBase64($data, $key); } reverted: --- b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +++ a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php @@ -332,9 +332,9 @@ /** * @covers ::transformRootRelativeUrlsToAbsolute * @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion + * @expectedException \AssertionError */ public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) { - $this->setExpectedException(\AssertionError::class); Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host); } reverted: --- b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -57,12 +57,12 @@ * Tests infinite loop prevention whilst generating random names. * * @covers ::name + * @expectedException \RuntimeException */ public function testRandomNameException() { // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. $random = new Random(); - $this->setExpectedException(\RuntimeException::class); for ($i = 0; $i <= 100; $i++) { $str = $random->name(1, TRUE); $names[$str] = TRUE; @@ -73,12 +73,12 @@ * Tests infinite loop prevention whilst generating random strings. * * @covers ::string + * @expectedException \RuntimeException */ public function testRandomStringException() { // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. $random = new Random(); - $this->setExpectedException(\RuntimeException::class); for ($i = 0; $i <= 100; $i++) { $str = $random->string(1, TRUE); $names[$str] = TRUE; reverted: --- b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php +++ a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php @@ -15,9 +15,10 @@ * Tests wrong rectangle width. * * @covers ::rotate + * + * @expectedException \InvalidArgumentException */ public function testWrongWidth() { - $this->setExpectedException(\InvalidArgumentException::class); $rect = new Rectangle(-40, 20); } @@ -25,9 +26,10 @@ * Tests wrong rectangle height. * * @covers ::rotate + * + * @expectedException \InvalidArgumentException */ public function testWrongHeight() { - $this->setExpectedException(\InvalidArgumentException::class); $rect = new Rectangle(40, 0); } reverted: --- b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -560,9 +560,9 @@ * * @covers ::externalIsLocal * @dataProvider providerTestExternalIsLocalInvalid + * @expectedException \InvalidArgumentException */ public function testExternalIsLocalInvalid($url, $base_url) { - $this->setExpectedException(\InvalidArgumentException::class); UrlHelper::externalIsLocal($url, $base_url); } reverted: --- b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -8,7 +8,6 @@ namespace Drupal\Tests\Core\Access; use Drupal\Core\Access\AccessCheckInterface; -use Drupal\Core\Access\AccessException; use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\CheckProvider; use Drupal\Core\Cache\Context\CacheContextsManager; @@ -475,6 +474,8 @@ * Tests that an access checker throws an exception for not allowed values. * * @dataProvider providerCheckException + * + * @expectedException \Drupal\Core\Access\AccessException */ public function testCheckException($return_value) { $route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface'); @@ -514,7 +515,6 @@ $this->checkProvider->setContainer($container); $this->checkProvider->addCheckService('test_incorrect_value', 'access'); - $this->setExpectedException(AccessException::class); $access_manager->checkNamedRoute('test_incorrect_value', [], $this->account); } reverted: --- b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php +++ a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php @@ -171,11 +171,11 @@ * * @covers ::validate * @dataProvider providerTestInvalidParameterTypes + * @expectedException InvalidArgumentException */ public function testInvalidParameterTypes($token, $value = '') { $this->setupDefaultExpectations(); - $this->setExpectedException(\InvalidArgumentException::class); $this->generator->validate($token, $value); } @@ -198,12 +198,12 @@ * Tests the exception thrown when no 'hash_salt' is provided in settings. * * @covers ::get + * @expectedException \RuntimeException */ public function testGetWithNoHashSalt() { // Update settings with no hash salt. new Settings([]); $generator = new CsrfTokenGenerator($this->privateKey, $this->sessionMetadata); - $this->setExpectedException(\RuntimeException::class); $generator->get(); } reverted: --- b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -7,9 +7,6 @@ namespace Drupal\Tests\Core\Asset; -use Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException; -use Drupal\Core\Asset\Exception\InvalidLibraryFileException; -use Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException; use Drupal\Core\Asset\LibraryDiscoveryParser; use Drupal\Tests\UnitTestCase; @@ -146,6 +143,8 @@ /** * Tests that an exception is thrown when a libraries file couldn't be parsed. * + * @expectedException \Drupal\Core\Asset\Exception\InvalidLibraryFileException + * * @covers ::buildByExtension */ public function testInvalidLibrariesFile() { @@ -158,13 +157,15 @@ $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'invalid_file', $path); - $this->setExpectedException(InvalidLibraryFileException::class); $this->libraryDiscoveryParser->buildByExtension('invalid_file'); } /** * Tests that an exception is thrown when no CSS/JS/setting is specified. * + * @expectedException \Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException + * @expectedExceptionMessage Incomplete library definition for definition 'example' in extension 'example_module_missing_information' + * * @covers ::buildByExtension */ public function testBuildByExtensionWithMissingInformation() { @@ -177,7 +178,6 @@ $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'); } @@ -276,6 +276,8 @@ /** * Ensures that you cannot provide positive weights for JavaScript libraries. * + * @expectedException \UnexpectedValueException + * * @covers ::buildByExtension */ public function testJsWithPositiveWeight() { @@ -288,7 +290,6 @@ $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'); } @@ -402,6 +403,9 @@ /** * Tests that an exception is thrown when license is missing when 3rd party. * + * @expectedException \Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException + * @expectedExceptionMessage Missing license information in library definition for definition 'no-license-info-but-remote' extension 'licenses_missing_information': it has a remote, but no license. + * * @covers ::buildByExtension */ public function testLibraryThirdPartyWithMissingLicense() { @@ -414,7 +418,6 @@ $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'); } reverted: --- b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php +++ a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php @@ -183,6 +183,8 @@ /** * Tests a breadcrumb builder with a bad return value. + * + * @expectedException \UnexpectedValueException */ public function testBuildWithInvalidBreadcrumbResult() { $builder = $this->getMock('Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface'); @@ -194,7 +196,6 @@ ->will($this->returnValue('invalid_result')); $this->breadcrumbManager->addBuilder($builder, 0); - $this->setExpectedException(\UnexpectedValueException::class); $this->breadcrumbManager->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface')); } reverted: --- b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php +++ a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php @@ -15,11 +15,12 @@ /** * @covers ::setLinks + * @expectedException \LogicException + * @expectedExceptionMessage Once breadcrumb links are set, only additional breadcrumb links can be added. */ public function testSetLinks() { $breadcrumb = new Breadcrumb(); $breadcrumb->setLinks([new Link('Home', Url::fromRoute(''))]); - $this->setExpectedException(\LogicException::class, 'Once breadcrumb links are set, only additional breadcrumb links can be added.'); $breadcrumb->setLinks([new Link('None', Url::fromRoute(''))]); } reverted: --- b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php +++ a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php @@ -14,10 +14,11 @@ /** * @covers ::invalidateTags + * + * @expectedException \AssertionError */ public function testInvalidateTagsWithInvalidTags() { $cache_tags_invalidator = new CacheTagsInvalidator(); - $this->setExpectedException(\AssertionError::class); $cache_tags_invalidator->invalidateTags(['node' => [2, 3, 5, 8, 13]]); } reverted: --- b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -105,25 +105,27 @@ /** * @covers ::convertTokensToKeys + * + * @expectedException \AssertionError */ public function testInvalidContext() { $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); - $this->setExpectedException(\AssertionError::class); $cache_contexts_manager->convertTokensToKeys(["non-cache-context"]); } /** * @covers ::convertTokensToKeys * + * @expectedException \Exception + * * @dataProvider providerTestInvalidCalculatedContext */ public function testInvalidCalculatedContext($context_token) { $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); - $this->setExpectedException(\Exception::class); $cache_contexts_manager->convertTokensToKeys([$context_token]); } reverted: --- b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -6,7 +6,6 @@ use Drupal\Core\Render\Markup; use Drupal\Tests\UnitTestCase; use Drupal\Core\Config\Config; -use Drupal\Core\Config\ConfigValueException; /** * Tests the Config. @@ -231,21 +230,21 @@ /** * @covers ::set + * @expectedException \Drupal\Core\Config\ConfigValueException */ public function testSetValidation() { - $this->setExpectedException(ConfigValueException::class); $this->config->set('testData', ['dot.key' => 1]); } /** * @covers ::set + * @expectedException PHPUnit_Framework_Error_Warning */ public function testSetIllegalOffsetValue() { // Set a single value. $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); } @@ -384,6 +383,7 @@ /** * @covers ::validateName + * @expectedException \Drupal\Core\Config\ConfigNameException * @dataProvider validateNameProvider */ public function testValidateNameException($name, $exception_message) { reverted: --- b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -8,7 +8,6 @@ namespace Drupal\Tests\Core\Config\Entity; use Drupal\Component\Plugin\PluginManagerInterface; -use Drupal\Core\Config\Schema\SchemaIncompleteException; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Language\Language; use Drupal\Core\Plugin\DefaultLazyPluginCollection; @@ -568,12 +567,13 @@ /** * @covers ::toArray + * + * @expectedException \Drupal\Core\Config\Schema\SchemaIncompleteException */ public function testToArrayFallback() { $this->entityType->expects($this->any()) ->method('getPropertiesToExport') ->willReturn([]); - $this->setExpectedException(SchemaIncompleteException::class); $this->entity->toArray(); } reverted: --- b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -6,7 +6,6 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\Config\Config; -use Drupal\Core\Config\ConfigDuplicateUUIDException; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Config\Entity\ConfigEntityBase; @@ -16,9 +15,7 @@ use Drupal\Core\Config\ImmutableConfig; use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\Query\QueryFactoryInterface; use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -379,19 +376,23 @@ /** * @covers ::save + * + * @expectedException \Drupal\Core\Entity\EntityMalformedException + * @expectedExceptionMessage The entity does not have an ID. */ public function testSaveInvalid() { $this->cacheTagsInvalidator->invalidateTags(Argument::cetera()) ->shouldNotBeCalled(); $entity = $this->getMockEntity(); - $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); $this->entityStorage->save($entity); } /** * @covers ::save * @covers ::doSave + * + * @expectedException \Drupal\Core\Entity\EntityStorageException */ public function testSaveDuplicate() { $config_object = $this->prophesize(ImmutableConfig::class); @@ -406,13 +407,15 @@ $entity = $this->getMockEntity(['id' => 'foo']); $entity->enforceIsNew(); - $this->setExpectedException(EntityStorageException::class); $this->entityStorage->save($entity); } /** * @covers ::save * @covers ::doSave + * + * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException + * @expectedExceptionMessage when this UUID is already used for */ public function testSaveMismatch() { $config_object = $this->prophesize(ImmutableConfig::class); @@ -428,7 +431,6 @@ $this->entityQuery->execute()->willReturn(['baz']); $entity = $this->getMockEntity(['id' => 'foo']); - $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this UUID is already used for'); $this->entityStorage->save($entity); } @@ -470,6 +472,9 @@ /** * @covers ::save * @covers ::doSave + * + * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException + * @expectedExceptionMessage when this entity already exists with UUID */ public function testSaveChangedUuid() { $config_object = $this->prophesize(ImmutableConfig::class); @@ -499,7 +504,6 @@ $entity = $this->getMockEntity(['id' => 'foo']); $entity->set('uuid', 'baz'); - $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this entity already exists with UUID'); $this->entityStorage->save($entity); } reverted: --- b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php +++ a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -4,7 +4,6 @@ use Drupal\Tests\UnitTestCase; use Drupal\Core\Config\Entity\ConfigEntityType; -use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException; /** * @coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityType @@ -80,9 +79,11 @@ /** * @covers ::__construct + * + * @expectedException \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException + * @expectedExceptionMessage \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it */ public function testConstructBadStorage() { - $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); new ConfigEntityType([ 'id' => 'example_config_entity_type', 'handlers' => ['storage' => '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'] @@ -91,10 +92,12 @@ /** * @covers ::setStorageClass + * + * @expectedException \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException + * @expectedExceptionMessage \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it */ public function testSetStorageClass() { $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'); } reverted: --- b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php +++ a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php @@ -96,8 +96,8 @@ } /** + * @expectedException \LogicException + * @expectedExceptionMessage test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup - * @covers ::getKeys - * @covers ::getValues */ public function testGetKeysWildCardEnd() { $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'); @@ -111,7 +111,6 @@ $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); } reverted: --- b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php +++ a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\Core\Config; use Drupal\Core\Config\ImmutableConfig; -use Drupal\Core\Config\ImmutableConfigException; use Drupal\Tests\UnitTestCase; /** @@ -29,33 +28,37 @@ /** * @covers ::set + * @expectedException \Drupal\Core\Config\ImmutableConfigException + * @expectedExceptionMessage Can not set values on immutable configuration test:name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object */ public function testSet() { - $this->setExpectedException(ImmutableConfigException::class, 'Can not set values on immutable configuration test:name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); $this->config->set('name', 'value'); } /** * @covers ::clear + * @expectedException \Drupal\Core\Config\ImmutableConfigException + * @expectedExceptionMessage Can not clear name key in immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object */ public function testClear() { - $this->setExpectedException(ImmutableConfigException::class, 'Can not clear name key in immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); $this->config->clear('name'); } /** * @covers ::save + * @expectedException \Drupal\Core\Config\ImmutableConfigException + * @expectedExceptionMessage Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object */ public function testSave() { - $this->setExpectedException(ImmutableConfigException::class, 'Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); $this->config->save(); } /** * @covers ::delete + * @expectedException \Drupal\Core\Config\ImmutableConfigException + * @expectedExceptionMessage Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object */ public function testDelete() { - $this->setExpectedException(ImmutableConfigException::class, 'Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); $this->config->delete(); } reverted: --- b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php +++ a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php @@ -120,17 +120,19 @@ /** * Tests createController() with a non-existent class. + * + * @expectedException \InvalidArgumentException */ public function testCreateControllerNonExistentClass() { - $this->setExpectedException(\InvalidArgumentException::class); $this->controllerResolver->getControllerFromDefinition('Class::method'); } /** * Tests createController() with an invalid name. + * + * @expectedException \LogicException */ public function testCreateControllerInvalidName() { - $this->setExpectedException(\LogicException::class); $this->controllerResolver->getControllerFromDefinition('ClassWithoutMethod'); } @@ -189,9 +191,10 @@ } /** * Tests getControllerFromDefinition() without a callable. + * + * @expectedException \InvalidArgumentException */ public function testGetControllerFromDefinitionNotCallable() { - $this->setExpectedException(\InvalidArgumentException::class); $this->controllerResolver->getControllerFromDefinition('Drupal\Tests\Core\Controller\MockController::bananas'); } reverted: --- b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php +++ a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php @@ -140,6 +140,7 @@ /** * @covers ::compile * + * @expectedException \PHPUnit_Framework_Error * @dataProvider providerTestCompileWithSqlInjectionForOperator */ public function testCompileWithSqlInjectionForOperator($operator) { @@ -161,7 +162,6 @@ $condition = new Condition('AND'); $condition->condition('name', 'value', $operator); - $this->setExpectedException(\PHPUnit_Framework_Error::class); $condition->compile($connection, $query_placeholder); } reverted: --- b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php +++ a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php @@ -5,7 +5,6 @@ use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; -use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; /** * @coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass @@ -65,13 +64,14 @@ /** * @covers ::process + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testContainerWithLazyServicesWithoutProxyClass() { $container = new ContainerBuilder(); $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist') ->setLazy(TRUE); - $this->setExpectedException(InvalidArgumentException::class); $this->proxyServicesPass->process($container); } reverted: --- b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -10,7 +10,6 @@ use Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Reference; /** @@ -45,6 +44,8 @@ /** * Tests a required consumer with no handlers. * + * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException + * @expectedExceptionMessage At least one service tagged with 'consumer_id' is required. * @covers ::process */ public function testProcessRequiredHandlers() { @@ -56,13 +57,14 @@ ]); $handler_pass = new TaggedHandlersPass(); - $this->setExpectedException(LogicException::class, "At least one service tagged with 'consumer_id' is required."); $handler_pass->process($container); } /** * Tests consumer with missing interface in non-production environment. * + * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException + * @expectedExceptionMessage Service consumer 'consumer_id1' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface. * @covers ::process */ public function testProcessMissingInterface() { @@ -75,7 +77,6 @@ ->addTag('service_collector'); $handler_pass = new TaggedHandlersPass(); - $this->setExpectedException(LogicException::class, "Service consumer 'consumer_id1' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface."); $handler_pass->process($container); } @@ -206,6 +207,7 @@ /** * Tests interface validation in non-production environment. * + * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException * @covers ::process */ public function testProcessInterfaceMismatch() { @@ -224,7 +226,6 @@ ]); $handler_pass = new TaggedHandlersPass(); - $this->setExpectedException(LogicException::class); $handler_pass->process($container); } diff -u b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php --- b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php @@ -35,39 +35,42 @@ /** * @covers ::set + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Service ID names must be lowercase: Bar */ public function testSetException() { $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); } /** * @covers ::setParameter + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Parameter names must be lowercase: Buzz */ public function testSetParameterException() { $container = new ContainerBuilder(); - $this->setExpectedException(\InvalidArgumentException::class, 'Parameter names must be lowercase: Buzz'); $container->setParameter('Buzz', 'buzz'); } /** * @covers ::register + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Service ID names must be lowercase: Bar */ public function testRegisterException() { $container = new ContainerBuilder(); - $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); $container->register('Bar'); } /** * Tests serialization. + * + * @expectedException \AssertionError */ public function testSerialize() { $container = new ContainerBuilder(); - $this->setExpectedException(\AssertionError::class); serialize($container); } reverted: --- b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php +++ a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php @@ -14,10 +14,11 @@ /** * Tests serialization. + * + * @expectedException \AssertionError */ public function testSerialize() { $container = new Container(); - $this->setExpectedException(\AssertionError::class); serialize($container); } reverted: --- b/core/tests/Drupal/Tests/Core/DrupalTest.php +++ a/core/tests/Drupal/Tests/Core/DrupalTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\Core; -use Drupal\Core\DependencyInjection\ContainerNotInitializedException; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\Query\QueryAggregateInterface; @@ -48,9 +47,11 @@ /** * @covers ::getContainer + * + * @expectedException \Drupal\Core\DependencyInjection\ContainerNotInitializedException + * @expectedExceptionMessage \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. */ public function testGetContainerException() { - $this->setExpectedException(ContainerNotInitializedException::class, '\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.'); \Drupal::getContainer(); } reverted: --- b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php @@ -313,12 +313,14 @@ * Tests invalid default value callbacks. * * @covers ::setDefaultValueCallback + * @expectedException \InvalidArgumentException */ public function testInvalidDefaultValueCallback() { $definition = BaseFieldDefinition::create($this->fieldType); // setDefaultValueCallback returns $this. + $this->assertSame($definition, + $definition->setDefaultValueCallback([get_class($this), 'mockDefaultValueCallback']) + ); - $this->setExpectedException(\InvalidArgumentException::class); - $definition->setDefaultValueCallback([get_class($this), 'mockDefaultValueCallback']); } /** reverted: --- b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -358,6 +358,9 @@ * @covers ::setValidationRequired * @covers ::save * @covers ::preSave + * + * @expectedException \LogicException + * @expectedExceptionMessage Entity validation was skipped. */ public function testRequiredValidation() { $validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface'); @@ -402,7 +405,6 @@ // 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(); } reverted: --- b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php @@ -310,6 +310,9 @@ * @covers ::getBaseFieldDefinitions * @covers ::buildBaseFieldDefinitions * + * @expectedException \LogicException + * @expectedExceptionMessage The Test entity type cannot be translatable as it does not define a translatable "langcode" field. + * * @dataProvider providerTestGetBaseFieldDefinitionsTranslatableEntityTypeLangcode */ public function testGetBaseFieldDefinitionsTranslatableEntityTypeLangcode($provide_key, $provide_field, $translatable) { @@ -330,7 +333,6 @@ $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'); } @@ -450,6 +452,8 @@ * * @covers ::getBaseFieldDefinitions * @covers ::buildBaseFieldDefinitions + * + * @expectedException \LogicException */ public function testGetBaseFieldDefinitionsInvalidDefinition() { $this->setUpEntityWithFieldDefinition(FALSE, 'langcode', ['langcode' => 'langcode']); @@ -457,7 +461,6 @@ $this->entityType->isTranslatable()->willReturn(TRUE); $this->entityType->getLabel()->willReturn('the_label'); - $this->setExpectedException(\LogicException::class); $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type'); } reverted: --- b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php @@ -8,7 +8,6 @@ namespace Drupal\Tests\Core\Entity; use Drupal\Component\Plugin\Discovery\DiscoveryInterface; -use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; @@ -18,7 +17,6 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Entity\Exception\InvalidLinkTemplateException; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Tests\UnitTestCase; @@ -251,13 +249,14 @@ * Tests the getFormObject() method with an invalid operation. * * @covers ::getFormObject + * + * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testGetFormObjectInvalidOperation() { $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'); } @@ -285,12 +284,13 @@ * Tests the getHandler() method when no controller is defined. * * @covers ::getHandler + * + * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testGetHandlerMissingHandler() { $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'); } @@ -315,6 +315,9 @@ * Tests the processDefinition() method. * * @covers ::processDefinition + * + * @expectedException \Drupal\Core\Entity\Exception\InvalidLinkTemplateException + * @expectedExceptionMessage Link template 'canonical' for entity type 'apple' must start with a leading slash, the current link template is 'path/to/apple' */ public function testProcessDefinition() { $apple = $this->prophesize(EntityTypeInterface::class); @@ -323,7 +326,6 @@ $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'); } @@ -369,11 +371,13 @@ * Tests the getDefinition() method with an invalid definition. * * @covers ::getDefinition + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException + * @expectedExceptionMessage The "pear" entity type does not exist. */ public function testGetDefinitionInvalidException() { $this->setUpEntityTypeDefinitions(); - $this->setExpectedException(PluginNotFoundException::class, 'The "pear" entity type does not exist.'); $this->entityTypeManager->getDefinition('pear', TRUE); } reverted: --- b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php @@ -7,8 +7,6 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeRepository; -use Drupal\Core\Entity\Exception\AmbiguousEntityClassException; -use Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; @@ -132,6 +130,9 @@ /** * @covers ::getEntityTypeFromClass + * + * @expectedException \Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException + * @expectedExceptionMessage The \Drupal\pear\Entity\Pear class does not correspond to an entity type. */ public function testGetEntityTypeFromClassNoMatch() { $apple = $this->prophesize(EntityTypeInterface::class); @@ -145,12 +146,14 @@ $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'); } /** * @covers ::getEntityTypeFromClass + * + * @expectedException \Drupal\Core\Entity\Exception\AmbiguousEntityClassException + * @expectedExceptionMessage Multiple entity types found for \Drupal\apple\Entity\Apple. */ public function testGetEntityTypeFromClassAmbiguous() { $boskoop = $this->prophesize(EntityTypeInterface::class); @@ -166,7 +169,6 @@ 'gala' => $gala, ]); - $this->setExpectedException(AmbiguousEntityClassException::class, 'Multiple entity types found for \Drupal\apple\Entity\Apple.'); $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\apple\Entity\Apple'); } reverted: --- b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -400,10 +400,11 @@ /** * @covers ::setLinkTemplate + * + * @expectedException \InvalidArgumentException */ public function testSetLinkTemplateWithInvalidPath() { $entity_type = $this->setUpEntityType(['id' => $this->randomMachineName()]); - $this->setExpectedException(\InvalidArgumentException::class); $entity_type->setLinkTemplate('test', 'invalid-path'); } diff -u b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php --- b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -5,8 +5,6 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityMalformedException; -use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Language\Language; use Drupal\Tests\UnitTestCase; use Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage; @@ -441,24 +439,29 @@ /** * @covers ::save * @covers ::doSave + * + * @expectedException \Drupal\Core\Entity\EntityMalformedException + * @expectedExceptionMessage The entity does not have an ID. */ public function testSaveInvalid() { $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'); $this->keyValueStore->expects($this->never()) ->method('set'); $this->keyValueStore->expects($this->never()) ->method('delete'); + $this->entityStorage->save($entity); } /** * @covers ::save * @covers ::doSave + * + * @expectedException \Drupal\Core\Entity\EntityStorageException + * @expectedExceptionMessage 'test_entity_type' entity with ID 'foo' already exists */ public function testSaveDuplicate() { $this->setUpKeyValueEntityStorage(); @@ -472,7 +475,6 @@ ->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); } reverted: --- b/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php @@ -4,7 +4,6 @@ use Drupal\Core\Entity\EntityType; use Drupal\Tests\UnitTestCase; -use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Query\Sql\Query; /** @@ -37,9 +36,11 @@ * Tests entity query for entity type without base table. * * @covers ::prepare + * + * @expectedException \Drupal\Core\Entity\Query\QueryException + * @expectedExceptionMessage No base table for example_entity_query, invalid query. */ public function testNoBaseTable() { - $this->setExpectedException(QueryException::class, 'No base table for example_entity_query, invalid query.'); $this->query->execute(); } @@ -47,9 +48,11 @@ * Tests revision entity query for entity type without revision table. * * @covers ::prepare + * + * @expectedException \Drupal\Core\Entity\Query\QueryException + * @expectedExceptionMessage No revision table for example_entity_query, invalid query. */ public function testNoRevisionTable() { - $this->setExpectedException(QueryException::class, 'No revision table for example_entity_query, invalid query.'); $this->query->allRevisions()->execute(); } reverted: --- b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\Core\Entity\Sql; use Drupal\Core\Entity\Sql\DefaultTableMapping; -use Drupal\Core\Entity\Sql\SqlContentEntityStorageException; use Drupal\Tests\UnitTestCase; /** @@ -295,6 +294,9 @@ * @param string $column * The name of the column to be processed. * + * @expectedException \Drupal\Core\Entity\Sql\SqlContentEntityStorageException + * @expectedExceptionMessage Column information not available for the 'test' field. + * * @covers ::getFieldColumnName * * @dataProvider providerTestGetFieldColumnName @@ -308,7 +310,6 @@ ->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); } @@ -439,11 +440,13 @@ /** * Tests DefaultTableMapping::getFieldTableName() with an invalid parameter. * + * @expectedException \Drupal\Core\Entity\Sql\SqlContentEntityStorageException + * @expectedExceptionMessage Table information not available for the 'invalid_field_name' field. + * * @covers ::getFieldTableName */ public function testGetFieldTableNameInvalid() { $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'); } reverted: --- b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php +++ a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php @@ -6,7 +6,6 @@ use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\TypedData\Exception\MissingDataException; use Drupal\Core\TypedData\TypedDataManagerInterface; use Drupal\Tests\UnitTestCase; use Drupal\Core\Language\Language; @@ -276,18 +275,18 @@ /** * @covers ::get + * @expectedException \InvalidArgumentException */ public function testGetInvalidField() { - $this->setExpectedException(\InvalidArgumentException::class); $this->entityAdapter->get('invalid'); } /** * @covers ::get + * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testGetWithoutData() { $this->entityAdapter->setValue(NULL); - $this->setExpectedException(MissingDataException::class); $this->entityAdapter->get('id'); } @@ -306,11 +305,11 @@ /** * @covers ::set + * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testSetWithoutData() { $this->entityAdapter->setValue(NULL); $id_items = [ ['value' => $this->id + 1] ]; - $this->setExpectedException(MissingDataException::class); $this->entityAdapter->set('id', $id_items); } @@ -336,10 +335,10 @@ /** * @covers ::toArray + * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testToArrayWithoutData() { $this->entityAdapter->setValue(NULL); - $this->setExpectedException(MissingDataException::class); $this->entityAdapter->toArray(); } diff -u b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php --- b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php @@ -115,6 +115,8 @@ /** * @dataProvider providerTestDestinationRedirectToExternalUrl + * + * @expectedException \PHPUnit_Framework_Error */ public function testDestinationRedirectToExternalUrl($request, $expected) { $dispatcher = new EventDispatcher(); @@ -124,10 +126,8 @@ $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, [$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()); } /** @@ -164,6 +164,8 @@ } /** + * @expectedException \PHPUnit_Framework_Error + * * @dataProvider providerTestDestinationRedirectWithInvalidUrl */ public function testDestinationRedirectWithInvalidUrl(Request $request) { @@ -174,10 +176,8 @@ $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, [$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()); } /** reverted: --- b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -89,6 +89,9 @@ * The route to check. * * @dataProvider providerTestOnRouteBuildingInvalidVariables + * @expectedException \PHPUnit_Framework_Error_Warning + * @expectedExceptionMessage uses reserved variable names + * * @covers ::onAlterRoutes */ public function testOnRouteBuildingInvalidVariables(Route $route) { @@ -97,7 +100,6 @@ $event = new RouteBuildEvent($route_collection, 'test'); $subscriber = new SpecialAttributesRouteSubscriber(); - $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'uses reserved variable names'); $subscriber->onAlterRoutes($event); } reverted: --- b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -50,6 +50,9 @@ * Test if correct exception is thrown for a broken info file. * * @covers ::parse + * + * @expectedException \Drupal\Core\Extension\InfoParserException + * @expectedExceptionMessageRegExp #broken\.info\.txt# */ public function testInfoParserBroken() { $broken_info = <<setExpectedException('\Drupal\Core\Extension\InfoParserException', 'broken.info.txt'); $this->infoParser->parse($filename); } @@ -79,6 +81,9 @@ * Tests that missing required keys are detected. * * @covers ::parse + * + * @expectedException \Drupal\Core\Extension\InfoParserException + * @expectedExceptionMessageRegExp #Missing required keys \(type, core, name\) in .+?missing_keys\.info\.txt# */ public function testInfoParserMissingKeys() { $missing_keys = <<setExpectedException('\Drupal\Core\Extension\InfoParserException', 'Missing required keys (type, core, name) in vfs://modules/fixtures/missing_keys.info.txt'); $this->infoParser->parse($filename); } @@ -104,6 +108,9 @@ * Tests that missing required key is detected. * * @covers ::parse + * + * @expectedException \Drupal\Core\Extension\InfoParserException + * @expectedExceptionMessageRegExp #Missing required keys \(type\) in .+?missing_key\.info\.txt# */ public function testInfoParserMissingKey() { $missing_key = <<setExpectedException('\Drupal\Core\Extension\InfoParserException', 'Missing required keys (type) in vfs://modules/fixtures/missing_key.info.txt'); $this->infoParser->parse($filename); } reverted: --- b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php +++ a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php @@ -146,9 +146,10 @@ /** * @covers ::getModule + * + * @expectedException \InvalidArgumentException */ public function testGetModuleWithNonExistingModule() { - $this->setExpectedException(\InvalidArgumentException::class); $this->moduleHandler->getModule('claire_alice_watch_my_little_pony_module_that_does_not_exist'); } reverted: --- b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php +++ a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php @@ -41,6 +41,8 @@ /** * @covers ::config + * @expectedException \LogicException + * @expectedExceptionMessage No config factory available for ConfigFormBaseTrait */ public function testConfigFactoryException() { $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait'); @@ -48,12 +50,13 @@ $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'); } /** * @covers ::config + * @expectedException \LogicException + * @expectedExceptionMessage No config factory available for ConfigFormBaseTrait */ public function testConfigFactoryExceptionInvalidProperty() { $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait'); @@ -62,7 +65,6 @@ $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'); } reverted: --- b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php +++ a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php @@ -9,7 +9,6 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Exception\HttpException; /** * @coversDefaultClass \Drupal\Core\Form\FormAjaxResponseBuilder @@ -44,6 +43,8 @@ /** * @covers ::buildResponse + * + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ public function testBuildResponseNoTriggeringElement() { $this->renderer->expects($this->never()) @@ -55,12 +56,13 @@ $commands = []; $expected = []; + $this->assertSame($expected, $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands)); - $this->setExpectedException(HttpException::class); - $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands); } /** * @covers ::buildResponse + * + * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ public function testBuildResponseNoCallable() { $this->renderer->expects($this->never()) @@ -74,8 +76,7 @@ $commands = []; $expected = []; + $this->assertSame($expected, $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands)); - $this->setExpectedException(HttpException::class); - $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands); } /** diff -u b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php --- b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -13,7 +13,6 @@ use Drupal\Core\Cache\Context\CacheContextsManager; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Form\EnforcedResponseException; -use Drupal\Core\Form\Exception\BrokenPostRequestException; use Drupal\Core\Form\FormBuilder; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormInterface; @@ -53,16 +52,17 @@ /** * Tests the getFormId() method with a string based form ID. + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The form argument foo is not a valid form. */ public function testGetFormIdWithString() { $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); $this->assertSame($clean_form_state, $form_state); } @@ -217,15 +217,15 @@ /** * Tests the getForm() method with a string based form ID. + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The form argument test_form_id is not a valid form. */ public function testGetFormWithString() { $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']); } /** @@ -259,16 +259,16 @@ /** * Tests the buildForm() method with a string based form ID. + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The form argument test_form_id is not a valid form. */ public function testBuildFormWithString() { $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); - } + } /** * Tests the buildForm() method with a class name based form ID. @@ -542,6 +542,8 @@ /** * @covers ::buildForm + * + * @expectedException \Drupal\Core\Form\Exception\BrokenPostRequestException */ public function testExceededFileSize() { $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]); @@ -558,7 +560,6 @@ $form_arg = $this->getMockForm('test_form_id'); $form_state = new FormState(); - $this->setExpectedException(BrokenPostRequestException::class); $this->formBuilder->buildForm($form_arg, $form_state); } reverted: --- b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php +++ a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php @@ -158,9 +158,10 @@ * @dataProvider providerSingleBooleanArgument * * @param bool $cache + * + * @expectedException \LogicException */ public function testSetCachedWithLogicException($cache) { - $this->setExpectedException(\LogicException::class); $this->decoratedFormState->setCached($cache) ->willThrow(\LogicException::class); reverted: --- b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php +++ a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php @@ -132,11 +132,13 @@ * Tests that form errors during submission throw an exception. * * @covers ::setErrorByName + * + * @expectedException \LogicException + * @expectedExceptionMessage Form errors cannot be set after form validation has finished. */ public function testFormErrorsDuringSubmission() { $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'); } @@ -313,11 +315,13 @@ /** * @covers ::setCached + * + * @expectedException \LogicException + * @expectedExceptionMessage Form state caching on GET requests is not allowed. */ public function testSetCachedGet() { $form_state = new FormState(); $form_state->setRequestMethod('GET'); - $this->setExpectedException(\LogicException::class, 'Form state caching on GET requests is not allowed.'); $form_state->setCached(); } reverted: --- b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php +++ a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php @@ -97,11 +97,12 @@ * * @dataProvider providerGetValuesBroken * + * @expectedException \UnexpectedValueException + * * @param string[] $parents * @param string $expected */ public function testGetValuesBroken(array $parents, $expected) { - $this->setExpectedException(\UnexpectedValueException::class); $this->testGetValues($parents, $expected); } @@ -160,9 +161,10 @@ * @covers ::getValue * * @dataProvider providerTestGetValueBroken + * + * @expectedException \UnexpectedValueException */ public function testGetValueBroken(array $parents, $key, $expected, $default = NULL) { - $this->setExpectedException(\UnexpectedValueException::class); $this->testGetValue($parents, $key, $expected, $default); } @@ -215,9 +217,10 @@ * @covers ::setValues * * @dataProvider providerTestSetValuesBroken + * + * @expectedException \UnexpectedValueException */ public function testSetValuesBroken($parents, $new_values, $expected) { - $this->setExpectedException(\UnexpectedValueException::class); $this->testSetValues($parents, $new_values, $expected); } reverted: --- b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\Core\Menu; -use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Access\AccessResult; use Drupal\Core\Language\Language; use Drupal\Core\Menu\ContextualLinkDefault; @@ -205,6 +204,8 @@ * Tests processDefinition() by passing a plugin definition without a route. * * @see \Drupal\Core\Menu\ContextualLinkManager::processDefinition() + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException */ public function testProcessDefinitionWithoutRoute() { $definition = [ @@ -212,7 +213,6 @@ 'group' => 'example', 'id' => 'test_plugin', ]; - $this->setExpectedException(PluginException::class); $this->contextualLinkManager->processDefinition($definition, 'test_plugin'); } @@ -220,6 +220,8 @@ * Tests processDefinition() by passing a plugin definition without a group. * * @see \Drupal\Core\Menu\ContextualLinkManager::processDefinition() + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException */ public function testProcessDefinitionWithoutGroup() { $definition = [ @@ -227,7 +229,6 @@ 'route_name' => 'example', 'id' => 'test_plugin', ]; - $this->setExpectedException(PluginException::class); $this->contextualLinkManager->processDefinition($definition, 'test_plugin'); } reverted: --- b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php +++ a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php @@ -63,6 +63,7 @@ /** * Asserts that check() throws an exception if a rule returns an invalid value. * + * @expectedException \UnexpectedValueException * @dataProvider providerChainExceptionOnInvalidReturnValue * @covers ::check */ @@ -75,7 +76,6 @@ $this->policy->addPolicy($rule); - $this->setExpectedException(\UnexpectedValueException::class); $this->policy->check($this->request); } reverted: --- b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php +++ a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php @@ -72,6 +72,7 @@ /** * Asserts that check() throws an exception if a rule returns an invalid value. * + * @expectedException \UnexpectedValueException * @dataProvider providerChainExceptionOnInvalidReturnValue * @covers ::check */ @@ -84,8 +85,8 @@ $this->policy->addPolicy($rule); + $actual_result = $this->policy->check($this->response, $this->request); + $this->assertSame(NULL, $actual_result); - $this->setExpectedException(\UnexpectedValueException::class); - $this->policy->check($this->response, $this->request); } /** reverted: --- b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php +++ a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php @@ -4,7 +4,6 @@ use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Core\ParamConverter\EntityConverter; -use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Tests\UnitTestCase; use Symfony\Component\Routing\Route; @@ -111,6 +110,8 @@ /** * Tests the convert() method with an invalid entity type. + * + * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testConvertWithInvalidEntityType() { $this->entityManager->expects($this->once()) @@ -118,15 +119,16 @@ ->with('invalid_id') ->willThrowException(new InvalidPluginDefinitionException('invalid_id')); - $this->setExpectedException(InvalidPluginDefinitionException::class); $this->entityConverter->convert('id', ['type' => 'entity:invalid_id'], 'foo', ['foo' => 'id']); } /** * Tests the convert() method with an invalid dynamic entity type. + * + * @expectedException \Drupal\Core\ParamConverter\ParamNotConvertedException + * @expectedExceptionMessage The "foo" parameter was not converted because the "invalid_id" parameter is missing */ public function testConvertWithInvalidDynamicEntityType() { - $this->setExpectedException(ParamNotConvertedException::class, 'The "foo" parameter was not converted because the "invalid_id" parameter is missing'); $this->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id']); } reverted: --- b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php +++ a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\Core\ParamConverter; use Drupal\Core\ParamConverter\ParamConverterManager; -use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Tests\UnitTestCase; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\Routing\Route; @@ -52,9 +51,10 @@ * Tests \Drupal\Core\ParamConverter\ParamConverterManager::getConverter(). * * @covers ::getConverter + * + * @expectedException \InvalidArgumentException */ public function testGetConverterException() { - $this->setExpectedException(\InvalidArgumentException::class); $this->manager->getConverter('undefined.converter'); } @@ -220,6 +220,9 @@ /** * @covers ::convert + * + * @expectedException \Drupal\Core\ParamConverter\ParamNotConvertedException + * @expectedExceptionMessage The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route") */ public function testConvertMissingParam() { $route = new Route('/test/{id}'); @@ -243,7 +246,6 @@ ->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); } reverted: --- b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php +++ a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php @@ -7,7 +7,6 @@ use Drupal\Core\PathProcessor\PathProcessorFront; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Test front page path processing. @@ -48,6 +47,7 @@ * Test inbound failure with broken config. * * @covers ::processInbound + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testProcessInboundBadConfig() { $config_factory = $this->prophesize(ConfigFactoryInterface::class); @@ -57,7 +57,6 @@ $config->get('page.front') ->willReturn(''); $processor = new PathProcessorFront($config_factory->reveal()); - $this->setExpectedException(NotFoundHttpException::class); $processor->processInbound('/', new Request()); } reverted: --- b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php +++ a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php @@ -107,6 +107,7 @@ } /** + * @expectedException \Exception * @dataProvider providerGetDataDefinition * @covers ::getDataDefinition * @uses \Drupal @@ -154,8 +155,10 @@ ->method('getDataType') ->willReturn($data_type); + $this->assertSame( + $mock_data_definition, + $mock_context_definition->getDataDefinition() + ); - $this->setExpectedException(\Exception::class); - $mock_context_definition->getDataDefinition(); } /** reverted: --- b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php +++ a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php @@ -66,10 +66,11 @@ /** * @covers ::getRuntimeContexts + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage You must provide the context IDs in the @{service_id}:{unqualified_context_id} format. */ public function testInvalidContextId() { $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']); } reverted: --- b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php +++ a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php @@ -8,7 +8,6 @@ namespace Drupal\Tests\Core\Plugin; use Drupal\Component\Plugin\ConfigurablePluginInterface; -use Drupal\Component\Plugin\Exception\ContextException; use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextHandler; use Drupal\Core\Plugin\ContextAwarePluginInterface; @@ -280,6 +279,9 @@ /** * @covers ::applyContextMapping + * + * @expectedException \Drupal\Component\Plugin\Exception\ContextException + * @expectedExceptionMessage Required contexts without a value: hit. */ public function testApplyContextMappingMissingRequired() { $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); @@ -309,7 +311,6 @@ $plugin->expects($this->never()) ->method('getContext'); - $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.'); $this->contextHandler->applyContextMapping($plugin, $contexts); } @@ -349,6 +350,9 @@ /** * @covers ::applyContextMapping + * + * @expectedException \Drupal\Component\Plugin\Exception\ContextException + * @expectedExceptionMessage Required contexts without a value: hit. */ public function testApplyContextMappingNoValueRequired() { $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); @@ -377,7 +381,6 @@ $plugin->expects($this->never()) ->method('setContextValue'); - $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.'); $this->contextHandler->applyContextMapping($plugin, $contexts); } @@ -461,6 +464,9 @@ /** * @covers ::applyContextMapping + * + * @expectedException \Drupal\Component\Plugin\Exception\ContextException + * @expectedExceptionMessage Assigned contexts were not satisfied: miss */ public function testApplyContextMappingConfigurableAssignedMiss() { $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); @@ -483,7 +489,6 @@ $plugin->expects($this->never()) ->method('setContextValue'); - $this->setExpectedException(ContextException::class, 'Assigned contexts were not satisfied: miss'); $this->contextHandler->applyContextMapping($plugin, $contexts, ['miss' => 'name']); } reverted: --- b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php +++ a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\Core\Plugin; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin; /** @@ -44,10 +43,11 @@ /** * @covers ::get + * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException + * @expectedExceptionMessage Plugin ID 'pear' was not found. */ public function testGetNotExistingPlugin() { $this->setupPluginCollection(); - $this->setExpectedException(PluginNotFoundException::class, "Plugin ID 'pear' was not found."); $this->defaultPluginCollection->get('pear'); } reverted: --- b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\Core\Plugin; use Drupal\Component\Plugin\Definition\PluginDefinition; -use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; @@ -272,6 +271,9 @@ * Tests plugins without the proper interface. * * @covers ::createInstance + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginException + * @expectedExceptionMessage Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface */ public function testCreateInstanceWithInvalidInterfaces() { $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); @@ -292,7 +294,6 @@ $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'); } reverted: --- b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php +++ a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php @@ -134,6 +134,9 @@ * Tests the getDerivativeFetcher method with a non-existent class. * * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\ + * + * @expectedException \Drupal\Component\Plugin\Exception\InvalidDeriverException + * @expectedExceptionMessage Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist. */ public function testNonExistentDerivativeFetcher() { $definitions = []; @@ -147,7 +150,6 @@ ->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(); } @@ -155,6 +157,9 @@ * Tests the getDerivativeFetcher method with an invalid class. * * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\ + * + * @expectedException \Drupal\Component\Plugin\Exception\InvalidDeriverException + * @expectedExceptionMessage Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface. */ public function testInvalidDerivativeFetcher() { $definitions = []; @@ -168,7 +173,6 @@ ->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(); } reverted: --- b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php +++ a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\Core\Plugin\Discovery; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Plugin\Discovery\HookDiscovery; use Drupal\Tests\UnitTestCase; @@ -119,13 +118,14 @@ * Tests the getDefinition method with an unknown plugin ID. * * @see \Drupal\Core\Plugin\Discovery::getDefinition() + * + * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function testGetDefinitionWithUnknownID() { $this->moduleHandler->expects($this->once()) ->method('getImplementations') ->will($this->returnValue([])); - $this->setExpectedException(PluginNotFoundException::class); $this->hookDiscovery->getDefinition('test_non_existant', TRUE); } reverted: --- b/core/tests/Drupal/Tests/Core/Render/ElementTest.php +++ a/core/tests/Drupal/Tests/Core/Render/ElementTest.php @@ -101,12 +101,14 @@ /** * Tests the children() method with an invalid key. + * + * @expectedException \PHPUnit_Framework_Error + * @expectedExceptionMessage "foo" is an invalid render array key */ public function testInvalidChildren() { $element = [ 'foo' => 'bar', ]; - $this->setExpectedException(\PHPUnit_Framework_Error::class, '"foo" is an invalid render array key'); Element::children($element); } reverted: --- b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php +++ a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php @@ -120,6 +120,9 @@ /** * @covers ::processPlaceholders + * + * @expectedException \AssertionError + * @expectedExceptionMessage At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present. */ public function testProcessPlaceholdersNoStrategies() { // Placeholders but no strategies defined. @@ -128,12 +131,14 @@ ]; $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); } /** * @covers ::processPlaceholders + * + * @expectedException \AssertionError + * @expectedExceptionMessage Processed placeholders must be a subset of all placeholders. */ public function testProcessPlaceholdersWithRoguePlaceholderStrategy() { // Placeholders but no strategies defined. @@ -152,7 +157,6 @@ $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); } reverted: --- b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php +++ a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php @@ -571,6 +571,9 @@ /** * Tests that an element's cache keys cannot be changed during its rendering. + * + * @expectedException \LogicException + * @expectedExceptionMessage Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata. */ public function testOverWriteCacheKeys() { $this->setUpRequest(); @@ -583,7 +586,6 @@ ], '#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); } reverted: --- b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php +++ a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php @@ -847,24 +847,28 @@ /** * @covers ::render * @covers ::doRender + * + * @expectedException \DomainException + * @expectedExceptionMessage The #lazy_builder property must have an array as a value. */ public function testInvalidLazyBuilder() { $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); } /** * @covers ::render * @covers ::doRender + * + * @expectedException \DomainException + * @expectedExceptionMessage The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback. */ public function testInvalidLazyBuilderArguments() { $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); } @@ -892,6 +896,9 @@ /** * @covers ::render * @covers ::doRender + * + * @expectedException \DomainException + * @expectedExceptionMessage A #lazy_builder callback's context may only contain scalar values or NULL. */ public function testNonScalarLazybuilderCallbackContext() { $element = []; @@ -905,13 +912,15 @@ 'array' => ['hi!'], ]]; - $this->setExpectedException(\DomainException::class, "A #lazy_builder callback's context may only contain scalar values or NULL."); $this->renderer->renderRoot($element); } /** * @covers ::render * @covers ::doRender + * + * @expectedException \DomainException + * @expectedExceptionMessage 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. */ public function testChildrenPlusBuilder() { $element = []; @@ -919,13 +928,15 @@ $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); } /** * @covers ::render * @covers ::doRender + * + * @expectedException \DomainException + * @expectedExceptionMessage 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. */ public function testPropertiesPlusBuilder() { $element = []; @@ -933,19 +944,20 @@ $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); } /** * @covers ::render * @covers ::doRender + * + * @expectedException \LogicException + * @expectedExceptionMessage When #create_placeholder is set, a #lazy_builder callback must be present as well. */ public function testCreatePlaceholderPropertyWithoutLazyBuilder() { $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); } reverted: --- b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php +++ a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php @@ -31,6 +31,8 @@ * @covers ::renderRoot * @covers ::render * @covers ::doRender + * + * @expectedException \LogicException */ public function testRenderRecursionWithNestedRenderRoot() { list($complex_child_markup, $parent_markup, $complex_child_template) = $this->setUpRenderRecursionComplexElements(); @@ -39,7 +41,6 @@ $complex_child = $complex_child_template; $callable = function () use ($renderer, $complex_child) { - $this->setExpectedException(\LogicException::class); $renderer->renderRoot($complex_child); }; diff -u b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php --- b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php @@ -76,17 +76,12 @@ ->method('checkRequest') ->with($request) ->willReturn($access_result); - $parameters = $this->router->matchRequest($request); - $expected = [ - RouteObjectInterface::ROUTE_OBJECT => $this->route, - AccessAwareRouterInterface::ACCESS_RESULT => $access_result, - ]; - $this->assertSame($expected, $request->attributes->all()); - $this->assertSame($expected, $parameters); } /** * Tests the matchRequest() function for access denied. + * + * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function testMatchRequestDenied() { $this->setupRouter(); @@ -96,7 +91,6 @@ ->method('checkRequest') ->with($request) ->willReturn($access_result); - $this->setExpectedException(AccessDeniedHttpException::class); $parameters = $this->router->matchRequest($request); $expected = [ AccessAwareRouterInterface::ACCESS_RESULT => $access_result, reverted: --- b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php +++ a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php @@ -75,6 +75,8 @@ /** * @covers ::filter + * @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException + * @expectedExceptionMessage No route found for the specified format xml. */ public function testNoRouteFound() { $collection = new RouteCollection(); @@ -86,7 +88,6 @@ $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); } reverted: --- b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php +++ a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php @@ -29,6 +29,7 @@ /** * @covers ::setTargetUrl + * @expectedException \InvalidArgumentException */ public function testSetTargetUrlWithUntrustedUrl() { $request_context = new RequestContext(); @@ -39,7 +40,6 @@ $redirect_response = new TrustedRedirectResponse('/example'); - $this->setExpectedException(\InvalidArgumentException::class); $redirect_response->setTargetUrl('http://evil-url.com/example'); } reverted: --- b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php +++ a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php @@ -80,11 +80,12 @@ * @covers ::getHashSalt * * @dataProvider providerTestGetHashSaltEmpty + * + * @expectedException \RuntimeException */ public function testGetHashSaltEmpty(array $config) { // Re-create settings with no 'hash_salt' key. $settings = new Settings($config); - $this->setExpectedException(\RuntimeException::class); $settings->getHashSalt(); } @@ -105,9 +106,10 @@ * Ensures settings cannot be serialized. * * @covers ::__sleep + * + * @expectedException \LogicException */ public function testSerialize() { - $this->setExpectedException(\LogicException::class); serialize(new Settings([])); } reverted: --- b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php +++ a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php @@ -82,20 +82,25 @@ } /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage $string ("foo") must be a string. + * * @covers ::__construct */ public function testIsStringAssertion() { $translation = $this->getStringTranslationStub(); - $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); new TranslatableMarkup(new TranslatableMarkup('foo', [], [], $translation)); } /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage $string ("foo") must be a string. + * * @covers ::__construct */ public function testIsStringAssertionWithFormattableMarkup() { + $translation = $this->getStringTranslationStub(); $formattable_string = new FormattableMarkup('@bar', ['@bar' => 'foo']); - $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); new TranslatableMarkup($formattable_string); } reverted: --- b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php +++ a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php @@ -45,10 +45,10 @@ * Tests that dangerous methods cannot be called in entity objects. * * @dataProvider getTwigEntityDangerousMethods + * @expectedException \Twig_Sandbox_SecurityError */ public function testEntityDangerousMethods($template) { $entity = $this->getMock('Drupal\Core\Entity\EntityInterface'); - $this->setExpectedException(\Twig_Sandbox_SecurityError::class); $this->twig->render($template, ['entity' => $entity]); } reverted: --- b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php +++ a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php @@ -95,9 +95,10 @@ * Ensures that passing an explicit group is not supported. * * @covers ::validate + * + * @expectedException \LogicException */ public function testValidateWithGroups() { - $this->setExpectedException(\LogicException::class); $this->recursiveValidator->validate('test', NULL, 'test group'); } @@ -105,9 +106,10 @@ * Ensures that passing a non typed data value is not supported. * * @covers ::validate + * + * @expectedException \InvalidArgumentException */ public function testValidateWithoutTypedData() { - $this->setExpectedException(\InvalidArgumentException::class); $this->recursiveValidator->validate('test'); } @@ -226,6 +228,8 @@ /** * @covers ::validateProperty + * + * @expectedException \LogicException */ public function testValidatePropertyWithCustomGroup() { $tree = [ @@ -235,7 +239,6 @@ ], ]; $typed_data = $this->setupTypedData($tree, 'test_name'); - $this->setExpectedException(\LogicException::class); $this->recursiveValidator->validateProperty($typed_data, 'key1', 'test group'); } @@ -243,9 +246,10 @@ * @covers ::validateProperty * * @dataProvider providerTestValidatePropertyWithInvalidObjects + * + * @expectedException \InvalidArgumentException */ public function testValidatePropertyWithInvalidObjects($object) { - $this->setExpectedException(\InvalidArgumentException::class); $this->recursiveValidator->validateProperty($object, 'key1', NULL); } @@ -285,9 +289,10 @@ * @covers ::validatePropertyValue * * @dataProvider providerTestValidatePropertyWithInvalidObjects + * + * @expectedException \InvalidArgumentException */ public function testValidatePropertyValueWithInvalidObjects($object) { - $this->setExpectedException(\InvalidArgumentException::class); $this->recursiveValidator->validatePropertyValue($object, 'key1', [], NULL); } reverted: --- b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php +++ a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php @@ -102,9 +102,9 @@ * * @covers ::fromUri * @dataProvider providerFromInvalidUri + * @expectedException \InvalidArgumentException */ public function testFromInvalidUri($uri) { - $this->setExpectedException(\InvalidArgumentException::class); $url = Url::fromUri($uri); } @@ -133,6 +133,8 @@ * Tests the createFromRequest method. * * @covers ::createFromRequest + * + * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException */ public function testCreateFromRequest() { $request = Request::create('/test-path'); @@ -142,8 +144,7 @@ ->with($request) ->will($this->throwException(new ResourceNotFoundException())); + $this->assertNull(Url::createFromRequest($request)); - $this->setExpectedException(ResourceNotFoundException::class); - Url::createFromRequest($request); } /** @@ -178,11 +179,12 @@ * @depends testFromUri * @dataProvider providerFromUri * + * @expectedException \UnexpectedValueException + * * @covers ::getRouteName */ public function testGetRouteName($uri) { $url = Url::fromUri($uri); - $this->setExpectedException(\UnexpectedValueException::class); $url->getRouteName(); } @@ -192,11 +194,12 @@ * @depends testFromUri * @dataProvider providerFromUri * + * @expectedException \UnexpectedValueException + * * @covers ::getRouteParameters */ public function testGetRouteParameters($uri) { $url = Url::fromUri($uri); - $this->setExpectedException(\UnexpectedValueException::class); $url->getRouteParameters(); } @@ -207,11 +210,12 @@ * @dataProvider providerFromUri * * @covers ::getInternalPath + * + * @expectedException \Exception */ public function testGetInternalPath($uri) { $url = Url::fromUri($uri); + $this->assertNull($url->getInternalPath()); - $this->setExpectedException(\Exception::class); - $url->getInternalPath(); } /** reverted: --- b/core/tests/Drupal/Tests/Core/UrlTest.php +++ a/core/tests/Drupal/Tests/Core/UrlTest.php @@ -215,10 +215,10 @@ * Tests the fromUserInput method with invalid paths. * * @covers ::fromUserInput + * @expectedException \InvalidArgumentException * @dataProvider providerFromInvalidInternalUri */ public function testFromInvalidUserInput($path) { - $this->setExpectedException(\InvalidArgumentException::class); $url = Url::fromUserInput($path); } @@ -280,6 +280,8 @@ * Tests that an invalid request will thrown an exception. * * @covers ::createFromRequest + * + * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException */ public function testUrlFromRequestInvalid() { $request = Request::create('/test-path'); @@ -289,8 +291,7 @@ ->with($request) ->will($this->throwException(new ResourceNotFoundException())); + $this->assertNull(Url::createFromRequest($request)); - $this->setExpectedException(ResourceNotFoundException::class); - Url::createFromRequest($request); } /** @@ -314,10 +315,11 @@ * * @depends testUrlFromRequest * + * @expectedException \UnexpectedValueException + * * @covers ::getUri */ public function testGetUriForInternalUrl($urls) { - $this->setExpectedException(\UnexpectedValueException::class); foreach ($urls as $url) { $url->getUri(); } @@ -416,10 +418,10 @@ * Tests the getRouteName() with an external URL. * * @covers ::getRouteName + * @expectedException \UnexpectedValueException */ public function testGetRouteNameWithExternalUrl() { $url = Url::fromUri('http://example.com'); - $this->setExpectedException(\UnexpectedValueException::class); $url->getRouteName(); } @@ -443,10 +445,10 @@ * Tests the getRouteParameters() with an external URL. * * @covers ::getRouteParameters + * @expectedException \UnexpectedValueException */ public function testGetRouteParametersWithExternalUrl() { $url = Url::fromUri('http://example.com'); - $this->setExpectedException(\UnexpectedValueException::class); $url->getRouteParameters(); } @@ -628,6 +630,7 @@ * Tests the fromUri() method with an invalid entity: URI. * * @covers ::fromUri + * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException */ public function testInvalidEntityUriParameter() { // Make the mocked URL generator behave like the actual one. @@ -636,7 +639,6 @@ ->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(); } @@ -751,10 +753,10 @@ * Tests the fromUri() method with an invalid internal: URI. * * @covers ::fromUri + * @expectedException \InvalidArgumentException * @dataProvider providerFromInvalidInternalUri */ public function testFromInvalidInternalUri($path) { - $this->setExpectedException(\InvalidArgumentException::class); Url::fromUri('internal:' . $path); } @@ -823,10 +825,10 @@ } /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The route URI 'route:' is invalid. - * @covers ::fromUri */ public function testFromRouteUriWithMissingRouteName() { - $this->setExpectedException(\InvalidArgumentException::class, "The route URI 'route:' is invalid."); Url::fromUri('route:'); } reverted: --- b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -56,17 +56,17 @@ /** * @covers ::assemble + * @expectedException \InvalidArgumentException */ public function testAssembleWithNeitherExternalNorDomainLocalUri() { - $this->setExpectedException(\InvalidArgumentException::class); $this->unroutedUrlAssembler->assemble('wrong-url'); } /** * @covers ::assemble + * @expectedException \InvalidArgumentException */ public function testAssembleWithLeadingSlash() { - $this->setExpectedException(\InvalidArgumentException::class); $this->unroutedUrlAssembler->assemble('/drupal.org'); }