diff --git a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php index 9123129..6612e63 100644 --- a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php +++ b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php @@ -28,14 +28,13 @@ class BigPipeResponseAttachmentsProcessorTest extends UnitTestCase { * @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(); $big_pipe_response_attachments_processor->processAttachments($non_html_response); + $this->setExpectedException(\AssertionError::class); } function nonHtmlResponseProvider() { diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php index 9e5c82c..0e0f751 100644 --- a/core/modules/contact/tests/src/Unit/MailHandlerTest.php +++ b/core/modules/contact/tests/src/Unit/MailHandlerTest.php @@ -3,6 +3,7 @@ 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; @@ -94,9 +95,6 @@ class MailHandlerTest extends UnitTestCase { /** * Tests the children() method with an invalid key. * - * @expectedException \Drupal\contact\MailHandlerException - * @expectedExceptionMessage Unable to determine message recipient - * * @covers ::sendMailMessages */ public function testInvalidRecipient() { @@ -122,6 +120,7 @@ class MailHandlerTest extends UnitTestCase { ->method('isAnonymous') ->willReturn(FALSE); $this->contactMailHandler->sendMailMessages($message, $sender); + $this->setExpectedException(MailHandlerException::class, 'Unable to determine message recipient'); } /** diff --git a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php index 3f687d4..e7c7c82 100644 --- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @@ -160,9 +160,6 @@ class FieldConfigEntityUnitTest extends UnitTestCase { /** * 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'); @@ -210,6 +207,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { 'field_type' => 'test_field', ), $this->entityTypeId); $field->calculateDependencies(); + $this->setExpectedException(\LogicException::class, 'Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.'); } /** diff --git a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php index 550c185..1555f42 100644 --- a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php +++ b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\hal\Unit; use Drupal\hal\Normalizer\FieldItemNormalizer; +use Symfony\Component\Serializer\Exception\InvalidArgumentException; /** * @coversDefaultClass \Drupal\hal\Normalizer\FieldItemNormalizer @@ -17,13 +18,13 @@ class FieldItemNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenorma * Context for FieldItemNormalizer::denormalize(). * * @dataProvider providerNormalizerDenormalizeExceptions - * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testFieldItemNormalizerDenormalizeExceptions($context) { $field_item_normalizer = new FieldItemNormalizer(); $data = array(); $class = array(); $field_item_normalizer->denormalize($data, $class, NULL, $context); + $this->setExpectedException(InvalidArgumentException::class); } } diff --git a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php index a257209..57aa5ff 100644 --- a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php +++ b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\hal\Unit; use Drupal\hal\Normalizer\FieldNormalizer; +use Symfony\Component\Serializer\Exception\InvalidArgumentException; /** * @coversDefaultClass \Drupal\hal\Normalizer\FieldNormalizer @@ -17,13 +18,13 @@ class FieldNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalize * Context for FieldNormalizer::denormalize(). * * @dataProvider providerNormalizerDenormalizeExceptions - * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testFieldNormalizerDenormalizeExceptions($context) { $field_item_normalizer = new FieldNormalizer(); $data = array(); $class = array(); $field_item_normalizer->denormalize($data, $class, NULL, $context); + $this->setExpectedException(InvalidArgumentException::class); } } diff --git a/core/modules/locale/tests/src/Unit/StringBaseTest.php b/core/modules/locale/tests/src/Unit/StringBaseTest.php index 58ea0ff..298049b 100644 --- a/core/modules/locale/tests/src/Unit/StringBaseTest.php +++ b/core/modules/locale/tests/src/Unit/StringBaseTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\locale\Unit; use Drupal\locale\SourceString; +use Drupal\locale\StringStorageException; use Drupal\Tests\UnitTestCase; /** @@ -13,23 +14,21 @@ class StringBaseTest extends UnitTestCase { /** * @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']); $string->save(); + $this->setExpectedException(StringStorageException::class, 'The string cannot be saved because its not bound to a storage: test'); } /** * @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']); $string->delete(); + $this->setExpectedException(StringStorageException::class, 'The string cannot be deleted because its not bound to a storage: test'); } } diff --git a/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php b/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php index 427d413..fc5faa3 100644 --- a/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\migrate\Kernel\process; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\KernelTests\Core\File\FileTestBase; +use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Plugin\migrate\process\FileCopy; use Drupal\migrate\Row; @@ -135,14 +136,11 @@ class CopyFileTest extends FileTestBase { /** * 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->doImport($source, 'public://wontmatter.jpg'); + $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist"); } /** diff --git a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php index ee75e45..5dfe463 100644 --- a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\migrate\Kernel\process; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\KernelTests\Core\File\FileTestBase; +use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\FileCopy; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Plugin\MigrateProcessInterface; @@ -110,14 +111,11 @@ class FileCopyTest extends FileTestBase { /** * 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->doTransform($source, 'public://wontmatter.jpg'); + $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist"); } /** diff --git a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php index 4a462e9..0782d7f 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php @@ -12,6 +12,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; 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; @@ -149,11 +150,11 @@ class MigrateSourceTest extends MigrateTestCase { /** * @covers ::__construct - * @expectedException \Drupal\migrate\MigrateException */ public function testHighwaterTrackChangesIncompatible() { $source_config = ['track_changes' => TRUE, 'high_water_property' => ['name' => 'something']]; $this->getSource($source_config); + $this->setExpectedException(MigrateException::class); } /** diff --git a/core/modules/migrate/tests/src/Unit/MigrationTest.php b/core/modules/migrate/tests/src/Unit/MigrationTest.php index 57ff64c..6dc3976 100644 --- a/core/modules/migrate/tests/src/Unit/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrationTest.php @@ -27,9 +27,6 @@ class MigrationTest extends UnitTestCase { * Tests checking requirements for source plugins. * * @covers ::checkRequirements - * - * @expectedException \Drupal\migrate\Exception\RequirementsException - * @expectedExceptionMessage Missing source requirement */ public function testRequirementsForSourcePlugin() { $migration = new TestMigration(); @@ -44,15 +41,13 @@ class MigrationTest extends UnitTestCase { $migration->setDestinationPlugin($destination_plugin); $migration->checkRequirements(); + $this->setExpectedException(RequirementsException::class, 'Missing source requirement'); } /** * Tests checking requirements for destination plugins. * * @covers ::checkRequirements - * - * @expectedException \Drupal\migrate\Exception\RequirementsException - * @expectedExceptionMessage Missing destination requirement */ public function testRequirementsForDestinationPlugin() { $migration = new TestMigration(); @@ -67,15 +62,13 @@ class MigrationTest extends UnitTestCase { $migration->setDestinationPlugin($destination_plugin); $migration->checkRequirements(); + $this->setExpectedException(RequirementsException::class, 'Missing destination requirement'); } /** * 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(); @@ -113,6 +106,7 @@ class MigrationTest extends UnitTestCase { ->willReturn(['test_b' => $migration_b, 'test_c' => $migration_c, 'test_d' => $migration_d]); $migration->checkRequirements(); + $this->setExpectedException(RequirementsException::class, 'Missing migrations test_a, test_c'); } } diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php index e5d63c4..550bfe8 100644 --- a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php +++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityManagerInterface; 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; @@ -84,8 +85,6 @@ class EntityContentBaseTest extends UnitTestCase { * 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 = []; @@ -97,13 +96,11 @@ class EntityContentBaseTest extends UnitTestCase { $this->prophesize(FieldTypePluginManagerInterface::class)->reveal()); $destination->setEntity(FALSE); $destination->import(new Row()); + $this->setExpectedException(MigrateException::class, 'Unable to get entity'); } /** * 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. @@ -126,6 +123,7 @@ class EntityContentBaseTest extends UnitTestCase { $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() ); $destination->getIds(); + $this->setExpectedException(MigrateException::class, 'This entity type does not support translation'); } } diff --git a/core/modules/migrate/tests/src/Unit/RowTest.php b/core/modules/migrate/tests/src/Unit/RowTest.php index ec04f82..d0e9f64 100644 --- a/core/modules/migrate/tests/src/Unit/RowTest.php +++ b/core/modules/migrate/tests/src/Unit/RowTest.php @@ -73,24 +73,22 @@ class RowTest extends UnitTestCase { /** * Tests object creation: invalid values. - * - * @expectedException \Exception */ public function testRowWithInvalidData() { $invalid_values = array( 'title' => 'node X', ); $row = new Row($invalid_values, $this->testSourceIds); + $this->setExpectedException(\Exception::class); } /** * Tests source immutability after freeze. - * - * @expectedException \Exception */ public function testSourceFreeze() { $row = new Row($this->testValues, $this->testSourceIds); $row->rehash(); + $this->setExpectedException(\Exception::class); $this->assertSame($this->testHash, $row->getHash(), 'Correct hash.'); $row->setSourceProperty('title', 'new title'); $row->rehash(); @@ -101,14 +99,12 @@ class RowTest extends UnitTestCase { /** * 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(); $row->setSourceProperty('title', 'new title'); + $this->setExpectedException(\Exception::class, "The source is frozen and can't be changed any more"); } /** diff --git a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php index 1d0d4c3..7a1dac1 100644 --- a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\migrate\Unit\process; +use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\Concat; /** @@ -34,11 +35,10 @@ class ConcatTest extends MigrateProcessTestCase { /** * Test concat fails properly on non-arrays. - * - * @expectedException \Drupal\migrate\MigrateException */ public function testConcatWithNonArray() { $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class); } /** diff --git a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php index 3245e60..25df581 100644 --- a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate\Unit\process; +use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\Explode; use Drupal\migrate\Plugin\migrate\process\Concat; @@ -53,25 +54,19 @@ class ExplodeTest extends MigrateProcessTestCase { /** * Test explode fails properly on non-strings. - * - * @expectedException \Drupal\migrate\MigrateException - * - * @expectedExceptionMessage is not a string */ public function testExplodeWithNonString() { $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class, 'is not a string'); } /** * Test explode fails with empty delimiter. - * - * @expectedException \Drupal\migrate\MigrateException - * - * @expectedExceptionMessage delimiter is empty */ public function testExplodeWithEmptyDelimiter() { $plugin = new Explode(['delimiter' => ''], 'map', []); $plugin->transform('foo,bar', $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class, 'delimiter is empty'); } } diff --git a/core/modules/migrate/tests/src/Unit/process/ExtractTest.php b/core/modules/migrate/tests/src/Unit/process/ExtractTest.php index 26c2cfe..bbf53c5 100644 --- a/core/modules/migrate/tests/src/Unit/process/ExtractTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ExtractTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate\Unit\process; +use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\Extract; /** @@ -29,22 +30,18 @@ class ExtractTest extends MigrateProcessTestCase { /** * Tests invalid input. - * - * @expectedException \Drupal\migrate\MigrateException - * @expectedExceptionMessage Input should be an array. */ public function testExtractFromString() { $this->plugin->transform('bar', $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class, 'Input should be an array.'); } /** * Tests unsuccessful extraction. - * - * @expectedException \Drupal\migrate\MigrateException - * @expectedExceptionMessage Array index missing, extraction failed. */ public function testExtractFail() { $this->plugin->transform(array('bar' => 'foo'), $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class, 'Array index missing, extraction failed.'); } /** diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php index 4eb52da..4d3623f 100644 --- a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php @@ -3,6 +3,7 @@ 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; @@ -89,8 +90,6 @@ class MigrationTest extends MigrateProcessTestCase { /** * Tests that processing is skipped when the input value is empty. - * - * @expectedException \Drupal\migrate\MigrateSkipProcessException */ public function testSkipOnEmpty() { $migration_plugin = $this->prophesize(MigrationInterface::class); @@ -103,6 +102,7 @@ class MigrationTest extends MigrateProcessTestCase { $migration_plugin->id()->willReturn(uniqid()); $migration = new Migration($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal()); $migration->transform(0, $this->migrateExecutable, $this->row, 'foo'); + $this->setExpectedException(MigrateSkipProcessException::class); } /** diff --git a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php index bf40dac..19d3f90 100644 --- a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php @@ -1,6 +1,8 @@ transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateSkipProcessException::class); } /** @@ -33,12 +35,12 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { /** * @covers ::row - * @expectedException \Drupal\migrate\MigrateSkipRowException */ public function testRowSkipsOnEmpty() { $configuration['method'] = 'row'; (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateSkipRowException::class); } /** diff --git a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php index 59db2e5..68097b3 100644 --- a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php +++ b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\migrate\Unit\process; +use Drupal\migrate\MigrateException; +use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Plugin\migrate\process\StaticMap; /** @@ -38,20 +40,18 @@ class StaticMapTest extends MigrateProcessTestCase { /** * Tests when the source is empty. - * - * @expectedException \Drupal\migrate\MigrateException */ public function testMapwithEmptySource() { $this->plugin->transform(array(), $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class); } /** * Tests when the source is invalid. - * - * @expectedException \Drupal\migrate\MigrateSkipRowException */ public function testMapwithInvalidSource() { $this->plugin->transform(array('bar'), $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateSkipRowException::class); } /** @@ -78,9 +78,6 @@ class StaticMapTest extends MigrateProcessTestCase { /** * 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'; @@ -88,6 +85,7 @@ class StaticMapTest extends MigrateProcessTestCase { $configuration['bypass'] = TRUE; $this->plugin = new StaticMap($configuration, 'map', array()); $this->plugin->transform(array('bar'), $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class, 'Setting both default_value and bypass is invalid.'); } } diff --git a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php index fb84509..006ac08 100644 --- a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\migrate\Unit\process; +use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\process\Substr; /** @@ -55,38 +56,32 @@ class SubstrTest extends MigrateProcessTestCase { /** * 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->plugin->transform(['Captain Janeway'], $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class, 'The input value must be a string.'); } /** * 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->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->setExpectedException(MigrateException::class, 'The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.'); } /** * 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->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); + $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.'); } } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php index 7021070..27901fe 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\serialization\Unit\Normalizer; use Drupal\serialization\Normalizer\EntityNormalizer; use Drupal\Tests\UnitTestCase; +use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** * @coversDefaultClass \Drupal\serialization\Normalizer\EntityNormalizer @@ -82,11 +83,10 @@ class EntityNormalizerTest extends UnitTestCase { * Tests the denormalize() method with no entity type provided in context. * * @covers ::denormalize - * - * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException */ public function testDenormalizeWithNoEntityType() { $this->entityNormalizer->denormalize(array(), 'Drupal\Core\Entity\ContentEntityBase'); + $this->setExpectedException(UnexpectedValueException::class); } /** @@ -178,8 +178,6 @@ class EntityNormalizerTest extends UnitTestCase { /** * Tests the denormalize method with a bundle property. * - * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException - * * @covers ::denormalize */ public function testDenormalizeWithInvalidBundle() { @@ -244,6 +242,7 @@ class EntityNormalizerTest extends UnitTestCase { $this->entityNormalizer->denormalize($test_data, 'Drupal\Core\Entity\ContentEntityBase', NULL, ['entity_type' => 'test']); + $this->setExpectedException(UnexpectedValueException::class); } /** diff --git a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php index df98377..ead5670 100644 --- a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php +++ b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php @@ -10,6 +10,7 @@ namespace Drupal\Tests\simpletest\Unit; 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; @@ -235,8 +236,6 @@ class TestInfoParsingTest extends UnitTestCase { /** * @covers ::getTestInfo - * @expectedException \Drupal\simpletest\Exception\MissingGroupException - * @expectedExceptionMessage Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest */ public function testTestInfoParserMissingGroup() { $classname = 'Drupal\KernelTests\field\BulkDeleteTest'; @@ -246,6 +245,7 @@ class TestInfoParsingTest extends UnitTestCase { */ EOT; TestDiscovery::getTestInfo($classname, $doc_comment); + $this->setExpectedException(MissingGroupException::class, 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest'); } /** diff --git a/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php b/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php index 16bb08f..50ea7e7 100644 --- a/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php +++ b/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php @@ -6,6 +6,7 @@ use Drupal\accept_header_routing_test\Routing\AcceptHeaderMatcher; 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. @@ -86,9 +87,6 @@ class AcceptHeaderMatcherTest extends UnitTestCase { /** * 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. @@ -104,6 +102,7 @@ class AcceptHeaderMatcherTest extends UnitTestCase { $this->matcher->filter($routes, $request); $this->matcher->filter($routes, $request); $this->fail('No exception was thrown.'); + $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified formats application/json text/xml.'); } } diff --git a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php index 1aa2f66..a456a29 100644 --- a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php +++ b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php @@ -8,6 +8,7 @@ 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; @@ -42,8 +43,6 @@ class DbCommandBaseTest extends KernelTestBase { /** * Invalid database names will throw a useful exception. - * - * @expectedException \Drupal\Core\Database\ConnectionNotDefinedException */ public function testSpecifyDatabaseDoesNotExist() { $command = new DbCommandBaseTester(); @@ -52,6 +51,7 @@ class DbCommandBaseTest extends KernelTestBase { '--database' => 'dne' ]); $command->getDatabaseConnection($command_tester->getInput()); + $this->setExpectedException(ConnectionNotDefinedException::class); } /** diff --git a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php index 515c862..9de3ce8 100644 --- a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\user\Unit; use Drupal\Tests\UnitTestCase; use Drupal\user\PrivateTempStore; +use Drupal\user\TempStoreException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -121,7 +122,6 @@ class PrivateTempStoreTest extends UnitTestCase { * Tests the set() method with no lock available. * * @covers ::set - * @expectedException \Drupal\user\TempStoreException */ public function testSetWithNoLockAvailable() { $this->lock->expects($this->at(0)) @@ -140,6 +140,7 @@ class PrivateTempStoreTest extends UnitTestCase { ->method('getCollectionName'); $this->tempStore->set('test', 'value'); + $this->setExpectedException(TempStoreException::class); } /** @@ -220,7 +221,6 @@ class PrivateTempStoreTest extends UnitTestCase { * Tests the delete() method with no lock available. * * @covers ::delete - * @expectedException \Drupal\user\TempStoreException */ public function testDeleteWithNoLockAvailable() { $this->keyValue->expects($this->once()) @@ -243,6 +243,7 @@ class PrivateTempStoreTest extends UnitTestCase { ->method('getCollectionName'); $this->tempStore->delete('test'); + $this->setExpectedException(TempStoreException::class); } /** diff --git a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php index 15a4ec6..18d4262 100644 --- a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\user\Unit; use Drupal\Tests\UnitTestCase; use Drupal\user\SharedTempStore; +use Drupal\user\TempStoreException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -132,7 +133,6 @@ class SharedTempStoreTest extends UnitTestCase { * Tests the set() method with no lock available. * * @covers ::set - * @expectedException \Drupal\user\TempStoreException */ public function testSetWithNoLockAvailable() { $this->lock->expects($this->at(0)) @@ -151,6 +151,7 @@ class SharedTempStoreTest extends UnitTestCase { ->method('getCollectionName'); $this->tempStore->set('test', 'value'); + $this->setExpectedException(TempStoreException::class); } /** @@ -296,7 +297,6 @@ class SharedTempStoreTest extends UnitTestCase { * Tests the delete() method with no lock available. * * @covers ::delete - * @expectedException \Drupal\user\TempStoreException */ public function testDeleteWithNoLockAvailable() { $this->lock->expects($this->at(0)) @@ -315,6 +315,7 @@ class SharedTempStoreTest extends UnitTestCase { ->method('getCollectionName'); $this->tempStore->delete('test'); + $this->setExpectedException(TempStoreException::class); } /** diff --git a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php index d6b2a1e..4be58fd 100644 --- a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php +++ b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php @@ -9,6 +9,8 @@ use Drupal\views\Controller\ViewAjaxController; 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 @@ -113,18 +115,15 @@ class ViewAjaxControllerTest extends UnitTestCase { /** * Tests missing view_name and view_display_id - * - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testMissingViewName() { $request = new Request(); $this->viewAjaxController->ajaxView($request); + $this->setExpectedException(NotFoundHttpException::class); } /** * Tests with view_name and view_display_id but not existing view. - * - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testMissingView() { $request = new Request(); @@ -137,12 +136,11 @@ class ViewAjaxControllerTest extends UnitTestCase { ->will($this->returnValue(FALSE)); $this->viewAjaxController->ajaxView($request); + $this->setExpectedException(NotFoundHttpException::class); } /** * Tests a view without having access to it. - * - * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function testAccessDeniedView() { $request = new Request(); @@ -171,6 +169,7 @@ class ViewAjaxControllerTest extends UnitTestCase { ->will($this->returnValue($executable)); $this->viewAjaxController->ajaxView($request); + $this->setExpectedException(AccessDeniedHttpException::class); } /** diff --git a/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php b/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php index 55ead47..03ae977 100644 --- a/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php @@ -30,10 +30,10 @@ class PageTest extends UnitTestCase { /** * @covers ::buildBasicRenderable - * @expectedException \BadFunctionCallException */ public function testBuildBasicRenderableWithMissingRoute() { Page::buildBasicRenderable('test_view', 'page_1', []); + $this->setExpectedException(\BadFunctionCallException::class); } } diff --git a/core/modules/views/tests/src/Unit/ViewExecutableTest.php b/core/modules/views/tests/src/Unit/ViewExecutableTest.php index fe64ec2..97f47f8 100644 --- a/core/modules/views/tests/src/Unit/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Unit/ViewExecutableTest.php @@ -182,8 +182,6 @@ class ViewExecutableTest extends UnitTestCase { } /** - * @expectedException \InvalidArgumentException - * * @covers ::getUrl */ public function testGetUrlWithoutRouterDisplay() { @@ -194,6 +192,7 @@ class ViewExecutableTest extends UnitTestCase { $this->executable->display_handler = $this->displayHandler; $this->executable->getUrl(); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php index cd42ad1..587dd03 100644 --- a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php +++ b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php @@ -107,11 +107,11 @@ class SafeMarkupKernelTest extends KernelTestBase { /** * @dataProvider providerTestSafeMarkupUriWithException - * @expectedException \InvalidArgumentException */ public function testSafeMarkupUriWithExceptionUri($string, $uri) { // Should throw an \InvalidArgumentException, due to Uri::toString(). $args = self::getSafeMarkupUriArgs($uri); + $this->setExpectedException(\InvalidArgumentException::class); SafeMarkup::format($string, $args); } diff --git a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php index 98423ca..00bf8ac 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php @@ -82,11 +82,10 @@ class ThemeRenderAndAutoescapeTest extends KernelTestBase { /** * Ensures invalid content is handled correctly. - * - * @expectedException \Exception */ public function testThemeEscapeAndRenderNotPrintable() { theme_render_and_autoescape(new NonPrintable()); + $this->setExpectedException(\Exception::class); } /** diff --git a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php index b8be130..ad0943a 100644 --- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php +++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php @@ -100,13 +100,13 @@ class DateTimePlusTest extends UnitTestCase { * Timezone argument for DateTimePlus. * * @dataProvider providerTestInvalidDateArrays - * @expectedException \Exception */ public function testInvalidDateArrays($input, $timezone) { $this->assertInstanceOf( '\Drupal\Component\DateTimePlus', DateTimePlus::createFromArray($input, $timezone) ); + $this->setExpectedException(\Exception::class); } /** @@ -236,10 +236,10 @@ class DateTimePlusTest extends UnitTestCase { * Message to print if no errors are thrown by the invalid dates. * * @dataProvider providerTestInvalidDates - * @expectedException \Exception */ public function testInvalidDates($input, $timezone, $format, $message) { DateTimePlus::createFromFormat($format, $input, $timezone); + $this->setExpectedException(\Exception::class); } /** diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index 3c89804..da63c58 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -9,6 +9,11 @@ namespace Drupal\Tests\Component\DependencyInjection; 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; /** @@ -59,13 +64,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * 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; $container = new $this->containerClass($container_definition); + $this->setExpectedException(InvalidArgumentException::class); } /** @@ -85,22 +89,20 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::getParameter * @covers ::getParameterAlternatives * @covers ::getAlternatives - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ public function testGetParameterIfNotFound() { $this->container->getParameter('parameter_that_does_not_exist'); + $this->setExpectedException(ParameterNotFoundException::class); } /** * Tests that Container::getParameter() works properly for NULL parameters. * * @covers ::getParameter - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ public function testGetParameterIfNotFoundBecauseNull() { $this->container->getParameter(NULL); + $this->setExpectedException(ParameterNotFoundException::class); } /** @@ -130,12 +132,11 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * 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->container->setParameter('some_config', 'new_value'); + $this->setExpectedException(LogicException::class); } /** @@ -235,12 +236,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { /** * Tests that Container::get() for circular dependencies works properly. - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException * @covers ::get * @covers ::createService */ public function testGetForCircularServices() { $this->container->get('circular_dependency'); + $this->setExpectedException(ServiceCircularReferenceException::class); } /** @@ -250,11 +251,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::createService * @covers ::getAlternatives * @covers ::getServiceAlternatives - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantService() { $this->container->get('service_not_exists'); + $this->setExpectedException(ServiceNotFoundException::class); } /** @@ -295,8 +295,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @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); @@ -305,6 +303,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { // Reset the service. $this->container->set('service_parameter_not_exists', NULL); $this->container->get('service_parameter_not_exists'); + $this->setExpectedException(InvalidArgumentException::class); } /** @@ -313,11 +312,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetForNonExistantParameterDependencyWithException() { $this->container->get('service_parameter_not_exists'); + $this->setExpectedException(InvalidArgumentException::class); } /** @@ -339,11 +337,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::createService * @covers ::resolveServicesAndParameters * @covers ::getAlternatives - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantServiceDependencyWithException() { $this->container->get('service_dependency_not_exists'); + $this->setExpectedException(ServiceNotFoundException::class); } /** @@ -360,11 +357,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * Tests that Container::get() for NULL service works properly. * @covers ::get * @covers ::createService - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantNULLService() { $this->container->get(NULL); + $this->setExpectedException(ServiceNotFoundException::class); } /** @@ -386,12 +382,11 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @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->container->get('service_not_exists'); + $this->setExpectedException(ServiceNotFoundException::class); } /** @@ -424,11 +419,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * * @covers ::get * @covers ::createService - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetForSyntheticServiceWithException() { $this->container->get('synthetic'); + $this->setExpectedException(RuntimeException::class); } /** @@ -464,11 +458,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * * @covers ::get * @covers ::createService - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetForWrongFactory() { $this->container->get('wrong_factory'); + $this->setExpectedException(RuntimeException::class); } /** @@ -503,11 +496,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * * @covers ::get * @covers ::createService - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetForConfiguratorWithException() { $this->container->get('configurable_service_exception'); + $this->setExpectedException(InvalidArgumentException::class); } /** @@ -602,11 +594,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testResolveServicesAndParametersForInvalidArgument() { $this->container->get('invalid_argument_service'); + $this->setExpectedException(InvalidArgumentException::class); } /** @@ -615,8 +606,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @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 @@ -624,6 +613,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { if (!$this->machineFormat) { throw new InvalidArgumentException('Simulating the test failure.'); } + $this->setExpectedException(InvalidArgumentException::class); $this->container->get('invalid_arguments_service'); } @@ -671,8 +661,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::hasScope * @covers ::isScopeActive * - * @expectedException \BadMethodCallException - * * @dataProvider scopeExceptionTestProvider */ public function testScopeFunctionsWithException($method, $argument) { @@ -682,6 +670,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { ); $callable($argument); + $this->setExpectedException(\BadMethodCallException::class); } /** diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 49b6556..b85e9af 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -8,6 +8,8 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\ExpressionLanguage\Expression; @@ -481,8 +483,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { * 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,6 +491,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->containerBuilder->getDefinitions()->willReturn($services); $this->dumper->getArray(); + $this->setExpectedException(InvalidArgumentException::class); } /** @@ -554,8 +555,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { * getDecoratedService(). * * @covers ::getServiceDefinition - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetServiceDefinitionForDecoratedService() { $bar_definition = new Definition('\stdClass'); @@ -564,14 +563,13 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->containerBuilder->getDefinitions()->willReturn($services); $this->dumper->getArray(); + $this->setExpectedException(InvalidArgumentException::class); } /** * Tests that the correct RuntimeException is thrown for expressions. * * @covers ::dumpValue - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetServiceDefinitionForExpression() { $expression = new Expression(); @@ -582,14 +580,13 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->containerBuilder->getDefinitions()->willReturn($services); $this->dumper->getArray(); + $this->setExpectedException(RuntimeException::class); } /** * 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(); @@ -600,14 +597,13 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->containerBuilder->getDefinitions()->willReturn($services); $this->dumper->getArray(); + $this->setExpectedException(RuntimeException::class); } /** * 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'); @@ -618,6 +614,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->containerBuilder->getDefinitions()->willReturn($services); $this->dumper->getArray(); + $this->setExpectedException(RuntimeException::class); } /** diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php index b4d8de9..d0886a6 100644 --- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php @@ -55,13 +55,11 @@ class FileCacheFactoryTest extends UnitTestCase { /** * @covers ::get - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Required prefix configuration is missing */ public function testGetNoPrefix() { FileCacheFactory::setPrefix(NULL); FileCacheFactory::get('test_foo_settings', []); + $this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing'); } /** diff --git a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php index 1fc805b..d43b5f7 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php @@ -3,6 +3,7 @@ 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; @@ -47,45 +48,37 @@ class DefaultFactoryTest extends UnitTestCase { * 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() { DefaultFactory::getPluginClass('cherry', []); + $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); } /** * 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); DefaultFactory::getPluginClass('cherry', $plugin_definition); + $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); } /** * 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() { DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']); + $this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.'); } /** * 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'; @@ -94,6 +87,7 @@ class DefaultFactoryTest extends UnitTestCase { ->method('getClass') ->willReturn($plugin_class); DefaultFactory::getPluginClass('kiwifruit', $plugin_definition); + $this->setExpectedException(PluginException::class); } /** @@ -128,21 +122,17 @@ class DefaultFactoryTest extends UnitTestCase { * 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; DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::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.'); } /** * Tests getPluginClass() with a required interface but no implementation. * * @covers ::getPluginClass - * - * @expectedException \Drupal\Component\Plugin\Exception\PluginException */ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() { $plugin_class = Kale::class; @@ -151,6 +141,7 @@ class DefaultFactoryTest extends UnitTestCase { ->method('getClass') ->willReturn($plugin_class); DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class); + $this->setExpectedException(PluginException::class); } } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php index 9f747f9..8dbc733 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Component\Plugin\Discovery; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Tests\UnitTestCase; /** @@ -58,7 +59,6 @@ class DiscoveryTraitTest extends UnitTestCase { /** * @covers ::doGetDefinition - * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException * @dataProvider providerDoGetDefinitionException * @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException */ @@ -68,6 +68,7 @@ class DiscoveryTraitTest extends UnitTestCase { // Un-protect the method using reflection. $method_ref = new \ReflectionMethod($trait, 'doGetDefinition'); $method_ref->setAccessible(TRUE); + $this->setExpectedException(PluginNotFoundException::class); // Call doGetDefinition, with $exception_on_invalid always TRUE. $this->assertSame( $expected, @@ -96,7 +97,6 @@ class DiscoveryTraitTest extends UnitTestCase { /** * @covers ::getDefinition - * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException * @dataProvider providerDoGetDefinitionException * @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException */ @@ -113,6 +113,7 @@ class DiscoveryTraitTest extends UnitTestCase { $expected, $trait->getDefinition($plugin_id, TRUE) ); + $this->setExpectedException(PluginNotFoundException::class); } /** diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php index ef0d7fb..5a423cb 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Component\Serialization; +use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Serialization\YamlPecl; /** @@ -74,10 +75,10 @@ foo: * Tests that invalid YAML throws an exception. * * @covers ::errorHandler - * @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException */ public function testError() { YamlPecl::decode('foo: [ads'); + $this->setExpectedException(InvalidDataTypeException::class); } } diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php index 3101efe..df45f85 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Component\Serialization; +use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Serialization\YamlSymfony; /** @@ -56,10 +57,10 @@ class YamlSymfonyTest extends YamlTestBase { * Tests that invalid YAML throws an exception. * * @covers ::decode - * @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException */ public function testError() { YamlSymfony::decode('foo: [ads'); + $this->setExpectedException(InvalidDataTypeException::class); } } diff --git a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php index 878bbfd..9fe48f2 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php @@ -121,9 +121,6 @@ class ArgumentsResolverTest extends UnitTestCase { * 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'); @@ -132,6 +129,7 @@ class ArgumentsResolverTest extends UnitTestCase { $callable = function($route) {}; $arguments = $resolver->getArguments($callable); + $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); $this->assertNull($arguments); } @@ -152,9 +150,6 @@ class ArgumentsResolverTest extends UnitTestCase { /** * Tests handleUnresolvedArgument() for a scalar argument. - * - * @expectedException \RuntimeException - * @expectedExceptionMessage requires a value for the "$foo" argument. */ public function testHandleNotUpcastedArgument() { $objects = ['foo' => 'bar']; @@ -163,20 +158,19 @@ class ArgumentsResolverTest extends UnitTestCase { $callable = function(\stdClass $foo) {}; $arguments = $resolver->getArguments($callable); + $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); $this->assertNull($arguments); } /** * 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->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); $this->assertNull($arguments); } diff --git a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php index 42d6015..7cd4375 100644 --- a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php @@ -69,7 +69,6 @@ class CryptTest extends UnitTestCase { * Tests the hmacBase64 method with invalid parameters. * * @dataProvider providerTestHmacBase64Invalid - * @expectedException InvalidArgumentException * @covers ::hmacBase64 * * @param string $data @@ -79,6 +78,7 @@ class CryptTest extends UnitTestCase { */ public function testHmacBase64Invalid($data, $key) { Crypt::hmacBase64($data, $key); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php index 6a106c7..e5421ce 100644 --- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php @@ -332,10 +332,10 @@ class HtmlTest extends UnitTestCase { /** * @covers ::transformRootRelativeUrlsToAbsolute * @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion - * @expectedException \AssertionError */ public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) { Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host); + $this->setExpectedException(\AssertionError::class); } /** diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php index b677585..307da44 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -57,7 +57,6 @@ class RandomTest extends UnitTestCase { * 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 @@ -67,13 +66,13 @@ class RandomTest extends UnitTestCase { $str = $random->name(1, TRUE); $names[$str] = TRUE; } + $this->setExpectedException(\RuntimeException::class); } /** * 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 @@ -83,6 +82,7 @@ class RandomTest extends UnitTestCase { $str = $random->string(1, TRUE); $names[$str] = TRUE; } + $this->setExpectedException(\RuntimeException::class); } /** diff --git a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php index 0aa29a6..2150486 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php @@ -15,22 +15,20 @@ class RectangleTest extends UnitTestCase { * Tests wrong rectangle width. * * @covers ::rotate - * - * @expectedException \InvalidArgumentException */ public function testWrongWidth() { $rect = new Rectangle(-40, 20); + $this->setExpectedException(\InvalidArgumentException::class); } /** * Tests wrong rectangle height. * * @covers ::rotate - * - * @expectedException \InvalidArgumentException */ public function testWrongHeight() { $rect = new Rectangle(40, 0); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php index 87ab75f..7a7e50a 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -560,10 +560,10 @@ class UrlHelperTest extends UnitTestCase { * * @covers ::externalIsLocal * @dataProvider providerTestExternalIsLocalInvalid - * @expectedException \InvalidArgumentException */ public function testExternalIsLocalInvalid($url, $base_url) { UrlHelper::externalIsLocal($url, $base_url); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index eee5260..9794aaf 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -8,6 +8,7 @@ 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; @@ -474,8 +475,6 @@ class AccessManagerTest extends UnitTestCase { * 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'); @@ -516,6 +515,7 @@ class AccessManagerTest extends UnitTestCase { $this->checkProvider->addCheckService('test_incorrect_value', 'access'); $access_manager->checkNamedRoute('test_incorrect_value', array(), $this->account); + $this->setExpectedException(AccessException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php index 6eabd37..d880557 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php @@ -171,12 +171,12 @@ class CsrfTokenGeneratorTest extends UnitTestCase { * * @covers ::validate * @dataProvider providerTestInvalidParameterTypes - * @expectedException InvalidArgumentException */ public function testInvalidParameterTypes($token, $value = '') { $this->setupDefaultExpectations(); $this->generator->validate($token, $value); + $this->setExpectedException(\InvalidArgumentException::class); } /** @@ -198,13 +198,13 @@ class CsrfTokenGeneratorTest extends UnitTestCase { * 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(array()); $generator = new CsrfTokenGenerator($this->privateKey, $this->sessionMetadata); $generator->get(); + $this->setExpectedException(\RuntimeException::class); } } diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index 121aebc..83cdd4b 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -7,6 +7,9 @@ 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; @@ -143,8 +146,6 @@ class LibraryDiscoveryParserTest extends UnitTestCase { /** * 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,14 +159,12 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $this->libraryDiscoveryParser->setPaths('module', 'invalid_file', $path); $this->libraryDiscoveryParser->buildByExtension('invalid_file'); + $this->setExpectedException(InvalidLibraryFileException::class); } /** * 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() { @@ -179,6 +178,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $this->libraryDiscoveryParser->setPaths('module', 'example_module_missing_information', $path); $this->libraryDiscoveryParser->buildByExtension('example_module_missing_information'); + $this->setExpectedException(IncompleteLibraryDefinitionException::class, "Incomplete library definition for definition 'example' in extension 'example_module_missing_information'"); } /** @@ -276,8 +276,6 @@ class LibraryDiscoveryParserTest extends UnitTestCase { /** * Ensures that you cannot provide positive weights for JavaScript libraries. * - * @expectedException \UnexpectedValueException - * * @covers ::buildByExtension */ public function testJsWithPositiveWeight() { @@ -291,6 +289,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $this->libraryDiscoveryParser->setPaths('module', 'js_positive_weight', $path); $this->libraryDiscoveryParser->buildByExtension('js_positive_weight'); + $this->setExpectedException(\UnexpectedValueException::class); } /** @@ -403,9 +402,6 @@ class LibraryDiscoveryParserTest extends UnitTestCase { /** * 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() { @@ -419,6 +415,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $this->libraryDiscoveryParser->setPaths('module', 'licenses_missing_information', $path); $this->libraryDiscoveryParser->buildByExtension('licenses_missing_information'); + $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."); } /** diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php index 32ea0d0..4af32b2 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php @@ -183,8 +183,6 @@ class BreadcrumbManagerTest extends UnitTestCase { /** * Tests a breadcrumb builder with a bad return value. - * - * @expectedException \UnexpectedValueException */ public function testBuildWithInvalidBreadcrumbResult() { $builder = $this->getMock('Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface'); @@ -197,6 +195,7 @@ class BreadcrumbManagerTest extends UnitTestCase { $this->breadcrumbManager->addBuilder($builder, 0); $this->breadcrumbManager->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface')); + $this->setExpectedException(\UnexpectedValueException::class); } } diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php index ca8acfc..67c7d98 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php @@ -15,12 +15,11 @@ class BreadcrumbTest extends UnitTestCase { /** * @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(''))]); } diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php index edb220a..10d5d9d 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php @@ -14,12 +14,11 @@ class CacheTagsInvalidatorTest extends UnitTestCase { /** * @covers ::invalidateTags - * - * @expectedException \AssertionError */ public function testInvalidateTagsWithInvalidTags() { $cache_tags_invalidator = new CacheTagsInvalidator(); $cache_tags_invalidator->invalidateTags(['node' => [2, 3, 5, 8, 13]]); + $this->setExpectedException(\AssertionError::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php index 0bc9d7f..e7b2d42 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -105,21 +105,18 @@ class CacheContextsManagerTest extends UnitTestCase { /** * @covers ::convertTokensToKeys - * - * @expectedException \AssertionError */ public function testInvalidContext() { $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); $cache_contexts_manager->convertTokensToKeys(["non-cache-context"]); + $this->setExpectedException(\AssertionError::class); } /** * @covers ::convertTokensToKeys * - * @expectedException \Exception - * * @dataProvider providerTestInvalidCalculatedContext */ public function testInvalidCalculatedContext($context_token) { @@ -127,6 +124,7 @@ class CacheContextsManagerTest extends UnitTestCase { $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); $cache_contexts_manager->convertTokensToKeys([$context_token]); + $this->setExpectedException(\Exception::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index 223d890..41d159d 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Config; +use Drupal\Core\Config\ConfigValueException; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Render\Markup; use Drupal\Tests\UnitTestCase; @@ -230,19 +231,19 @@ class ConfigTest extends UnitTestCase { /** * @covers ::set - * @expectedException \Drupal\Core\Config\ConfigValueException */ public function testSetValidation() { $this->config->set('testData', array('dot.key' => 1)); + $this->setExpectedException(ConfigValueException::class); } /** * @covers ::set - * @expectedException PHPUnit_Framework_Error_Warning */ public function testSetIllegalOffsetValue() { // Set a single value. $this->config->set('testData', 1); + $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class); // Attempt to treat the single value as a nested item. $this->config->set('testData.illegalOffset', 1); @@ -383,7 +384,6 @@ class ConfigTest extends UnitTestCase { /** * @covers ::validateName - * @expectedException \Drupal\Core\Config\ConfigNameException * @dataProvider validateNameProvider */ public function testValidateNameException($name, $exception_message) { diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index 4710765..69661c7 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -8,6 +8,7 @@ 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; @@ -567,14 +568,13 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { /** * @covers ::toArray - * - * @expectedException \Drupal\Core\Config\Schema\SchemaIncompleteException */ public function testToArrayFallback() { $this->entityType->expects($this->any()) ->method('getPropertiesToExport') ->willReturn([]); $this->entity->toArray(); + $this->setExpectedException(SchemaIncompleteException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 6f02023..86635e0 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -3,8 +3,11 @@ namespace Drupal\Tests\Core\Config\Entity; use Drupal\Core\Cache\Cache; +use Drupal\Core\Config\ConfigDuplicateUUIDException; use Drupal\Core\Config\Entity\ConfigEntityInterface; 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 Symfony\Component\DependencyInjection\ContainerBuilder; @@ -470,9 +473,6 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * @covers ::save - * - * @expectedException \Drupal\Core\Entity\EntityMalformedException - * @expectedExceptionMessage The entity does not have an ID. */ public function testSaveInvalid() { $this->cacheTagsInvalidator->expects($this->never()) @@ -480,13 +480,12 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity = $this->getMockEntity(); $this->entityStorage->save($entity); + $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); } /** * @covers ::save * @covers ::doSave - * - * @expectedException \Drupal\Core\Entity\EntityStorageException */ public function testSaveDuplicate() { $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') @@ -512,14 +511,12 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity->enforceIsNew(); $this->entityStorage->save($entity); + $this->setExpectedException(EntityStorageException::class); } /** * @covers ::save * @covers ::doSave - * - * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException - * @expectedExceptionMessage when this UUID is already used for */ public function testSaveMismatch() { $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') @@ -548,6 +545,7 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity = $this->getMockEntity(array('id' => 'foo')); $this->entityStorage->save($entity); + $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this UUID is already used for'); } /** @@ -600,9 +598,6 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * @covers ::save * @covers ::doSave - * - * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException - * @expectedExceptionMessage when this entity already exists with UUID */ public function testSaveChangedUuid() { $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') @@ -666,6 +661,7 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity->set('uuid', 'baz'); $this->entityStorage->save($entity); + $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this entity already exists with UUID'); } /** diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php index b131b26..9dbc97b 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Config\Entity; +use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException; use Drupal\Tests\UnitTestCase; use Drupal\Core\Config\Entity\ConfigEntityType; @@ -79,26 +80,22 @@ class ConfigEntityTypeTest extends UnitTestCase { /** * @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() { new ConfigEntityType([ 'id' => 'example_config_entity_type', 'handlers' => ['storage' => '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'] ]); + $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); } /** * @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([]); $config_entity->setStorageClass('\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'); + $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); } /** diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php index 75fe625..bd76e09 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php @@ -96,8 +96,6 @@ class QueryFactoryTest extends UnitTestCase { } /** - * @expectedException \LogicException - * @expectedExceptionMessage test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup */ public function testGetKeysWildCardEnd() { $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'); @@ -112,6 +110,7 @@ class QueryFactoryTest extends UnitTestCase { $method = new \ReflectionMethod($query_factory, 'getKeys'); $method->setAccessible(TRUE); $method->invoke($query_factory, $this->getConfigObject('test'), 'test.*', 'get', $config_entity_type); + $this->setExpectedException(\LogicException::class, 'test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup'); } /** diff --git a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php index 5b5c498..8c6cb2e 100644 --- a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Config; use Drupal\Core\Config\ImmutableConfig; +use Drupal\Core\Config\ImmutableConfigException; use Drupal\Tests\UnitTestCase; /** @@ -28,38 +29,34 @@ class ImmutableConfigTest extends UnitTestCase { /** * @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->config->set('name', 'value'); + $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'); } /** * @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->config->clear('name'); + $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'); } /** * @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->config->save(); + $this->setExpectedException(ImmutableConfigException::class, 'Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); } /** * @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->config->delete(); + $this->setExpectedException(ImmutableConfigException::class, 'Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); } } diff --git a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php index 98a18a3..847e9d8 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php @@ -120,20 +120,18 @@ class ControllerResolverTest extends UnitTestCase { /** * Tests createController() with a non-existent class. - * - * @expectedException \InvalidArgumentException */ public function testCreateControllerNonExistentClass() { $this->controllerResolver->getControllerFromDefinition('Class::method'); + $this->setExpectedException(\InvalidArgumentException::class); } /** * Tests createController() with an invalid name. - * - * @expectedException \LogicException */ public function testCreateControllerInvalidName() { $this->controllerResolver->getControllerFromDefinition('ClassWithoutMethod'); + $this->setExpectedException(\LogicException::class); } /** @@ -191,11 +189,10 @@ class ControllerResolverTest extends UnitTestCase { } /** * Tests getControllerFromDefinition() without a callable. - * - * @expectedException \InvalidArgumentException */ public function testGetControllerFromDefinitionNotCallable() { $this->controllerResolver->getControllerFromDefinition('Drupal\Tests\Core\Controller\MockController::bananas'); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php index f33e3c3..3009888 100644 --- a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php @@ -140,7 +140,6 @@ class ConditionTest extends UnitTestCase { /** * @covers ::compile * - * @expectedException \PHPUnit_Framework_Error * @dataProvider providerTestCompileWithSqlInjectionForOperator */ public function testCompileWithSqlInjectionForOperator($operator) { @@ -163,6 +162,7 @@ class ConditionTest extends UnitTestCase { $condition = new Condition('AND'); $condition->condition('name', 'value', $operator); $condition->compile($connection, $query_placeholder); + $this->setExpectedException(\PHPUnit_Framework_Error::class); } public function providerTestCompileWithSqlInjectionForOperator() { diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php index b43971d..3b7b896 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\DependencyInjection\Compiler; 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 @@ -64,8 +65,6 @@ class ProxyServicesPassTest extends UnitTestCase { /** * @covers ::process - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testContainerWithLazyServicesWithoutProxyClass() { $container = new ContainerBuilder(); @@ -73,6 +72,7 @@ class ProxyServicesPassTest extends UnitTestCase { ->setLazy(TRUE); $this->proxyServicesPass->process($container); + $this->setExpectedException(InvalidArgumentException::class); } } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php index 2eeb603..3544a8d 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -10,6 +10,7 @@ namespace Drupal\Tests\Core\DependencyInjection\Compiler; 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; /** @@ -44,8 +45,6 @@ class TaggedHandlersPassTest extends UnitTestCase { /** * 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() { @@ -58,13 +57,12 @@ class TaggedHandlersPassTest extends UnitTestCase { $handler_pass = new TaggedHandlersPass(); $handler_pass->process($container); + $this->setExpectedException(LogicException::class, "At least one service tagged with 'consumer_id' is required."); } /** * Tests consumer with missing interface in non-production environment. * - * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException - * @expectedExceptionMessage Service consumer 'consumer_id' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface. * @covers ::process */ public function testProcessMissingInterface() { @@ -75,6 +73,7 @@ class TaggedHandlersPassTest extends UnitTestCase { $handler_pass = new TaggedHandlersPass(); $handler_pass->process($container); + $this->setExpectedException(LogicException::class, "Service consumer 'consumer_id' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface."); } /** @@ -204,7 +203,6 @@ class TaggedHandlersPassTest extends UnitTestCase { /** * Tests interface validation in non-production environment. * - * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException * @covers ::process */ public function testProcessInterfaceMismatch() { @@ -224,6 +222,7 @@ class TaggedHandlersPassTest extends UnitTestCase { $handler_pass = new TaggedHandlersPass(); $handler_pass->process($container); + $this->setExpectedException(LogicException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php index 4a6eae7..fbc0911 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php @@ -35,44 +35,40 @@ class ContainerBuilderTest extends UnitTestCase { /** * @covers ::set - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Service ID names must be lowercase: Bar */ public function testSetException() { $container = new ContainerBuilder(); $class = new BarClass(); $container->set('Bar', $class); + $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); $this->assertNotEquals('bar', $class->_serviceId); } /** * @covers ::setParameter - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Parameter names must be lowercase: Buzz */ public function testSetParameterException() { $container = new ContainerBuilder(); $container->setParameter('Buzz', 'buzz'); + $this->setExpectedException(\InvalidArgumentException::class, 'Parameter names must be lowercase: Buzz'); } /** * @covers ::register - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Service ID names must be lowercase: Bar */ public function testRegisterException() { $container = new ContainerBuilder(); $container->register('Bar'); + $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); } /** * Tests serialization. - * - * @expectedException \AssertionError */ public function testSerialize() { $container = new ContainerBuilder(); serialize($container); + $this->setExpectedException(\AssertionError::class); } } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php index 0ae5dd5..f98e310 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php @@ -14,12 +14,11 @@ class ContainerTest extends UnitTestCase { /** * Tests serialization. - * - * @expectedException \AssertionError */ public function testSerialize() { $container = new Container(); serialize($container); + $this->setExpectedException(\AssertionError::class); } /** diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php index de94bf8..a4028d8 100644 --- a/core/tests/Drupal/Tests/Core/DrupalTest.php +++ b/core/tests/Drupal/Tests/Core/DrupalTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core; +use Drupal\Core\DependencyInjection\ContainerNotInitializedException; use Drupal\Tests\UnitTestCase; use Drupal\Core\Url; use Symfony\Component\HttpFoundation\RequestStack; @@ -43,12 +44,10 @@ class DrupalTest extends UnitTestCase { /** * @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() { \Drupal::getContainer(); + $this->setExpectedException(ContainerNotInitializedException::class, '\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php index dbd50e7..04aabf1 100644 --- a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php @@ -298,7 +298,6 @@ class BaseFieldDefinitionTest extends UnitTestCase { * Tests invalid default value callbacks. * * @covers ::setDefaultValueCallback - * @expectedException \InvalidArgumentException */ public function testInvalidDefaultValueCallback() { $definition = BaseFieldDefinition::create($this->fieldType); @@ -306,6 +305,7 @@ class BaseFieldDefinitionTest extends UnitTestCase { $this->assertSame($definition, $definition->setDefaultValueCallback([get_class($this), 'mockDefaultValueCallback']) ); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index cb73533..6e9856d 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -352,9 +352,6 @@ class ContentEntityBaseUnitTest extends UnitTestCase { * @covers ::setValidationRequired * @covers ::save * @covers ::preSave - * - * @expectedException \LogicException - * @expectedExceptionMessage Entity validation was skipped. */ public function testRequiredValidation() { $validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface'); @@ -393,6 +390,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase { $this->entity->setValidationRequired(TRUE); $this->assertTrue($this->entity->isValidationRequired()); $this->entity->validate(); + $this->setExpectedException(\LogicException::class, 'Entity validation was skipped.'); $this->entity->save(); // Check that the "validated" status is reset after saving the entity and diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php index 7cad93c..47f1905 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php @@ -310,9 +310,6 @@ class EntityFieldManagerTest extends UnitTestCase { * @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) { @@ -334,6 +331,7 @@ class EntityFieldManagerTest extends UnitTestCase { $this->entityType->getLabel()->willReturn('Test'); $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type'); + $this->setExpectedException(\LogicException::class, 'The Test entity type cannot be translatable as it does not define a translatable "langcode" field.'); } /** @@ -452,8 +450,6 @@ class EntityFieldManagerTest extends UnitTestCase { * * @covers ::getBaseFieldDefinitions * @covers ::buildBaseFieldDefinitions - * - * @expectedException \LogicException */ public function testGetBaseFieldDefinitionsInvalidDefinition() { $this->setUpEntityWithFieldDefinition(FALSE, 'langcode', ['langcode' => 'langcode']); @@ -462,6 +458,7 @@ class EntityFieldManagerTest extends UnitTestCase { $this->entityType->getLabel()->willReturn('the_label'); $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type'); + $this->setExpectedException(\LogicException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php index c2325d4..84893d9 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php @@ -8,6 +8,7 @@ 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; @@ -17,6 +18,7 @@ use Drupal\Core\Entity\EntityManagerInterface; 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; @@ -248,8 +250,6 @@ class EntityTypeManagerTest extends UnitTestCase { * Tests the getFormObject() method with an invalid operation. * * @covers ::getFormObject - * - * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testGetFormObjectInvalidOperation() { $entity = $this->prophesize(EntityTypeInterface::class); @@ -257,6 +257,7 @@ class EntityTypeManagerTest extends UnitTestCase { $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]); $this->entityTypeManager->getFormObject('test_entity_type', 'edit'); + $this->setExpectedException(InvalidPluginDefinitionException::class); } /** @@ -283,14 +284,13 @@ class EntityTypeManagerTest extends UnitTestCase { * 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->entityTypeManager->getHandler('test_entity_type', 'storage'); + $this->setExpectedException(InvalidPluginDefinitionException::class); } /** @@ -314,9 +314,6 @@ class EntityTypeManagerTest extends UnitTestCase { * 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); @@ -326,6 +323,7 @@ class EntityTypeManagerTest extends UnitTestCase { $definition = $apple->reveal(); $this->entityTypeManager->processDefinition($definition, 'apple'); + $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'"); } /** @@ -370,14 +368,12 @@ class EntityTypeManagerTest extends UnitTestCase { * 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->entityTypeManager->getDefinition('pear', TRUE); + $this->setExpectedException(PluginNotFoundException::class, 'The "pear" entity type does not exist.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php index 3761e0d..37373b8 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php @@ -7,6 +7,8 @@ use Drupal\Core\Entity\EntityInterface; 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; @@ -130,9 +132,6 @@ class EntityTypeRepositoryTest extends UnitTestCase { /** * @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); @@ -147,13 +146,11 @@ class EntityTypeRepositoryTest extends UnitTestCase { $banana->getOriginalClass()->willReturn('\Drupal\banana\Entity\Banana'); $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\pear\Entity\Pear'); + $this->setExpectedException(NoCorrespondingEntityClassException::class, 'The \Drupal\pear\Entity\Pear class does not correspond to an entity type.'); } /** * @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); @@ -170,6 +167,7 @@ class EntityTypeRepositoryTest extends UnitTestCase { ]); $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\apple\Entity\Apple'); + $this->setExpectedException(AmbiguousEntityClassException::class, 'Multiple entity types found for \Drupal\apple\Entity\Apple.'); } } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index d633afc..4a5bbce 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -390,12 +390,11 @@ class EntityTypeTest extends UnitTestCase { /** * @covers ::setLinkTemplate - * - * @expectedException \InvalidArgumentException */ public function testSetLinkTemplateWithInvalidPath() { $entity_type = $this->setUpEntityType(['id' => $this->randomMachineName()]); $entity_type->setLinkTemplate('test', 'invalid-path'); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 4fbdba3..748e2f9 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -5,6 +5,8 @@ namespace Drupal\Tests\Core\Entity\KeyValueStore; 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; @@ -439,15 +441,13 @@ class KeyValueEntityStorageTest extends UnitTestCase { /** * @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->entityStorage->save($entity); + $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); $this->keyValueStore->expects($this->never()) ->method('has'); $this->keyValueStore->expects($this->never()) @@ -459,9 +459,6 @@ class KeyValueEntityStorageTest extends UnitTestCase { /** * @covers ::save * @covers ::doSave - * - * @expectedException \Drupal\Core\Entity\EntityStorageException - * @expectedExceptionMessage 'test_entity_type' entity with ID 'foo' already exists */ public function testSaveDuplicate() { $this->setUpKeyValueEntityStorage(); @@ -476,6 +473,7 @@ class KeyValueEntityStorageTest extends UnitTestCase { $this->keyValueStore->expects($this->never()) ->method('delete'); $this->entityStorage->save($entity); + $this->setExpectedException(EntityStorageException::class, "'test_entity_type' entity with ID 'foo' already exists"); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php b/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php index 22c606d..3e3efd5 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\Core\Entity\Query\Sql; use Drupal\Core\Entity\EntityType; use Drupal\Tests\UnitTestCase; +use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Query\Sql\Query; /** @@ -36,24 +37,20 @@ class QueryTest extends UnitTestCase { * 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->query->execute(); + $this->setExpectedException(QueryException::class, 'No base table for example_entity_query, invalid query.'); } /** * 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->query->allRevisions()->execute(); + $this->setExpectedException(QueryException::class, 'No revision table for example_entity_query, invalid query.'); } } diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php index 8ce420b..8097c10 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Entity\Sql; use Drupal\Core\Entity\Sql\DefaultTableMapping; +use Drupal\Core\Entity\Sql\SqlContentEntityStorageException; use Drupal\Tests\UnitTestCase; /** @@ -294,9 +295,6 @@ class DefaultTableMappingTest extends UnitTestCase { * @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 @@ -311,6 +309,7 @@ class DefaultTableMappingTest extends UnitTestCase { $table_mapping = new DefaultTableMapping($this->entityType, $definitions); $table_mapping->getFieldColumnName($definitions['test'], $column); + $this->setExpectedException(SqlContentEntityStorageException::class, "Column information not available for the 'test' field."); } /** @@ -440,14 +439,12 @@ class DefaultTableMappingTest extends UnitTestCase { /** * 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, []); $table_mapping->getFieldTableName('invalid_field_name'); + $this->setExpectedException(SqlContentEntityStorageException::class, "Table information not available for the 'invalid_field_name' field."); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php index 646f17a..0c35232 100644 --- a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php @@ -6,6 +6,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; 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; @@ -275,19 +276,19 @@ class EntityAdapterUnitTest extends UnitTestCase { /** * @covers ::get - * @expectedException \InvalidArgumentException */ public function testGetInvalidField() { $this->entityAdapter->get('invalid'); + $this->setExpectedException(\InvalidArgumentException::class); } /** * @covers ::get - * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testGetWithoutData() { $this->entityAdapter->setValue(NULL); $this->entityAdapter->get('id'); + $this->setExpectedException(MissingDataException::class); } /** @@ -305,12 +306,12 @@ class EntityAdapterUnitTest extends UnitTestCase { /** * @covers ::set - * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testSetWithoutData() { $this->entityAdapter->setValue(NULL); $id_items = [ array('value' => $this->id + 1) ]; $this->entityAdapter->set('id', $id_items); + $this->setExpectedException(MissingDataException::class); } /** @@ -335,11 +336,11 @@ class EntityAdapterUnitTest extends UnitTestCase { /** * @covers ::toArray - * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testToArrayWithoutData() { $this->entityAdapter->setValue(NULL); $this->entityAdapter->toArray(); + $this->setExpectedException(MissingDataException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php index b945b14..7035ed8 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php @@ -115,8 +115,6 @@ class RedirectResponseSubscriberTest extends UnitTestCase { /** * @dataProvider providerTestDestinationRedirectToExternalUrl - * - * @expectedException \PHPUnit_Framework_Error */ public function testDestinationRedirectToExternalUrl($request, $expected) { $dispatcher = new EventDispatcher(); @@ -127,6 +125,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase { $dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'checkRedirectUrl')); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $this->setExpectedException(\PHPUnit_Framework_Error::class); $this->assertEquals(400, $event->getResponse()->getStatusCode()); } @@ -165,8 +164,6 @@ class RedirectResponseSubscriberTest extends UnitTestCase { } /** - * @expectedException \PHPUnit_Framework_Error - * * @dataProvider providerTestDestinationRedirectWithInvalidUrl */ public function testDestinationRedirectWithInvalidUrl(Request $request) { @@ -178,6 +175,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase { $dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'checkRedirectUrl')); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $this->setExpectedException(\PHPUnit_Framework_Error::class); $this->assertEquals(400, $event->getResponse()->getStatusCode()); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index 55db07e..0972457 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -89,9 +89,6 @@ class SpecialAttributesRouteSubscriberTest extends UnitTestCase { * The route to check. * * @dataProvider providerTestOnRouteBuildingInvalidVariables - * @expectedException \PHPUnit_Framework_Error_Warning - * @expectedExceptionMessage uses reserved variable names - * * @covers ::onAlterRoutes */ public function testOnRouteBuildingInvalidVariables(Route $route) { @@ -101,6 +98,7 @@ class SpecialAttributesRouteSubscriberTest extends UnitTestCase { $event = new RouteBuildEvent($route_collection, 'test'); $subscriber = new SpecialAttributesRouteSubscriber(); $subscriber->onAlterRoutes($event); + $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'uses reserved variable names'); } } diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php index 74a7649..924167d 100644 --- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -50,9 +50,6 @@ class InfoParserUnitTest extends UnitTestCase { * 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); } @@ -82,8 +80,6 @@ BROKEN_INFO; * * @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); } @@ -108,9 +105,6 @@ MISSINGKEYS; * 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); } diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php index aa45b3b..dba1756 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php @@ -146,11 +146,10 @@ class ModuleHandlerTest extends UnitTestCase { /** * @covers ::getModule - * - * @expectedException \InvalidArgumentException */ public function testGetModuleWithNonExistingModule() { $this->moduleHandler->getModule('claire_alice_watch_my_little_pony_module_that_does_not_exist'); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php index 18d270e..f3932a2 100644 --- a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php @@ -41,8 +41,6 @@ class ConfigFormBaseTraitTest extends UnitTestCase { /** * @covers ::config - * @expectedException \LogicException - * @expectedExceptionMessage No config factory available for ConfigFormBaseTrait */ public function testConfigFactoryException() { $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait'); @@ -51,12 +49,11 @@ class ConfigFormBaseTraitTest extends UnitTestCase { // There is no config factory available this should result in an exception. $config_method->invoke($trait, 'editable.config'); + $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait'); } /** * @covers ::config - * @expectedException \LogicException - * @expectedExceptionMessage No config factory available for ConfigFormBaseTrait */ public function testConfigFactoryExceptionInvalidProperty() { $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait'); @@ -66,6 +63,7 @@ class ConfigFormBaseTraitTest extends UnitTestCase { // There is no config factory available this should result in an exception. $config_method->invoke($trait, 'editable.config'); + $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait'); } } diff --git a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php index 067ba47..48ddca4 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Form\FormState; 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 @@ -43,8 +44,6 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { /** * @covers ::buildResponse - * - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ public function testBuildResponseNoTriggeringElement() { $this->renderer->expects($this->never()) @@ -57,12 +56,11 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { $expected = []; $this->assertSame($expected, $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands)); + $this->setExpectedException(HttpException::class); } /** * @covers ::buildResponse - * - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ public function testBuildResponseNoCallable() { $this->renderer->expects($this->never()) @@ -77,6 +75,7 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { $expected = []; $this->assertSame($expected, $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands)); + $this->setExpectedException(HttpException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index dfbf843..3c53655 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -18,6 +18,7 @@ use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Form\Exception\BrokenPostRequestException; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountProxyInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -52,9 +53,6 @@ class FormBuilderTest extends FormTestBase { /** * 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'; @@ -62,6 +60,7 @@ class FormBuilderTest extends FormTestBase { $clean_form_state = new FormState(); $form_state = new FormState(); $form_id = $this->formBuilder->getFormId($form_arg, $form_state); + $this->setExpectedException(\InvalidArgumentException::class, 'The form argument foo is not a valid form.'); $this->assertSame($form_arg, $form_id); $this->assertSame($clean_form_state, $form_state); @@ -218,15 +217,13 @@ class FormBuilderTest extends FormTestBase { /** * 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(); $form = $this->formBuilder->getForm($form_id); + $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.'); $this->assertFormElement($expected_form, $form, 'test'); $this->assertSame('test-form-id', $form['#id']); } @@ -262,15 +259,13 @@ class FormBuilderTest extends FormTestBase { /** * 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(); $form = $this->formBuilder->getForm($form_id); + $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.'); $this->assertFormElement($expected_form, $form, 'test'); $this->assertArrayHasKey('#id', $form); } @@ -547,8 +542,6 @@ class FormBuilderTest extends FormTestBase { /** * @covers ::buildForm - * - * @expectedException \Drupal\Core\Form\Exception\BrokenPostRequestException */ public function testExceededFileSize() { $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]); @@ -566,6 +559,7 @@ class FormBuilderTest extends FormTestBase { $form_state = new FormState(); $this->formBuilder->buildForm($form_arg, $form_state); + $this->setExpectedException(BrokenPostRequestException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php index 67e7a86..86f206f 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php @@ -158,12 +158,11 @@ class FormStateDecoratorBaseTest extends UnitTestCase { * @dataProvider providerSingleBooleanArgument * * @param bool $cache - * - * @expectedException \LogicException */ public function testSetCachedWithLogicException($cache) { $this->decoratedFormState->setCached($cache) ->willThrow(\LogicException::class); + $this->setExpectedException(\LogicException::class); $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setCached($cache)); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php index 69118a8..09c1862 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php @@ -132,14 +132,12 @@ class FormStateTest extends UnitTestCase { * 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(); $form_state->setErrorByName('test', 'message'); + $this->setExpectedException(\LogicException::class, 'Form errors cannot be set after form validation has finished.'); } /** @@ -315,14 +313,12 @@ class FormStateTest extends UnitTestCase { /** * @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'); $form_state->setCached(); + $this->setExpectedException(\LogicException::class, 'Form state caching on GET requests is not allowed.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php index ec2ac8b..d575d3a 100644 --- a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php @@ -97,13 +97,12 @@ class SubformStateTest extends UnitTestCase { * * @dataProvider providerGetValuesBroken * - * @expectedException \UnexpectedValueException - * * @param string[] $parents * @param string $expected */ public function testGetValuesBroken(array $parents, $expected) { $this->testGetValues($parents, $expected); + $this->setExpectedException(\UnexpectedValueException::class); } /** @@ -161,11 +160,10 @@ class SubformStateTest extends UnitTestCase { * @covers ::getValue * * @dataProvider providerTestGetValueBroken - * - * @expectedException \UnexpectedValueException */ public function testGetValueBroken(array $parents, $key, $expected, $default = NULL) { $this->testGetValue($parents, $key, $expected, $default); + $this->setExpectedException(\UnexpectedValueException::class); } /** @@ -217,11 +215,10 @@ class SubformStateTest extends UnitTestCase { * @covers ::setValues * * @dataProvider providerTestSetValuesBroken - * - * @expectedException \UnexpectedValueException */ public function testSetValuesBroken($parents, $new_values, $expected) { $this->testSetValues($parents, $new_values, $expected); + $this->setExpectedException(\UnexpectedValueException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index b3f0151..2238f31 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Menu; +use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Access\AccessResult; use Drupal\Core\Language\Language; use Drupal\Tests\UnitTestCase; @@ -203,8 +204,6 @@ class ContextualLinkManagerTest extends UnitTestCase { * 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 = array( @@ -213,14 +212,13 @@ class ContextualLinkManagerTest extends UnitTestCase { 'id' => 'test_plugin', ); $this->contextualLinkManager->processDefinition($definition, 'test_plugin'); + $this->setExpectedException(PluginException::class); } /** * 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 = array( @@ -229,6 +227,7 @@ class ContextualLinkManagerTest extends UnitTestCase { 'id' => 'test_plugin', ); $this->contextualLinkManager->processDefinition($definition, 'test_plugin'); + $this->setExpectedException(PluginException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php index 82a6581..d264936 100644 --- a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php +++ b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php @@ -63,7 +63,6 @@ class ChainRequestPolicyTest extends UnitTestCase { /** * Asserts that check() throws an exception if a rule returns an invalid value. * - * @expectedException \UnexpectedValueException * @dataProvider providerChainExceptionOnInvalidReturnValue * @covers ::check */ @@ -77,6 +76,7 @@ class ChainRequestPolicyTest extends UnitTestCase { $this->policy->addPolicy($rule); $this->policy->check($this->request); + $this->setExpectedException(\UnexpectedValueException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php index 1575ac1..4fe6bb7 100644 --- a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php +++ b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php @@ -72,7 +72,6 @@ class ChainResponsePolicyTest extends UnitTestCase { /** * Asserts that check() throws an exception if a rule returns an invalid value. * - * @expectedException \UnexpectedValueException * @dataProvider providerChainExceptionOnInvalidReturnValue * @covers ::check */ @@ -86,6 +85,7 @@ class ChainResponsePolicyTest extends UnitTestCase { $this->policy->addPolicy($rule); $actual_result = $this->policy->check($this->response, $this->request); + $this->setExpectedException(\UnexpectedValueException::class); $this->assertSame(NULL, $actual_result); } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php index ebafab0..d095082 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\Core\ParamConverter; 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; @@ -110,8 +111,6 @@ class EntityConverterTest extends UnitTestCase { /** * Tests the convert() method with an invalid entity type. - * - * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testConvertWithInvalidEntityType() { $this->entityManager->expects($this->once()) @@ -120,16 +119,15 @@ class EntityConverterTest extends UnitTestCase { ->willThrowException(new InvalidPluginDefinitionException('invalid_id')); $this->entityConverter->convert('id', ['type' => 'entity:invalid_id'], 'foo', ['foo' => 'id']); + $this->setExpectedException(InvalidPluginDefinitionException::class); } /** * 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->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id']); + $this->setExpectedException(ParamNotConvertedException::class, 'The "foo" parameter was not converted because the "invalid_id" parameter is missing'); } } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php index cc248b0..a92a84d 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php @@ -3,6 +3,7 @@ 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; @@ -51,11 +52,10 @@ class ParamConverterManagerTest extends UnitTestCase { * Tests \Drupal\Core\ParamConverter\ParamConverterManager::getConverter(). * * @covers ::getConverter - * - * @expectedException \InvalidArgumentException */ public function testGetConverterException() { $this->manager->getConverter('undefined.converter'); + $this->setExpectedException(\InvalidArgumentException::class); } /** @@ -220,9 +220,6 @@ class ParamConverterManagerTest extends UnitTestCase { /** * @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}'); @@ -247,6 +244,7 @@ class ParamConverterManagerTest extends UnitTestCase { $this->manager->addConverter($converter, 'test_convert'); $this->manager->convert($defaults); + $this->setExpectedException(ParamNotConvertedException::class, 'The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")'); } } diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php index 4076f1e..5ae3fdb 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Config\ImmutableConfig; 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. @@ -47,7 +48,6 @@ class PathProcessorFrontTest extends UnitTestCase { * Test inbound failure with broken config. * * @covers ::processInbound - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testProcessInboundBadConfig() { $config_factory = $this->prophesize(ConfigFactoryInterface::class); @@ -58,6 +58,7 @@ class PathProcessorFrontTest extends UnitTestCase { ->willReturn(''); $processor = new PathProcessorFront($config_factory->reveal()); $processor->processInbound('/', new Request()); + $this->setExpectedException(NotFoundHttpException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php index fb1a442..caf94dc 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php @@ -107,7 +107,6 @@ class ContextDefinitionTest extends UnitTestCase { } /** - * @expectedException \Exception * @dataProvider providerGetDataDefinition * @covers ::getDataDefinition * @uses \Drupal @@ -159,6 +158,7 @@ class ContextDefinitionTest extends UnitTestCase { $mock_data_definition, $mock_context_definition->getDataDefinition() ); + $this->setExpectedException(\Exception::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php index 02fea32..cc2cd0a 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php @@ -66,12 +66,11 @@ class LazyContextRepositoryTest extends UnitTestCase { /** * @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']); $lazy_context_repository->getRuntimeContexts(['test_context', '@test_provider:test_context1']); + $this->setExpectedException(\InvalidArgumentException::class, 'You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php index 981f4c2..a33010a 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php @@ -8,6 +8,7 @@ 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; @@ -279,9 +280,6 @@ class ContextHandlerTest extends UnitTestCase { /** * @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'); @@ -312,6 +310,7 @@ class ContextHandlerTest extends UnitTestCase { ->method('getContext'); $this->contextHandler->applyContextMapping($plugin, $contexts); + $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.'); } /** @@ -350,9 +349,6 @@ class ContextHandlerTest extends UnitTestCase { /** * @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'); @@ -382,6 +378,7 @@ class ContextHandlerTest extends UnitTestCase { ->method('setContextValue'); $this->contextHandler->applyContextMapping($plugin, $contexts); + $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.'); } @@ -464,9 +461,6 @@ class ContextHandlerTest extends UnitTestCase { /** * @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'); @@ -490,6 +484,7 @@ class ContextHandlerTest extends UnitTestCase { ->method('setContextValue'); $this->contextHandler->applyContextMapping($plugin, $contexts, ['miss' => 'name']); + $this->setExpectedException(ContextException::class, 'Assigned contexts were not satisfied: miss'); } } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php index fbd6bc2..a69c967 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Plugin; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin; /** @@ -43,12 +44,11 @@ class DefaultLazyPluginCollectionTest extends LazyPluginCollectionTestBase { /** * @covers ::get - * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException - * @expectedExceptionMessage Plugin ID 'pear' was not found. */ public function testGetNotExistingPlugin() { $this->setupPluginCollection(); $this->defaultPluginCollection->get('pear'); + $this->setExpectedException(PluginNotFoundException::class, "Plugin ID 'pear' was not found."); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index ffdac5a..8dc2db1 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Plugin; +use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; @@ -270,9 +271,6 @@ class DefaultPluginManagerTest extends UnitTestCase { * 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'); @@ -294,6 +292,7 @@ class DefaultPluginManagerTest extends UnitTestCase { $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); $plugin_manager->createInstance('kale'); + $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'); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php index d81360f..fad7610 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Plugin\Discovery; use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; +use Drupal\Component\Plugin\Exception\InvalidDeriverException; use Drupal\Tests\UnitTestCase; /** @@ -86,9 +87,6 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { * 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 = array(); @@ -103,15 +101,13 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); $discovery->getDefinitions(); + $this->setExpectedException(InvalidDeriverException::class, 'Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); } /** * 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 = array(); @@ -126,6 +122,7 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); $discovery->getDefinitions(); + $this->setExpectedException(InvalidDeriverException::class, 'Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php index 1472dc0..8fa0a7b 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Plugin\Discovery; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Plugin\Discovery\HookDiscovery; use Drupal\Tests\UnitTestCase; @@ -118,8 +119,6 @@ class HookDiscoveryTest extends UnitTestCase { * 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()) @@ -127,6 +126,7 @@ class HookDiscoveryTest extends UnitTestCase { ->will($this->returnValue(array())); $this->hookDiscovery->getDefinition('test_non_existant', TRUE); + $this->setExpectedException(PluginNotFoundException::class); } protected function hookDiscoveryTestTestPlugin() { diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php index 604d391..d5068ed 100644 --- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php +++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php @@ -101,15 +101,13 @@ class ElementTest extends UnitTestCase { /** * Tests the children() method with an invalid key. - * - * @expectedException \PHPUnit_Framework_Error - * @expectedExceptionMessage "foo" is an invalid render array key */ public function testInvalidChildren() { $element = array( 'foo' => 'bar', ); Element::children($element); + $this->setExpectedException(\PHPUnit_Framework_Error::class, '"foo" is an invalid render array key'); } /** diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php index fc90e5d..498903e 100644 --- a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php @@ -120,9 +120,6 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { /** * @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. @@ -132,13 +129,11 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { $chained_placeholder_strategy = new ChainedPlaceholderStrategy(); $chained_placeholder_strategy->processPlaceholders($placeholders); + $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.'); } /** * @covers ::processPlaceholders - * - * @expectedException \AssertionError - * @expectedExceptionMessage Processed placeholders must be a subset of all placeholders. */ public function testProcessPlaceholdersWithRoguePlaceholderStrategy() { // Placeholders but no strategies defined. @@ -158,6 +153,7 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { $chained_placeholder_strategy = new ChainedPlaceholderStrategy(); $chained_placeholder_strategy->addPlaceholderStrategy($rogue_strategy); $chained_placeholder_strategy->processPlaceholders($placeholders); + $this->setExpectedException(\AssertionError::class, 'Processed placeholders must be a subset of all placeholders.'); } } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php index a3835e1..5c396ee 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php @@ -570,9 +570,6 @@ class RendererBubblingTest extends RendererTestBase { /** * 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(); @@ -586,6 +583,7 @@ class RendererBubblingTest extends RendererTestBase { '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingCacheOverwritePrerender'], ]; $this->renderer->renderRoot($data); + $this->setExpectedException(\LogicException::class, 'Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.'); } } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php index 530f603..11d9557 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php @@ -846,29 +846,25 @@ class RendererPlaceholdersTest extends RendererTestBase { /** * @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->renderer->renderRoot($element); + $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value.'); } /** * @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->renderer->renderRoot($element); + $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.'); } /** @@ -895,9 +891,6 @@ class RendererPlaceholdersTest extends RendererTestBase { /** * @covers ::render * @covers ::doRender - * - * @expectedException \DomainException - * @expectedExceptionMessage A #lazy_builder callback's context may only contain scalar values or NULL. */ public function testNonScalarLazybuilderCallbackContext() { $element = []; @@ -912,14 +905,12 @@ class RendererPlaceholdersTest extends RendererTestBase { ]]; $this->renderer->renderRoot($element); + $this->setExpectedException(\DomainException::class, "A #lazy_builder callback's context may only contain scalar values or NULL."); } /** * @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 = []; @@ -928,14 +919,12 @@ class RendererPlaceholdersTest extends RendererTestBase { $element['child_b']['#markup'] = 'kthxbai'; $this->renderer->renderRoot($element); + $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.'); } /** * @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 = []; @@ -944,20 +933,19 @@ class RendererPlaceholdersTest extends RendererTestBase { $element['#piglet'] = '#cute'; $this->renderer->renderRoot($element); + $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.'); } /** * @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->renderer->renderRoot($element); + $this->setExpectedException(\LogicException::class, 'When #create_placeholder is set, a #lazy_builder callback must be present as well.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php index bffbd22..74d5e46 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php @@ -31,8 +31,6 @@ class RendererRecursionTest extends RendererTestBase { * @covers ::renderRoot * @covers ::render * @covers ::doRender - * - * @expectedException \LogicException */ public function testRenderRecursionWithNestedRenderRoot() { list($complex_child_markup, $parent_markup, $complex_child_template) = $this->setUpRenderRecursionComplexElements(); @@ -42,6 +40,7 @@ class RendererRecursionTest extends RendererTestBase { $complex_child = $complex_child_template; $callable = function () use ($renderer, $complex_child) { $renderer->renderRoot($complex_child); + $this->setExpectedException(\LogicException::class); }; $page = [ diff --git a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php index 0b7bcc6..f25f796 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php @@ -87,8 +87,6 @@ class AccessAwareRouterTest extends UnitTestCase { /** * Tests the matchRequest() function for access denied. - * - * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function testMatchRequestDenied() { $this->setupRouter(); @@ -99,6 +97,7 @@ class AccessAwareRouterTest extends UnitTestCase { ->with($request) ->willReturn($access_result); $parameters = $this->router->matchRequest($request); + $this->setExpectedException(AccessDeniedHttpException::class); $expected = [ AccessAwareRouterInterface::ACCESS_RESULT => $access_result, ]; diff --git a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php index 39a960b..8654599 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Routing; use Drupal\Core\Routing\RequestFormatRouteFilter; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -61,8 +62,6 @@ class RequestFormatRouteFilterTest extends UnitTestCase { /** * @covers ::filter - * @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException - * @expectedExceptionMessage No route found for the specified format xml. */ public function testNoRouteFound() { $collection = new RouteCollection(); @@ -75,6 +74,7 @@ class RequestFormatRouteFilterTest extends UnitTestCase { $request->setRequestFormat('xml'); $route_filter = new RequestFormatRouteFilter(); $route_filter->filter($collection, $request); + $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified format xml.'); } } diff --git a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php index 0cfbad5..3f14135 100644 --- a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php @@ -29,7 +29,6 @@ class TrustedRedirectResponseTest extends UnitTestCase { /** * @covers ::setTargetUrl - * @expectedException \InvalidArgumentException */ public function testSetTargetUrlWithUntrustedUrl() { $request_context = new RequestContext(); @@ -41,6 +40,7 @@ class TrustedRedirectResponseTest extends UnitTestCase { $redirect_response = new TrustedRedirectResponse('/example'); $redirect_response->setTargetUrl('http://evil-url.com/example'); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php index 3cf50fc..b5e8c52 100644 --- a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php +++ b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php @@ -80,13 +80,12 @@ class SettingsTest extends UnitTestCase { * @covers ::getHashSalt * * @dataProvider providerTestGetHashSaltEmpty - * - * @expectedException \RuntimeException */ public function testGetHashSaltEmpty(array $config) { // Re-create settings with no 'hash_salt' key. $settings = new Settings($config); $settings->getHashSalt(); + $this->setExpectedException(\RuntimeException::class); } /** @@ -106,11 +105,10 @@ class SettingsTest extends UnitTestCase { * Ensures settings cannot be serialized. * * @covers ::__sleep - * - * @expectedException \LogicException */ public function testSerialize() { serialize(new Settings([])); + $this->setExpectedException(\LogicException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php index 3ed2b3d..25f5b7a 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php @@ -82,25 +82,21 @@ class TranslatableMarkupTest extends UnitTestCase { } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage $string ("foo") must be a string. - * * @covers ::__construct */ public function testIsStringAssertion() { $translation = $this->getStringTranslationStub(); new TranslatableMarkup(new TranslatableMarkup('foo', [], [], $translation)); + $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); } /** - * @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); } diff --git a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php index 7a3dd3a..67b27ac 100644 --- a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php +++ b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php @@ -45,11 +45,11 @@ class TwigSandboxTest extends UnitTestCase { * 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->twig->render($template, ['entity' => $entity]); + $this->setExpectedException(\Twig_Sandbox_SecurityError::class); } /** diff --git a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php index 5e3558e..0f8ee06 100644 --- a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php @@ -95,22 +95,20 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * Ensures that passing an explicit group is not supported. * * @covers ::validate - * - * @expectedException \LogicException */ public function testValidateWithGroups() { $this->recursiveValidator->validate('test', NULL, 'test group'); + $this->setExpectedException(\LogicException::class); } /** * Ensures that passing a non typed data value is not supported. * * @covers ::validate - * - * @expectedException \InvalidArgumentException */ public function testValidateWithoutTypedData() { $this->recursiveValidator->validate('test'); + $this->setExpectedException(\InvalidArgumentException::class); } /** @@ -228,8 +226,6 @@ class RecursiveContextualValidatorTest extends UnitTestCase { /** * @covers ::validateProperty - * - * @expectedException \LogicException */ public function testValidatePropertyWithCustomGroup() { $tree = [ @@ -240,17 +236,17 @@ class RecursiveContextualValidatorTest extends UnitTestCase { ]; $typed_data = $this->setupTypedData($tree, 'test_name'); $this->recursiveValidator->validateProperty($typed_data, 'key1', 'test group'); + $this->setExpectedException(\LogicException::class); } /** * @covers ::validateProperty * * @dataProvider providerTestValidatePropertyWithInvalidObjects - * - * @expectedException \InvalidArgumentException */ public function testValidatePropertyWithInvalidObjects($object) { $this->recursiveValidator->validateProperty($object, 'key1', NULL); + $this->setExpectedException(\InvalidArgumentException::class); } /** @@ -289,11 +285,10 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * @covers ::validatePropertyValue * * @dataProvider providerTestValidatePropertyWithInvalidObjects - * - * @expectedException \InvalidArgumentException */ public function testValidatePropertyValueWithInvalidObjects($object) { $this->recursiveValidator->validatePropertyValue($object, 'key1', [], NULL); + $this->setExpectedException(\InvalidArgumentException::class); } /** diff --git a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php index ef6dd25..59e6d00 100644 --- a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php +++ b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php @@ -102,10 +102,10 @@ class UnroutedUrlTest extends UnitTestCase { * * @covers ::fromUri * @dataProvider providerFromInvalidUri - * @expectedException \InvalidArgumentException */ public function testFromInvalidUri($uri) { $url = Url::fromUri($uri); + $this->setExpectedException(\InvalidArgumentException::class); } /** @@ -133,8 +133,6 @@ class UnroutedUrlTest extends UnitTestCase { * Tests the createFromRequest method. * * @covers ::createFromRequest - * - * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException */ public function testCreateFromRequest() { $request = Request::create('/test-path'); @@ -145,6 +143,7 @@ class UnroutedUrlTest extends UnitTestCase { ->will($this->throwException(new ResourceNotFoundException())); $this->assertNull(Url::createFromRequest($request)); + $this->setExpectedException(ResourceNotFoundException::class); } /** @@ -179,13 +178,12 @@ class UnroutedUrlTest extends UnitTestCase { * @depends testFromUri * @dataProvider providerFromUri * - * @expectedException \UnexpectedValueException - * * @covers ::getRouteName */ public function testGetRouteName($uri) { $url = Url::fromUri($uri); $url->getRouteName(); + $this->setExpectedException(\UnexpectedValueException::class); } /** @@ -194,13 +192,12 @@ class UnroutedUrlTest extends UnitTestCase { * @depends testFromUri * @dataProvider providerFromUri * - * @expectedException \UnexpectedValueException - * * @covers ::getRouteParameters */ public function testGetRouteParameters($uri) { $url = Url::fromUri($uri); $url->getRouteParameters(); + $this->setExpectedException(\UnexpectedValueException::class); } /** @@ -210,12 +207,11 @@ class UnroutedUrlTest extends UnitTestCase { * @dataProvider providerFromUri * * @covers ::getInternalPath - * - * @expectedException \Exception */ public function testGetInternalPath($uri) { $url = Url::fromUri($uri); $this->assertNull($url->getInternalPath()); + $this->setExpectedException(\Exception::class); } /** diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index 5324c26..c4904ff 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -215,11 +215,11 @@ class UrlTest extends UnitTestCase { * Tests the fromUserInput method with invalid paths. * * @covers ::fromUserInput - * @expectedException \InvalidArgumentException * @dataProvider providerFromInvalidInternalUri */ public function testFromInvalidUserInput($path) { $url = Url::fromUserInput($path); + $this->setExpectedException(\InvalidArgumentException::class); } /** @@ -280,8 +280,6 @@ class UrlTest extends UnitTestCase { * 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'); @@ -292,6 +290,7 @@ class UrlTest extends UnitTestCase { ->will($this->throwException(new ResourceNotFoundException())); $this->assertNull(Url::createFromRequest($request)); + $this->setExpectedException(ResourceNotFoundException::class); } /** @@ -315,14 +314,13 @@ class UrlTest extends UnitTestCase { * * @depends testUrlFromRequest * - * @expectedException \UnexpectedValueException - * * @covers ::getUri */ public function testGetUriForInternalUrl($urls) { foreach ($urls as $url) { $url->getUri(); } + $this->setExpectedException(\UnexpectedValueException::class); } /** @@ -418,11 +416,11 @@ class UrlTest extends UnitTestCase { * Tests the getRouteName() with an external URL. * * @covers ::getRouteName - * @expectedException \UnexpectedValueException */ public function testGetRouteNameWithExternalUrl() { $url = Url::fromUri('http://example.com'); $url->getRouteName(); + $this->setExpectedException(\UnexpectedValueException::class); } /** @@ -445,11 +443,11 @@ class UrlTest extends UnitTestCase { * Tests the getRouteParameters() with an external URL. * * @covers ::getRouteParameters - * @expectedException \UnexpectedValueException */ public function testGetRouteParametersWithExternalUrl() { $url = Url::fromUri('http://example.com'); $url->getRouteParameters(); + $this->setExpectedException(\UnexpectedValueException::class); } /** @@ -605,7 +603,6 @@ class UrlTest extends UnitTestCase { * 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. @@ -615,6 +612,7 @@ class UrlTest extends UnitTestCase { ->willThrowException(new InvalidParameterException('Parameter "test_entity" for route "/test_entity/{test_entity}" must match "[^/]++" ("1/blah" given) to generate a corresponding URL..')); Url::fromUri('entity:test_entity/1/blah')->toString(); + $this->setExpectedException(InvalidParameterException::class); } /** @@ -728,11 +726,11 @@ class UrlTest extends UnitTestCase { * Tests the fromUri() method with an invalid internal: URI. * * @covers ::fromUri - * @expectedException \InvalidArgumentException * @dataProvider providerFromInvalidInternalUri */ public function testFromInvalidInternalUri($path) { Url::fromUri('internal:' . $path); + $this->setExpectedException(\InvalidArgumentException::class); } /** @@ -800,11 +798,10 @@ class UrlTest extends UnitTestCase { } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The route URI 'route:' is invalid. */ public function testFromRouteUriWithMissingRouteName() { Url::fromUri('route:'); + $this->setExpectedException(\InvalidArgumentException::class, "The route URI 'route:' is invalid."); } /** diff --git a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php index b2d7700..d635056 100644 --- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -56,18 +56,18 @@ class UnroutedUrlAssemblerTest extends UnitTestCase { /** * @covers ::assemble - * @expectedException \InvalidArgumentException */ public function testAssembleWithNeitherExternalNorDomainLocalUri() { $this->unroutedUrlAssembler->assemble('wrong-url'); + $this->setExpectedException(\InvalidArgumentException::class); } /** * @covers ::assemble - * @expectedException \InvalidArgumentException */ public function testAssembleWithLeadingSlash() { $this->unroutedUrlAssembler->assemble('/drupal.org'); + $this->setExpectedException(\InvalidArgumentException::class); } /**