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..53d5015 100644 --- a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php +++ b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php @@ -28,10 +28,10 @@ class BigPipeResponseAttachmentsProcessorTest extends UnitTestCase { * @covers ::processAttachments * * @dataProvider nonHtmlResponseProvider - * - * @expectedException \AssertionError */ public function testNonHtmlResponse($response_class) { + $this->setExpectedException('\AssertionError'); + $big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($this->prophesize(AttachmentsResponseProcessorInterface::class)); $non_html_response = new $response_class(); diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php index 9e5c82c..963ccee 100644 --- a/core/modules/contact/tests/src/Unit/MailHandlerTest.php +++ b/core/modules/contact/tests/src/Unit/MailHandlerTest.php @@ -94,12 +94,12 @@ 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() { + $this->setExpectedException('\Drupal\contact\MailHandlerException', 'Unable to determine message recipient'); + $message = $this->getMock('\Drupal\contact\MessageInterface'); $message->expects($this->once()) ->method('isPersonal') diff --git a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php index 3f687d4..a2e8d48 100644 --- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @@ -160,11 +160,10 @@ 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() { + $this->setExpectedException('\LogicException', 'Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.'); + $storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface'); $storage->expects($this->any()) ->method('load') diff --git a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php index 550c185..85c7379 100644 --- a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php +++ b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php @@ -17,9 +17,10 @@ class FieldItemNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenorma * Context for FieldItemNormalizer::denormalize(). * * @dataProvider providerNormalizerDenormalizeExceptions - * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testFieldItemNormalizerDenormalizeExceptions($context) { + $this->setExpectedException('\Symfony\Component\Serializer\Exception\InvalidArgumentException'); + $field_item_normalizer = new FieldItemNormalizer(); $data = array(); $class = array(); diff --git a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php index a257209..de41b67 100644 --- a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php +++ b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php @@ -17,9 +17,10 @@ class FieldNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalize * Context for FieldNormalizer::denormalize(). * * @dataProvider providerNormalizerDenormalizeExceptions - * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testFieldNormalizerDenormalizeExceptions($context) { + $this->setExpectedException('\Symfony\Component\Serializer\Exception\InvalidArgumentException'); + $field_item_normalizer = new FieldNormalizer(); $data = array(); $class = array(); diff --git a/core/modules/locale/tests/src/Unit/StringBaseTest.php b/core/modules/locale/tests/src/Unit/StringBaseTest.php index 58ea0ff..ae93019 100644 --- a/core/modules/locale/tests/src/Unit/StringBaseTest.php +++ b/core/modules/locale/tests/src/Unit/StringBaseTest.php @@ -13,10 +13,10 @@ 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() { + $this->setExpectedException('\Drupal\locale\StringStorageException', 'The string cannot be saved because its not bound to a storage: test'); + $string = new SourceString(['source' => 'test']); $string->save(); } @@ -24,10 +24,10 @@ class StringBaseTest extends UnitTestCase { /** * @covers ::delete - * @expectedException \Drupal\locale\StringStorageException - * @expectedExceptionMessage The string cannot be deleted because its not bound to a storage: test */ public function testDeleteWithoutStorage() { + $this->setExpectedException('\Drupal\locale\StringStorageException', 'The string cannot be deleted because its not bound to a storage: test'); + $string = new SourceString(['lid' => 1, 'source' => 'test']); $string->delete(); } diff --git a/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php b/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php index 427d413..e21f1ee 100644 --- a/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/CopyFileTest.php @@ -136,11 +136,10 @@ 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() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'File "/non/existent/file" does not exist'); + $source = '/non/existent/file'; $this->doImport($source, 'public://wontmatter.jpg'); } diff --git a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php index ee75e45..e0292de 100644 --- a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php @@ -111,11 +111,10 @@ 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() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'File "/non/existent/file" does not exist'); + $source = '/non/existent/file'; $this->doTransform($source, 'public://wontmatter.jpg'); } diff --git a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php index 4a462e9..c7e2769 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php @@ -149,9 +149,10 @@ class MigrateSourceTest extends MigrateTestCase { /** * @covers ::__construct - * @expectedException \Drupal\migrate\MigrateException */ public function testHighwaterTrackChangesIncompatible() { + $this->setExpectedException('\Drupal\migrate\MigrateException'); + $source_config = ['track_changes' => TRUE, 'high_water_property' => ['name' => 'something']]; $this->getSource($source_config); } diff --git a/core/modules/migrate/tests/src/Unit/MigrationTest.php b/core/modules/migrate/tests/src/Unit/MigrationTest.php index 57ff64c..23c38af 100644 --- a/core/modules/migrate/tests/src/Unit/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrationTest.php @@ -27,11 +27,10 @@ class MigrationTest extends UnitTestCase { * Tests checking requirements for source plugins. * * @covers ::checkRequirements - * - * @expectedException \Drupal\migrate\Exception\RequirementsException - * @expectedExceptionMessage Missing source requirement */ public function testRequirementsForSourcePlugin() { + $this->setExpectedException('\Drupal\migrate\Exception\RequirementsException', 'Missing source requirement'); + $migration = new TestMigration(); $source_plugin = $this->getMock('Drupal\Tests\migrate\Unit\RequirementsAwareSourceInterface'); @@ -50,11 +49,10 @@ class MigrationTest extends UnitTestCase { * Tests checking requirements for destination plugins. * * @covers ::checkRequirements - * - * @expectedException \Drupal\migrate\Exception\RequirementsException - * @expectedExceptionMessage Missing destination requirement */ public function testRequirementsForDestinationPlugin() { + $this->setExpectedException('\Drupal\migrate\Exception\RequirementsException', 'Missing destination requirement'); + $migration = new TestMigration(); $source_plugin = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface'); @@ -73,11 +71,10 @@ class MigrationTest extends UnitTestCase { * Tests checking requirements for destination plugins. * * @covers ::checkRequirements - * - * @expectedException \Drupal\migrate\Exception\RequirementsException - * @expectedExceptionMessage Missing migrations test_a, test_c */ public function testRequirementsForMigrations() { + $this->setExpectedException('\Drupal\migrate\Exception\RequirementsException', 'Missing migrations test_a, test_c'); + $migration = new TestMigration(); // Setup source and destination plugins without any requirements. 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..9129528 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 @@ -84,10 +84,10 @@ 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() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'Unable to get entity'); + $bundles = []; $destination = new EntityTestDestination([], '', [], $this->migration->reveal(), @@ -101,11 +101,10 @@ class EntityContentBaseTest extends UnitTestCase { /** * Test that translation destination fails for untranslatable entities. - * - * @expectedException \Drupal\migrate\MigrateException - * @expectedExceptionMessage This entity type does not support translation */ public function testUntranslatable() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'This entity type does not support translation'); + // An entity type without a language. $entity_type = $this->prophesize(ContentEntityType::class); $entity_type->getKey('langcode')->willReturn(''); diff --git a/core/modules/migrate/tests/src/Unit/RowTest.php b/core/modules/migrate/tests/src/Unit/RowTest.php index ec04f82..b118f08 100644 --- a/core/modules/migrate/tests/src/Unit/RowTest.php +++ b/core/modules/migrate/tests/src/Unit/RowTest.php @@ -73,10 +73,10 @@ class RowTest extends UnitTestCase { /** * Tests object creation: invalid values. - * - * @expectedException \Exception */ public function testRowWithInvalidData() { + $this->setExpectedException('\Exception'); + $invalid_values = array( 'title' => 'node X', ); @@ -85,10 +85,10 @@ class RowTest extends UnitTestCase { /** * Tests source immutability after freeze. - * - * @expectedException \Exception */ public function testSourceFreeze() { + $this->setExpectedException('\Exception'); + $row = new Row($this->testValues, $this->testSourceIds); $row->rehash(); $this->assertSame($this->testHash, $row->getHash(), 'Correct hash.'); @@ -101,11 +101,10 @@ 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() { + $this->setExpectedException('\Exception', 'The source is frozen and can\'t be changed any more'); + $row = new Row($this->testValues, $this->testSourceIds); $row->freezeSource(); $row->setSourceProperty('title', 'new title'); diff --git a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php index 1d0d4c3..2b35aa8 100644 --- a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php @@ -34,10 +34,10 @@ class ConcatTest extends MigrateProcessTestCase { /** * Test concat fails properly on non-arrays. - * - * @expectedException \Drupal\migrate\MigrateException */ public function testConcatWithNonArray() { + $this->setExpectedException('\Drupal\migrate\MigrateException'); + $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php index 3245e60..0f89a5b 100644 --- a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php @@ -54,22 +54,20 @@ class ExplodeTest extends MigrateProcessTestCase { /** * Test explode fails properly on non-strings. * - * @expectedException \Drupal\migrate\MigrateException - * - * @expectedExceptionMessage is not a string */ public function testExplodeWithNonString() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'is not a string'); + $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } /** * Test explode fails with empty delimiter. * - * @expectedException \Drupal\migrate\MigrateException - * - * @expectedExceptionMessage delimiter is empty */ public function testExplodeWithEmptyDelimiter() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'delimiter is empty'); + $plugin = new Explode(['delimiter' => ''], 'map', []); $plugin->transform('foo,bar', $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/ExtractTest.php b/core/modules/migrate/tests/src/Unit/process/ExtractTest.php index 26c2cfe..fb17299 100644 --- a/core/modules/migrate/tests/src/Unit/process/ExtractTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ExtractTest.php @@ -29,21 +29,19 @@ class ExtractTest extends MigrateProcessTestCase { /** * Tests invalid input. - * - * @expectedException \Drupal\migrate\MigrateException - * @expectedExceptionMessage Input should be an array. */ public function testExtractFromString() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'Input should be an array.'); + $this->plugin->transform('bar', $this->migrateExecutable, $this->row, 'destinationproperty'); } /** * Tests unsuccessful extraction. - * - * @expectedException \Drupal\migrate\MigrateException - * @expectedExceptionMessage Array index missing, extraction failed. */ public function testExtractFail() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'Array index missing, extraction failed.'); + $this->plugin->transform(array('bar' => 'foo'), $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php index 4eb52da..3fb8f10 100644 --- a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php @@ -89,10 +89,10 @@ class MigrationTest extends MigrateProcessTestCase { /** * Tests that processing is skipped when the input value is empty. - * - * @expectedException \Drupal\migrate\MigrateSkipProcessException */ public function testSkipOnEmpty() { + $this->setExpectedException('\Drupal\migrate\MigrateSkipProcessException'); + $migration_plugin = $this->prophesize(MigrationInterface::class); $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); $process_plugin_manager = $this->prophesize(MigratePluginManager::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..21f2525 100644 --- a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php @@ -13,9 +13,10 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { /** * @covers ::process - * @expectedException \Drupal\migrate\MigrateSkipProcessException */ public function testProcessSkipsOnEmpty() { + $this->setExpectedException('\Drupal\migrate\MigrateSkipProcessException'); + $configuration['method'] = 'process'; (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); @@ -33,9 +34,10 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { /** * @covers ::row - * @expectedException \Drupal\migrate\MigrateSkipRowException */ public function testRowSkipsOnEmpty() { + $this->setExpectedException('\Drupal\migrate\MigrateSkipRowException'); + $configuration['method'] = 'row'; (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); diff --git a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php index 59db2e5..7fab8c8 100644 --- a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php +++ b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php @@ -38,19 +38,19 @@ class StaticMapTest extends MigrateProcessTestCase { /** * Tests when the source is empty. - * - * @expectedException \Drupal\migrate\MigrateException */ public function testMapwithEmptySource() { + $this->setExpectedException('\Drupal\migrate\MigrateException'); + $this->plugin->transform(array(), $this->migrateExecutable, $this->row, 'destinationproperty'); } /** * Tests when the source is invalid. - * - * @expectedException \Drupal\migrate\MigrateSkipRowException */ public function testMapwithInvalidSource() { + $this->setExpectedException('\Drupal\migrate\MigrateSkipRowException'); + $this->plugin->transform(array('bar'), $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -78,11 +78,10 @@ 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() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'Setting both default_value and bypass is invalid.'); + $configuration['map']['foo']['bar'] = 'baz'; $configuration['default_value'] = 'test'; $configuration['bypass'] = TRUE; diff --git a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php index fb84509..189a47f 100644 --- a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php @@ -55,11 +55,10 @@ class SubstrTest extends MigrateProcessTestCase { /** * Tests invalid input type. - * - * @expectedException \Drupal\migrate\MigrateException - * @expectedExceptionMessage The input value must be a string. */ public function testSubstrFail() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'The input value must be a string.'); + $configuration = []; $this->plugin = new Substr($configuration, 'map', []); $this->plugin->transform(['Captain Janeway'], $this->migrateExecutable, $this->row, 'destinationproperty'); @@ -67,11 +66,10 @@ class SubstrTest extends MigrateProcessTestCase { /** * 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() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.'); + $configuration['start'] = '2'; $this->plugin = new Substr($configuration, 'map', []); $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); @@ -79,11 +77,10 @@ class SubstrTest extends MigrateProcessTestCase { /** * 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() { + $this->setExpectedException('\Drupal\migrate\MigrateException', 'The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.'); + $configuration['length'] = '1'; $this->plugin = new Substr($configuration, 'map', []); $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php index 7021070..8b70f01 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php @@ -82,10 +82,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->setExpectedException('\Symfony\Component\Serializer\Exception\UnexpectedValueException'); + $this->entityNormalizer->denormalize(array(), 'Drupal\Core\Entity\ContentEntityBase'); } @@ -178,11 +178,12 @@ class EntityNormalizerTest extends UnitTestCase { /** * Tests the denormalize method with a bundle property. * - * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException * * @covers ::denormalize */ public function testDenormalizeWithInvalidBundle() { + $this->setExpectedException('\Symfony\Component\Serializer\Exception\UnexpectedValueException'); + $test_data = [ 'key_1' => 'value_1', 'key_2' => 'value_2', diff --git a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php index df98377..58a9dcb 100644 --- a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php +++ b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php @@ -235,10 +235,10 @@ class TestInfoParsingTest extends UnitTestCase { /** * @covers ::getTestInfo - * @expectedException \Drupal\simpletest\Exception\MissingGroupException - * @expectedExceptionMessage Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest */ public function testTestInfoParserMissingGroup() { + $this->setExpectedException('\Drupal\simpletest\Exception\MissingGroupException', 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest'); + $classname = 'Drupal\KernelTests\field\BulkDeleteTest'; $doc_comment = <<setExpectedException('\Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException', 'No route found for the specified formats application/json text/xml.'); + // Remove the sample routes that would match any method. $routes = $this->fixtures->sampleRouteCollection(); $routes->remove('route_a'); diff --git a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php index 1aa2f66..b4b315c 100644 --- a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php +++ b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php @@ -42,10 +42,10 @@ class DbCommandBaseTest extends KernelTestBase { /** * Invalid database names will throw a useful exception. - * - * @expectedException \Drupal\Core\Database\ConnectionNotDefinedException */ public function testSpecifyDatabaseDoesNotExist() { + $this->setExpectedException('\Drupal\Core\Database\ConnectionNotDefinedException'); + $command = new DbCommandBaseTester(); $command_tester = new CommandTester($command); $command_tester->execute([ diff --git a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php index 515c862..2301eac 100644 --- a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php @@ -121,9 +121,10 @@ class PrivateTempStoreTest extends UnitTestCase { * Tests the set() method with no lock available. * * @covers ::set - * @expectedException \Drupal\user\TempStoreException */ public function testSetWithNoLockAvailable() { + $this->setExpectedException('\Drupal\user\TempStoreException'); + $this->lock->expects($this->at(0)) ->method('acquire') ->with('1:test') @@ -220,9 +221,10 @@ class PrivateTempStoreTest extends UnitTestCase { * Tests the delete() method with no lock available. * * @covers ::delete - * @expectedException \Drupal\user\TempStoreException */ public function testDeleteWithNoLockAvailable() { + $this->setExpectedException('\Drupal\user\TempStoreException'); + $this->keyValue->expects($this->once()) ->method('get') ->with('1:test') diff --git a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php index 15a4ec6..6acedfe 100644 --- a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php @@ -132,9 +132,10 @@ class SharedTempStoreTest extends UnitTestCase { * Tests the set() method with no lock available. * * @covers ::set - * @expectedException \Drupal\user\TempStoreException */ public function testSetWithNoLockAvailable() { + $this->setExpectedException('\Drupal\user\TempStoreException'); + $this->lock->expects($this->at(0)) ->method('acquire') ->with('test') @@ -296,9 +297,10 @@ class SharedTempStoreTest extends UnitTestCase { * Tests the delete() method with no lock available. * * @covers ::delete - * @expectedException \Drupal\user\TempStoreException */ public function testDeleteWithNoLockAvailable() { + $this->setExpectedException('\Drupal\user\TempStoreException'); + $this->lock->expects($this->at(0)) ->method('acquire') ->with('test') diff --git a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php index d6b2a1e..af697d8 100644 --- a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php +++ b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php @@ -113,20 +113,20 @@ class ViewAjaxControllerTest extends UnitTestCase { /** * Tests missing view_name and view_display_id - * - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testMissingViewName() { + $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\NotFoundHttpException'); + $request = new Request(); $this->viewAjaxController->ajaxView($request); } /** * Tests with view_name and view_display_id but not existing view. - * - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testMissingView() { + $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\NotFoundHttpException'); + $request = new Request(); $request->request->set('view_name', 'test_view'); $request->request->set('view_display_id', 'page_1'); @@ -141,10 +141,10 @@ class ViewAjaxControllerTest extends UnitTestCase { /** * Tests a view without having access to it. - * - * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function testAccessDeniedView() { + $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException'); + $request = new Request(); $request->request->set('view_name', 'test_view'); $request->request->set('view_display_id', 'page_1'); 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..149d494 100644 --- a/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php @@ -30,9 +30,10 @@ class PageTest extends UnitTestCase { /** * @covers ::buildBasicRenderable - * @expectedException \BadFunctionCallException */ public function testBuildBasicRenderableWithMissingRoute() { + $this->setExpectedException('\BadFunctionCallException'); + Page::buildBasicRenderable('test_view', 'page_1', []); } diff --git a/core/modules/views/tests/src/Unit/ViewExecutableTest.php b/core/modules/views/tests/src/Unit/ViewExecutableTest.php index fe64ec2..c606850 100644 --- a/core/modules/views/tests/src/Unit/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Unit/ViewExecutableTest.php @@ -182,11 +182,12 @@ class ViewExecutableTest extends UnitTestCase { } /** - * @expectedException \InvalidArgumentException * * @covers ::getUrl */ public function testGetUrlWithoutRouterDisplay() { + $this->setExpectedException('\InvalidArgumentException'); + $this->displayHandler = $this->getMock('Drupal\views\Plugin\views\display\DisplayPluginInterface'); $this->displayHandlers->expects($this->any()) ->method('get') diff --git a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php index cd42ad1..044eb3c 100644 --- a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php +++ b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php @@ -107,9 +107,10 @@ class SafeMarkupKernelTest extends KernelTestBase { /** * @dataProvider providerTestSafeMarkupUriWithException - * @expectedException \InvalidArgumentException */ public function testSafeMarkupUriWithExceptionUri($string, $uri) { + $this->setExpectedException('\InvalidArgumentException'); + // Should throw an \InvalidArgumentException, due to Uri::toString(). $args = self::getSafeMarkupUriArgs($uri); diff --git a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php index 98423ca..9c1915c 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php @@ -82,10 +82,10 @@ class ThemeRenderAndAutoescapeTest extends KernelTestBase { /** * Ensures invalid content is handled correctly. - * - * @expectedException \Exception */ public function testThemeEscapeAndRenderNotPrintable() { + $this->setExpectedException('\Exception'); + theme_render_and_autoescape(new NonPrintable()); } diff --git a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php index b8be130..482add2 100644 --- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php +++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php @@ -100,9 +100,10 @@ class DateTimePlusTest extends UnitTestCase { * Timezone argument for DateTimePlus. * * @dataProvider providerTestInvalidDateArrays - * @expectedException \Exception */ public function testInvalidDateArrays($input, $timezone) { + $this->setExpectedException('\Exception'); + $this->assertInstanceOf( '\Drupal\Component\DateTimePlus', DateTimePlus::createFromArray($input, $timezone) @@ -236,9 +237,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) { + $this->setExpectedException('\Exception'); + DateTimePlus::createFromFormat($format, $input, $timezone); } diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index 3c89804..9f19fc4 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -59,10 +59,10 @@ 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() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $container_definition = $this->getMockContainerDefinition(); $container_definition['machine_format'] = !$this->machineFormat; $container = new $this->containerClass($container_definition); @@ -85,10 +85,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::getParameter * @covers ::getParameterAlternatives * @covers ::getAlternatives - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ public function testGetParameterIfNotFound() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException'); + $this->container->getParameter('parameter_that_does_not_exist'); } @@ -96,10 +96,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * Tests that Container::getParameter() works properly for NULL parameters. * * @covers ::getParameter - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ public function testGetParameterIfNotFoundBecauseNull() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException'); + $this->container->getParameter(NULL); } @@ -130,10 +130,10 @@ 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->setExpectedException('\Symfony\Component\DependencyInjection\Exception\LogicException'); + $this->container = new $this->containerClass($this->containerDefinition); $this->container->setParameter('some_config', 'new_value'); } @@ -235,11 +235,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->setExpectedException('\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException'); + $this->container->get('circular_dependency'); } @@ -250,10 +251,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::createService * @covers ::getAlternatives * @covers ::getServiceAlternatives - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantService() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); + $this->container->get('service_not_exists'); } @@ -295,10 +296,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetForParameterDependencyWithExceptionOnSecondCall() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); $this->assertNull($service, 'Service is NULL.'); @@ -313,10 +314,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetForNonExistantParameterDependencyWithException() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->container->get('service_parameter_not_exists'); } @@ -339,10 +340,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::createService * @covers ::resolveServicesAndParameters * @covers ::getAlternatives - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantServiceDependencyWithException() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); + $this->container->get('service_dependency_not_exists'); } @@ -360,10 +361,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->setExpectedException('\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); + $this->container->get(NULL); } @@ -386,10 +387,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::get * @covers ::createService * @covers ::getAlternatives - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ public function testGetForNonExistantServiceWithExceptionOnSecondCall() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'); + $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'); } @@ -424,10 +425,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * * @covers ::get * @covers ::createService - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetForSyntheticServiceWithException() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->container->get('synthetic'); } @@ -464,10 +465,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * * @covers ::get * @covers ::createService - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetForWrongFactory() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->container->get('wrong_factory'); } @@ -503,10 +504,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * * @covers ::get * @covers ::createService - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetForConfiguratorWithException() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->container->get('configurable_service_exception'); } @@ -602,10 +603,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testResolveServicesAndParametersForInvalidArgument() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->container->get('invalid_argument_service'); } @@ -615,10 +616,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testResolveServicesAndParametersForInvalidArguments() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + // In case the machine-optimized format is not used, we need to simulate the // test failure. if (!$this->machineFormat) { @@ -671,11 +672,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { * @covers ::hasScope * @covers ::isScopeActive * - * @expectedException \BadMethodCallException * * @dataProvider scopeExceptionTestProvider */ public function testScopeFunctionsWithException($method, $argument) { + $this->setExpectedException('\BadMethodCallException'); + $callable = array( $this->container, $method, diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 49b6556..a058c6e 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -481,10 +481,10 @@ 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() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $bar_definition = new Definition('\stdClass'); $bar_definition->setScope('foo_scope'); $services['bar'] = $bar_definition; @@ -554,10 +554,10 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { * getDecoratedService(). * * @covers ::getServiceDefinition - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testGetServiceDefinitionForDecoratedService() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $bar_definition = new Definition('\stdClass'); $bar_definition->setDecoratedService(new Reference('foo')); $services['bar'] = $bar_definition; @@ -570,10 +570,10 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { * Tests that the correct RuntimeException is thrown for expressions. * * @covers ::dumpValue - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetServiceDefinitionForExpression() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $expression = new Expression(); $bar_definition = new Definition('\stdClass'); @@ -588,10 +588,10 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { * Tests that the correct RuntimeException is thrown for dumping an object. * * @covers ::dumpValue - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetServiceDefinitionForObject() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $service = new \stdClass(); $bar_definition = new Definition('\stdClass'); @@ -606,10 +606,10 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { * Tests that the correct RuntimeException is thrown for dumping a resource. * * @covers ::dumpValue - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ public function testGetServiceDefinitionForResource() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $resource = fopen('php://memory', 'r'); $bar_definition = new Definition('\stdClass'); diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php index b4d8de9..461d1bc 100644 --- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php @@ -55,11 +55,10 @@ class FileCacheFactoryTest extends UnitTestCase { /** * @covers ::get - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Required prefix configuration is missing */ public function testGetNoPrefix() { + $this->setExpectedException('\InvalidArgumentException', 'Required prefix configuration is missing'); + FileCacheFactory::setPrefix(NULL); FileCacheFactory::get('test_foo_settings', []); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php index 1fc805b..cf6cf82 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php @@ -47,11 +47,10 @@ 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() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException', 'The plugin (cherry) did not specify an instance class.'); + DefaultFactory::getPluginClass('cherry', []); } @@ -59,11 +58,10 @@ 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 testGetPluginClassWithMissingClassWithObjectPluginDefinition() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException', 'The plugin (cherry) did not specify an instance class.'); + $plugin_definition = $this->getMock(PluginDefinitionInterface::class); DefaultFactory::getPluginClass('cherry', $plugin_definition); } @@ -72,11 +70,10 @@ class DefaultFactoryTest extends UnitTestCase { * Tests getPluginClass() with a not existing class definition. * * @covers ::getPluginClass - * - * @expectedException \Drupal\Component\Plugin\Exception\PluginException - * @expectedExceptionMessage Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist. */ public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException', 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.'); + DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']); } @@ -84,10 +81,10 @@ class DefaultFactoryTest extends UnitTestCase { * Tests getPluginClass() with a not existing class definition. * * @covers ::getPluginClass - * - * @expectedException \Drupal\Component\Plugin\Exception\PluginException */ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException'); + $plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit'; $plugin_definition = $this->getMock(PluginDefinitionInterface::class); $plugin_definition->expects($this->atLeastOnce()) @@ -128,11 +125,10 @@ 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() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException', 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.'); + $plugin_class = Kale::class; DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::class); } @@ -141,10 +137,10 @@ class DefaultFactoryTest extends UnitTestCase { * Tests getPluginClass() with a required interface but no implementation. * * @covers ::getPluginClass - * - * @expectedException \Drupal\Component\Plugin\Exception\PluginException */ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException'); + $plugin_class = Kale::class; $plugin_definition = $this->getMock(PluginDefinitionInterface::class); $plugin_definition->expects($this->atLeastOnce()) diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php index 9f747f9..7141aff 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php @@ -58,11 +58,12 @@ class DiscoveryTraitTest extends UnitTestCase { /** * @covers ::doGetDefinition - * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException * @dataProvider providerDoGetDefinitionException * @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function testDoGetDefinitionException($expected, $definitions, $plugin_id) { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginNotFoundException'); + // Mock the trait. $trait = $this->getMockForTrait('Drupal\Component\Plugin\Discovery\DiscoveryTrait'); // Un-protect the method using reflection. @@ -96,11 +97,12 @@ class DiscoveryTraitTest extends UnitTestCase { /** * @covers ::getDefinition - * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException * @dataProvider providerDoGetDefinitionException * @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function testGetDefinitionException($expected, $definitions, $plugin_id) { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginNotFoundException'); + // Since getDefinition is a wrapper around doGetDefinition(), we can re-use // its data provider. We just have to tell abstract method getDefinitions() // to use the $definitions array. diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php index ef0d7fb..6a74103 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php @@ -74,9 +74,10 @@ foo: * Tests that invalid YAML throws an exception. * * @covers ::errorHandler - * @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException */ public function testError() { + $this->setExpectedException('\Drupal\Component\Serialization\Exception\InvalidDataTypeException'); + YamlPecl::decode('foo: [ads'); } diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php index 3101efe..f509dfe 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php @@ -56,9 +56,10 @@ class YamlSymfonyTest extends YamlTestBase { * Tests that invalid YAML throws an exception. * * @covers ::decode - * @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException */ public function testError() { + $this->setExpectedException('\Drupal\Component\Serialization\Exception\InvalidDataTypeException'); + YamlSymfony::decode('foo: [ads'); } diff --git a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php index 878bbfd..fa655e2 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php @@ -121,11 +121,10 @@ 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() { + $this->setExpectedException('\RuntimeException', 'requires a value for the "$route" argument.'); + $a = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1'); $wildcards = [$a]; $resolver = new ArgumentsResolver([], [], $wildcards); @@ -152,11 +151,10 @@ class ArgumentsResolverTest extends UnitTestCase { /** * Tests handleUnresolvedArgument() for a scalar argument. - * - * @expectedException \RuntimeException - * @expectedExceptionMessage requires a value for the "$foo" argument. */ public function testHandleNotUpcastedArgument() { + $this->setExpectedException('\RuntimeException', 'requires a value for the "$foo" argument.'); + $objects = ['foo' => 'bar']; $scalars = ['foo' => 'baz']; $resolver = new ArgumentsResolver($scalars, $objects, []); @@ -169,12 +167,12 @@ class ArgumentsResolverTest extends UnitTestCase { /** * Tests handleUnresolvedArgument() for missing arguments. * - * @expectedException \RuntimeException - * @expectedExceptionMessage requires a value for the "$foo" argument. * * @dataProvider providerTestHandleUnresolvedArgument */ public function testHandleUnresolvedArgument($callable) { + $this->setExpectedException('\RuntimeException', 'requires a value for the "$foo" argument.'); + $resolver = new ArgumentsResolver([], [], []); $arguments = $resolver->getArguments($callable); $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..b6c987a 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 @@ -78,6 +77,8 @@ class CryptTest extends UnitTestCase { * Key to use in hashing process. */ public function testHmacBase64Invalid($data, $key) { + $this->setExpectedException('InvalidArgumentException'); + Crypt::hmacBase64($data, $key); } diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php index 6a106c7..1aa8245 100644 --- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php @@ -332,9 +332,10 @@ class HtmlTest extends UnitTestCase { /** * @covers ::transformRootRelativeUrlsToAbsolute * @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion - * @expectedException \AssertionError */ public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) { + $this->setExpectedException('\AssertionError'); + Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host); } diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php index b677585..e273079 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -57,9 +57,10 @@ class RandomTest extends UnitTestCase { * Tests infinite loop prevention whilst generating random names. * * @covers ::name - * @expectedException \RuntimeException */ public function testRandomNameException() { + $this->setExpectedException('\RuntimeException'); + // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. $random = new Random(); @@ -73,9 +74,10 @@ class RandomTest extends UnitTestCase { * Tests infinite loop prevention whilst generating random strings. * * @covers ::string - * @expectedException \RuntimeException */ public function testRandomStringException() { + $this->setExpectedException('\RuntimeException'); + // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. $random = new Random(); diff --git a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php index 0aa29a6..d424b62 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php @@ -15,10 +15,10 @@ class RectangleTest extends UnitTestCase { * Tests wrong rectangle width. * * @covers ::rotate - * - * @expectedException \InvalidArgumentException */ public function testWrongWidth() { + $this->setExpectedException('\InvalidArgumentException'); + $rect = new Rectangle(-40, 20); } @@ -26,10 +26,10 @@ class RectangleTest extends UnitTestCase { * Tests wrong rectangle height. * * @covers ::rotate - * - * @expectedException \InvalidArgumentException */ public function testWrongHeight() { + $this->setExpectedException('\InvalidArgumentException'); + $rect = new Rectangle(40, 0); } diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php index 87ab75f..0f52519 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -560,9 +560,10 @@ class UrlHelperTest extends UnitTestCase { * * @covers ::externalIsLocal * @dataProvider providerTestExternalIsLocalInvalid - * @expectedException \InvalidArgumentException */ public function testExternalIsLocalInvalid($url, $base_url) { + $this->setExpectedException('\InvalidArgumentException'); + UrlHelper::externalIsLocal($url, $base_url); } diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index eee5260..a2e8664 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -474,10 +474,10 @@ 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) { + $this->setExpectedException('\Drupal\Core\Access\AccessException'); + $route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface'); // Setup a test route for each access configuration. diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php index 6eabd37..47f3427 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php @@ -171,9 +171,10 @@ class CsrfTokenGeneratorTest extends UnitTestCase { * * @covers ::validate * @dataProvider providerTestInvalidParameterTypes - * @expectedException InvalidArgumentException */ public function testInvalidParameterTypes($token, $value = '') { + $this->setExpectedException('InvalidArgumentException'); + $this->setupDefaultExpectations(); $this->generator->validate($token, $value); @@ -198,9 +199,10 @@ class CsrfTokenGeneratorTest extends UnitTestCase { * Tests the exception thrown when no 'hash_salt' is provided in settings. * * @covers ::get - * @expectedException \RuntimeException */ public function testGetWithNoHashSalt() { + $this->setExpectedException('\RuntimeException'); + // Update settings with no hash salt. new Settings(array()); $generator = new CsrfTokenGenerator($this->privateKey, $this->sessionMetadata); diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index 121aebc..e0cb9b1 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -143,11 +143,12 @@ 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() { + $this->setExpectedException('\Drupal\Core\Asset\Exception\InvalidLibraryFileException'); + $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('invalid_file') @@ -163,12 +164,12 @@ class LibraryDiscoveryParserTest extends UnitTestCase { /** * 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() { + $this->setExpectedException('\Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException', 'Incomplete library definition for definition "example" in extension "example_module_missing_information"'); + $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('example_module_missing_information') @@ -276,11 +277,12 @@ class LibraryDiscoveryParserTest extends UnitTestCase { /** * Ensures that you cannot provide positive weights for JavaScript libraries. * - * @expectedException \UnexpectedValueException * * @covers ::buildByExtension */ public function testJsWithPositiveWeight() { + $this->setExpectedException('\UnexpectedValueException'); + $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('js_positive_weight') @@ -403,12 +405,12 @@ 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() { + $this->setExpectedException('\Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException', 'Missing license information in library definition for definition "no-license-info-but-remote" extension "licenses_missing_information": it has a remote, but no license.'); + $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') ->with('licenses_missing_information') diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php index 32ea0d0..680e9f8 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php @@ -183,10 +183,10 @@ class BreadcrumbManagerTest extends UnitTestCase { /** * Tests a breadcrumb builder with a bad return value. - * - * @expectedException \UnexpectedValueException */ public function testBuildWithInvalidBreadcrumbResult() { + $this->setExpectedException('\UnexpectedValueException'); + $builder = $this->getMock('Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface'); $builder->expects($this->once()) ->method('applies') diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php index ca8acfc..f4f3dfc 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php @@ -15,10 +15,10 @@ class BreadcrumbTest extends UnitTestCase { /** * @covers ::setLinks - * @expectedException \LogicException - * @expectedExceptionMessage Once breadcrumb links are set, only additional breadcrumb links can be added. */ public function testSetLinks() { + $this->setExpectedException('\LogicException', 'Once breadcrumb links are set, only additional breadcrumb links can be added.'); + $breadcrumb = new Breadcrumb(); $breadcrumb->setLinks([new Link('Home', Url::fromRoute(''))]); $breadcrumb->setLinks([new Link('None', Url::fromRoute(''))]); diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php index edb220a..fff0c61 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php @@ -14,10 +14,10 @@ class CacheTagsInvalidatorTest extends UnitTestCase { /** * @covers ::invalidateTags - * - * @expectedException \AssertionError */ public function testInvalidateTagsWithInvalidTags() { + $this->setExpectedException('\AssertionError'); + $cache_tags_invalidator = new CacheTagsInvalidator(); $cache_tags_invalidator->invalidateTags(['node' => [2, 3, 5, 8, 13]]); } diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php index 0bc9d7f..751cade 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -105,10 +105,10 @@ class CacheContextsManagerTest extends UnitTestCase { /** * @covers ::convertTokensToKeys - * - * @expectedException \AssertionError */ public function testInvalidContext() { + $this->setExpectedException('\AssertionError'); + $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); @@ -118,11 +118,12 @@ class CacheContextsManagerTest extends UnitTestCase { /** * @covers ::convertTokensToKeys * - * @expectedException \Exception * * @dataProvider providerTestInvalidCalculatedContext */ public function testInvalidCalculatedContext($context_token) { + $this->setExpectedException('\Exception'); + $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index 223d890..683945b 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -230,17 +230,19 @@ class ConfigTest extends UnitTestCase { /** * @covers ::set - * @expectedException \Drupal\Core\Config\ConfigValueException */ public function testSetValidation() { + $this->setExpectedException('\Drupal\Core\Config\ConfigValueException'); + $this->config->set('testData', array('dot.key' => 1)); } /** * @covers ::set - * @expectedException PHPUnit_Framework_Error_Warning */ public function testSetIllegalOffsetValue() { + $this->setExpectedException('PHPUnit_Framework_Error_Warning'); + // Set a single value. $this->config->set('testData', 1); @@ -383,10 +385,11 @@ class ConfigTest extends UnitTestCase { /** * @covers ::validateName - * @expectedException \Drupal\Core\Config\ConfigNameException * @dataProvider validateNameProvider */ public function testValidateNameException($name, $exception_message) { + $this->setExpectedException('\Drupal\Core\Config\ConfigNameException'); + $this->setExpectedException('\Drupal\Core\Config\ConfigNameException', $exception_message); $this->config->validateName($name); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index 4710765..a79c207 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -567,10 +567,10 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { /** * @covers ::toArray - * - * @expectedException \Drupal\Core\Config\Schema\SchemaIncompleteException */ public function testToArrayFallback() { + $this->setExpectedException('\Drupal\Core\Config\Schema\SchemaIncompleteException'); + $this->entityType->expects($this->any()) ->method('getPropertiesToExport') ->willReturn([]); diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 6f02023..0668191 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -470,11 +470,10 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * @covers ::save - * - * @expectedException \Drupal\Core\Entity\EntityMalformedException - * @expectedExceptionMessage The entity does not have an ID. */ public function testSaveInvalid() { + $this->setExpectedException('\Drupal\Core\Entity\EntityMalformedException', 'The entity does not have an ID.'); + $this->cacheTagsInvalidator->expects($this->never()) ->method('invalidateTags'); @@ -485,10 +484,10 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * @covers ::save * @covers ::doSave - * - * @expectedException \Drupal\Core\Entity\EntityStorageException */ public function testSaveDuplicate() { + $this->setExpectedException('\Drupal\Core\Entity\EntityStorageException'); + $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') ->disableOriginalConstructor() ->getMock(); @@ -517,11 +516,10 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * @covers ::save * @covers ::doSave - * - * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException - * @expectedExceptionMessage when this UUID is already used for */ public function testSaveMismatch() { + $this->setExpectedException('\Drupal\Core\Config\ConfigDuplicateUUIDException', 'when this UUID is already used for'); + $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') ->disableOriginalConstructor() ->getMock(); @@ -600,11 +598,10 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * @covers ::save * @covers ::doSave - * - * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException - * @expectedExceptionMessage when this entity already exists with UUID */ public function testSaveChangedUuid() { + $this->setExpectedException('\Drupal\Core\Config\ConfigDuplicateUUIDException', 'when this entity already exists with UUID'); + $config_object = $this->getMockBuilder('Drupal\Core\Config\Config') ->disableOriginalConstructor() ->getMock(); diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php index b131b26..1cde85e 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -79,11 +79,10 @@ 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() { + $this->setExpectedException('\Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException', '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); + new ConfigEntityType([ 'id' => 'example_config_entity_type', 'handlers' => ['storage' => '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'] @@ -92,11 +91,10 @@ class ConfigEntityTypeTest extends UnitTestCase { /** * @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() { + $this->setExpectedException('\Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException', '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); + $config_entity = $this->setUpConfigEntityType([]); $config_entity->setStorageClass('\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php index 75fe625..38c18aa 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php @@ -96,10 +96,10 @@ 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() { + $this->setExpectedException('\LogicException', 'test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup'); + $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'); $key_value_factory = $this->getMock('Drupal\Core\KeyValueStore\KeyValueFactoryInterface'); $config_manager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface'); diff --git a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php index 5b5c498..0785fe9 100644 --- a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php @@ -28,37 +28,37 @@ 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->setExpectedException('\Drupal\Core\Config\ImmutableConfigException', 'Can not set values on immutable configuration test:name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); + $this->config->set('name', 'value'); } /** * @covers ::clear - * @expectedException \Drupal\Core\Config\ImmutableConfigException - * @expectedExceptionMessage Can not clear name key in immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object */ public function testClear() { + $this->setExpectedException('\Drupal\Core\Config\ImmutableConfigException', 'Can not clear name key in immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); + $this->config->clear('name'); } /** * @covers ::save - * @expectedException \Drupal\Core\Config\ImmutableConfigException - * @expectedExceptionMessage Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object */ public function testSave() { + $this->setExpectedException('\Drupal\Core\Config\ImmutableConfigException', 'Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); + $this->config->save(); } /** * @covers ::delete - * @expectedException \Drupal\Core\Config\ImmutableConfigException - * @expectedExceptionMessage Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object */ public function testDelete() { + $this->setExpectedException('\Drupal\Core\Config\ImmutableConfigException', 'Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); + $this->config->delete(); } diff --git a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php index 98a18a3..f236697 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php @@ -120,19 +120,19 @@ class ControllerResolverTest extends UnitTestCase { /** * Tests createController() with a non-existent class. - * - * @expectedException \InvalidArgumentException */ public function testCreateControllerNonExistentClass() { + $this->setExpectedException('\InvalidArgumentException'); + $this->controllerResolver->getControllerFromDefinition('Class::method'); } /** * Tests createController() with an invalid name. - * - * @expectedException \LogicException */ public function testCreateControllerInvalidName() { + $this->setExpectedException('\LogicException'); + $this->controllerResolver->getControllerFromDefinition('ClassWithoutMethod'); } @@ -191,10 +191,10 @@ class ControllerResolverTest extends UnitTestCase { } /** * Tests getControllerFromDefinition() without a callable. - * - * @expectedException \InvalidArgumentException */ public function testGetControllerFromDefinitionNotCallable() { + $this->setExpectedException('\InvalidArgumentException'); + $this->controllerResolver->getControllerFromDefinition('Drupal\Tests\Core\Controller\MockController::bananas'); } diff --git a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php index f33e3c3..84d01d3 100644 --- a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php @@ -140,10 +140,11 @@ class ConditionTest extends UnitTestCase { /** * @covers ::compile * - * @expectedException \PHPUnit_Framework_Error * @dataProvider providerTestCompileWithSqlInjectionForOperator */ public function testCompileWithSqlInjectionForOperator($operator) { + $this->setExpectedException('\PHPUnit_Framework_Error'); + $connection = $this->prophesize(Connection::class); $connection->escapeField(Argument::any())->will(function ($args) { return preg_replace('/[^A-Za-z0-9_.]+/', '', $args[0]); diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php index b43971d..011cd5c 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php @@ -64,10 +64,10 @@ class ProxyServicesPassTest extends UnitTestCase { /** * @covers ::process - * - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testContainerWithLazyServicesWithoutProxyClass() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $container = new ContainerBuilder(); $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist') ->setLazy(TRUE); diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php index 2eeb603..1d68ab2 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -44,11 +44,11 @@ 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() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\LogicException', 'At least one service tagged with "consumer_id" is required.'); + $container = $this->buildContainer(); $container ->register('consumer_id', __NAMESPACE__ . '\ValidConsumer') @@ -63,11 +63,11 @@ class TaggedHandlersPassTest extends UnitTestCase { /** * 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() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\LogicException', 'Service consumer "consumer_id" class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface.'); + $container = $this->buildContainer(); $container ->register('consumer_id', __NAMESPACE__ . '\InvalidConsumer') @@ -204,10 +204,11 @@ class TaggedHandlersPassTest extends UnitTestCase { /** * Tests interface validation in non-production environment. * - * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException * @covers ::process */ public function testProcessInterfaceMismatch() { + $this->setExpectedException('\Symfony\Component\DependencyInjection\Exception\LogicException'); + $container = $this->buildContainer(); $container diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php index 4a6eae7..8e97868 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php @@ -35,10 +35,10 @@ class ContainerBuilderTest extends UnitTestCase { /** * @covers ::set - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Service ID names must be lowercase: Bar */ public function testSetException() { + $this->setExpectedException('\InvalidArgumentException', 'Service ID names must be lowercase: Bar'); + $container = new ContainerBuilder(); $class = new BarClass(); $container->set('Bar', $class); @@ -47,30 +47,30 @@ class ContainerBuilderTest extends UnitTestCase { /** * @covers ::setParameter - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Parameter names must be lowercase: Buzz */ public function testSetParameterException() { + $this->setExpectedException('\InvalidArgumentException', 'Parameter names must be lowercase: Buzz'); + $container = new ContainerBuilder(); $container->setParameter('Buzz', 'buzz'); } /** * @covers ::register - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Service ID names must be lowercase: Bar */ public function testRegisterException() { + $this->setExpectedException('\InvalidArgumentException', 'Service ID names must be lowercase: Bar'); + $container = new ContainerBuilder(); $container->register('Bar'); } /** * Tests serialization. - * - * @expectedException \AssertionError */ public function testSerialize() { + $this->setExpectedException('\AssertionError'); + $container = new ContainerBuilder(); serialize($container); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php index 0ae5dd5..294eba2 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php @@ -14,10 +14,10 @@ class ContainerTest extends UnitTestCase { /** * Tests serialization. - * - * @expectedException \AssertionError */ public function testSerialize() { + $this->setExpectedException('\AssertionError'); + $container = new Container(); serialize($container); } diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php index de94bf8..fbddb3a 100644 --- a/core/tests/Drupal/Tests/Core/DrupalTest.php +++ b/core/tests/Drupal/Tests/Core/DrupalTest.php @@ -43,11 +43,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() { + $this->setExpectedException('\Drupal\Core\DependencyInjection\ContainerNotInitializedException', '\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.'); + \Drupal::getContainer(); } diff --git a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php index dbd50e7..7f9b679 100644 --- a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php @@ -298,9 +298,10 @@ class BaseFieldDefinitionTest extends UnitTestCase { * Tests invalid default value callbacks. * * @covers ::setDefaultValueCallback - * @expectedException \InvalidArgumentException */ public function testInvalidDefaultValueCallback() { + $this->setExpectedException('\InvalidArgumentException'); + $definition = BaseFieldDefinition::create($this->fieldType); // setDefaultValueCallback returns $this. $this->assertSame($definition, diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index cb73533..ef9bc44 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -352,11 +352,10 @@ class ContentEntityBaseUnitTest extends UnitTestCase { * @covers ::setValidationRequired * @covers ::save * @covers ::preSave - * - * @expectedException \LogicException - * @expectedExceptionMessage Entity validation was skipped. */ public function testRequiredValidation() { + $this->setExpectedException('\LogicException', 'Entity validation was skipped.'); + $validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface'); /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */ $empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList') diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php index 7cad93c..70723ed 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php @@ -310,12 +310,12 @@ 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) { + $this->setExpectedException('\LogicException', 'The Test entity type cannot be translatable as it does not define a translatable "langcode" field.'); + $keys = $provide_key ? ['langcode' => 'langcode'] : []; $this->setUpEntityWithFieldDefinition(FALSE, 'id', $keys); @@ -452,10 +452,10 @@ class EntityFieldManagerTest extends UnitTestCase { * * @covers ::getBaseFieldDefinitions * @covers ::buildBaseFieldDefinitions - * - * @expectedException \LogicException */ public function testGetBaseFieldDefinitionsInvalidDefinition() { + $this->setExpectedException('\LogicException'); + $this->setUpEntityWithFieldDefinition(FALSE, 'langcode', ['langcode' => 'langcode']); $this->entityType->isTranslatable()->willReturn(TRUE); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php index c2325d4..8e0fee8 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php @@ -248,10 +248,10 @@ class EntityTypeManagerTest extends UnitTestCase { * Tests the getFormObject() method with an invalid operation. * * @covers ::getFormObject - * - * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testGetFormObjectInvalidOperation() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException'); + $entity = $this->prophesize(EntityTypeInterface::class); $entity->getFormClass('edit')->willReturn(''); $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]); @@ -283,10 +283,10 @@ class EntityTypeManagerTest extends UnitTestCase { * Tests the getHandler() method when no controller is defined. * * @covers ::getHandler - * - * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testGetHandlerMissingHandler() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException'); + $entity = $this->prophesize(EntityTypeInterface::class); $entity->getHandlerClass('storage')->willReturn(''); $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]); @@ -314,11 +314,10 @@ 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() { + $this->setExpectedException('\Drupal\Core\Entity\Exception\InvalidLinkTemplateException', 'Link template "canonical" for entity type "apple" must start with a leading slash, the current link template is "path/to/apple"'); + $apple = $this->prophesize(EntityTypeInterface::class); $this->setUpEntityTypeDefinitions(['apple' => $apple]); @@ -370,11 +369,10 @@ 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->setExpectedException('\Drupal\Component\Plugin\Exception\PluginNotFoundException', 'The "pear" entity type does not exist.'); + $this->setUpEntityTypeDefinitions(); $this->entityTypeManager->getDefinition('pear', TRUE); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php index 3761e0d..baa0a89 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php @@ -130,11 +130,10 @@ 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() { + $this->setExpectedException('\Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException', 'The \Drupal\pear\Entity\Pear class does not correspond to an entity type.'); + $apple = $this->prophesize(EntityTypeInterface::class); $banana = $this->prophesize(EntityTypeInterface::class); @@ -151,11 +150,10 @@ class EntityTypeRepositoryTest extends UnitTestCase { /** * @covers ::getEntityTypeFromClass - * - * @expectedException \Drupal\Core\Entity\Exception\AmbiguousEntityClassException - * @expectedExceptionMessage Multiple entity types found for \Drupal\apple\Entity\Apple. */ public function testGetEntityTypeFromClassAmbiguous() { + $this->setExpectedException('\Drupal\Core\Entity\Exception\AmbiguousEntityClassException', 'Multiple entity types found for \Drupal\apple\Entity\Apple.'); + $boskoop = $this->prophesize(EntityTypeInterface::class); $boskoop->getOriginalClass()->willReturn('\Drupal\apple\Entity\Apple'); $boskoop->id()->willReturn('boskop'); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index d633afc..5deacf8 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -390,10 +390,10 @@ class EntityTypeTest extends UnitTestCase { /** * @covers ::setLinkTemplate - * - * @expectedException \InvalidArgumentException */ public function testSetLinkTemplateWithInvalidPath() { + $this->setExpectedException('\InvalidArgumentException'); + $entity_type = $this->setUpEntityType(['id' => $this->randomMachineName()]); $entity_type->setLinkTemplate('test', 'invalid-path'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 4fbdba3..5d067d9 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -439,11 +439,10 @@ 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->setExpectedException('\Drupal\Core\Entity\EntityMalformedException', 'The entity does not have an ID.'); + $this->setUpKeyValueEntityStorage(); $entity = $this->getMockEntity('Drupal\Core\Config\Entity\ConfigEntityBase'); @@ -459,11 +458,10 @@ 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->setExpectedException('\Drupal\Core\Entity\EntityStorageException', '"test_entity_type" entity with ID "foo" already exists'); + $this->setUpKeyValueEntityStorage(); $entity = $this->getMockEntity('Drupal\Core\Entity\Entity', array(array('id' => 'foo'))); 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..10b7c33 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php @@ -36,11 +36,10 @@ 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->setExpectedException('\Drupal\Core\Entity\Query\QueryException', 'No base table for example_entity_query, invalid query.'); + $this->query->execute(); } @@ -48,11 +47,10 @@ class QueryTest extends UnitTestCase { * Tests revision entity query for entity type without revision table. * * @covers ::prepare - * - * @expectedException \Drupal\Core\Entity\Query\QueryException - * @expectedExceptionMessage No revision table for example_entity_query, invalid query. */ public function testNoRevisionTable() { + $this->setExpectedException('\Drupal\Core\Entity\Query\QueryException', 'No revision table for example_entity_query, invalid query.'); + $this->query->allRevisions()->execute(); } diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php index 8ce420b..d71659e 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php @@ -294,14 +294,14 @@ 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 */ public function testGetFieldColumnNameInvalid($base_field, $columns, $column) { + $this->setExpectedException('\Drupal\Core\Entity\Sql\SqlContentEntityStorageException', 'Column information not available for the "test" field.'); + $definitions['test'] = $this->setUpDefinition('test', $columns, $base_field); // Mark field storage definition as custom storage. @@ -440,12 +440,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() { + $this->setExpectedException('\Drupal\Core\Entity\Sql\SqlContentEntityStorageException', 'Table information not available for the "invalid_field_name" field.'); + $table_mapping = new DefaultTableMapping($this->entityType, []); $table_mapping->getFieldTableName('invalid_field_name'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php index 646f17a..5223bb3 100644 --- a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php @@ -275,17 +275,19 @@ class EntityAdapterUnitTest extends UnitTestCase { /** * @covers ::get - * @expectedException \InvalidArgumentException */ public function testGetInvalidField() { + $this->setExpectedException('\InvalidArgumentException'); + $this->entityAdapter->get('invalid'); } /** * @covers ::get - * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testGetWithoutData() { + $this->setExpectedException('\Drupal\Core\TypedData\Exception\MissingDataException'); + $this->entityAdapter->setValue(NULL); $this->entityAdapter->get('id'); } @@ -305,9 +307,10 @@ class EntityAdapterUnitTest extends UnitTestCase { /** * @covers ::set - * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testSetWithoutData() { + $this->setExpectedException('\Drupal\Core\TypedData\Exception\MissingDataException'); + $this->entityAdapter->setValue(NULL); $id_items = [ array('value' => $this->id + 1) ]; $this->entityAdapter->set('id', $id_items); @@ -335,9 +338,10 @@ class EntityAdapterUnitTest extends UnitTestCase { /** * @covers ::toArray - * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException */ public function testToArrayWithoutData() { + $this->setExpectedException('\Drupal\Core\TypedData\Exception\MissingDataException'); + $this->entityAdapter->setValue(NULL); $this->entityAdapter->toArray(); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php index b945b14..b26f0a0 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php @@ -115,10 +115,10 @@ class RedirectResponseSubscriberTest extends UnitTestCase { /** * @dataProvider providerTestDestinationRedirectToExternalUrl - * - * @expectedException \PHPUnit_Framework_Error */ public function testDestinationRedirectToExternalUrl($request, $expected) { + $this->setExpectedException('\PHPUnit_Framework_Error'); + $dispatcher = new EventDispatcher(); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $response = new RedirectResponse('http://other-example.com'); @@ -165,11 +165,12 @@ class RedirectResponseSubscriberTest extends UnitTestCase { } /** - * @expectedException \PHPUnit_Framework_Error * * @dataProvider providerTestDestinationRedirectWithInvalidUrl */ public function testDestinationRedirectWithInvalidUrl(Request $request) { + $this->setExpectedException('\PHPUnit_Framework_Error'); + $dispatcher = new EventDispatcher(); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $response = new RedirectResponse('http://example.com/drupal'); diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index 55db07e..51f9759 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -89,12 +89,12 @@ 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) { + $this->setExpectedException('\PHPUnit_Framework_Error_Warning', 'uses reserved variable names'); + $route_collection = $this->getMock('Symfony\Component\Routing\RouteCollection', NULL); $route_collection->add('test', $route); diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php index 74a7649..27bd668 100644 --- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -50,11 +50,10 @@ 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() { + $this->setExpectedException('\Drupal\Core\Extension\InfoParserException'); + $broken_info = <<setExpectedException('\Drupal\Core\Extension\InfoParserException'); + $missing_keys = <<setExpectedException('\Drupal\Core\Extension\InfoParserException'); + $missing_key = <<setExpectedException('\InvalidArgumentException'); + $this->moduleHandler->getModule('claire_alice_watch_my_little_pony_module_that_does_not_exist'); } diff --git a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php index 18d270e..7ba307a 100644 --- a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php @@ -41,10 +41,10 @@ class ConfigFormBaseTraitTest extends UnitTestCase { /** * @covers ::config - * @expectedException \LogicException - * @expectedExceptionMessage No config factory available for ConfigFormBaseTrait */ public function testConfigFactoryException() { + $this->setExpectedException('\LogicException', 'No config factory available for ConfigFormBaseTrait'); + $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait'); $config_method = new \ReflectionMethod($trait, 'config'); $config_method->setAccessible(TRUE); @@ -55,10 +55,10 @@ class ConfigFormBaseTraitTest extends UnitTestCase { /** * @covers ::config - * @expectedException \LogicException - * @expectedExceptionMessage No config factory available for ConfigFormBaseTrait */ public function testConfigFactoryExceptionInvalidProperty() { + $this->setExpectedException('\LogicException', 'No config factory available for ConfigFormBaseTrait'); + $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait'); $trait->configFactory = TRUE; $config_method = new \ReflectionMethod($trait, 'config'); diff --git a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php index 067ba47..3b61020 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php @@ -43,10 +43,10 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { /** * @covers ::buildResponse - * - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ public function testBuildResponseNoTriggeringElement() { + $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\HttpException'); + $this->renderer->expects($this->never()) ->method('renderResponse'); @@ -61,10 +61,10 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { /** * @covers ::buildResponse - * - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException */ public function testBuildResponseNoCallable() { + $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\HttpException'); + $this->renderer->expects($this->never()) ->method('renderResponse'); diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index dfbf843..29bfd32 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -52,11 +52,10 @@ 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() { + $this->setExpectedException('\InvalidArgumentException', 'The form argument foo is not a valid form.'); + $form_arg = 'foo'; $clean_form_state = new FormState(); @@ -218,11 +217,10 @@ 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() { + $this->setExpectedException('\InvalidArgumentException', 'The form argument test_form_id is not a valid form.'); + $form_id = 'test_form_id'; $expected_form = $form_id(); @@ -262,11 +260,10 @@ 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() { + $this->setExpectedException('\InvalidArgumentException', 'The form argument test_form_id is not a valid form.'); + $form_id = 'test_form_id'; $expected_form = $form_id(); @@ -547,10 +544,10 @@ class FormBuilderTest extends FormTestBase { /** * @covers ::buildForm - * - * @expectedException \Drupal\Core\Form\Exception\BrokenPostRequestException */ public function testExceededFileSize() { + $this->setExpectedException('\Drupal\Core\Form\Exception\BrokenPostRequestException'); + $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]); $request_stack = new RequestStack(); $request_stack->push($request); diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php index 67e7a86..f54756d 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php @@ -158,10 +158,10 @@ class FormStateDecoratorBaseTest extends UnitTestCase { * @dataProvider providerSingleBooleanArgument * * @param bool $cache - * - * @expectedException \LogicException */ public function testSetCachedWithLogicException($cache) { + $this->setExpectedException('\LogicException'); + $this->decoratedFormState->setCached($cache) ->willThrow(\LogicException::class); diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php index 69118a8..d2916f0 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php @@ -132,11 +132,10 @@ 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() { + $this->setExpectedException('\LogicException', 'Form errors cannot be set after form validation has finished.'); + $form_state = new FormState(); $form_state->setValidationComplete(); $form_state->setErrorByName('test', 'message'); @@ -315,11 +314,10 @@ class FormStateTest extends UnitTestCase { /** * @covers ::setCached - * - * @expectedException \LogicException - * @expectedExceptionMessage Form state caching on GET requests is not allowed. */ public function testSetCachedGet() { + $this->setExpectedException('\LogicException', 'Form state caching on GET requests is not allowed.'); + $form_state = new FormState(); $form_state->setRequestMethod('GET'); $form_state->setCached(); diff --git a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php index ec2ac8b..d82af82 100644 --- a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php @@ -97,12 +97,13 @@ class SubformStateTest extends UnitTestCase { * * @dataProvider providerGetValuesBroken * - * @expectedException \UnexpectedValueException * * @param string[] $parents * @param string $expected */ public function testGetValuesBroken(array $parents, $expected) { + $this->setExpectedException('\UnexpectedValueException'); + $this->testGetValues($parents, $expected); } @@ -161,10 +162,10 @@ class SubformStateTest extends UnitTestCase { * @covers ::getValue * * @dataProvider providerTestGetValueBroken - * - * @expectedException \UnexpectedValueException */ public function testGetValueBroken(array $parents, $key, $expected, $default = NULL) { + $this->setExpectedException('\UnexpectedValueException'); + $this->testGetValue($parents, $key, $expected, $default); } @@ -217,10 +218,10 @@ class SubformStateTest extends UnitTestCase { * @covers ::setValues * * @dataProvider providerTestSetValuesBroken - * - * @expectedException \UnexpectedValueException */ public function testSetValuesBroken($parents, $new_values, $expected) { + $this->setExpectedException('\UnexpectedValueException'); + $this->testSetValues($parents, $new_values, $expected); } diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index b3f0151..19b3419 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -203,10 +203,10 @@ 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() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException'); + $definition = array( 'class' => '\Drupal\Core\Menu\ContextualLinkDefault', 'group' => 'example', @@ -219,10 +219,10 @@ class ContextualLinkManagerTest extends UnitTestCase { * 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() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException'); + $definition = array( 'class' => '\Drupal\Core\Menu\ContextualLinkDefault', 'route_name' => 'example', diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php index 82a6581..c2c2bd5 100644 --- a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php +++ b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php @@ -63,11 +63,12 @@ class ChainRequestPolicyTest extends UnitTestCase { /** * Asserts that check() throws an exception if a rule returns an invalid value. * - * @expectedException \UnexpectedValueException * @dataProvider providerChainExceptionOnInvalidReturnValue * @covers ::check */ public function testChainExceptionOnInvalidReturnValue($return_value) { + $this->setExpectedException('\UnexpectedValueException'); + $rule = $this->getMock('Drupal\Core\PageCache\RequestPolicyInterface'); $rule->expects($this->once()) ->method('check') diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php index 1575ac1..09181ac 100644 --- a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php +++ b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php @@ -72,11 +72,12 @@ class ChainResponsePolicyTest extends UnitTestCase { /** * Asserts that check() throws an exception if a rule returns an invalid value. * - * @expectedException \UnexpectedValueException * @dataProvider providerChainExceptionOnInvalidReturnValue * @covers ::check */ public function testChainExceptionOnInvalidReturnValue($return_value) { + $this->setExpectedException('\UnexpectedValueException'); + $rule = $this->getMock('Drupal\Core\PageCache\ResponsePolicyInterface'); $rule->expects($this->once()) ->method('check') diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php index ebafab0..ed5fdfc 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php @@ -110,10 +110,10 @@ class EntityConverterTest extends UnitTestCase { /** * Tests the convert() method with an invalid entity type. - * - * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testConvertWithInvalidEntityType() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException'); + $this->entityManager->expects($this->once()) ->method('getStorage') ->with('invalid_id') @@ -124,11 +124,10 @@ class EntityConverterTest extends UnitTestCase { /** * Tests the convert() method with an invalid dynamic entity type. - * - * @expectedException \Drupal\Core\ParamConverter\ParamNotConvertedException - * @expectedExceptionMessage The "foo" parameter was not converted because the "invalid_id" parameter is missing */ public function testConvertWithInvalidDynamicEntityType() { + $this->setExpectedException('\Drupal\Core\ParamConverter\ParamNotConvertedException', 'The "foo" parameter was not converted because the "invalid_id" parameter is missing'); + $this->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id']); } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php index cc248b0..ee71add 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php @@ -51,10 +51,10 @@ class ParamConverterManagerTest extends UnitTestCase { * Tests \Drupal\Core\ParamConverter\ParamConverterManager::getConverter(). * * @covers ::getConverter - * - * @expectedException \InvalidArgumentException */ public function testGetConverterException() { + $this->setExpectedException('\InvalidArgumentException'); + $this->manager->getConverter('undefined.converter'); } @@ -220,11 +220,10 @@ 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() { + $this->setExpectedException('\Drupal\Core\ParamConverter\ParamNotConvertedException', 'The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")'); + $route = new Route('/test/{id}'); $parameters = array( 'id' => array( diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php index 4076f1e..4b5c46a 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php @@ -47,9 +47,10 @@ class PathProcessorFrontTest extends UnitTestCase { * Test inbound failure with broken config. * * @covers ::processInbound - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function testProcessInboundBadConfig() { + $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\NotFoundHttpException'); + $config_factory = $this->prophesize(ConfigFactoryInterface::class); $config = $this->prophesize(ImmutableConfig::class); $config_factory->get('system.site') diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php index fb1a442..b0f5a02 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php @@ -107,13 +107,14 @@ class ContextDefinitionTest extends UnitTestCase { } /** - * @expectedException \Exception * @dataProvider providerGetDataDefinition * @covers ::getDataDefinition * @uses \Drupal * @uses \Drupal\Component\Utility\SafeMarkup */ public function testGetDataDefinitionInvalidType($is_multiple) { + $this->setExpectedException('\Exception'); + // Since we're trying to make getDataDefinition() throw an exception in // isolation, we use a data type which is not valid. $data_type = 'not_valid'; diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php index 02fea32..1460d3a 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php @@ -66,10 +66,10 @@ 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() { + $this->setExpectedException('\InvalidArgumentException', 'You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); + $lazy_context_repository = new LazyContextRepository($this->container, ['test_provider']); $lazy_context_repository->getRuntimeContexts(['test_context', '@test_provider:test_context1']); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php index 981f4c2..e917c7d 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php @@ -279,11 +279,10 @@ class ContextHandlerTest extends UnitTestCase { /** * @covers ::applyContextMapping - * - * @expectedException \Drupal\Component\Plugin\Exception\ContextException - * @expectedExceptionMessage Required contexts without a value: hit. */ public function testApplyContextMappingMissingRequired() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\ContextException', 'Required contexts without a value: hit.'); + $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); $context->expects($this->never()) ->method('getContextValue'); @@ -350,11 +349,10 @@ class ContextHandlerTest extends UnitTestCase { /** * @covers ::applyContextMapping - * - * @expectedException \Drupal\Component\Plugin\Exception\ContextException - * @expectedExceptionMessage Required contexts without a value: hit. */ public function testApplyContextMappingNoValueRequired() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\ContextException', 'Required contexts without a value: hit.'); + $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); $context->expects($this->never()) ->method('getContextValue'); @@ -464,11 +462,10 @@ class ContextHandlerTest extends UnitTestCase { /** * @covers ::applyContextMapping - * - * @expectedException \Drupal\Component\Plugin\Exception\ContextException - * @expectedExceptionMessage Assigned contexts were not satisfied: miss */ public function testApplyContextMappingConfigurableAssignedMiss() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\ContextException', 'Assigned contexts were not satisfied: miss'); + $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface'); $context->expects($this->never()) ->method('getContextValue'); diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php index fbd6bc2..d1912da 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php @@ -43,10 +43,10 @@ class DefaultLazyPluginCollectionTest extends LazyPluginCollectionTestBase { /** * @covers ::get - * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException - * @expectedExceptionMessage Plugin ID 'pear' was not found. */ public function testGetNotExistingPlugin() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginNotFoundException', 'Plugin ID "pear" was not found.'); + $this->setupPluginCollection(); $this->defaultPluginCollection->get('pear'); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index ffdac5a..09210fc 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -270,11 +270,10 @@ 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() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\PluginException', 'Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); + $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $module_handler->expects($this->any()) diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php index d81360f..d3c5b7c 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php @@ -86,11 +86,10 @@ 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() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\InvalidDeriverException', 'Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); + $definitions = array(); // Do this with a class that doesn't exist. $definitions['non_existent_discovery'] = array( @@ -109,11 +108,10 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { * 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() { + $this->setExpectedException('\Drupal\Component\Plugin\Exception\InvalidDeriverException', 'Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.'); + $definitions = array(); // Do this with a class that doesn't implement the interface. $definitions['invalid_discovery'] = array( diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php index 1472dc0..98aaedd 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php @@ -118,10 +118,10 @@ 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->setExpectedException('\Drupal\Component\Plugin\Exception\PluginNotFoundException'); + $this->moduleHandler->expects($this->once()) ->method('getImplementations') ->will($this->returnValue(array())); diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php index 604d391..23c7455 100644 --- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php +++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php @@ -101,11 +101,10 @@ 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() { + $this->setExpectedException('\PHPUnit_Framework_Error', '"foo" is an invalid render array key'); + $element = array( 'foo' => 'bar', ); diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php index fc90e5d..a67c9c8 100644 --- a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php @@ -120,11 +120,10 @@ 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() { + $this->setExpectedException('\AssertionError', 'At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.'); + // Placeholders but no strategies defined. $placeholders = [ 'assert-me' => ['#markup' => 'I-am-a-llama-that-will-lead-to-an-assertion-by-the-chained-placeholder-strategy.'], @@ -136,11 +135,10 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { /** * @covers ::processPlaceholders - * - * @expectedException \AssertionError - * @expectedExceptionMessage Processed placeholders must be a subset of all placeholders. */ public function testProcessPlaceholdersWithRoguePlaceholderStrategy() { + $this->setExpectedException('\AssertionError', 'Processed placeholders must be a subset of all placeholders.'); + // Placeholders but no strategies defined. $placeholders = [ 'assert-me' => ['#markup' => 'llama'], diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php index a3835e1..a8dc85f 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php @@ -570,11 +570,10 @@ 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->setExpectedException('\LogicException', 'Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.'); + $this->setUpRequest(); $this->setupMemoryCache(); diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php index 530f603..38ddc65 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php @@ -846,11 +846,10 @@ 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() { + $this->setExpectedException('\DomainException', 'The #lazy_builder property must have an array as a value.'); + $element = []; $element['#lazy_builder'] = '\Drupal\Tests\Core\Render\PlaceholdersTest::callback'; @@ -860,11 +859,10 @@ class RendererPlaceholdersTest extends RendererTestBase { /** * @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() { + $this->setExpectedException('\DomainException', 'The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback.'); + $element = []; $element['#lazy_builder'] = ['\Drupal\Tests\Core\Render\PlaceholdersTest::callback', 'arg1', 'arg2']; @@ -895,11 +893,10 @@ 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() { + $this->setExpectedException('\DomainException', 'A #lazy_builder callback\'s context may only contain scalar values or NULL.'); + $element = []; $element['#lazy_builder'] = ['\Drupal\Tests\Core\Render\PlaceholdersTest::callback', [ 'string' => 'foo', @@ -917,11 +914,10 @@ class RendererPlaceholdersTest extends RendererTestBase { /** * @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() { + $this->setExpectedException('\DomainException', 'When a #lazy_builder callback is specified, no children can exist; all children must be generated by the #lazy_builder callback. You specified the following children: child_a, child_b.'); + $element = []; $element['#lazy_builder'] = ['Drupal\Tests\Core\Render\RecursivePlaceholdersTest::callback', []]; $element['child_a']['#markup'] = 'Oh hai!'; @@ -933,11 +929,10 @@ class RendererPlaceholdersTest extends RendererTestBase { /** * @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() { + $this->setExpectedException('\DomainException', 'When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #llama, #piglet.'); + $element = []; $element['#lazy_builder'] = ['Drupal\Tests\Core\Render\RecursivePlaceholdersTest::callback', []]; $element['#llama'] = '#awesome'; @@ -949,11 +944,10 @@ class RendererPlaceholdersTest extends RendererTestBase { /** * @covers ::render * @covers ::doRender - * - * @expectedException \LogicException - * @expectedExceptionMessage When #create_placeholder is set, a #lazy_builder callback must be present as well. */ public function testCreatePlaceholderPropertyWithoutLazyBuilder() { + $this->setExpectedException('\LogicException', 'When #create_placeholder is set, a #lazy_builder callback must be present as well.'); + $element = []; $element['#create_placeholder'] = TRUE; diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php index bffbd22..e14f4bf 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php @@ -31,10 +31,10 @@ class RendererRecursionTest extends RendererTestBase { * @covers ::renderRoot * @covers ::render * @covers ::doRender - * - * @expectedException \LogicException */ public function testRenderRecursionWithNestedRenderRoot() { + $this->setExpectedException('\LogicException'); + list($complex_child_markup, $parent_markup, $complex_child_template) = $this->setUpRenderRecursionComplexElements(); $renderer = $this->renderer; $this->setUpRequest(); diff --git a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php index 0b7bcc6..e62c143 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php @@ -87,10 +87,10 @@ class AccessAwareRouterTest extends UnitTestCase { /** * Tests the matchRequest() function for access denied. - * - * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function testMatchRequestDenied() { + $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException'); + $this->setupRouter(); $request = new Request(); $access_result = AccessResult::forbidden(); diff --git a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php index 39a960b..56afb1f 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php @@ -61,10 +61,10 @@ class RequestFormatRouteFilterTest extends UnitTestCase { /** * @covers ::filter - * @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException - * @expectedExceptionMessage No route found for the specified format xml. */ public function testNoRouteFound() { + $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException', 'No route found for the specified format xml.'); + $collection = new RouteCollection(); $route_with_format = $route = new Route('/test'); $route_with_format->setRequirement('_format', 'json'); diff --git a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php index 0cfbad5..050b024 100644 --- a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php @@ -29,9 +29,10 @@ class TrustedRedirectResponseTest extends UnitTestCase { /** * @covers ::setTargetUrl - * @expectedException \InvalidArgumentException */ public function testSetTargetUrlWithUntrustedUrl() { + $this->setExpectedException('\InvalidArgumentException'); + $request_context = new RequestContext(); $request_context->setCompleteBaseUrl('https://www.drupal.org'); $container = new ContainerBuilder(); diff --git a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php index 3cf50fc..00f9e4e 100644 --- a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php +++ b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php @@ -80,10 +80,10 @@ class SettingsTest extends UnitTestCase { * @covers ::getHashSalt * * @dataProvider providerTestGetHashSaltEmpty - * - * @expectedException \RuntimeException */ public function testGetHashSaltEmpty(array $config) { + $this->setExpectedException('\RuntimeException'); + // Re-create settings with no 'hash_salt' key. $settings = new Settings($config); $settings->getHashSalt(); @@ -106,10 +106,10 @@ class SettingsTest extends UnitTestCase { * Ensures settings cannot be serialized. * * @covers ::__sleep - * - * @expectedException \LogicException */ public function testSerialize() { + $this->setExpectedException('\LogicException'); + serialize(new Settings([])); } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php index 3ed2b3d..b8dbc36 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php @@ -82,23 +82,23 @@ class TranslatableMarkupTest extends UnitTestCase { } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage $string ("foo") must be a string. * * @covers ::__construct */ public function testIsStringAssertion() { + $this->setExpectedException('\InvalidArgumentException', '$string ("foo") must be a string.'); + $translation = $this->getStringTranslationStub(); new TranslatableMarkup(new TranslatableMarkup('foo', [], [], $translation)); } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage $string ("foo") must be a string. * * @covers ::__construct */ public function testIsStringAssertionWithFormattableMarkup() { + $this->setExpectedException('\InvalidArgumentException', '$string ("foo") must be a string.'); + $translation = $this->getStringTranslationStub(); $formattable_string = new FormattableMarkup('@bar', ['@bar' => 'foo']); new TranslatableMarkup($formattable_string); diff --git a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php index 7a3dd3a..1959508 100644 --- a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php +++ b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php @@ -45,9 +45,10 @@ class TwigSandboxTest extends UnitTestCase { * Tests that dangerous methods cannot be called in entity objects. * * @dataProvider getTwigEntityDangerousMethods - * @expectedException \Twig_Sandbox_SecurityError */ public function testEntityDangerousMethods($template) { + $this->setExpectedException('\Twig_Sandbox_SecurityError'); + $entity = $this->getMock('Drupal\Core\Entity\EntityInterface'); $this->twig->render($template, ['entity' => $entity]); } diff --git a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php index 5e3558e..85d18a7 100644 --- a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php @@ -95,10 +95,10 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * Ensures that passing an explicit group is not supported. * * @covers ::validate - * - * @expectedException \LogicException */ public function testValidateWithGroups() { + $this->setExpectedException('\LogicException'); + $this->recursiveValidator->validate('test', NULL, 'test group'); } @@ -106,10 +106,10 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * Ensures that passing a non typed data value is not supported. * * @covers ::validate - * - * @expectedException \InvalidArgumentException */ public function testValidateWithoutTypedData() { + $this->setExpectedException('\InvalidArgumentException'); + $this->recursiveValidator->validate('test'); } @@ -228,10 +228,10 @@ class RecursiveContextualValidatorTest extends UnitTestCase { /** * @covers ::validateProperty - * - * @expectedException \LogicException */ public function testValidatePropertyWithCustomGroup() { + $this->setExpectedException('\LogicException'); + $tree = [ 'value' => [], 'properties' => [ @@ -246,10 +246,10 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * @covers ::validateProperty * * @dataProvider providerTestValidatePropertyWithInvalidObjects - * - * @expectedException \InvalidArgumentException */ public function testValidatePropertyWithInvalidObjects($object) { + $this->setExpectedException('\InvalidArgumentException'); + $this->recursiveValidator->validateProperty($object, 'key1', NULL); } @@ -289,10 +289,10 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * @covers ::validatePropertyValue * * @dataProvider providerTestValidatePropertyWithInvalidObjects - * - * @expectedException \InvalidArgumentException */ public function testValidatePropertyValueWithInvalidObjects($object) { + $this->setExpectedException('\InvalidArgumentException'); + $this->recursiveValidator->validatePropertyValue($object, 'key1', [], NULL); } diff --git a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php index ef6dd25..1c72318 100644 --- a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php +++ b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php @@ -102,9 +102,10 @@ class UnroutedUrlTest extends UnitTestCase { * * @covers ::fromUri * @dataProvider providerFromInvalidUri - * @expectedException \InvalidArgumentException */ public function testFromInvalidUri($uri) { + $this->setExpectedException('\InvalidArgumentException'); + $url = Url::fromUri($uri); } @@ -133,10 +134,10 @@ class UnroutedUrlTest extends UnitTestCase { * Tests the createFromRequest method. * * @covers ::createFromRequest - * - * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException */ public function testCreateFromRequest() { + $this->setExpectedException('\Symfony\Component\Routing\Exception\ResourceNotFoundException'); + $request = Request::create('/test-path'); $this->router->expects($this->once()) @@ -179,11 +180,12 @@ class UnroutedUrlTest extends UnitTestCase { * @depends testFromUri * @dataProvider providerFromUri * - * @expectedException \UnexpectedValueException * * @covers ::getRouteName */ public function testGetRouteName($uri) { + $this->setExpectedException('\UnexpectedValueException'); + $url = Url::fromUri($uri); $url->getRouteName(); } @@ -194,11 +196,12 @@ class UnroutedUrlTest extends UnitTestCase { * @depends testFromUri * @dataProvider providerFromUri * - * @expectedException \UnexpectedValueException * * @covers ::getRouteParameters */ public function testGetRouteParameters($uri) { + $this->setExpectedException('\UnexpectedValueException'); + $url = Url::fromUri($uri); $url->getRouteParameters(); } @@ -210,10 +213,10 @@ class UnroutedUrlTest extends UnitTestCase { * @dataProvider providerFromUri * * @covers ::getInternalPath - * - * @expectedException \Exception */ public function testGetInternalPath($uri) { + $this->setExpectedException('\Exception'); + $url = Url::fromUri($uri); $this->assertNull($url->getInternalPath()); } diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index 5324c26..8cd2feb 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -215,10 +215,11 @@ class UrlTest extends UnitTestCase { * Tests the fromUserInput method with invalid paths. * * @covers ::fromUserInput - * @expectedException \InvalidArgumentException * @dataProvider providerFromInvalidInternalUri */ public function testFromInvalidUserInput($path) { + $this->setExpectedException('\InvalidArgumentException'); + $url = Url::fromUserInput($path); } @@ -280,10 +281,10 @@ class UrlTest extends UnitTestCase { * Tests that an invalid request will thrown an exception. * * @covers ::createFromRequest - * - * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException */ public function testUrlFromRequestInvalid() { + $this->setExpectedException('\Symfony\Component\Routing\Exception\ResourceNotFoundException'); + $request = Request::create('/test-path'); $this->router->expects($this->once()) @@ -315,11 +316,12 @@ class UrlTest extends UnitTestCase { * * @depends testUrlFromRequest * - * @expectedException \UnexpectedValueException * * @covers ::getUri */ public function testGetUriForInternalUrl($urls) { + $this->setExpectedException('\UnexpectedValueException'); + foreach ($urls as $url) { $url->getUri(); } @@ -418,9 +420,10 @@ class UrlTest extends UnitTestCase { * Tests the getRouteName() with an external URL. * * @covers ::getRouteName - * @expectedException \UnexpectedValueException */ public function testGetRouteNameWithExternalUrl() { + $this->setExpectedException('\UnexpectedValueException'); + $url = Url::fromUri('http://example.com'); $url->getRouteName(); } @@ -445,9 +448,10 @@ class UrlTest extends UnitTestCase { * Tests the getRouteParameters() with an external URL. * * @covers ::getRouteParameters - * @expectedException \UnexpectedValueException */ public function testGetRouteParametersWithExternalUrl() { + $this->setExpectedException('\UnexpectedValueException'); + $url = Url::fromUri('http://example.com'); $url->getRouteParameters(); } @@ -605,9 +609,10 @@ class UrlTest extends UnitTestCase { * Tests the fromUri() method with an invalid entity: URI. * * @covers ::fromUri - * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException */ public function testInvalidEntityUriParameter() { + $this->setExpectedException('\Symfony\Component\Routing\Exception\InvalidParameterException'); + // Make the mocked URL generator behave like the actual one. $this->urlGenerator->expects($this->once()) ->method('generateFromRoute') @@ -728,10 +733,11 @@ class UrlTest extends UnitTestCase { * Tests the fromUri() method with an invalid internal: URI. * * @covers ::fromUri - * @expectedException \InvalidArgumentException * @dataProvider providerFromInvalidInternalUri */ public function testFromInvalidInternalUri($path) { + $this->setExpectedException('\InvalidArgumentException'); + Url::fromUri('internal:' . $path); } @@ -800,10 +806,10 @@ class UrlTest extends UnitTestCase { } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The route URI 'route:' is invalid. */ public function testFromRouteUriWithMissingRouteName() { + $this->setExpectedException('\InvalidArgumentException', 'The route URI "route:" is invalid.'); + Url::fromUri('route:'); } diff --git a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php index b2d7700..abb95db 100644 --- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -56,17 +56,19 @@ class UnroutedUrlAssemblerTest extends UnitTestCase { /** * @covers ::assemble - * @expectedException \InvalidArgumentException */ public function testAssembleWithNeitherExternalNorDomainLocalUri() { + $this->setExpectedException('\InvalidArgumentException'); + $this->unroutedUrlAssembler->assemble('wrong-url'); } /** * @covers ::assemble - * @expectedException \InvalidArgumentException */ public function testAssembleWithLeadingSlash() { + $this->setExpectedException('\InvalidArgumentException'); + $this->unroutedUrlAssembler->assemble('/drupal.org'); }