From e82e0c0573ba346754208eb48578d5a9b9d1ab95 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 11 Jun 2019 12:38:53 +0300 Subject: [PATCH] Issue #3059090 by clepson, mondrake, alexpott: Deprecate \Drupal\Tests\PhpunitCompatibilityTrait::setExpectedException() --- ...igPipeResponseAttachmentsProcessorTest.php | 2 +- .../migrate/process/BlockVisibilityTest.php | 3 +- .../Rest/MessageResourceTestBase.php | 9 ++- .../tests/src/Unit/MailHandlerTest.php | 3 +- .../ContentModerationStateResourceTest.php | 3 +- .../src/Kernel/ContentModerationStateTest.php | 2 +- .../ModerationStateFieldItemListTest.php | 2 +- .../tests/src/Kernel/DateTimeItemTest.php | 4 +- .../Plugin/migrate/field/DateFieldTest.php | 3 +- .../Plugin/migrate/field/d6/DateFieldTest.php | 3 +- .../src/Unit/FieldConfigEntityUnitTest.php | 3 +- .../Unit/FieldStorageConfigEntityUnitTest.php | 3 +- .../migrate/process/ProcessFieldTest.php | 3 +- .../process/d6/FieldTypeDefaultsTest.php | 4 +- .../hal/tests/src/Kernel/DenormalizeTest.php | 10 +-- ...ormalizerDenormalizeExceptionsUnitTest.php | 2 +- ...ormalizerDenormalizeExceptionsUnitTest.php | 2 +- .../tests/src/Functional/MessageTest.php | 18 +++-- .../src/Kernel/Context/FieldResolverTest.php | 10 ++- .../Kernel/Controller/EntityResourceTest.php | 8 ++- .../tests/src/Kernel/Query/FilterTest.php | 18 +++-- .../Revisions/VersionNegotiatorTest.php | 6 +- .../JsonApiDocumentTopLevelNormalizerTest.php | 6 +- .../ResourceIdentifierNormalizerTest.php | 2 +- .../Unit/Query/EntityConditionGroupTest.php | 2 +- .../src/Unit/Query/EntityConditionTest.php | 3 +- .../tests/src/Unit/Query/OffsetPageTest.php | 2 +- .../jsonapi/tests/src/Unit/Query/SortTest.php | 2 +- .../Unit/process/LanguageNegotiationTest.php | 3 +- .../src/Unit/process/LanguageTypesTest.php | 3 +- .../src/Kernel/DefaultsSectionStorageTest.php | 3 +- .../tests/src/Kernel/FieldBlockTest.php | 2 +- .../LayoutBuilderEntityViewDisplayTest.php | 2 +- .../Kernel/OverridesSectionStorageTest.php | 3 +- .../tests/src/Kernel/SectionListTraitTest.php | 3 +- .../src/Kernel/SectionStorageTestBase.php | 3 +- .../src/Unit/DefaultsSectionStorageTest.php | 2 +- .../Unit/LayoutTempstoreRepositoryTest.php | 3 +- .../src/Unit/OverridesSectionStorageTest.php | 2 +- .../tests/src/Unit/SectionRenderTest.php | 3 +- .../tests/src/Unit/SectionTest.php | 12 ++-- .../src/Kernel/LinkItemSerializationTest.php | 3 +- .../locale/tests/src/Unit/StringBaseTest.php | 6 +- .../src/Functional/ProviderRepositoryTest.php | 6 +- .../src/Kernel/OEmbedIframeControllerTest.php | 3 +- .../src/Kernel/MediaLibraryAddFormTest.php | 6 +- .../src/Kernel/MediaLibraryStateTest.php | 9 ++- .../Plugin/migrate/process/LinkUriTest.php | 3 +- .../Plugin/MigrationProvidersExistTest.php | 6 +- .../tests/src/Kernel/Plugin/MigrationTest.php | 6 +- .../tests/src/Kernel/QueryBatchTest.php | 6 +- .../migrate/tests/src/Kernel/SqlBaseTest.php | 4 +- .../tests/src/Kernel/process/FileCopyTest.php | 6 +- .../tests/src/Unit/MigrateExecutableTest.php | 3 +- .../tests/src/Unit/MigrateSourceTest.php | 2 +- .../migrate/tests/src/Unit/MigrationTest.php | 9 ++- .../destination/CheckRequirementsTest.php | 3 +- .../destination/EntityContentBaseTest.php | 6 +- .../destination/EntityRevisionTest.php | 6 +- .../migrate/tests/src/Unit/RowTest.php | 7 +- .../tests/src/Unit/process/ArrayBuildTest.php | 12 ++-- .../tests/src/Unit/process/CallbackTest.php | 3 +- .../tests/src/Unit/process/ConcatTest.php | 2 +- .../src/Unit/process/DedupeEntityTest.php | 6 +- .../tests/src/Unit/process/ExplodeTest.php | 9 ++- .../tests/src/Unit/process/ExtractTest.php | 6 +- .../tests/src/Unit/process/FormatDateTest.php | 12 ++-- .../process/MakeUniqueEntityFieldTest.php | 6 +- .../src/Unit/process/MenuLinkParentTest.php | 3 +- .../src/Unit/process/MigrationLookupTest.php | 2 +- .../tests/src/Unit/process/MigrationTest.php | 2 +- .../src/Unit/process/SkipOnEmptyTest.php | 9 +-- .../src/Unit/process/SkipRowIfNotSetTest.php | 5 +- .../tests/src/Unit/process/StaticMapTest.php | 8 ++- .../tests/src/Unit/process/SubstrTest.php | 9 ++- .../Kernel/MigrateFieldPluginManagerTest.php | 3 +- .../migrate/source/ContentEntityTest.php | 12 ++-- .../tests/src/Unit/FieldDiscoveryTest.php | 5 +- .../Unit/MigrateFieldPluginManagerTest.php | 3 +- .../src/Unit/source/DrupalSqlBaseTest.php | 6 +- .../FormatSpecificGetBcRouteTestTrait.php | 2 +- .../EntityResourceValidationTraitTest.php | 2 +- .../src/Kernel/EntitySerializationTest.php | 12 ++-- .../src/Kernel/FieldItemSerializationTest.php | 3 +- .../DateTimeIso8601NormalizerTest.php | 9 ++- .../Normalizer/DateTimeNormalizerTest.php | 3 +- .../Unit/Normalizer/EntityNormalizerTest.php | 4 +- ...EntityReferenceFieldItemNormalizerTest.php | 9 ++- .../Normalizer/TimestampNormalizerTest.php | 3 +- .../tests/src/Unit/TestDiscoveryTest.php | 5 +- .../Kernel/Extension/ModuleHandlerTest.php | 6 +- .../src/Kernel/Scripts/DbCommandBaseTest.php | 2 +- .../MachineNameControllerTest.php | 6 +- .../d6/ProfileFieldCheckRequirementsTest.php | 3 +- .../d7/ProfileFieldCheckRequirementsTest.php | 3 +- .../tests/src/Unit/PrivateTempStoreTest.php | 4 +- .../tests/src/Unit/SharedTempStoreTest.php | 4 +- .../src/Unit/UserRegistrationResourceTest.php | 8 +-- .../Controller/ViewAjaxControllerTest.php | 8 +-- .../src/Unit/Plugin/display/PageTest.php | 2 +- .../tests/src/Unit/ViewExecutableTest.php | 2 +- .../tests/src/Kernel/RequiredStatesTest.php | 6 +- .../workflows/tests/src/Unit/StateTest.php | 3 +- ...ateTransitionOperationsAccessCheckTest.php | 3 +- .../workflows/tests/src/Unit/WorkflowTest.php | 69 ++++++++++++------- .../src/Kernel/WorkspaceIntegrationTest.php | 9 ++- .../Kernel/WorkspaceInternalResourceTest.php | 3 +- .../BrowserWithJavascriptTest.php | 2 +- .../FunctionalTests/BrowserTestBaseTest.php | 12 ++-- .../Utility/SafeMarkupKernelTest.php | 2 +- .../Core/Config/ConfigInstallTest.php | 3 +- .../Config/Entity/ConfigEntityUpdaterTest.php | 3 +- .../KernelTests/Core/Database/SchemaTest.php | 9 ++- .../Core/Entity/ConfigEntityAdapterTest.php | 3 +- .../KernelTests/Core/Entity/EntityApiTest.php | 6 +- .../Core/Entity/EntityFieldTest.php | 2 +- .../Entity/EntityQueryRelationshipTest.php | 2 +- .../FieldableEntityDefinitionUpdateTest.php | 6 +- .../Core/Extension/ModuleInstallerTest.php | 2 +- .../Core/Field/FieldMissingTypeTest.php | 6 +- .../KernelTests/Core/File/DirectoryTest.php | 3 +- .../KernelTests/Core/File/FileCopyTest.php | 4 +- .../KernelTests/Core/File/FileMoveTest.php | 4 +- .../KernelTests/Core/File/FileSystemTest.php | 15 ++-- .../KernelTests/Core/File/PharWrapperTest.php | 2 +- .../Theme/ThemeRenderAndAutoescapeTest.php | 2 +- .../AllowedValuesConstraintValidatorTest.php | 3 +- .../ZfExtensionManagerSfContainerTest.php | 6 +- .../Component/Datetime/DateTimePlusTest.php | 12 ++-- .../DependencyInjection/ContainerTest.php | 32 ++++----- .../Dumper/OptimizedPhpArrayDumperTest.php | 8 +-- .../Component/Diff/Engine/DiffOpTest.php | 2 +- .../Discovery/YamlDirectoryDiscoveryTest.php | 6 +- .../FileCache/FileCacheFactoryTest.php | 3 +- .../Component/Gettext/PoStreamWriterTest.php | 9 ++- .../Component/PhpStorage/FileStorageTest.php | 3 +- .../Component/Plugin/Context/ContextTest.php | 6 +- .../Component/Plugin/DefaultFactoryTest.php | 16 +++-- .../Plugin/Discovery/DiscoveryTraitTest.php | 4 +- .../StaticDiscoveryDecoratorTest.php | 2 +- .../Plugin/Factory/ReflectionFactoryTest.php | 2 +- .../Plugin/PluginManagerBaseTest.php | 3 +- .../Component/Serialization/YamlPeclTest.php | 2 +- .../Serialization/YamlSymfonyTest.php | 5 +- .../Utility/ArgumentsResolverTest.php | 9 ++- .../Tests/Component/Utility/ColorTest.php | 2 +- .../Tests/Component/Utility/CryptTest.php | 2 +- .../Component/Utility/EmailValidatorTest.php | 3 +- .../Tests/Component/Utility/HtmlTest.php | 2 +- .../Tests/Component/Utility/RandomTest.php | 4 +- .../Tests/Component/Utility/RectangleTest.php | 4 +- .../Tests/Component/Utility/UrlHelperTest.php | 2 +- .../Tests/Core/Access/AccessManagerTest.php | 2 +- .../Core/Access/CsrfTokenGeneratorTest.php | 4 +- .../Core/Access/CustomAccessCheckTest.php | 3 +- .../Core/Annotation/PluralTranslationTest.php | 2 +- .../Core/Assert/AssertLegacyTraitTest.php | 10 +-- .../Asset/CssCollectionRendererUnitTest.php | 3 +- .../Tests/Core/Asset/CssOptimizerUnitTest.php | 6 +- .../Asset/LibraryDependencyResolverTest.php | 3 +- .../Core/Asset/LibraryDiscoveryParserTest.php | 13 ++-- .../Tests/Core/Batch/BatchBuilderTest.php | 6 +- .../Core/Breadcrumb/BreadcrumbManagerTest.php | 2 +- .../Tests/Core/Breadcrumb/BreadcrumbTest.php | 3 +- .../Core/Cache/CacheTagsInvalidatorTest.php | 2 +- .../Drupal/Tests/Core/Cache/CacheTest.php | 3 +- .../Core/Cache/CacheableMetadataTest.php | 2 +- .../Context/CacheContextsManagerTest.php | 7 +- .../Drupal/Tests/Core/Config/ConfigTest.php | 7 +- .../Entity/ConfigEntityBaseUnitTest.php | 3 +- .../Config/Entity/ConfigEntityStorageTest.php | 14 ++-- .../Config/Entity/ConfigEntityTypeTest.php | 12 ++-- .../Config/Entity/Query/QueryFactoryTest.php | 3 +- .../Tests/Core/Config/ImmutableConfigTest.php | 12 ++-- .../Controller/ControllerResolverTest.php | 6 +- .../Tests/Core/Database/ConditionTest.php | 2 +- .../Tests/Core/Database/UrlConversionTest.php | 6 +- .../Core/Datetime/DrupalDateTimeTest.php | 6 +- .../Compiler/ProxyServicesPassTest.php | 2 +- .../Compiler/TaggedHandlersPassTest.php | 11 +-- .../ContainerBuilderTest.php | 11 +-- .../DependencyInjection/ContainerTest.php | 2 +- core/tests/Drupal/Tests/Core/DrupalTest.php | 3 +- .../Core/Entity/BaseFieldDefinitionTest.php | 2 +- .../Core/Entity/ContentEntityBaseUnitTest.php | 6 +- .../Core/Entity/EntityFieldManagerTest.php | 5 +- .../Core/Entity/EntityTypeManagerTest.php | 10 +-- .../Core/Entity/EntityTypeRepositoryTest.php | 6 +- .../Tests/Core/Entity/EntityTypeTest.php | 5 +- .../Tests/Core/Entity/EntityUrlTest.php | 6 +- .../Tests/Core/Entity/FieldDefinitionTest.php | 2 +- .../KeyValueEntityStorageTest.php | 6 +- .../Tests/Core/Entity/Query/Sql/QueryTest.php | 6 +- .../Entity/Sql/DefaultTableMappingTest.php | 6 +- .../TypedData/EntityAdapterUnitTest.php | 8 +-- .../EntityReferenceSelectionUnitTest.php | 6 +- .../RedirectResponseSubscriberTest.php | 4 +- .../SpecialAttributesRouteSubscriberTest.php | 3 +- .../Tests/Core/Extension/DependencyTest.php | 9 ++- .../Core/Extension/ExtensionListTest.php | 4 +- .../Core/Extension/InfoParserUnitTest.php | 9 ++- .../Core/Extension/ModuleHandlerTest.php | 2 +- .../FieldInputValueNormalizerTraitTest.php | 3 +- .../Drupal/Tests/Core/File/FileSystemTest.php | 3 +- .../Core/Form/ConfigFormBaseTraitTest.php | 6 +- .../Core/Form/FormAjaxResponseBuilderTest.php | 4 +- .../Tests/Core/Form/FormBuilderTest.php | 11 +-- .../Core/Form/FormStateDecoratorBaseTest.php | 2 +- .../Drupal/Tests/Core/Form/FormStateTest.php | 6 +- .../Tests/Core/Form/SubformStateTest.php | 6 +- .../Core/Layout/LayoutPluginManagerTest.php | 3 +- .../Core/Menu/ContextualLinkManagerTest.php | 4 +- .../Core/PageCache/ChainRequestPolicyTest.php | 2 +- .../PageCache/ChainResponsePolicyTest.php | 2 +- .../ParamConverter/EntityConverterTest.php | 5 +- .../EntityRevisionParamConverterTest.php | 8 ++- .../ParamConverterManagerTest.php | 5 +- .../PathProcessor/PathProcessorFrontTest.php | 2 +- .../Context/ContextAwarePluginBaseTest.php | 3 +- .../Plugin/Context/ContextDefinitionTest.php | 2 +- .../Context/LazyContextRepositoryTest.php | 3 +- .../Tests/Core/Plugin/ContextHandlerTest.php | 9 ++- .../DefaultLazyPluginCollectionTest.php | 3 +- .../Core/Plugin/DefaultPluginManagerTest.php | 6 +- .../DerivativeDiscoveryDecoratorTest.php | 9 ++- .../Plugin/Discovery/HookDiscoveryTest.php | 2 +- .../Core/Plugin/PluginFormFactoryTest.php | 6 +- .../Drupal/Tests/Core/Render/ElementTest.php | 3 +- .../ChainedPlaceholderStrategyTest.php | 6 +- .../Core/Render/RendererBubblingTest.php | 3 +- .../Core/Render/RendererPlaceholdersTest.php | 18 +++-- .../Core/Render/RendererRecursionTest.php | 2 +- .../Core/Routing/AcceptHeaderMatcherTest.php | 3 +- .../Core/Routing/AccessAwareRouterTest.php | 5 +- .../Routing/ContentTypeHeaderMatcherTest.php | 6 +- .../Tests/Core/Routing/MethodFilterTest.php | 4 +- .../Routing/RequestFormatRouteFilterTest.php | 6 +- .../Routing/TrustedRedirectResponseTest.php | 2 +- .../Tests/Core/Session/AccountProxyTest.php | 2 +- .../Drupal/Tests/Core/Site/SettingsTest.php | 6 +- .../TranslatableMarkupTest.php | 6 +- .../Core/TempStore/PrivateTempStoreTest.php | 4 +- .../Core/TempStore/SharedTempStoreTest.php | 4 +- .../Tests/Core/Template/TwigSandboxTest.php | 2 +- .../Tests/Core/Test/BrowserTestBaseTest.php | 3 +- .../Tests/Core/Test/TestDatabaseTest.php | 3 +- .../RecursiveContextualValidatorTest.php | 10 +-- .../Drupal/Tests/Core/UnroutedUrlTest.php | 10 +-- core/tests/Drupal/Tests/Core/UrlTest.php | 17 ++--- .../Core/Utility/UnroutedUrlAssemblerTest.php | 4 +- .../Tests/PhpunitCompatibilityTrait.php | 6 ++ .../Tests/PhpunitCompatibilityTraitTest.php | 14 ++++ 252 files changed, 853 insertions(+), 525 deletions(-) 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 ba69bfee603f..2f77684e5544 100644 --- a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php +++ b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php @@ -33,7 +33,7 @@ class BigPipeResponseAttachmentsProcessorTest extends UnitTestCase { $big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($this->prophesize(AttachmentsResponseProcessorInterface::class)); $non_html_response = new $response_class(); - $this->setExpectedException(\AssertionError::class); + $this->expectException(\AssertionError::class); $big_pipe_response_attachments_processor->processAttachments($non_html_response); } diff --git a/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockVisibilityTest.php b/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockVisibilityTest.php index 9cb15523d1e4..3f7eeca0c2d6 100644 --- a/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockVisibilityTest.php +++ b/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockVisibilityTest.php @@ -95,7 +95,8 @@ class BlockVisibilityTest extends MigrateProcessTestCase { ->method('getSourceProperty') ->willReturnMap([['bid', 99], ['module', 'foobar']]); $this->plugin = new BlockVisibility(['skip_php' => TRUE], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal()); - $this->setExpectedException(MigrateSkipRowException::class, "The block with bid '99' from module 'foobar' will have no PHP or request_path visibility configuration."); + $this->expectException(MigrateSkipRowException::class); + $this->expectExceptionMessage("The block with bid '99' from module 'foobar' will have no PHP or request_path visibility configuration."); $this->plugin->transform([2, 'migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/contact/tests/src/Functional/Rest/MessageResourceTestBase.php b/core/modules/contact/tests/src/Functional/Rest/MessageResourceTestBase.php index f0ff8f85f905..91c49d5d7e16 100644 --- a/core/modules/contact/tests/src/Functional/Rest/MessageResourceTestBase.php +++ b/core/modules/contact/tests/src/Functional/Rest/MessageResourceTestBase.php @@ -116,7 +116,8 @@ abstract class MessageResourceTestBase extends EntityResourceTestBase { */ public function testGet() { // Contact Message entities are not stored, so they cannot be retrieved. - $this->setExpectedException(RouteNotFoundException::class, 'Route "rest.entity.contact_message.GET" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "rest.entity.contact_message.GET" does not exist.'); $this->provisionEntityResource(); Url::fromRoute('rest.entity.contact_message.GET')->toString(TRUE); @@ -127,7 +128,8 @@ abstract class MessageResourceTestBase extends EntityResourceTestBase { */ public function testPatch() { // Contact Message entities are not stored, so they cannot be modified. - $this->setExpectedException(RouteNotFoundException::class, 'Route "rest.entity.contact_message.PATCH" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "rest.entity.contact_message.PATCH" does not exist.'); $this->provisionEntityResource(); Url::fromRoute('rest.entity.contact_message.PATCH')->toString(TRUE); @@ -138,7 +140,8 @@ abstract class MessageResourceTestBase extends EntityResourceTestBase { */ public function testDelete() { // Contact Message entities are not stored, so they cannot be deleted. - $this->setExpectedException(RouteNotFoundException::class, 'Route "rest.entity.contact_message.DELETE" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "rest.entity.contact_message.DELETE" does not exist.'); $this->provisionEntityResource(); Url::fromRoute('rest.entity.contact_message.DELETE')->toString(TRUE); diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php index ccb4355b60cd..66a34a813957 100644 --- a/core/modules/contact/tests/src/Unit/MailHandlerTest.php +++ b/core/modules/contact/tests/src/Unit/MailHandlerTest.php @@ -120,7 +120,8 @@ class MailHandlerTest extends UnitTestCase { $sender->expects($this->once()) ->method('isAnonymous') ->willReturn(FALSE); - $this->setExpectedException(MailHandlerException::class, 'Unable to determine message recipient'); + $this->expectException(MailHandlerException::class); + $this->expectExceptionMessage('Unable to determine message recipient'); $this->contactMailHandler->sendMailMessages($message, $sender); } diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateResourceTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateResourceTest.php index 2ea1d8f901ff..a54cb2c1e15a 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateResourceTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateResourceTest.php @@ -21,7 +21,8 @@ class ContentModerationStateResourceTest extends KernelTestBase { * @see \Drupal\content_moderation\Entity\ContentModerationState */ public function testCreateContentModerationStateResource() { - $this->setExpectedException(PluginNotFoundException::class, 'The "entity:content_moderation_state" plugin does not exist.'); + $this->expectException(PluginNotFoundException::class); + $this->expectExceptionMessage('The "entity:content_moderation_state" plugin does not exist.'); RestResourceConfig::create([ 'id' => 'entity.content_moderation_state', 'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY, diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 86c43895977e..735d8814d5be 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -147,7 +147,7 @@ class ContentModerationStateTest extends KernelTestBase { } // Set an invalid moderation state. - $this->setExpectedException(EntityStorageException::class); + $this->expectException(EntityStorageException::class); $entity->moderation_state->value = 'foobar'; $entity->save(); } diff --git a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php index df572ebe4c0d..6ae55c791621 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php @@ -101,7 +101,7 @@ class ModerationStateFieldItemListTest extends KernelTestBase { */ public function testGet() { $this->assertEquals('draft', $this->testNode->moderation_state->get(0)->value); - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->testNode->moderation_state->get(2); } diff --git a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php index 70045dfdd778..7c1ca1ef9b7b 100644 --- a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php +++ b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php @@ -255,7 +255,7 @@ class DateTimeItemTest extends FieldKernelTestBase { * @dataProvider datetimeValidationProvider */ public function testDatetimeValidation($value) { - $this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class); + $this->expectException(\PHPUnit_Framework_AssertionFailedError::class); $this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATETIME); $this->fieldStorage->save(); @@ -315,7 +315,7 @@ class DateTimeItemTest extends FieldKernelTestBase { * @dataProvider dateonlyValidationProvider */ public function testDateonlyValidation($value) { - $this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class); + $this->expectException(\PHPUnit_Framework_AssertionFailedError::class); $this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATE); $this->fieldStorage->save(); diff --git a/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/DateFieldTest.php b/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/DateFieldTest.php index 500eac2307bb..b12694adc759 100644 --- a/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/DateFieldTest.php +++ b/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/DateFieldTest.php @@ -18,7 +18,8 @@ class DateFieldTest extends UnitTestCase { $migration = $this->prophesize('Drupal\migrate\Plugin\MigrationInterface')->reveal(); $plugin = new DateField([], '', []); - $this->setExpectedException(MigrateException::class, "Field field_date of type 'timestamp' is an unknown date field type."); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("Field field_date of type 'timestamp' is an unknown date field type."); $plugin->$method($migration, 'field_date', ['type' => 'timestamp']); } diff --git a/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php b/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php index 6c212aff8de1..a19442041725 100644 --- a/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php +++ b/core/modules/datetime/tests/src/Unit/Plugin/migrate/field/d6/DateFieldTest.php @@ -35,7 +35,8 @@ class DateFieldTest extends UnitTestCase { public function testUnknownDateType($method = 'defineValueProcessPipeline') { $plugin = new DateField([], '', []); - $this->setExpectedException(MigrateException::class, "Field field_date of type 'timestamp' is an unknown date field type."); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("Field field_date of type 'timestamp' is an unknown date field type."); $plugin->$method($this->migration, 'field_date', ['type' => 'timestamp']); } diff --git a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php index 72a94a885cc3..4c98484901d4 100644 --- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @@ -207,7 +207,8 @@ class FieldConfigEntityUnitTest extends UnitTestCase { 'bundle' => 'test_bundle_not_exists', 'field_type' => 'test_field', ], $this->entityTypeId); - $this->setExpectedException(\LogicException::class, 'Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.'); $field->calculateDependencies(); } diff --git a/core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php index 09e2d554cb57..6a008c101767 100644 --- a/core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php @@ -192,7 +192,8 @@ class FieldStorageConfigEntityUnitTest extends UnitTestCase { 'module' => 'test_module', ]); - $this->setExpectedException(FieldException::class, "Invalid enforced cardinality '$enforced_cardinality'. Allowed values: a positive integer or -1."); + $this->expectException(FieldException::class); + $this->expectExceptionMessage("Invalid enforced cardinality '$enforced_cardinality'. Allowed values: a positive integer or -1."); $field_storage->getCardinality(); } diff --git a/core/modules/field/tests/src/Unit/Plugin/migrate/process/ProcessFieldTest.php b/core/modules/field/tests/src/Unit/Plugin/migrate/process/ProcessFieldTest.php index db9709e2e75f..60fbbde1f846 100644 --- a/core/modules/field/tests/src/Unit/Plugin/migrate/process/ProcessFieldTest.php +++ b/core/modules/field/tests/src/Unit/Plugin/migrate/process/ProcessFieldTest.php @@ -63,7 +63,8 @@ class ProcessFieldTest extends MigrateTestCase { $this->plugin = new ProcessField(['method' => $method], $value, [], $this->cckFieldManager->reveal(), $this->fieldManager->reveal(), $this->migration->reveal()); if ($migrate_exception) { - $this->setExpectedException(MigrateException::class, $migrate_exception); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage($migrate_exception); } if ($plugin_not_found) { diff --git a/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldTypeDefaultsTest.php b/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldTypeDefaultsTest.php index 1a4c8e1ff404..03c1cb1b3b86 100644 --- a/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldTypeDefaultsTest.php +++ b/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldTypeDefaultsTest.php @@ -47,8 +47,8 @@ class FieldTypeDefaultsTest extends MigrateProcessTestCase { * @covers ::transform */ public function testDefaultsException() { - $this->setExpectedException(MigrateException::class, - sprintf('Failed to lookup field type %s in the static map.', var_export([], TRUE))); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage(sprintf('Failed to lookup field type %s in the static map.', var_export([], TRUE))); $this->plugin->transform([], $this->migrateExecutable, $this->row, 'property'); } diff --git a/core/modules/hal/tests/src/Kernel/DenormalizeTest.php b/core/modules/hal/tests/src/Kernel/DenormalizeTest.php index 6c6fb731c98a..320ab65a5c30 100644 --- a/core/modules/hal/tests/src/Kernel/DenormalizeTest.php +++ b/core/modules/hal/tests/src/Kernel/DenormalizeTest.php @@ -86,7 +86,7 @@ class DenormalizeTest extends NormalizerTestBase { ], ]; - $this->setExpectedException(UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->serializer->denormalize($data_with_invalid_type, $this->entityClass, $this->format); } @@ -100,7 +100,7 @@ class DenormalizeTest extends NormalizerTestBase { ], ]; - $this->setExpectedException(UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->serializer->denormalize($data_with_no_types, $this->entityClass, $this->format); } @@ -146,7 +146,8 @@ class DenormalizeTest extends NormalizerTestBase { public function testDenormalizeSerializedItem() { $entity = EntitySerializedField::create(['serialized' => 'boo']); $normalized = $this->serializer->normalize($entity, $this->format); - $this->setExpectedException(\LogicException::class, 'The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized" field (field item class: Drupal\entity_test\Plugin\Field\FieldType\SerializedItem).'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized" field (field item class: Drupal\entity_test\Plugin\Field\FieldType\SerializedItem).'); $this->serializer->denormalize($normalized, EntitySerializedField::class, $this->format); } @@ -159,7 +160,8 @@ class DenormalizeTest extends NormalizerTestBase { $this->assertEquals($normalized['serialized_long'][0]['value'], ['Hello world!']); $normalized['serialized_long'][0]['value'] = 'boo'; - $this->setExpectedException(\LogicException::class, 'The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_long" field (field item class: Drupal\Core\Field\Plugin\Field\FieldType\StringLongItem).'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_long" field (field item class: Drupal\Core\Field\Plugin\Field\FieldType\StringLongItem).'); $this->serializer->denormalize($normalized, EntitySerializedField::class); } diff --git a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php index 4af4a3cc6c77..33fa4dc33b36 100644 --- a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php +++ b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php @@ -23,7 +23,7 @@ class FieldItemNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenorma $field_item_normalizer = new FieldItemNormalizer(); $data = []; $class = []; - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $field_item_normalizer->denormalize($data, $class, NULL, $context); } diff --git a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php index 792e6333a637..2ac34ebbbd3b 100644 --- a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php +++ b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php @@ -23,7 +23,7 @@ class FieldNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalize $field_item_normalizer = new FieldNormalizer(); $data = []; $class = []; - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $field_item_normalizer->denormalize($data, $class, NULL, $context); } diff --git a/core/modules/jsonapi/tests/src/Functional/MessageTest.php b/core/modules/jsonapi/tests/src/Functional/MessageTest.php index 48b82ed2b16a..9b9ddf71a9f9 100644 --- a/core/modules/jsonapi/tests/src/Functional/MessageTest.php +++ b/core/modules/jsonapi/tests/src/Functional/MessageTest.php @@ -115,7 +115,8 @@ class MessageTest extends ResourceTestBase { */ public function testGetIndividual() { // Contact Message entities are not stored, so they cannot be retrieved. - $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.individual" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "jsonapi.contact_message--camelids.individual" does not exist.'); Url::fromRoute('jsonapi.contact_message--camelids.individual')->toString(TRUE); } @@ -125,7 +126,8 @@ class MessageTest extends ResourceTestBase { */ public function testPatchIndividual() { // Contact Message entities are not stored, so they cannot be modified. - $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.individual" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "jsonapi.contact_message--camelids.individual" does not exist.'); Url::fromRoute('jsonapi.contact_message--camelids.individual')->toString(TRUE); } @@ -135,7 +137,8 @@ class MessageTest extends ResourceTestBase { */ public function testDeleteIndividual() { // Contact Message entities are not stored, so they cannot be deleted. - $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.individual" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "jsonapi.contact_message--camelids.individual" does not exist.'); Url::fromRoute('jsonapi.contact_message--camelids.individual')->toString(TRUE); } @@ -145,7 +148,8 @@ class MessageTest extends ResourceTestBase { */ public function testRelated() { // Contact Message entities are not stored, so they cannot be retrieved. - $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.related" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "jsonapi.contact_message--camelids.related" does not exist.'); Url::fromRoute('jsonapi.contact_message--camelids.related')->toString(TRUE); } @@ -155,7 +159,8 @@ class MessageTest extends ResourceTestBase { */ public function testRelationships() { // Contact Message entities are not stored, so they cannot be retrieved. - $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.relationship.get" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "jsonapi.contact_message--camelids.relationship.get" does not exist.'); Url::fromRoute('jsonapi.contact_message--camelids.relationship.get')->toString(TRUE); } @@ -181,7 +186,8 @@ class MessageTest extends ResourceTestBase { */ public function testRevisions() { // Contact Message entities are not stored, so they cannot be retrieved. - $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.individual" does not exist.'); + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route "jsonapi.contact_message--camelids.individual" does not exist.'); Url::fromRoute('jsonapi.contact_message--camelids.individual')->toString(TRUE); } diff --git a/core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php b/core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php index e3c569a96389..e1ebc3c57a67 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php @@ -126,7 +126,10 @@ class FieldResolverTest extends JsonapiKernelTestBase { */ public function testResolveInternalIncludePathError($entity_type, $bundle, $external_path, $expected_message = '') { $path_parts = explode('.', $external_path); - $this->setExpectedException(CacheableBadRequestHttpException::class, $expected_message); + $this->expectException(CacheableBadRequestHttpException::class); + if (!empty($expected_message)) { + $this->expectExceptionMessage($expected_message); + } $resource_type = $this->resourceTypeRepository->get($entity_type, $bundle); $this->sut->resolveInternalIncludePath($resource_type, $path_parts); } @@ -245,7 +248,10 @@ class FieldResolverTest extends JsonapiKernelTestBase { * @dataProvider resolveInternalEntityQueryPathErrorProvider */ public function testResolveInternalEntityQueryPathError($entity_type, $bundle, $external_path, $expected_message = '') { - $this->setExpectedException(CacheableBadRequestHttpException::class, $expected_message); + $this->expectException(CacheableBadRequestHttpException::class); + if (!empty($expected_message)) { + $this->expectExceptionMessage($expected_message); + } $this->sut->resolveInternalEntityQueryPath($entity_type, $bundle, $external_path); } diff --git a/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php b/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php index 3bbe465aad92..ce37fec23b45 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php @@ -205,7 +205,7 @@ class EntityResourceTest extends JsonapiKernelTestBase { $role = Role::load(RoleInterface::ANONYMOUS_ID); $role->revokePermission('access content'); $role->save(); - $this->setExpectedException(EntityAccessDeniedHttpException::class); + $this->expectException(EntityAccessDeniedHttpException::class); $this->entityResource->getIndividual($this->node, Request::create('/jsonapi/node/article')); } @@ -420,7 +420,8 @@ class EntityResourceTest extends JsonapiKernelTestBase { Role::load(Role::ANONYMOUS_ID) ->grantPermission('create article content') ->save(); - $this->setExpectedException(HttpException::class, 'Unprocessable Entity: validation failed.'); + $this->expectException(HttpException::class); + $this->expectExceptionMessage('Unprocessable Entity: validation failed.'); $resource_type = new ResourceType('node', 'article', Node::class); $payload = Json::encode([ 'data' => [ @@ -455,7 +456,8 @@ class EntityResourceTest extends JsonapiKernelTestBase { ], ]); - $this->setExpectedException(ConflictHttpException::class, 'Conflict: Entity already exists.'); + $this->expectException(ConflictHttpException::class); + $this->expectExceptionMessage('Conflict: Entity already exists.'); $resource_type = new ResourceType('node', 'article', Node::class); $resource_type->setRelatableResourceTypes([ 'field_relationships' => [new ResourceType('node', 'article', NULL)], diff --git a/core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php b/core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php index 2a149acc23c6..74e9c291a4f2 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php @@ -74,7 +74,8 @@ class FilterTest extends JsonapiKernelTestBase { * @covers ::queryCondition */ public function testInvalidFilterPathDueToMissingPropertyName() { - $this->setExpectedException(CacheableBadRequestHttpException::class, 'Invalid nested filtering. The field `colors`, given in the path `colors` is incomplete, it must end with one of the following specifiers: `value`, `format`, `processed`.'); + $this->expectException(CacheableBadRequestHttpException::class); + $this->expectExceptionMessage('Invalid nested filtering. The field `colors`, given in the path `colors` is incomplete, it must end with one of the following specifiers: `value`, `format`, `processed`.'); $resource_type = new ResourceType('node', 'painting', NULL); Filter::createFromQueryParameter(['colors' => ''], $resource_type, $this->fieldResolver); } @@ -83,7 +84,8 @@ class FilterTest extends JsonapiKernelTestBase { * @covers ::queryCondition */ public function testInvalidFilterPathDueToMissingPropertyNameReferenceFieldWithMetaProperties() { - $this->setExpectedException(CacheableBadRequestHttpException::class, 'Invalid nested filtering. The field `photo`, given in the path `photo` is incomplete, it must end with one of the following specifiers: `id`, `meta.alt`, `meta.title`, `meta.width`, `meta.height`.'); + $this->expectException(CacheableBadRequestHttpException::class); + $this->expectExceptionMessage('Invalid nested filtering. The field `photo`, given in the path `photo` is incomplete, it must end with one of the following specifiers: `id`, `meta.alt`, `meta.title`, `meta.width`, `meta.height`.'); $resource_type = new ResourceType('node', 'painting', NULL); Filter::createFromQueryParameter(['photo' => ''], $resource_type, $this->fieldResolver); } @@ -92,7 +94,8 @@ class FilterTest extends JsonapiKernelTestBase { * @covers ::queryCondition */ public function testInvalidFilterPathDueMissingMetaPrefixReferenceFieldWithMetaProperties() { - $this->setExpectedException(CacheableBadRequestHttpException::class, 'Invalid nested filtering. The property `alt`, given in the path `photo.alt` belongs to the meta object of a relationship and must be preceded by `meta`.'); + $this->expectException(CacheableBadRequestHttpException::class); + $this->expectExceptionMessage('Invalid nested filtering. The property `alt`, given in the path `photo.alt` belongs to the meta object of a relationship and must be preceded by `meta`.'); $resource_type = new ResourceType('node', 'painting', NULL); Filter::createFromQueryParameter(['photo.alt' => ''], $resource_type, $this->fieldResolver); } @@ -101,7 +104,8 @@ class FilterTest extends JsonapiKernelTestBase { * @covers ::queryCondition */ public function testInvalidFilterPathDueToMissingPropertyNameReferenceFieldWithoutMetaProperties() { - $this->setExpectedException(CacheableBadRequestHttpException::class, 'Invalid nested filtering. The field `uid`, given in the path `uid` is incomplete, it must end with one of the following specifiers: `id`.'); + $this->expectException(CacheableBadRequestHttpException::class); + $this->expectExceptionMessage('Invalid nested filtering. The field `uid`, given in the path `uid` is incomplete, it must end with one of the following specifiers: `id`.'); $resource_type = new ResourceType('node', 'painting', NULL); Filter::createFromQueryParameter(['uid' => ''], $resource_type, $this->fieldResolver); } @@ -110,7 +114,8 @@ class FilterTest extends JsonapiKernelTestBase { * @covers ::queryCondition */ public function testInvalidFilterPathDueToNonexistentProperty() { - $this->setExpectedException(CacheableBadRequestHttpException::class, 'Invalid nested filtering. The property `foobar`, given in the path `colors.foobar`, does not exist. Must be one of the following property names: `value`, `format`, `processed`.'); + $this->expectException(CacheableBadRequestHttpException::class); + $this->expectExceptionMessage('Invalid nested filtering. The property `foobar`, given in the path `colors.foobar`, does not exist. Must be one of the following property names: `value`, `format`, `processed`.'); $resource_type = new ResourceType('node', 'painting', NULL); Filter::createFromQueryParameter(['colors.foobar' => ''], $resource_type, $this->fieldResolver); } @@ -119,7 +124,8 @@ class FilterTest extends JsonapiKernelTestBase { * @covers ::queryCondition */ public function testInvalidFilterPathDueToElidedSoleProperty() { - $this->setExpectedException(CacheableBadRequestHttpException::class, 'Invalid nested filtering. The property `value`, given in the path `promote.value`, does not exist. Filter by `promote`, not `promote.value` (the JSON:API module elides property names from single-property fields).'); + $this->expectException(CacheableBadRequestHttpException::class); + $this->expectExceptionMessage('Invalid nested filtering. The property `value`, given in the path `promote.value`, does not exist. Filter by `promote`, not `promote.value` (the JSON:API module elides property names from single-property fields).'); $resource_type = new ResourceType('node', 'painting', NULL); Filter::createFromQueryParameter(['promote.value' => ''], $resource_type, $this->fieldResolver); } diff --git a/core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php b/core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php index e432e8ff9f91..774b51ec51f4 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php @@ -134,7 +134,8 @@ class VersionNegotiatorTest extends JsonapiKernelTestBase { * @covers \Drupal\jsonapi\Revisions\VersionById::getRevision */ public function testInvalidRevisionId() { - $this->setExpectedException(CacheableNotFoundHttpException::class, sprintf('The requested version, identified by `id:%s`, could not be found.', $this->node2->getRevisionId())); + $this->expectException(CacheableNotFoundHttpException::class); + $this->expectExceptionMessage(sprintf('The requested version, identified by `id:%s`, could not be found.', $this->node2->getRevisionId())); $this->versionNegotiator->getRevision($this->node, 'id:' . $this->node2->getRevisionId()); } @@ -161,7 +162,8 @@ class VersionNegotiatorTest extends JsonapiKernelTestBase { * @covers \Drupal\jsonapi\Revisions\VersionByRel::getRevision */ public function testInvalidRevisionRel() { - $this->setExpectedException(CacheableBadRequestHttpException::class, 'An invalid resource version identifier, `rel:erroneous-revision-name`, was provided.'); + $this->expectException(CacheableBadRequestHttpException::class); + $this->expectExceptionMessage('An invalid resource version identifier, `rel:erroneous-revision-name`, was provided.'); $this->versionNegotiator->getRevision($this->node, 'rel:erroneous-revision-name'); } diff --git a/core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index a30b1f6a183a..2cef29f9fb66 100644 --- a/core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -216,10 +216,8 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { ['type' => 'node--article']; if ($expect_exception) { - $this->setExpectedException( - UnprocessableEntityHttpException::class, - 'IDs should be properly generated and formatted UUIDs as described in RFC 4122.' - ); + $this->expectException(UnprocessableEntityHttpException::class); + $this->expectExceptionMessage('IDs should be properly generated and formatted UUIDs as described in RFC 4122.'); } $denormalized = $this->normalizer->denormalize($data, NULL, 'api_json', [ diff --git a/core/modules/jsonapi/tests/src/Unit/Normalizer/ResourceIdentifierNormalizerTest.php b/core/modules/jsonapi/tests/src/Unit/Normalizer/ResourceIdentifierNormalizerTest.php index a2af02e82056..390d59d5cda2 100644 --- a/core/modules/jsonapi/tests/src/Unit/Normalizer/ResourceIdentifierNormalizerTest.php +++ b/core/modules/jsonapi/tests/src/Unit/Normalizer/ResourceIdentifierNormalizerTest.php @@ -149,7 +149,7 @@ class ResourceIdentifierNormalizerTest extends UnitTestCase { 'related' => $field_name, 'target_entity' => $this->prophesize(FieldableEntityInterface::class)->reveal(), ]; - $this->setExpectedException(BadRequestHttpException::class); + $this->expectException(BadRequestHttpException::class); $this->normalizer->denormalize($data, NULL, 'api_json', $context); } diff --git a/core/modules/jsonapi/tests/src/Unit/Query/EntityConditionGroupTest.php b/core/modules/jsonapi/tests/src/Unit/Query/EntityConditionGroupTest.php index e7813de97a2f..cc0c416398fd 100644 --- a/core/modules/jsonapi/tests/src/Unit/Query/EntityConditionGroupTest.php +++ b/core/modules/jsonapi/tests/src/Unit/Query/EntityConditionGroupTest.php @@ -32,7 +32,7 @@ class EntityConditionGroupTest extends UnitTestCase { * @covers ::__construct */ public function testConstructException() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); new EntityConditionGroup('NOT_ALLOWED', []); } diff --git a/core/modules/jsonapi/tests/src/Unit/Query/EntityConditionTest.php b/core/modules/jsonapi/tests/src/Unit/Query/EntityConditionTest.php index 4b07ced975b5..1659b6f80bfb 100644 --- a/core/modules/jsonapi/tests/src/Unit/Query/EntityConditionTest.php +++ b/core/modules/jsonapi/tests/src/Unit/Query/EntityConditionTest.php @@ -75,7 +75,8 @@ class EntityConditionTest extends UnitTestCase { */ public function testValidation($input, $exception) { if ($exception) { - $this->setExpectedException(get_class($exception), $exception->getMessage()); + $this->expectException(get_class($exception)); + $this->expectExceptionMessage($exception->getMessage()); } EntityCondition::createFromQueryParameter($input); $this->assertTrue(is_null($exception), 'No exception was expected.'); diff --git a/core/modules/jsonapi/tests/src/Unit/Query/OffsetPageTest.php b/core/modules/jsonapi/tests/src/Unit/Query/OffsetPageTest.php index b1272c0ff971..a845f4904782 100644 --- a/core/modules/jsonapi/tests/src/Unit/Query/OffsetPageTest.php +++ b/core/modules/jsonapi/tests/src/Unit/Query/OffsetPageTest.php @@ -58,7 +58,7 @@ class OffsetPageTest extends UnitTestCase { * @covers ::createFromQueryParameter */ public function testCreateFromQueryParameterFail() { - $this->setExpectedException(BadRequestHttpException::class); + $this->expectException(BadRequestHttpException::class); OffsetPage::createFromQueryParameter('lorem'); } diff --git a/core/modules/jsonapi/tests/src/Unit/Query/SortTest.php b/core/modules/jsonapi/tests/src/Unit/Query/SortTest.php index fdf1dbbaf2d0..cb2be5153eca 100644 --- a/core/modules/jsonapi/tests/src/Unit/Query/SortTest.php +++ b/core/modules/jsonapi/tests/src/Unit/Query/SortTest.php @@ -84,7 +84,7 @@ class SortTest extends UnitTestCase { * @dataProvider badParameterProvider */ public function testCreateFromQueryParameterFail($input) { - $this->setExpectedException(BadRequestHttpException::class); + $this->expectException(BadRequestHttpException::class); Sort::createFromQueryParameter($input); } diff --git a/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php b/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php index 695c91f19564..27aa0999eafc 100644 --- a/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php +++ b/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php @@ -79,7 +79,8 @@ class LanguageNegotiationTest extends MigrateProcessTestCase { */ public function testStringInput() { $this->plugin = new LanguageNegotiation([], 'map', []); - $this->setExpectedException(MigrateException::class, 'The input should be an array'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The input should be an array'); $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php b/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php index 606572ecd858..b65c9d050870 100644 --- a/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php +++ b/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php @@ -53,7 +53,8 @@ class LanguageTypesTest extends MigrateProcessTestCase { */ public function testStringInput() { $this->plugin = new LanguageTypes([], 'map', []); - $this->setExpectedException(MigrateException::class, 'The input should be an array'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The input should be an array'); $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php b/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php index 637da2994751..8682e26f7a58 100644 --- a/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php @@ -179,7 +179,8 @@ class DefaultsSectionStorageTest extends KernelTestBase { */ public function testSetSectionList() { $section_list = $this->prophesize(SectionListInterface::class); - $this->setExpectedException(\Exception::class, '\Drupal\layout_builder\SectionStorageInterface::setSectionList() must no longer be called. The section list should be derived from context. See https://www.drupal.org/node/3016262.'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('\Drupal\layout_builder\SectionStorageInterface::setSectionList() must no longer be called. The section list should be derived from context. See https://www.drupal.org/node/3016262.'); $this->plugin->setSectionList($section_list->reveal()); } diff --git a/core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php b/core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php index 4675046a89e6..4fba461ae8ec 100644 --- a/core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php @@ -300,7 +300,7 @@ class FieldBlockTest extends EntityKernelTestBase { $entity->get('the_field_name')->willReturn($field->reveal()); $block = $this->getTestBlock($entity); - $this->setExpectedException(EnforcedResponseException::class); + $this->expectException(EnforcedResponseException::class); $block->build(); } diff --git a/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php b/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php index 2282c1b90918..0e1639f8e2e0 100644 --- a/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php @@ -37,7 +37,7 @@ class LayoutBuilderEntityViewDisplayTest extends SectionStorageTestBase { * Tests that configuration schema enforces valid values. */ public function testInvalidConfiguration() { - $this->setExpectedException(SchemaIncompleteException::class); + $this->expectException(SchemaIncompleteException::class); $this->sectionStorage->getSection(0)->getComponent('first-uuid')->setConfiguration(['id' => 'foo', 'bar' => 'baz']); $this->sectionStorage->save(); } diff --git a/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php b/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php index 66b4f1434b41..aa2532e1bbdf 100644 --- a/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php @@ -216,7 +216,8 @@ class OverridesSectionStorageTest extends KernelTestBase { */ public function testSetSectionList() { $section_list = $this->prophesize(SectionListInterface::class); - $this->setExpectedException(\Exception::class, '\Drupal\layout_builder\SectionStorageInterface::setSectionList() must no longer be called. The section list should be derived from context. See https://www.drupal.org/node/3016262.'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('\Drupal\layout_builder\SectionStorageInterface::setSectionList() must no longer be called. The section list should be derived from context. See https://www.drupal.org/node/3016262.'); $this->plugin->setSectionList($section_list->reveal()); } diff --git a/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php b/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php index bb5b84d4bf7a..023200e2c090 100644 --- a/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php @@ -23,7 +23,8 @@ class SectionListTraitTest extends SectionStorageTestBase { * @covers ::addBlankSection */ public function testAddBlankSection() { - $this->setExpectedException(\Exception::class, 'A blank section must only be added to an empty list'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('A blank section must only be added to an empty list'); $this->sectionStorage->addBlankSection(); } diff --git a/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php b/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php index f943d5183f07..5ec39f25d59b 100644 --- a/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php +++ b/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php @@ -83,7 +83,8 @@ abstract class SectionStorageTestBase extends EntityKernelTestBase { * @covers ::getSection */ public function testGetSectionInvalidDelta() { - $this->setExpectedException(\OutOfBoundsException::class, 'Invalid delta "2"'); + $this->expectException(\OutOfBoundsException::class); + $this->expectExceptionMessage('Invalid delta "2"'); $this->sectionStorage->getSection(2); } diff --git a/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php b/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php index 5281d08d7a60..f9ee5a6925ff 100644 --- a/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php @@ -164,7 +164,7 @@ class DefaultsSectionStorageTest extends UnitTestCase { } if (!$success) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); } $result = $this->plugin->getSectionListFromId($value); diff --git a/core/modules/layout_builder/tests/src/Unit/LayoutTempstoreRepositoryTest.php b/core/modules/layout_builder/tests/src/Unit/LayoutTempstoreRepositoryTest.php index fb46e608ae33..6269c7afa4a0 100644 --- a/core/modules/layout_builder/tests/src/Unit/LayoutTempstoreRepositoryTest.php +++ b/core/modules/layout_builder/tests/src/Unit/LayoutTempstoreRepositoryTest.php @@ -77,7 +77,8 @@ class LayoutTempstoreRepositoryTest extends UnitTestCase { $repository = new LayoutTempstoreRepository($tempstore_factory->reveal()); - $this->setExpectedException(\UnexpectedValueException::class, 'The entry with storage type "my_storage_type" and ID "my_storage_id" is invalid'); + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('The entry with storage type "my_storage_type" and ID "my_storage_id" is invalid'); $repository->get($section_storage->reveal()); } diff --git a/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php b/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php index 293a55c0aa88..eb03ae2e7678 100644 --- a/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php @@ -149,7 +149,7 @@ class OverridesSectionStorageTest extends UnitTestCase { } if (!$success) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); } $result = $this->plugin->getSectionListFromId($id); diff --git a/core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php b/core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php index 574c00d492e0..0989da8487fd 100644 --- a/core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php +++ b/core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php @@ -296,7 +296,8 @@ class SectionRenderTest extends UnitTestCase { * @covers ::toRenderArray */ public function testToRenderArrayMissingPluginId() { - $this->setExpectedException(PluginException::class, 'No plugin ID specified for component with "some_uuid" UUID'); + $this->expectException(PluginException::class); + $this->expectExceptionMessage('No plugin ID specified for component with "some_uuid" UUID'); (new Section('layout_onecol', [], [new SectionComponent('some_uuid', 'content')]))->toRenderArray(); } diff --git a/core/modules/layout_builder/tests/src/Unit/SectionTest.php b/core/modules/layout_builder/tests/src/Unit/SectionTest.php index 232e1719c525..576eba7e1d25 100644 --- a/core/modules/layout_builder/tests/src/Unit/SectionTest.php +++ b/core/modules/layout_builder/tests/src/Unit/SectionTest.php @@ -59,7 +59,8 @@ class SectionTest extends UnitTestCase { * @covers ::getComponent */ public function testGetComponentInvalidUuid() { - $this->setExpectedException(\InvalidArgumentException::class, 'Invalid UUID "invalid-uuid"'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid UUID "invalid-uuid"'); $this->section->getComponent('invalid-uuid'); } @@ -122,7 +123,8 @@ class SectionTest extends UnitTestCase { * @covers ::insertAfterComponent */ public function testInsertAfterComponentValidUuidRegionMismatch() { - $this->setExpectedException(\InvalidArgumentException::class, 'Invalid preceding UUID "existing-uuid"'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid preceding UUID "existing-uuid"'); $this->section->insertAfterComponent('existing-uuid', new SectionComponent('new-uuid', 'ordered-region')); } @@ -130,7 +132,8 @@ class SectionTest extends UnitTestCase { * @covers ::insertAfterComponent */ public function testInsertAfterComponentInvalidUuid() { - $this->setExpectedException(\InvalidArgumentException::class, 'Invalid preceding UUID "invalid-uuid"'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid preceding UUID "invalid-uuid"'); $this->section->insertAfterComponent('invalid-uuid', new SectionComponent('new-uuid', 'ordered-region')); } @@ -169,7 +172,8 @@ class SectionTest extends UnitTestCase { * @covers ::insertComponent */ public function testInsertComponentInvalidDelta() { - $this->setExpectedException(\OutOfBoundsException::class, 'Invalid delta "7" for the "new-uuid" component'); + $this->expectException(\OutOfBoundsException::class); + $this->expectExceptionMessage('Invalid delta "7" for the "new-uuid" component'); $this->section->insertComponent(7, new SectionComponent('new-uuid', 'ordered-region')); } diff --git a/core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php b/core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php index 66209eff6f35..9d6b21666626 100644 --- a/core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php +++ b/core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php @@ -97,7 +97,8 @@ class LinkItemSerializationTest extends FieldKernelTestBase { $json = json_decode($this->serializer->serialize($entity, 'json'), TRUE); $json['field_test'][0]['options'] = 'string data'; $serialized = json_encode($json, TRUE); - $this->setExpectedException(\LogicException::class, 'The generic FieldItemNormalizer cannot denormalize string values for "options" properties of the "field_test" field (field item class: Drupal\link\Plugin\Field\FieldType\LinkItem).'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "options" properties of the "field_test" field (field item class: Drupal\link\Plugin\Field\FieldType\LinkItem).'); $this->serializer->deserialize($serialized, EntityTest::class, 'json'); } diff --git a/core/modules/locale/tests/src/Unit/StringBaseTest.php b/core/modules/locale/tests/src/Unit/StringBaseTest.php index 7436c70072aa..99bb0377a4c0 100644 --- a/core/modules/locale/tests/src/Unit/StringBaseTest.php +++ b/core/modules/locale/tests/src/Unit/StringBaseTest.php @@ -17,7 +17,8 @@ class StringBaseTest extends UnitTestCase { */ public function testSaveWithoutStorage() { $string = new SourceString(['source' => 'test']); - $this->setExpectedException(StringStorageException::class, 'The string cannot be saved because its not bound to a storage: test'); + $this->expectException(StringStorageException::class); + $this->expectExceptionMessage('The string cannot be saved because its not bound to a storage: test'); $string->save(); } @@ -26,7 +27,8 @@ class StringBaseTest extends UnitTestCase { */ public function testDeleteWithoutStorage() { $string = new SourceString(['lid' => 1, 'source' => 'test']); - $this->setExpectedException(StringStorageException::class, 'The string cannot be deleted because its not bound to a storage: test'); + $this->expectException(StringStorageException::class); + $this->expectExceptionMessage('The string cannot be deleted because its not bound to a storage: test'); $string->delete(); } diff --git a/core/modules/media/tests/src/Functional/ProviderRepositoryTest.php b/core/modules/media/tests/src/Functional/ProviderRepositoryTest.php index 43a71053ab22..d04d46f91c69 100644 --- a/core/modules/media/tests/src/Functional/ProviderRepositoryTest.php +++ b/core/modules/media/tests/src/Functional/ProviderRepositoryTest.php @@ -29,7 +29,8 @@ class ProviderRepositoryTest extends MediaFunctionalTestBase { $client->method('request')->withAnyParameters()->willReturn($response->reveal()); $this->container->set('http_client', $client); - $this->setExpectedException(ProviderException::class, 'Remote oEmbed providers database returned invalid or empty list.'); + $this->expectException(ProviderException::class); + $this->expectExceptionMessage('Remote oEmbed providers database returned invalid or empty list.'); $this->container->get('media.oembed.provider_repository')->getAll(); } @@ -62,7 +63,8 @@ class ProviderRepositoryTest extends MediaFunctionalTestBase { ->set('oembed_providers_url', $providers_url) ->save(); - $this->setExpectedException(ProviderException::class, $exception_message); + $this->expectException(ProviderException::class); + $this->expectExceptionMessage($exception_message); $this->container->get('media.oembed.provider_repository')->getAll(); } diff --git a/core/modules/media/tests/src/Kernel/OEmbedIframeControllerTest.php b/core/modules/media/tests/src/Kernel/OEmbedIframeControllerTest.php index 84fe4397daae..3b71cdc92fa9 100644 --- a/core/modules/media/tests/src/Kernel/OEmbedIframeControllerTest.php +++ b/core/modules/media/tests/src/Kernel/OEmbedIframeControllerTest.php @@ -45,7 +45,8 @@ class OEmbedIframeControllerTest extends MediaKernelTestBase { $this->assertInternalType('callable', $controller); - $this->setExpectedException('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException', 'This resource is not available'); + $this->expectException('\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException'); + $this->expectExceptionMessage('This resource is not available'); $request = new Request([ 'url' => 'https://example.com/path/to/resource', 'hash' => $hash, diff --git a/core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php b/core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php index 833ede9a6546..51b70c978063 100644 --- a/core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php +++ b/core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php @@ -120,7 +120,8 @@ class MediaLibraryAddFormTest extends KernelTestBase { */ public function testFormStateValidation() { $form_state = new FormState(); - $this->setExpectedException(\InvalidArgumentException::class, 'The media library state is not present in the form state.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The media library state is not present in the form state.'); \Drupal::formBuilder()->buildForm(FileUploadForm::class, $form_state); } @@ -131,7 +132,8 @@ class MediaLibraryAddFormTest extends KernelTestBase { $state = MediaLibraryState::create('test', ['image', 'remote_video', 'header_image'], 'header_image', -1); $form_state = new FormState(); $form_state->set('media_library_state', $state); - $this->setExpectedException(\InvalidArgumentException::class, "The 'header_image' media type does not exist."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The 'header_image' media type does not exist."); \Drupal::formBuilder()->buildForm(FileUploadForm::class, $form_state); } diff --git a/core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php b/core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php index c4ea9c76dce0..28df912345eb 100644 --- a/core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php +++ b/core/modules/media_library/tests/src/Kernel/MediaLibraryStateTest.php @@ -99,7 +99,8 @@ class MediaLibraryStateTest extends KernelTestBase { */ public function testCreate($opener_id, array $allowed_media_type_ids, $selected_type_id, $remaining_slots, $exception_message = '') { if ($exception_message) { - $this->setExpectedException(\InvalidArgumentException::class, $exception_message); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage($exception_message); } $state = MediaLibraryState::create($opener_id, $allowed_media_type_ids, $selected_type_id, $remaining_slots); $this->assertInstanceOf(MediaLibraryState::class, $state); @@ -275,7 +276,8 @@ class MediaLibraryStateTest extends KernelTestBase { $query = MediaLibraryState::create('test', ['file', 'image'], 'image', 2)->all(); $query = array_merge($query, $query_overrides); if ($exception_expected) { - $this->setExpectedException(BadRequestHttpException::class, "Invalid media library parameters specified."); + $this->expectException(BadRequestHttpException::class); + $this->expectExceptionMessage("Invalid media library parameters specified."); } $state = MediaLibraryState::fromRequest(new Request($query)); $this->assertInstanceOf(MediaLibraryState::class, $state); @@ -285,7 +287,8 @@ class MediaLibraryStateTest extends KernelTestBase { * @covers ::fromRequest */ public function testFromRequestQueryLess() { - $this->setExpectedException(\InvalidArgumentException::class, 'The opener ID parameter is required and must be a string.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The opener ID parameter is required and must be a string.'); $state = MediaLibraryState::fromRequest(new Request()); $this->assertInstanceOf(MediaLibraryState::class, $state); } diff --git a/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php b/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php index 1ec75f9d4e88..6b86bc080a1f 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php @@ -99,7 +99,8 @@ class LinkUriTest extends KernelTestBase { * @dataProvider providerTestNotRouted */ public function testNotRouted($value, $exception_message) { - $this->setExpectedException(MigrateException::class, $exception_message); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage($exception_message); $this->doTransform($value); } diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php index dce4264bc399..e90260755046 100644 --- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php +++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php @@ -21,7 +21,8 @@ class MigrationProvidersExistTest extends MigrateDrupalTestBase { */ public function testSourceProvider() { $this->enableModules(['migration_provider_test']); - $this->setExpectedException(BadPluginDefinitionException::class, 'The no_source_module plugin must define the source_module property.'); + $this->expectException(BadPluginDefinitionException::class); + $this->expectExceptionMessage('The no_source_module plugin must define the source_module property.'); $this->container->get('plugin.manager.migration')->getDefinition('migration_provider_no_annotation'); } @@ -173,7 +174,8 @@ class MigrationProvidersExistTest extends MigrateDrupalTestBase { $plugin_manager->method('getDiscovery') ->willReturn($discovery); - $this->setExpectedException(BadPluginDefinitionException::class, "The missing_{$missing_property} plugin must define the $missing_property property."); + $this->expectException(BadPluginDefinitionException::class); + $this->expectExceptionMessage("The missing_{$missing_property} plugin must define the $missing_property property."); $plugin_manager->getDefinitions(); } diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php index a8dddd277ac9..85ec74f8e619 100644 --- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php +++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php @@ -36,7 +36,8 @@ class MigrationTest extends KernelTestBase { */ public function testGetProcessPluginsException() { $migration = \Drupal::service('plugin.manager.migration')->createStubMigration([]); - $this->setExpectedException(MigrateException::class, 'Invalid process configuration for foobar'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Invalid process configuration for foobar'); $migration->getProcessPlugins(['foobar' => ['plugin' => 'get']]); } @@ -123,7 +124,8 @@ class MigrationTest extends KernelTestBase { */ public function testGetDestinationPlugin() { $migration = \Drupal::service('plugin.manager.migration')->createStubMigration(['destination' => ['no_stub' => TRUE]]); - $this->setExpectedException(MigrateSkipRowException::class, "Stub requested but not made because no_stub configuration is set."); + $this->expectException(MigrateSkipRowException::class); + $this->expectExceptionMessage("Stub requested but not made because no_stub configuration is set."); $migration->getDestinationPlugin(TRUE); } diff --git a/core/modules/migrate/tests/src/Kernel/QueryBatchTest.php b/core/modules/migrate/tests/src/Kernel/QueryBatchTest.php index e92e1441e15b..4bb8359ff558 100644 --- a/core/modules/migrate/tests/src/Kernel/QueryBatchTest.php +++ b/core/modules/migrate/tests/src/Kernel/QueryBatchTest.php @@ -57,7 +57,8 @@ class QueryBatchTest extends KernelTestBase { * Tests a negative batch size throws an exception. */ public function testBatchSizeNegative() { - $this->setExpectedException(MigrateException::class, 'batch_size must be greater than or equal to zero'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('batch_size must be greater than or equal to zero'); $plugin = $this->getPlugin(['batch_size' => -1]); $plugin->next(); } @@ -66,7 +67,8 @@ class QueryBatchTest extends KernelTestBase { * Tests a non integer batch size throws an exception. */ public function testBatchSizeNonInteger() { - $this->setExpectedException(MigrateException::class, 'batch_size must be greater than or equal to zero'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('batch_size must be greater than or equal to zero'); $plugin = $this->getPlugin(['batch_size' => '1']); $plugin->next(); } diff --git a/core/modules/migrate/tests/src/Kernel/SqlBaseTest.php b/core/modules/migrate/tests/src/Kernel/SqlBaseTest.php index e13f8f88ac0b..a851ec196063 100644 --- a/core/modules/migrate/tests/src/Kernel/SqlBaseTest.php +++ b/core/modules/migrate/tests/src/Kernel/SqlBaseTest.php @@ -123,8 +123,8 @@ class SqlBaseTest extends MigrateTestBase { \Drupal::state()->delete('migrate.fallback_state_key'); $sql_base->setConfiguration([]); Database::renameConnection('migrate', 'fallback_connection'); - $this->setExpectedException(RequirementsException::class, - 'No database connection configured for source plugin'); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage('No database connection configured for source plugin'); $sql_base->getDatabase(); } diff --git a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php index a8c6ac660c6b..148d322f2b79 100644 --- a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php @@ -165,7 +165,8 @@ class FileCopyTest extends FileTestBase { */ public function testNonExistentSourceFile() { $source = '/non/existent/file'; - $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist"); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("File '/non/existent/file' does not exist"); $this->doTransform($source, 'public://wontmatter.jpg'); } @@ -191,7 +192,8 @@ class FileCopyTest extends FileTestBase { $this->fileSystem->chmod('public://dir', 0); // Check that the proper exception is raised. - $this->setExpectedException(MigrateException::class, "Could not create or write to directory 'public://dir/subdir2'"); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("Could not create or write to directory 'public://dir/subdir2'"); $this->doTransform($source, 'public://dir/subdir2/file.txt'); } diff --git a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php index 8027dd39ecf5..91bb000ba15a 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php @@ -435,7 +435,8 @@ class MigrateExecutableTest extends MigrateTestCase { $plugins['destination_id'] = [$plugin, $plugin]; $this->migration->method('getProcessPlugins')->willReturn($plugins); - $this->setExpectedException(MigrateException::class, 'Pipeline failed at plugin_id plugin for destination destination_id: transform_return_string received instead of an array,'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Pipeline failed at plugin_id plugin for destination destination_id: transform_return_string received instead of an array,'); $this->executable->processRow($row); } diff --git a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php index 471897a51c54..f8dc7541faa5 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php @@ -156,7 +156,7 @@ class MigrateSourceTest extends MigrateTestCase { */ public function testHighwaterTrackChangesIncompatible() { $source_config = ['track_changes' => TRUE, 'high_water_property' => ['name' => 'something']]; - $this->setExpectedException(MigrateException::class); + $this->expectException(MigrateException::class); $this->getSource($source_config); } diff --git a/core/modules/migrate/tests/src/Unit/MigrationTest.php b/core/modules/migrate/tests/src/Unit/MigrationTest.php index 2f810d6aad9b..85935674f668 100644 --- a/core/modules/migrate/tests/src/Unit/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrationTest.php @@ -40,7 +40,8 @@ class MigrationTest extends UnitTestCase { $migration->setSourcePlugin($source_plugin); $migration->setDestinationPlugin($destination_plugin); - $this->setExpectedException(RequirementsException::class, 'Missing source requirement'); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage('Missing source requirement'); $migration->checkRequirements(); } @@ -61,7 +62,8 @@ class MigrationTest extends UnitTestCase { $migration->setSourcePlugin($source_plugin); $migration->setDestinationPlugin($destination_plugin); - $this->setExpectedException(RequirementsException::class, 'Missing destination requirement'); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage('Missing destination requirement'); $migration->checkRequirements(); } @@ -105,7 +107,8 @@ class MigrationTest extends UnitTestCase { ->with(['test_a', 'test_b', 'test_c', 'test_d']) ->willReturn(['test_b' => $migration_b, 'test_c' => $migration_c, 'test_d' => $migration_d]); - $this->setExpectedException(RequirementsException::class, 'Missing migrations test_a, test_c'); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage('Missing migrations test_a, test_c'); $migration->checkRequirements(); } diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/CheckRequirementsTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/CheckRequirementsTest.php index deca2c924d8e..23326ed3d1a5 100644 --- a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/CheckRequirementsTest.php +++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/CheckRequirementsTest.php @@ -28,7 +28,8 @@ class CheckRequirementsTest extends UnitTestCase { $this->prophesize(ConfigFactoryInterface::class)->reveal(), $this->prophesize(LanguageManagerInterface::class)->reveal() ); - $this->setExpectedException(RequirementsException::class, "Destination plugin 'test' did not meet the requirements"); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage("Destination plugin 'test' did not meet the requirements"); $destination->checkRequirements(); } diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php index a43f36c97bd2..9b1ede8dfe4e 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 @@ -63,7 +63,8 @@ class EntityContentBaseTest extends EntityTestBase { $this->entityFieldManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal()); $destination->setEntity(FALSE); - $this->setExpectedException(MigrateException::class, 'Unable to get entity'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Unable to get entity'); $destination->import(new Row()); } @@ -87,7 +88,8 @@ class EntityContentBaseTest extends EntityTestBase { $this->entityFieldManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() ); - $this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support translations.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The "foo" entity type does not support translations.'); $destination->getIds(); } diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php index 2aa837e60357..f0b0379b0f14 100644 --- a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php +++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php @@ -55,7 +55,8 @@ class EntityRevisionTest extends EntityTestBase { $this->entityFieldManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() ); - $this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support revisions.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The "foo" entity type does not support revisions.'); $destination->getIds(); } @@ -82,7 +83,8 @@ class EntityRevisionTest extends EntityTestBase { $this->entityFieldManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() ); - $this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support translations.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The "foo" entity type does not support translations.'); $destination->getIds(); } diff --git a/core/modules/migrate/tests/src/Unit/RowTest.php b/core/modules/migrate/tests/src/Unit/RowTest.php index edc31b095d74..4161900784d2 100644 --- a/core/modules/migrate/tests/src/Unit/RowTest.php +++ b/core/modules/migrate/tests/src/Unit/RowTest.php @@ -115,7 +115,7 @@ class RowTest extends UnitTestCase { $invalid_values = [ 'title' => 'node X', ]; - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $row = new Row($invalid_values, $this->testSourceIds); } @@ -130,7 +130,7 @@ class RowTest extends UnitTestCase { $row->rehash(); $this->assertSame($this->testHashMod, $row->getHash(), 'Hash changed correctly.'); $row->freezeSource(); - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $row->setSourceProperty('title', 'new title'); } @@ -140,7 +140,8 @@ class RowTest extends UnitTestCase { public function testSetFrozenRow() { $row = new Row($this->testValues, $this->testSourceIds); $row->freezeSource(); - $this->setExpectedException(\Exception::class, "The source is frozen and can't be changed any more"); + $this->expectException(\Exception::class); + $this->expectExceptionMessage("The source is frozen and can't be changed any more"); $row->setSourceProperty('title', 'new title'); } diff --git a/core/modules/migrate/tests/src/Unit/process/ArrayBuildTest.php b/core/modules/migrate/tests/src/Unit/process/ArrayBuildTest.php index bbfef8b192ca..66ffedddcecb 100644 --- a/core/modules/migrate/tests/src/Unit/process/ArrayBuildTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ArrayBuildTest.php @@ -46,7 +46,8 @@ class ArrayBuildTest extends MigrateProcessTestCase { $source = [ ['bar' => 'foo'], ]; - $this->setExpectedException(MigrateException::class, "The key 'foo' does not exist"); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("The key 'foo' does not exist"); $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -57,7 +58,8 @@ class ArrayBuildTest extends MigrateProcessTestCase { $source = [ ['foo' => 'bar'], ]; - $this->setExpectedException(MigrateException::class, "The key 'bar' does not exist"); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("The key 'bar' does not exist"); $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -66,7 +68,8 @@ class ArrayBuildTest extends MigrateProcessTestCase { */ public function testOneDimensionalArrayInput() { $source = ['foo' => 'bar']; - $this->setExpectedException(MigrateException::class, 'The input should be an array of arrays'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The input should be an array of arrays'); $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -75,7 +78,8 @@ class ArrayBuildTest extends MigrateProcessTestCase { */ public function testStringInput() { $source = 'foo'; - $this->setExpectedException(MigrateException::class, 'The input should be an array of arrays'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The input should be an array of arrays'); $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/CallbackTest.php b/core/modules/migrate/tests/src/Unit/process/CallbackTest.php index 6d894c09c269..260e9a7a20aa 100644 --- a/core/modules/migrate/tests/src/Unit/process/CallbackTest.php +++ b/core/modules/migrate/tests/src/Unit/process/CallbackTest.php @@ -39,7 +39,8 @@ class CallbackTest extends MigrateProcessTestCase { * @dataProvider providerCallbackExceptions */ public function testCallbackExceptions($message, $configuration) { - $this->setExpectedException(\InvalidArgumentException::class, $message); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage($message); $this->plugin = new Callback($configuration, 'map', []); } diff --git a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php index 8acbc11573a1..6f6181d84db4 100644 --- a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php @@ -37,7 +37,7 @@ class ConcatTest extends MigrateProcessTestCase { * Test concat fails properly on non-arrays. */ public function testConcatWithNonArray() { - $this->setExpectedException(MigrateException::class); + $this->expectException(MigrateException::class); $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/DedupeEntityTest.php b/core/modules/migrate/tests/src/Unit/process/DedupeEntityTest.php index 67c47f2a8dae..c28a8deb2720 100644 --- a/core/modules/migrate/tests/src/Unit/process/DedupeEntityTest.php +++ b/core/modules/migrate/tests/src/Unit/process/DedupeEntityTest.php @@ -91,7 +91,8 @@ class DedupeEntityTest extends MigrateProcessTestCase { 'start' => 'foobar', ]; $plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager); - $this->setExpectedException('Drupal\migrate\MigrateException', 'The start position configuration key should be an integer. Omit this key to capture from the beginning of the string.'); + $this->expectException('Drupal\migrate\MigrateException'); + $this->expectExceptionMessage('The start position configuration key should be an integer. Omit this key to capture from the beginning of the string.'); $plugin->transform('test_start', $this->migrateExecutable, $this->row, 'testproperty'); } @@ -105,7 +106,8 @@ class DedupeEntityTest extends MigrateProcessTestCase { 'length' => 'foobar', ]; $plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager); - $this->setExpectedException('Drupal\migrate\MigrateException', 'The character length configuration key should be an integer. Omit this key to capture the entire string.'); + $this->expectException('Drupal\migrate\MigrateException'); + $this->expectExceptionMessage('The character length configuration key should be an integer. Omit this key to capture the entire string.'); $plugin->transform('test_length', $this->migrateExecutable, $this->row, 'testproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php index 466d002c9c74..2d3f0be3206b 100644 --- a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php @@ -56,7 +56,8 @@ class ExplodeTest extends MigrateProcessTestCase { * Test explode fails properly on non-strings. */ public function testExplodeWithNonString() { - $this->setExpectedException(MigrateException::class, 'is not a string'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('is not a string'); $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -93,7 +94,8 @@ class ExplodeTest extends MigrateProcessTestCase { */ public function testExplodeWithNonStrictAndNonCastable() { $plugin = new Explode(['delimiter' => '|', 'strict' => FALSE], 'map', []); - $this->setExpectedException(MigrateException::class, 'cannot be casted to a string'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('cannot be casted to a string'); $processed = $plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); $this->assertSame(['foo'], $processed); } @@ -112,7 +114,8 @@ class ExplodeTest extends MigrateProcessTestCase { * Test explode fails with empty delimiter. */ public function testExplodeWithEmptyDelimiter() { - $this->setExpectedException(MigrateException::class, 'delimiter is empty'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('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 ad0a45a2560a..2af2dc3b7831 100644 --- a/core/modules/migrate/tests/src/Unit/process/ExtractTest.php +++ b/core/modules/migrate/tests/src/Unit/process/ExtractTest.php @@ -32,7 +32,8 @@ class ExtractTest extends MigrateProcessTestCase { * Tests invalid input. */ public function testExtractFromString() { - $this->setExpectedException(MigrateException::class, 'Input should be an array.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Input should be an array.'); $this->plugin->transform('bar', $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -40,7 +41,8 @@ class ExtractTest extends MigrateProcessTestCase { * Tests unsuccessful extraction. */ public function testExtractFail() { - $this->setExpectedException(MigrateException::class, 'Array index missing, extraction failed.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Array index missing, extraction failed.'); $this->plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/FormatDateTest.php b/core/modules/migrate/tests/src/Unit/process/FormatDateTest.php index f931c618a6ee..629243c84cff 100644 --- a/core/modules/migrate/tests/src/Unit/process/FormatDateTest.php +++ b/core/modules/migrate/tests/src/Unit/process/FormatDateTest.php @@ -23,7 +23,8 @@ class FormatDateTest extends MigrateProcessTestCase { 'to_format' => 'Y-m-d', ]; - $this->setExpectedException(MigrateException::class, 'Format date plugin is missing from_format configuration.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Format date plugin is missing from_format configuration.'); $this->plugin = new FormatDate($configuration, 'test_format_date', []); $this->plugin->transform('01/05/1955', $this->migrateExecutable, $this->row, 'field_date'); } @@ -37,7 +38,8 @@ class FormatDateTest extends MigrateProcessTestCase { 'to_format' => '', ]; - $this->setExpectedException(MigrateException::class, 'Format date plugin is missing to_format configuration.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Format date plugin is missing to_format configuration.'); $this->plugin = new FormatDate($configuration, 'test_format_date', []); $this->plugin->transform('01/05/1955', $this->migrateExecutable, $this->row, 'field_date'); } @@ -51,7 +53,8 @@ class FormatDateTest extends MigrateProcessTestCase { 'to_format' => 'Y-m-d', ]; - $this->setExpectedException(MigrateException::class, "Format date plugin could not transform 'January 5, 1955' using the format 'm/d/Y' for destination 'field_date'. Error: The date cannot be created from a format."); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("Format date plugin could not transform 'January 5, 1955' using the format 'm/d/Y' for destination 'field_date'. Error: The date cannot be created from a format."); $this->plugin = new FormatDate($configuration, 'test_format_date', []); $this->plugin->transform('January 5, 1955', $this->migrateExecutable, $this->row, 'field_date'); } @@ -65,7 +68,8 @@ class FormatDateTest extends MigrateProcessTestCase { 'to_format' => 'Y-m-d', ]; - $this->setExpectedException(MigrateException::class, "Format date plugin could not transform '01/05/55' using the format 'm/d/Y' for destination 'field_date'. Error: The created date does not match the input value."); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage("Format date plugin could not transform '01/05/55' using the format 'm/d/Y' for destination 'field_date'. Error: The created date does not match the input value."); $this->plugin = new FormatDate($configuration, 'test_format_date', []); $this->plugin->transform('01/05/55', $this->migrateExecutable, $this->row, 'field_date'); } diff --git a/core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php b/core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php index 25b6a02d5782..4632d96492b0 100644 --- a/core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MakeUniqueEntityFieldTest.php @@ -90,7 +90,8 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase { 'start' => 'foobar', ]; $plugin = new MakeUniqueEntityField($configuration, 'make_unique', [], $this->getMigration(), $this->entityTypeManager); - $this->setExpectedException('Drupal\migrate\MigrateException', 'The start position configuration key should be an integer. Omit this key to capture from the beginning of the string.'); + $this->expectException('Drupal\migrate\MigrateException'); + $this->expectExceptionMessage('The start position configuration key should be an integer. Omit this key to capture from the beginning of the string.'); $plugin->transform('test_start', $this->migrateExecutable, $this->row, 'testproperty'); } @@ -104,7 +105,8 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase { 'length' => 'foobar', ]; $plugin = new MakeUniqueEntityField($configuration, 'make_unique', [], $this->getMigration(), $this->entityTypeManager); - $this->setExpectedException('Drupal\migrate\MigrateException', 'The character length configuration key should be an integer. Omit this key to capture the entire string.'); + $this->expectException('Drupal\migrate\MigrateException'); + $this->expectExceptionMessage('The character length configuration key should be an integer. Omit this key to capture the entire string.'); $plugin->transform('test_length', $this->migrateExecutable, $this->row, 'testproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php index 4e283ef1d4dd..238362a0ad45 100644 --- a/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php @@ -33,7 +33,8 @@ class MenuLinkParentTest extends MigrateProcessTestCase { * @covers ::transform */ public function testTransformException() { - $this->setExpectedException(MigrateSkipRowException::class, "No parent link found for plid '1' in menu 'admin'."); + $this->expectException(MigrateSkipRowException::class); + $this->expectExceptionMessage("No parent link found for plid '1' in menu 'admin'."); $this->plugin->transform([1, 'admin', NULL], $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php index 65073b72b61b..c03687cd5a3f 100644 --- a/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php @@ -105,7 +105,7 @@ class MigrationLookupTest extends MigrateProcessTestCase { $migration_plugin_manager->createInstances(['foobaz']) ->willReturn(['foobaz' => $migration_plugin->reveal()]); $migration = new MigrationLookup($configuration, 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal()); - $this->setExpectedException(MigrateSkipProcessException::class); + $this->expectException(MigrateSkipProcessException::class); $migration->transform($value, $this->migrateExecutable, $this->row, 'foo'); } diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php index cdf34fdd50cb..bf3500575f94 100644 --- a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php @@ -127,7 +127,7 @@ class MigrationTest extends MigrateProcessTestCase { $this->migration_plugin_manager->createInstances(['foobaz']) ->willReturn(['foobaz' => $this->migration_plugin->reveal()]); $migration = new Migration($configuration, 'migration', [], $this->migration_plugin->reveal(), $this->migration_plugin_manager->reveal(), $this->process_plugin_manager->reveal()); - $this->setExpectedException(MigrateSkipProcessException::class); + $this->expectException(MigrateSkipProcessException::class); $migration->transform(FALSE, $this->migrateExecutable, $this->row, 'foo'); } diff --git a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php index d409a88e5338..56e85cd4a211 100644 --- a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php @@ -19,7 +19,7 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { */ public function testProcessSkipsOnEmpty() { $configuration['method'] = 'process'; - $this->setExpectedException(MigrateSkipProcessException::class); + $this->expectException(MigrateSkipProcessException::class); (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -39,7 +39,7 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { */ public function testRowSkipsOnEmpty() { $configuration['method'] = 'row'; - $this->setExpectedException(MigrateSkipRowException::class); + $this->expectException(MigrateSkipRowException::class); (new SkipOnEmpty($configuration, 'skip_on_empty', [])) ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -64,7 +64,7 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { 'method' => 'row', ]; $process = new SkipOnEmpty($configuration, 'skip_on_empty', []); - $this->setExpectedException(MigrateSkipRowException::class); + $this->expectException(MigrateSkipRowException::class); $process->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -79,7 +79,8 @@ class SkipOnEmptyTest extends MigrateProcessTestCase { 'message' => 'The value is empty', ]; $process = new SkipOnEmpty($configuration, 'skip_on_empty', []); - $this->setExpectedException(MigrateSkipRowException::class, 'The value is empty'); + $this->expectException(MigrateSkipRowException::class); + $this->expectExceptionMessage('The value is empty'); $process->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/SkipRowIfNotSetTest.php b/core/modules/migrate/tests/src/Unit/process/SkipRowIfNotSetTest.php index 26e5b3fb4afb..21c8aa0710c2 100644 --- a/core/modules/migrate/tests/src/Unit/process/SkipRowIfNotSetTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SkipRowIfNotSetTest.php @@ -23,7 +23,7 @@ class SkipRowIfNotSetTest extends MigrateProcessTestCase { 'index' => 'some_key', ]; $process = new SkipRowIfNotSet($configuration, 'skip_row_if_not_set', []); - $this->setExpectedException(MigrateSkipRowException::class); + $this->expectException(MigrateSkipRowException::class); $process->transform('', $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -38,7 +38,8 @@ class SkipRowIfNotSetTest extends MigrateProcessTestCase { 'message' => "The 'some_key' key is not set", ]; $process = new SkipRowIfNotSet($configuration, 'skip_row_if_not_set', []); - $this->setExpectedException(MigrateSkipRowException::class, "The 'some_key' key is not set"); + $this->expectException(MigrateSkipRowException::class); + $this->expectExceptionMessage("The 'some_key' key is not set"); $process->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 1a9a61acd68a..cc77c393cd14 100644 --- a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php +++ b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php @@ -43,7 +43,7 @@ class StaticMapTest extends MigrateProcessTestCase { * Tests when the source is empty. */ public function testMapwithEmptySource() { - $this->setExpectedException(MigrateException::class); + $this->expectException(MigrateException::class); $this->plugin->transform([], $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -51,7 +51,8 @@ class StaticMapTest extends MigrateProcessTestCase { * Tests when the source is invalid. */ public function testMapwithInvalidSource() { - $this->setExpectedException(MigrateSkipRowException::class, sprintf("No static mapping found for '%s' and no default value provided for destination '%s'.", Variable::export(['bar']), 'destinationproperty')); + $this->expectException(MigrateSkipRowException::class); + $this->expectExceptionMessage(sprintf("No static mapping found for '%s' and no default value provided for destination '%s'.", Variable::export(['bar']), 'destinationproperty')); $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -85,7 +86,8 @@ class StaticMapTest extends MigrateProcessTestCase { $configuration['default_value'] = 'test'; $configuration['bypass'] = TRUE; $this->plugin = new StaticMap($configuration, 'map', []); - $this->setExpectedException(MigrateException::class, 'Setting both default_value and bypass is invalid.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('Setting both default_value and bypass is invalid.'); $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php index 6a73905d1470..54ef1c2b21c9 100644 --- a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php @@ -60,7 +60,8 @@ class SubstrTest extends MigrateProcessTestCase { public function testSubstrFail() { $configuration = []; $this->plugin = new Substr($configuration, 'map', []); - $this->setExpectedException(MigrateException::class, 'The input value must be a string.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The input value must be a string.'); $this->plugin->transform(['Captain Janeway'], $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -70,7 +71,8 @@ class SubstrTest extends MigrateProcessTestCase { public function testStartIsString() { $configuration['start'] = '2'; $this->plugin = new Substr($configuration, 'map', []); - $this->setExpectedException(MigrateException::class, 'The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.'); $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } @@ -80,7 +82,8 @@ class SubstrTest extends MigrateProcessTestCase { public function testLengthIsString() { $configuration['length'] = '1'; $this->plugin = new Substr($configuration, 'map', []); - $this->setExpectedException(MigrateException::class, 'The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.'); + $this->expectException(MigrateException::class); + $this->expectExceptionMessage('The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.'); $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } diff --git a/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php b/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php index bd03eea3d010..5ea0b96de56d 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php @@ -72,7 +72,8 @@ class MigrateFieldPluginManagerTest extends MigrateDrupalTestBase { * @dataProvider nonExistentPluginExceptionsData */ public function testNonExistentPluginExceptions($core, $field_type) { - $this->setExpectedException(PluginNotFoundException::class, sprintf("Plugin ID '%s' was not found.", $field_type)); + $this->expectException(PluginNotFoundException::class); + $this->expectExceptionMessage(sprintf("Plugin ID '%s' was not found.", $field_type)); $this->pluginManager->getPluginIdFromFieldType($field_type, ['core' => $core]); } diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php index cf5d3da4f89f..84bb7cae3b09 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php @@ -188,7 +188,8 @@ class ContentEntityTest extends KernelTestBase { $plugin_definition = [ 'entity_type' => '', ]; - $this->setExpectedException(InvalidPluginDefinitionException::class, 'Missing required "entity_type" definition.'); + $this->expectException(InvalidPluginDefinitionException::class); + $this->expectExceptionMessage('Missing required "entity_type" definition.'); ContentEntity::create($this->container, $configuration, 'content_entity', $plugin_definition, $migration); } @@ -201,7 +202,8 @@ class ContentEntityTest extends KernelTestBase { $plugin_definition = [ 'entity_type' => 'node_type', ]; - $this->setExpectedException(InvalidPluginDefinitionException::class, 'The entity type (node_type) is not supported. The "content_entity" source plugin only supports content entities.'); + $this->expectException(InvalidPluginDefinitionException::class); + $this->expectExceptionMessage('The entity type (node_type) is not supported. The "content_entity" source plugin only supports content entities.'); ContentEntity::create($this->container, $configuration, 'content_entity:node_type', $plugin_definition, $migration); } @@ -216,7 +218,8 @@ class ContentEntityTest extends KernelTestBase { $plugin_definition = [ 'entity_type' => 'user', ]; - $this->setExpectedException(\InvalidArgumentException::class, 'A bundle was provided but the entity type (user) is not bundleable'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('A bundle was provided but the entity type (user) is not bundleable'); ContentEntity::create($this->container, $configuration, 'content_entity:user', $plugin_definition, $migration); } @@ -231,7 +234,8 @@ class ContentEntityTest extends KernelTestBase { $plugin_definition = [ 'entity_type' => 'node', ]; - $this->setExpectedException(\InvalidArgumentException::class, 'The provided bundle (foo) is not valid for the (node) entity type.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The provided bundle (foo) is not valid for the (node) entity type.'); ContentEntity::create($this->container, $configuration, 'content_entity:node', $plugin_definition, $migration); } diff --git a/core/modules/migrate_drupal/tests/src/Unit/FieldDiscoveryTest.php b/core/modules/migrate_drupal/tests/src/Unit/FieldDiscoveryTest.php index 852d4fa31961..813c8b78f8ef 100644 --- a/core/modules/migrate_drupal/tests/src/Unit/FieldDiscoveryTest.php +++ b/core/modules/migrate_drupal/tests/src/Unit/FieldDiscoveryTest.php @@ -228,7 +228,7 @@ class FieldDiscoveryTest extends UnitTestCase { $migration->getMigrationTags()->willReturn($tags); $field_discovery = new FieldDiscoveryTestClass($this->fieldPluginManager->reveal(), $this->migrationPluginManager->reveal(), $this->logger->reveal()); if (!$expected_result) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); } $actual_result = $field_discovery->getCoreVersion($migration->reveal()); $this->assertEquals($expected_result, $actual_result); @@ -316,7 +316,8 @@ class FieldDiscoveryTest extends UnitTestCase { public function testGetFieldInstanceStubMigrationDefinition($core, $expected_definition) { $field_discovery = new FieldDiscoveryTestClass($this->fieldPluginManager->reveal(), $this->migrationPluginManager->reveal(), $this->logger->reveal()); if (!$expected_definition) { - $this->setExpectedException(\InvalidArgumentException::class, sprintf("Drupal version %s is not supported. Valid values for Drupal core version are '6' and '7'.", $core)); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage(sprintf("Drupal version %s is not supported. Valid values for Drupal core version are '6' and '7'.", $core)); } $actual_definition = $field_discovery->getFieldInstanceStubMigrationDefinition($core); $this->assertSame($expected_definition, $actual_definition); diff --git a/core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php b/core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php index e8a5224b058d..dd8d6aca9a71 100644 --- a/core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php +++ b/core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php @@ -35,7 +35,8 @@ class MigrateFieldPluginManagerTest extends UnitTestCase { $discovery->getDefinitions()->willReturn($this->pluginFixtureData()); $manager = new MigrateFieldPluginManagerTestClass('field', new \ArrayObject(), $cache, $module_handler, MigrateField::class, $discovery->reveal()); if (!$expected_plugin_id) { - $this->setExpectedException(PluginNotFoundException::class, sprintf("Plugin ID '%s' was not found.", $field_type)); + $this->expectException(PluginNotFoundException::class); + $this->expectExceptionMessage(sprintf("Plugin ID '%s' was not found.", $field_type)); } $actual_plugin_id = $manager->getPluginIdFromFieldType($field_type, ['core' => $core]); $this->assertSame($expected_plugin_id, $actual_plugin_id); diff --git a/core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php b/core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php index b9d9dc41baab..9f7662c7f0b1 100644 --- a/core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php +++ b/core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php @@ -51,7 +51,8 @@ class DrupalSqlBaseTest extends MigrateTestCase { $plugin = new TestDrupalSqlBase([], 'placeholder_id', $plugin_definition, $this->getMigration(), $state, $entity_type_manager); $plugin->setDatabase($this->getDatabase($this->databaseContents)); $system_data = $plugin->getSystemData(); - $this->setExpectedException(RequirementsException::class, 'The module module1 is not enabled in the source site.'); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage('The module module1 is not enabled in the source site.'); try { $plugin->checkRequirements(); } @@ -75,7 +76,8 @@ class DrupalSqlBaseTest extends MigrateTestCase { $entity_manager = $this->createMock('Drupal\Core\Entity\EntityTypeManagerInterface'); $plugin = new TestDrupalSqlBase([], 'test', $plugin_definition, $this->getMigration(), $state, $entity_manager); $system_data = $plugin->getSystemData(); - $this->setExpectedException(RequirementsException::class, 'No database connection configured for source plugin test'); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage('No database connection configured for source plugin test'); $plugin->checkRequirements(); } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php b/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php index 54bf816c29a8..9313a159b5e9 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php @@ -35,7 +35,7 @@ trait FormatSpecificGetBcRouteTestTrait { * @see \Drupal\rest\Plugin\ResourceBase::routes */ public function testNoFormatSpecificGetBcRouteForOtherFormats() { - $this->setExpectedException(RouteNotFoundException::class); + $this->expectException(RouteNotFoundException::class); $this->provisionEntityResource(); $url = $this->getEntityResourceUrl(); diff --git a/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php b/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php index 8c9758e8a0ac..800bbaba47bc 100644 --- a/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php +++ b/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php @@ -64,7 +64,7 @@ class EntityResourceValidationTraitTest extends UnitTestCase { $method = new \ReflectionMethod($trait, 'validate'); $method->setAccessible(TRUE); - $this->setExpectedException(UnprocessableEntityHttpException::class); + $this->expectException(UnprocessableEntityHttpException::class); $method->invoke($trait, $entity->reveal()); } diff --git a/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php b/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php index 5cd9fa8f7d2a..fd5702e3ec2e 100644 --- a/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php +++ b/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php @@ -265,7 +265,8 @@ class EntitySerializationTest extends NormalizerTestBase { * Tests denormalizing serialized columns. */ public function testDenormalizeSerializedItem() { - $this->setExpectedException(\LogicException::class, 'The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized" field (field item class: Drupal\entity_test\Plugin\Field\FieldType\SerializedItem).'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized" field (field item class: Drupal\entity_test\Plugin\Field\FieldType\SerializedItem).'); $this->serializer->denormalize([ 'serialized' => [ [ @@ -283,7 +284,8 @@ class EntitySerializationTest extends NormalizerTestBase { $entity = EntitySerializedField::create(['serialized_text' => serialize(['Hello world!'])]); $normalized = $this->serializer->normalize($entity); $this->assertEquals($normalized['serialized_text'][0]['value'], ['Hello world!']); - $this->setExpectedException(\LogicException::class, 'The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_text" field (field item class: Drupal\entity_test\Plugin\Field\FieldType\SerializedPropertyItem).'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_text" field (field item class: Drupal\entity_test\Plugin\Field\FieldType\SerializedPropertyItem).'); $this->serializer->denormalize([ 'serialized_text' => [ [ @@ -301,7 +303,8 @@ class EntitySerializationTest extends NormalizerTestBase { $entity = EntitySerializedField::create(['serialized_long' => serialize(['Hello world!'])]); $normalized = $this->serializer->normalize($entity); $this->assertEquals($normalized['serialized_long'][0]['value'], ['Hello world!']); - $this->setExpectedException(\LogicException::class, 'The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_long" field (field item class: Drupal\Core\Field\Plugin\Field\FieldType\StringLongItem).'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_long" field (field item class: Drupal\Core\Field\Plugin\Field\FieldType\StringLongItem).'); $this->serializer->denormalize([ 'serialized_long' => [ [ @@ -342,7 +345,8 @@ class EntitySerializationTest extends NormalizerTestBase { * Tests normalizing/denormalizing using string values. */ public function testDenormalizeStringValue() { - $this->setExpectedException(\LogicException::class, 'The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_long" field (field item class: Drupal\Core\Field\Plugin\Field\FieldType\StringLongItem).'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_long" field (field item class: Drupal\Core\Field\Plugin\Field\FieldType\StringLongItem).'); $this->serializer->denormalize([ 'serialized_long' => ['boo'], 'type' => 'entity_test_serialized_field', diff --git a/core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php b/core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php index 9b9888d78bab..0933bb442888 100644 --- a/core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php +++ b/core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php @@ -138,7 +138,8 @@ class FieldItemSerializationTest extends NormalizerTestBase { * Tests denormalizing using a scalar field value. */ public function testFieldDenormalizeWithScalarValue() { - $this->setExpectedException(UnexpectedValueException::class, 'Field values for "uuid" must use an array structure'); + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Field values for "uuid" must use an array structure'); $normalized = $this->serializer->normalize($this->entity, 'json'); diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php index 188d0b54cd64..bcb6a349075f 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php @@ -231,7 +231,8 @@ class DateTimeIso8601NormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeDateOnlyException() { - $this->setExpectedException(UnexpectedValueException::class, 'The specified date "2016/11/06" is not in an accepted format: "Y-m-d" (date-only).'); + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('The specified date "2016/11/06" is not in an accepted format: "Y-m-d" (date-only).'); $normalized = '2016/11/06'; @@ -246,7 +247,8 @@ class DateTimeIso8601NormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeDateAndTimeException() { - $this->setExpectedException(UnexpectedValueException::class, 'The specified date "on a rainy day" is not in an accepted format: "Y-m-d\TH:i:sP" (RFC 3339), "Y-m-d\TH:i:sO" (ISO 8601), "Y-m-d\TH:i:s" (backward compatibility — deprecated).'); + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('The specified date "on a rainy day" is not in an accepted format: "Y-m-d\TH:i:sP" (RFC 3339), "Y-m-d\TH:i:sO" (ISO 8601), "Y-m-d\TH:i:s" (backward compatibility — deprecated).'); $normalized = 'on a rainy day'; @@ -261,7 +263,8 @@ class DateTimeIso8601NormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeNoTargetInstanceOrFieldDefinitionException() { - $this->setExpectedException(InvalidArgumentException::class, '$context[\'target_instance\'] or $context[\'field_definition\'] must be set to denormalize with the DateTimeIso8601Normalizer'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('$context[\'target_instance\'] or $context[\'field_definition\'] must be set to denormalize with the DateTimeIso8601Normalizer'); $this->normalizer->denormalize('', DateTimeIso8601::class, NULL, []); } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php index 8914186e244c..e6b6c788e8f9 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php @@ -166,7 +166,8 @@ class DateTimeNormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeException() { - $this->setExpectedException(UnexpectedValueException::class, 'The specified date "2016/11/06 09:02am GMT" is not in an accepted format: "Y-m-d\TH:i:sP" (RFC 3339), "Y-m-d\TH:i:sO" (ISO 8601).'); + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('The specified date "2016/11/06 09:02am GMT" is not in an accepted format: "Y-m-d\TH:i:sP" (RFC 3339), "Y-m-d\TH:i:sO" (ISO 8601).'); $normalized = '2016/11/06 09:02am GMT'; diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php index 5ed08662d073..98bc162f60be 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php @@ -111,7 +111,7 @@ class EntityNormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeWithNoEntityType() { - $this->setExpectedException(UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->entityNormalizer->denormalize([], 'Drupal\Core\Entity\ContentEntityBase'); } @@ -310,7 +310,7 @@ class EntityNormalizerTest extends UnitTestCase { ->with('test_bundle') ->will($this->returnValue($entity_type_storage)); - $this->setExpectedException(UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->entityNormalizer->denormalize($test_data, 'Drupal\Core\Entity\ContentEntityBase', NULL, ['entity_type' => 'test']); } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php index 581f43181d59..04a9c5cbf27c 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php @@ -349,7 +349,8 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeWithUuidWithIncorrectType() { - $this->setExpectedException(UnexpectedValueException::class, 'The field "field_reference" property "target_type" must be set to "test_type" or omitted.'); + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('The field "field_reference" property "target_type" must be set to "test_type" or omitted.'); $data = [ 'target_id' => 'test', @@ -369,7 +370,8 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeWithTypeWithIncorrectUuid() { - $this->setExpectedException(InvalidArgumentException::class, 'No "test_type" entity found with UUID "unique-but-none-non-existent" for field "field_reference"'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('No "test_type" entity found with UUID "unique-but-none-non-existent" for field "field_reference"'); $data = [ 'target_id' => 'test', @@ -392,7 +394,8 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeWithEmtpyUuid() { - $this->setExpectedException(InvalidArgumentException::class, 'If provided "target_uuid" cannot be empty for field "test_type".'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('If provided "target_uuid" cannot be empty for field "test_type".'); $data = [ 'target_id' => 'test', diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php index e7ddb8656ac6..81c456d674d0 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php @@ -122,7 +122,8 @@ class TimestampNormalizerTest extends UnitTestCase { * @covers ::denormalize */ public function testDenormalizeException() { - $this->setExpectedException(UnexpectedValueException::class, 'The specified date "2016/11/06 09:02am GMT" is not in an accepted format: "U" (UNIX timestamp), "Y-m-d\TH:i:sO" (ISO 8601), "Y-m-d\TH:i:sP" (RFC 3339).'); + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('The specified date "2016/11/06 09:02am GMT" is not in an accepted format: "U" (UNIX timestamp), "Y-m-d\TH:i:sO" (ISO 8601), "Y-m-d\TH:i:sP" (RFC 3339).'); $normalized = '2016/11/06 09:02am GMT'; diff --git a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php b/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php index fa3a93bf633e..7bf10a0664e9 100644 --- a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php +++ b/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php @@ -279,7 +279,8 @@ class TestDiscoveryTest extends UnitTestCase { * Bulk delete storages and fields, and clean up afterwards. */ EOT; - $this->setExpectedException(MissingGroupException::class, 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest'); + $this->expectException(MissingGroupException::class); + $this->expectExceptionMessage('Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest'); TestDiscovery::getTestInfo($classname, $doc_comment); } @@ -530,7 +531,7 @@ EOF; // We want to make sure it didn't do that, because we already did some // analysis and already have an empty docblock. getTestInfo() will throw // MissingGroupException because the annotation is empty. - $this->setExpectedException(MissingGroupException::class); + $this->expectException(MissingGroupException::class); TestDiscovery::getTestInfo('Drupal\Tests\simpletest\ThisTestDoesNotExistTest', ''); } diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php index e68d0939fc32..ffaf56bdb338 100644 --- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php @@ -222,7 +222,8 @@ class ModuleHandlerTest extends KernelTestBase { $this->assertNotContains($profile, $uninstalled_modules, 'The installation profile is not in the list of uninstalled modules.'); // Try uninstalling the required module. - $this->setExpectedException(ModuleUninstallValidatorException::class, 'The following reasons prevent the modules from being uninstalled: The Testing install profile dependencies module is required'); + $this->expectException(ModuleUninstallValidatorException::class); + $this->expectExceptionMessage('The following reasons prevent the modules from being uninstalled: The Testing install profile dependencies module is required'); $this->moduleInstaller()->uninstall([$dependency]); } @@ -253,7 +254,8 @@ class ModuleHandlerTest extends KernelTestBase { } // Try uninstalling the dependencies. - $this->setExpectedException(ModuleUninstallValidatorException::class, 'The following reasons prevent the modules from being uninstalled: The Testing install profile all dependencies module is required'); + $this->expectException(ModuleUninstallValidatorException::class); + $this->expectExceptionMessage('The following reasons prevent the modules from being uninstalled: The Testing install profile all dependencies module is required'); $this->moduleInstaller()->uninstall($dependencies); } diff --git a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php index 3bee38d1abf2..33a58492b3c3 100644 --- a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php +++ b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php @@ -50,7 +50,7 @@ class DbCommandBaseTest extends KernelTestBase { $command_tester->execute([ '--database' => 'dne', ]); - $this->setExpectedException(ConnectionNotDefinedException::class); + $this->expectException(ConnectionNotDefinedException::class); $command->getDatabaseConnection($command_tester->getInput()); } diff --git a/core/modules/system/tests/src/Unit/Transliteration/MachineNameControllerTest.php b/core/modules/system/tests/src/Unit/Transliteration/MachineNameControllerTest.php index 689c1782abea..3ee793984615 100644 --- a/core/modules/system/tests/src/Unit/Transliteration/MachineNameControllerTest.php +++ b/core/modules/system/tests/src/Unit/Transliteration/MachineNameControllerTest.php @@ -103,7 +103,8 @@ class MachineNameControllerTest extends UnitTestCase { public function testMachineNameControllerWithInvalidReplacePattern() { $request = Request::create('', 'GET', ['text' => 'Bob', 'langcode' => 'en', 'replace' => 'Alice', 'replace_pattern' => 'Bob', 'replace_token' => 'invalid']); - $this->setExpectedException(AccessDeniedHttpException::class, "Invalid 'replace_token' query parameter."); + $this->expectException(AccessDeniedHttpException::class); + $this->expectExceptionMessage("Invalid 'replace_token' query parameter."); $this->machineNameController->transliterate($request); } @@ -113,7 +114,8 @@ class MachineNameControllerTest extends UnitTestCase { public function testMachineNameControllerWithMissingToken() { $request = Request::create('', 'GET', ['text' => 'Bob', 'langcode' => 'en', 'replace' => 'Alice', 'replace_pattern' => 'Bob']); - $this->setExpectedException(AccessDeniedHttpException::class, "Missing 'replace_token' query parameter."); + $this->expectException(AccessDeniedHttpException::class); + $this->expectExceptionMessage("Missing 'replace_token' query parameter."); $this->machineNameController->transliterate($request); } diff --git a/core/modules/user/tests/src/Kernel/Migrate/d6/ProfileFieldCheckRequirementsTest.php b/core/modules/user/tests/src/Kernel/Migrate/d6/ProfileFieldCheckRequirementsTest.php index ffa19a5386e7..7fa4eceaab3c 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d6/ProfileFieldCheckRequirementsTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d6/ProfileFieldCheckRequirementsTest.php @@ -24,7 +24,8 @@ class ProfileFieldCheckRequirementsTest extends MigrateDrupal6TestBase { * Tests exception in thrown when profile_fields tables does not exist. */ public function testCheckRequirements() { - $this->setExpectedException(RequirementsException::class, 'Profile module not enabled on source site'); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage('Profile module not enabled on source site'); $this->getMigration('user_profile_field') ->getSourcePlugin() ->checkRequirements(); diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/ProfileFieldCheckRequirementsTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/ProfileFieldCheckRequirementsTest.php index fb2d82a000ea..85d163948bc7 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d7/ProfileFieldCheckRequirementsTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d7/ProfileFieldCheckRequirementsTest.php @@ -24,7 +24,8 @@ class ProfileFieldCheckRequirementsTest extends MigrateDrupal7TestBase { * Tests exception in thrown when profile_fields tables does not exist. */ public function testCheckRequirements() { - $this->setExpectedException(RequirementsException::class, 'Profile module not enabled on source site'); + $this->expectException(RequirementsException::class); + $this->expectExceptionMessage('Profile module not enabled on source site'); $this->getMigration('user_profile_field') ->getSourcePlugin() ->checkRequirements(); diff --git a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php index 99863f758665..a721386abb5d 100644 --- a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php @@ -143,7 +143,7 @@ class PrivateTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); + $this->expectException(TempStoreException::class); $this->tempStore->set('test', 'value'); } @@ -250,7 +250,7 @@ class PrivateTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); + $this->expectException(TempStoreException::class); $this->tempStore->delete('test'); } diff --git a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php index 1dcf41be1bff..6a8bbc418def 100644 --- a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php +++ b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php @@ -156,7 +156,7 @@ class SharedTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); + $this->expectException(TempStoreException::class); $this->tempStore->set('test', 'value'); } @@ -328,7 +328,7 @@ class SharedTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); + $this->expectException(TempStoreException::class); $this->tempStore->delete('test'); } diff --git a/core/modules/user/tests/src/Unit/UserRegistrationResourceTest.php b/core/modules/user/tests/src/Unit/UserRegistrationResourceTest.php index 95b756038c7f..65e62de5d78d 100644 --- a/core/modules/user/tests/src/Unit/UserRegistrationResourceTest.php +++ b/core/modules/user/tests/src/Unit/UserRegistrationResourceTest.php @@ -77,7 +77,7 @@ class UserRegistrationResourceTest extends UnitTestCase { * Tests that an exception is thrown when no data provided for the account. */ public function testEmptyPost() { - $this->setExpectedException(BadRequestHttpException::class); + $this->expectException(BadRequestHttpException::class); $this->testClass->post(NULL); } @@ -87,7 +87,7 @@ class UserRegistrationResourceTest extends UnitTestCase { public function testExistedEntityPost() { $entity = $this->prophesize(User::class); $entity->isNew()->willReturn(FALSE); - $this->setExpectedException(BadRequestHttpException::class); + $this->expectException(BadRequestHttpException::class); $this->testClass->post($entity->reveal()); } @@ -106,7 +106,7 @@ class UserRegistrationResourceTest extends UnitTestCase { $entity = $this->prophesize(User::class); $entity->isNew()->willReturn(TRUE); - $this->setExpectedException(AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $this->testClass->post($entity->reveal()); } @@ -122,7 +122,7 @@ class UserRegistrationResourceTest extends UnitTestCase { $entity = $this->prophesize(User::class); $entity->isNew()->willReturn(TRUE); - $this->setExpectedException(AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $this->testClass->post($entity->reveal()); } diff --git a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php index e7baf867b23e..25c0079ade72 100644 --- a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php +++ b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php @@ -121,7 +121,7 @@ class ViewAjaxControllerTest extends UnitTestCase { */ public function testMissingViewName() { $request = new Request(); - $this->setExpectedException(NotFoundHttpException::class); + $this->expectException(NotFoundHttpException::class); $this->viewAjaxController->ajaxView($request); } @@ -138,7 +138,7 @@ class ViewAjaxControllerTest extends UnitTestCase { ->with('test_view') ->will($this->returnValue(FALSE)); - $this->setExpectedException(NotFoundHttpException::class); + $this->expectException(NotFoundHttpException::class); $this->viewAjaxController->ajaxView($request); } @@ -171,7 +171,7 @@ class ViewAjaxControllerTest extends UnitTestCase { ->with($view) ->will($this->returnValue($executable)); - $this->setExpectedException(AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $this->viewAjaxController->ajaxView($request); } @@ -215,7 +215,7 @@ class ViewAjaxControllerTest extends UnitTestCase { $this->setupValidMocks(static::USE_NO_AJAX); - $this->setExpectedException(AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $this->viewAjaxController->ajaxView($request); } 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 f00918395607..89b1cf2c836b 100644 --- a/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php @@ -32,7 +32,7 @@ class PageTest extends UnitTestCase { * @covers ::buildBasicRenderable */ public function testBuildBasicRenderableWithMissingRoute() { - $this->setExpectedException(\BadFunctionCallException::class); + $this->expectException(\BadFunctionCallException::class); 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 28f580772fad..a1e3b865b327 100644 --- a/core/modules/views/tests/src/Unit/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Unit/ViewExecutableTest.php @@ -191,7 +191,7 @@ class ViewExecutableTest extends UnitTestCase { ->willReturn($this->displayHandler); $this->executable->display_handler = $this->displayHandler; - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->executable->getUrl(); } diff --git a/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php b/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php index 8d4edc901244..0a44e3d9bf40 100644 --- a/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php +++ b/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php @@ -49,7 +49,8 @@ class RequiredStatesTest extends KernelTestBase { ], 'workflow'); $workflow->save(); // Ensure that required states can't be deleted. - $this->setExpectedException(RequiredStateMissingException::class, "Required State Type Test' requires states with the ID 'fresh' in workflow 'test'"); + $this->expectException(RequiredStateMissingException::class); + $this->expectExceptionMessage("Required State Type Test' requires states with the ID 'fresh' in workflow 'test'"); $workflow->getTypePlugin()->deleteState('fresh'); $workflow->save(); } @@ -65,7 +66,8 @@ class RequiredStatesTest extends KernelTestBase { 'states' => [], ], ], 'workflow'); - $this->setExpectedException(RequiredStateMissingException::class, "Required State Type Test' requires states with the ID 'fresh', 'rotten' in workflow 'test'"); + $this->expectException(RequiredStateMissingException::class); + $this->expectExceptionMessage("Required State Type Test' requires states with the ID 'fresh', 'rotten' in workflow 'test'"); $workflow->save(); } diff --git a/core/modules/workflows/tests/src/Unit/StateTest.php b/core/modules/workflows/tests/src/Unit/StateTest.php index 92edbb9f334b..2790a8051a50 100644 --- a/core/modules/workflows/tests/src/Unit/StateTest.php +++ b/core/modules/workflows/tests/src/Unit/StateTest.php @@ -67,7 +67,8 @@ class StateTest extends UnitTestCase { * @covers ::getTransitionTo */ public function testGetTransitionToException() { - $this->setExpectedException(\InvalidArgumentException::class, "Can not transition to 'published' state"); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Can not transition to 'published' state"); $workflow_type = new TestType([], '', []); $workflow_type->addState('draft', 'Draft'); $state = $workflow_type->getState('draft'); diff --git a/core/modules/workflows/tests/src/Unit/WorkflowStateTransitionOperationsAccessCheckTest.php b/core/modules/workflows/tests/src/Unit/WorkflowStateTransitionOperationsAccessCheckTest.php index c8f5d5e7097d..d99390e26472 100644 --- a/core/modules/workflows/tests/src/Unit/WorkflowStateTransitionOperationsAccessCheckTest.php +++ b/core/modules/workflows/tests/src/Unit/WorkflowStateTransitionOperationsAccessCheckTest.php @@ -126,7 +126,8 @@ class WorkflowStateTransitionOperationsAccessCheckTest extends UnitTestCase { * @dataProvider invalidOperationNameTestCases */ public function testInvalidOperationName($operation_name) { - $this->setExpectedException(\Exception::class, "Invalid _workflow_access operation '$operation_name' specified for route 'Foo Route'."); + $this->expectException(\Exception::class); + $this->expectExceptionMessage("Invalid _workflow_access operation '$operation_name' specified for route 'Foo Route'."); $route = new Route('', [], [ '_workflow_access' => $operation_name, ]); diff --git a/core/modules/workflows/tests/src/Unit/WorkflowTest.php b/core/modules/workflows/tests/src/Unit/WorkflowTest.php index c10ddf95a94d..8da8e5fd19c9 100644 --- a/core/modules/workflows/tests/src/Unit/WorkflowTest.php +++ b/core/modules/workflows/tests/src/Unit/WorkflowTest.php @@ -58,7 +58,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::addState */ public function testAddStateException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'draft' already exists in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'draft' already exists in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('draft', 'Draft'); $workflow->getTypePlugin()->addState('draft', 'Draft'); @@ -68,7 +69,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::addState */ public function testAddStateInvalidIdException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state ID 'draft-draft' must contain only lowercase letters, numbers, and underscores"); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state ID 'draft-draft' must contain only lowercase letters, numbers, and underscores"); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('draft-draft', 'Draft'); } @@ -142,7 +144,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::getStates */ public function testGetStatesException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'state_that_does_not_exist' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'state_that_does_not_exist' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->getStates(['state_that_does_not_exist']); } @@ -180,7 +183,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::getState */ public function testGetStateException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'state_that_does_not_exist' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'state_that_does_not_exist' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->getState('state_that_does_not_exist'); } @@ -200,7 +204,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setStateLabel */ public function testSetStateLabelException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'draft' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'draft' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->setStateLabel('draft', 'Draft'); } @@ -220,7 +225,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setStateWeight */ public function testSetStateWeightException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'draft' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'draft' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->setStateWeight('draft', 10); } @@ -229,7 +235,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setStateWeight */ public function testSetStateWeightNonNumericException() { - $this->setExpectedException(\InvalidArgumentException::class, "The weight 'foo' must be numeric for state 'Published'."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The weight 'foo' must be numeric for state 'Published'."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->setStateWeight('published', 'foo'); @@ -261,7 +268,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::deleteState */ public function testDeleteStateException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'draft' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'draft' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->deleteState('draft'); } @@ -270,7 +278,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::deleteState */ public function testDeleteOnlyStateException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'draft' can not be deleted from workflow as it is the only state"); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'draft' can not be deleted from workflow as it is the only state"); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('draft', 'Draft'); $workflow->getTypePlugin()->deleteState('draft'); @@ -304,7 +313,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::addTransition */ public function testAddTransitionDuplicateException() { - $this->setExpectedException(\InvalidArgumentException::class, "The transition 'publish' already exists in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The transition 'publish' already exists in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->addTransition('publish', 'Publish', ['published'], 'published'); @@ -315,7 +325,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::addTransition */ public function testAddTransitionInvalidIdException() { - $this->setExpectedException(\InvalidArgumentException::class, "The transition ID 'publish-publish' must contain only lowercase letters, numbers, and underscores"); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The transition ID 'publish-publish' must contain only lowercase letters, numbers, and underscores"); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->addTransition('publish-publish', 'Publish', ['published'], 'published'); @@ -325,7 +336,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::addTransition */ public function testAddTransitionMissingFromException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'draft' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'draft' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->addTransition('publish', 'Publish', ['draft'], 'published'); @@ -335,7 +347,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::addTransition */ public function testAddTransitionDuplicateTransitionStatesException() { - $this->setExpectedException(\InvalidArgumentException::class, "The 'publish' transition already allows 'draft' to 'published' transitions in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The 'publish' transition already allows 'draft' to 'published' transitions in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow ->getTypePlugin() @@ -366,7 +379,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::addTransition */ public function testAddTransitionMissingToException() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'published' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'published' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('draft', 'Draft'); $workflow->getTypePlugin()->addTransition('publish', 'Publish', ['draft'], 'published'); @@ -445,7 +459,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::getTransition */ public function testGetTransitionException() { - $this->setExpectedException(\InvalidArgumentException::class, "The transition 'transition_that_does_not_exist' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The transition 'transition_that_does_not_exist' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->getTransition('transition_that_does_not_exist'); } @@ -499,7 +514,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::getTransitionFromStateToState */ public function testGetTransitionFromStateToStateException() { - $this->setExpectedException(\InvalidArgumentException::class, "The transition from 'archived' to 'archived' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The transition from 'archived' to 'archived' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); // By default states are ordered in the order added. $workflow @@ -533,7 +549,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setTransitionLabel */ public function testSetTransitionLabelException() { - $this->setExpectedException(\InvalidArgumentException::class, "The transition 'draft-published' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The transition 'draft-published' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->setTransitionLabel('draft-published', 'Publish'); @@ -558,7 +575,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setTransitionWeight */ public function testSetTransitionWeightException() { - $this->setExpectedException(\InvalidArgumentException::class, "The transition 'draft-published' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The transition 'draft-published' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->setTransitionWeight('draft-published', 10); @@ -568,7 +586,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setTransitionWeight */ public function testSetTransitionWeightNonNumericException() { - $this->setExpectedException(\InvalidArgumentException::class, "The weight 'foo' must be numeric for transition 'Publish'."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The weight 'foo' must be numeric for transition 'Publish'."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->addTransition('publish', 'Publish', [], 'published'); @@ -604,7 +623,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setTransitionFromStates */ public function testSetTransitionFromStatesMissingTransition() { - $this->setExpectedException(\InvalidArgumentException::class, "The transition 'test' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The transition 'test' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow ->getTypePlugin() @@ -620,7 +640,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setTransitionFromStates */ public function testSetTransitionFromStatesMissingState() { - $this->setExpectedException(\InvalidArgumentException::class, "The state 'published' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The state 'published' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow ->getTypePlugin() @@ -635,7 +656,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::setTransitionFromStates */ public function testSetTransitionFromStatesAlreadyExists() { - $this->setExpectedException(\InvalidArgumentException::class, "The 'create_new_draft' transition already allows 'draft' to 'draft' transitions in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The 'create_new_draft' transition already allows 'draft' to 'draft' transitions in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow ->getTypePlugin() @@ -668,7 +690,8 @@ class WorkflowTest extends UnitTestCase { * @covers ::deleteTransition */ public function testDeleteTransitionException() { - $this->setExpectedException(\InvalidArgumentException::class, "The transition 'draft-published' does not exist in workflow."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The transition 'draft-published' does not exist in workflow."); $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); $workflow->getTypePlugin()->addState('published', 'Published'); $workflow->getTypePlugin()->deleteTransition('draft-published'); diff --git a/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php b/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php index c58b6642e63c..d50cf327fc24 100644 --- a/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php +++ b/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php @@ -476,18 +476,21 @@ class WorkspaceIntegrationTest extends KernelTestBase { // Check updating an existing entity. $entity_test->name->value = 'stage entity_test_mulrev'; $entity_test->setNewRevision(TRUE); - $this->setExpectedException(EntityStorageException::class, 'This entity can only be saved in the default workspace.'); + $this->expectException(EntityStorageException::class); + $this->expectExceptionMessage('This entity can only be saved in the default workspace.'); $entity_test->save(); // Check saving a new entity. $new_entity_test = EntityTestMulRev::create([ 'name' => 'stage entity_test_mulrev', ]); - $this->setExpectedException(EntityStorageException::class, 'This entity can only be saved in the default workspace.'); + $this->expectException(EntityStorageException::class); + $this->expectExceptionMessage('This entity can only be saved in the default workspace.'); $new_entity_test->save(); // Check deleting an existing entity. - $this->setExpectedException(EntityStorageException::class, 'This entity can only be deleted in the default workspace.'); + $this->expectException(EntityStorageException::class); + $this->expectExceptionMessage('This entity can only be deleted in the default workspace.'); $entity_test->delete(); } diff --git a/core/modules/workspaces/tests/src/Kernel/WorkspaceInternalResourceTest.php b/core/modules/workspaces/tests/src/Kernel/WorkspaceInternalResourceTest.php index 2c7758b962c9..06201ce7446d 100644 --- a/core/modules/workspaces/tests/src/Kernel/WorkspaceInternalResourceTest.php +++ b/core/modules/workspaces/tests/src/Kernel/WorkspaceInternalResourceTest.php @@ -25,7 +25,8 @@ class WorkspaceInternalResourceTest extends KernelTestBase { * @see \Drupal\workspaces\Entity\WorkspaceAssociation */ public function testCreateWorkspaceAssociationResource() { - $this->setExpectedException(PluginNotFoundException::class, 'The "entity:workspace_association" plugin does not exist.'); + $this->expectException(PluginNotFoundException::class); + $this->expectExceptionMessage('The "entity:workspace_association" plugin does not exist.'); RestResourceConfig::create([ 'id' => 'entity.workspace_association', 'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY, diff --git a/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php b/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php index 98a3b9726228..8d096c14c067 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php @@ -47,7 +47,7 @@ JS; // We expected the following assertion to fail because the window has been // re-sized to have a width of 500 not 400. - $this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class); + $this->expectException(\PHPUnit_Framework_AssertionFailedError::class); $this->assertJsCondition($javascript, 100); } diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 6c1bd8be50fc..659fb5bd8182 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -168,7 +168,8 @@ class BrowserTestBaseTest extends BrowserTestBase { } public function testError() { - $this->setExpectedException('\Exception', 'User notice: foo'); + $this->expectException('\Exception'); + $this->expectExceptionMessage('User notice: foo'); $this->drupalGet('test-error'); } @@ -199,7 +200,8 @@ class BrowserTestBaseTest extends BrowserTestBase { */ public function testInvalidLinkExistsExact() { $this->drupalGet('test-pipe-char'); - $this->setExpectedException(ExpectationException::class, 'Link with label foo|bar found'); + $this->expectException(ExpectationException::class); + $this->expectExceptionMessage('Link with label foo|bar found'); $this->assertSession()->linkExistsExact('foo|bar'); } @@ -220,7 +222,8 @@ class BrowserTestBaseTest extends BrowserTestBase { */ public function testInvalidLinkNotExistsExact() { $this->drupalGet('test-pipe-char'); - $this->setExpectedException(ExpectationException::class, 'Link with label foo|bar|baz not found'); + $this->expectException(ExpectationException::class); + $this->expectExceptionMessage('Link with label foo|bar|baz not found'); $this->assertSession()->linkNotExistsExact('foo|bar|baz'); } @@ -685,7 +688,8 @@ class BrowserTestBaseTest extends BrowserTestBase { * Ensures we can't access modules we shouldn't be able to after install. */ public function testProfileModules() { - $this->setExpectedException(\InvalidArgumentException::class, 'The module demo_umami_content does not exist.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The module demo_umami_content does not exist.'); $this->assertFileExists('core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.info.yml'); \Drupal::service('extension.list.module')->getPathname('demo_umami_content'); } diff --git a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php index 3028b62dd027..b8f4693545a3 100644 --- a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php +++ b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php @@ -112,7 +112,7 @@ class SafeMarkupKernelTest extends KernelTestBase { */ public function testSafeMarkupUriWithExceptionUri($string, $uri) { // Should throw an \InvalidArgumentException, due to Uri::toString(). - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $args = self::getSafeMarkupUriArgs($uri); new FormattableMarkup($string, $args); diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php index 89b284612c5b..a8d0f6601830 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php @@ -257,7 +257,8 @@ class ConfigInstallTest extends KernelTestBase { * Tests installing configuration where the filename and ID do not match. */ public function testIdMisMatch() { - $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'The configuration name "config_test.dynamic.no_id_match" does not match the ID "does_not_match"'); + $this->expectException(\PHPUnit_Framework_Error_Warning::class); + $this->expectExceptionMessage('The configuration name "config_test.dynamic.no_id_match" does not match the ID "does_not_match"'); $this->installModules(['config_test_id_mismatch']); } diff --git a/core/tests/Drupal/KernelTests/Core/Config/Entity/ConfigEntityUpdaterTest.php b/core/tests/Drupal/KernelTests/Core/Config/Entity/ConfigEntityUpdaterTest.php index 5aae17f7d64c..f76578f99cf5 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/Entity/ConfigEntityUpdaterTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/Entity/ConfigEntityUpdaterTest.php @@ -118,7 +118,8 @@ class ConfigEntityUpdaterTest extends KernelTestBase { */ public function testUpdateException() { $this->enableModules(['entity_test']); - $this->setExpectedException(\InvalidArgumentException::class, 'The provided entity type ID \'entity_test_mul_changed\' is not a configuration entity type'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The provided entity type ID \'entity_test_mul_changed\' is not a configuration entity type'); $updater = $this->container->get('class_resolver')->getInstanceFromDefinition(ConfigEntityUpdater::class); $sandbox = []; $updater->update($sandbox, 'entity_test_mul_changed'); diff --git a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php index 240bee29e2d8..a900e2d47239 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php @@ -917,7 +917,8 @@ class SchemaTest extends KernelTestBase { ], 'primary key' => ['test_field'], ]; - $this->setExpectedException(SchemaException::class, "The 'test_field' field specification does not define 'not null' as TRUE."); + $this->expectException(SchemaException::class); + $this->expectExceptionMessage("The 'test_field' field specification does not define 'not null' as TRUE."); $this->schema->createTable($table_name, $table_spec); } @@ -935,7 +936,8 @@ class SchemaTest extends KernelTestBase { ]; $this->schema->createTable($table_name, $table_spec); - $this->setExpectedException(SchemaException::class, "The 'new_test_field' field specification does not define 'not null' as TRUE."); + $this->expectException(SchemaException::class); + $this->expectExceptionMessage("The 'new_test_field' field specification does not define 'not null' as TRUE."); $this->schema->addField($table_name, 'new_test_field', ['type' => 'int'], ['primary key' => ['test_field', 'new_test_field']]); } @@ -953,7 +955,8 @@ class SchemaTest extends KernelTestBase { ]; $this->schema->createTable($table_name, $table_spec); - $this->setExpectedException(SchemaException::class, "The 'changed_test_field' field specification does not define 'not null' as TRUE."); + $this->expectException(SchemaException::class); + $this->expectExceptionMessage("The 'changed_test_field' field specification does not define 'not null' as TRUE."); $this->schema->dropPrimaryKey($table_name); $this->schema->changeField($table_name, 'test_field', 'changed_test_field', ['type' => 'int'], ['primary key' => ['changed_test_field']]); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php index af9403c320aa..843cb83a5b71 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php @@ -141,7 +141,8 @@ class ConfigEntityAdapterTest extends KernelTestBase { * @covers ::applyDefaultValue */ public function testApplyDefaultValue() { - $this->setExpectedException(\BadMethodCallException::class, 'Method not supported'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Method not supported'); $adapter = ConfigEntityAdapter::createFromEntity($this->entity); $adapter->applyDefaultValue(); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php index 4ad3a49b2b27..ed47d096c3be 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php @@ -253,7 +253,8 @@ class EntityApiTest extends EntityKernelTestBase { $entity = $storage->create(['name' => 'revision_test']); $entity->save(); - $this->setExpectedException(EntityStorageException::class, "Update existing 'entity_test_mulrev' entity revision while changing the revision ID is not supported."); + $this->expectException(EntityStorageException::class); + $this->expectExceptionMessage("Update existing 'entity_test_mulrev' entity revision while changing the revision ID is not supported."); $entity->revision_id = 60; $entity->save(); @@ -270,7 +271,8 @@ class EntityApiTest extends EntityKernelTestBase { $entity = $storage->create(['name' => 'revision_test']); $entity->save(); - $this->setExpectedException(EntityStorageException::class, "Update existing 'entity_test_mulrev' entity while changing the ID is not supported."); + $this->expectException(EntityStorageException::class); + $this->expectExceptionMessage("Update existing 'entity_test_mulrev' entity while changing the ID is not supported."); $entity->id = 60; $entity->save(); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php index ef86d20ca5bb..0c36fbbe0115 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php @@ -944,7 +944,7 @@ class EntityFieldTest extends EntityKernelTestBase { $this->assertTrue($entity); // Check that an ID cannot be explicitly assigned on update. - $this->setExpectedException(EntityStorageException::class); + $this->expectException(EntityStorageException::class); $entity->set('id', $entity_id + 1); $storage->save($entity); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php index 1b1ffd03de1b..c560b953c57d 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php @@ -195,7 +195,7 @@ class EntityQueryRelationshipTest extends EntityKernelTestBase { * Tests the invalid specifier in the query relationship. */ public function testInvalidSpecifier() { - $this->setExpectedException(PluginNotFoundException::class); + $this->expectException(PluginNotFoundException::class); $this->container ->get('entity_type.manager') ->getStorage('taxonomy_term') diff --git a/core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php index d9a50feb65b0..937a2ab5a452 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php @@ -141,7 +141,8 @@ class FieldableEntityDefinitionUpdateTest extends EntityKernelTestBase { $updated_field_storage_definitions = $this->getUpdatedFieldStorageDefinitions($new_rev, $new_mul); if (!$data_migration_supported) { - $this->setExpectedException(EntityStorageException::class, 'Converting an entity type from revisionable to non-revisionable or from translatable to non-translatable is not supported.'); + $this->expectException(EntityStorageException::class); + $this->expectExceptionMessage('Converting an entity type from revisionable to non-revisionable or from translatable to non-translatable is not supported.'); } // Check that existing data can be retrieved from the storage before the @@ -620,7 +621,8 @@ class FieldableEntityDefinitionUpdateTest extends EntityKernelTestBase { // Make the update throw an exception during the entity save process. \Drupal::state()->set('entity_test_update.throw_exception', TRUE); - $this->setExpectedException(EntityStorageException::class, 'The entity update process failed while processing the entity type entity_test_update, ID: 1.'); + $this->expectException(EntityStorageException::class); + $this->expectExceptionMessage('The entity update process failed while processing the entity type entity_test_update, ID: 1.'); try { $updated_entity_type = $this->getUpdatedEntityTypeDefinition(TRUE, TRUE); diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php index b453afc92ffc..ff87c327601a 100644 --- a/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php @@ -31,7 +31,7 @@ class ModuleInstallerTest extends KernelTestBase { $this->assertEquals('/router_test/test1', $route->getPath()); $this->container->get('module_installer')->uninstall(['router_test']); - $this->setExpectedException(RouteNotFoundException::class); + $this->expectException(RouteNotFoundException::class); $this->container->get('router.route_provider')->getRouteByName('router_test.1'); } diff --git a/core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php b/core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php index 02e3939d3f0d..ecaa729821e3 100644 --- a/core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php +++ b/core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php @@ -60,7 +60,8 @@ class FieldMissingTypeTest extends EntityKernelTestBase { * @see \Drupal\field\FieldStorageConfigStorage::mapFromStorageRecords() */ public function testFieldStorageMissingType() { - $this->setExpectedException(\RuntimeException::class, "Unable to determine class for field type 'foo_field_storage' found in the 'field.storage.entity_test_mulrev.{$this->fieldName}' configuration"); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Unable to determine class for field type 'foo_field_storage' found in the 'field.storage.entity_test_mulrev.{$this->fieldName}' configuration"); $entity = EntityTestMulRev::create([ 'name' => $this->randomString(), 'field_test_item' => $this->randomString(), @@ -79,7 +80,8 @@ class FieldMissingTypeTest extends EntityKernelTestBase { * @see \Drupal\field\FieldConfigStorageBase::mapFromStorageRecords() */ public function testFieldMissingType() { - $this->setExpectedException(\RuntimeException::class, "Unable to determine class for field type 'foo_field' found in the 'field.field.entity_test_mulrev.entity_test_mulrev.{$this->fieldName}' configuration"); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Unable to determine class for field type 'foo_field' found in the 'field.field.entity_test_mulrev.entity_test_mulrev.{$this->fieldName}' configuration"); $entity = EntityTestMulRev::create([ 'name' => $this->randomString(), 'field_test_item' => $this->randomString(), diff --git a/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php b/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php index e4168459af27..f346d31ee5c7 100644 --- a/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php @@ -160,7 +160,8 @@ class DirectoryTest extends FileTestBase { $this->assertEqual($path, FALSE, 'An error is returned when filepath destination already exists with FileSystemInterface::EXISTS_ERROR.', 'File'); // Invalid UTF-8 causes an exception. - $this->setExpectedException(FileException::class, "Invalid filename 'a\xFFtest\x80€.txt'"); + $this->expectException(FileException::class); + $this->expectExceptionMessage("Invalid filename 'a\xFFtest\x80€.txt'"); $file_system->getDestinationFilename("core/misc/a\xFFtest\x80€.txt", FileSystemInterface::EXISTS_REPLACE); } diff --git a/core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php b/core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php index 516c4a0673f2..d124cfd49568 100644 --- a/core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php @@ -52,7 +52,7 @@ class FileCopyTest extends FileTestBase { // Copy non-existent file $desired_filepath = $this->randomMachineName(); $this->assertFalse(file_exists($desired_filepath), "Randomly named file doesn't exist."); - $this->setExpectedException(FileNotExistsException::class); + $this->expectException(FileNotExistsException::class); $new_filepath = \Drupal::service('file_system')->copy($desired_filepath, $this->randomMachineName()); $this->assertFalse($new_filepath, 'Copying a missing file fails.'); } @@ -75,7 +75,7 @@ class FileCopyTest extends FileTestBase { $this->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FileSystem::CHMOD_FILE)); // Copy the file onto itself without renaming fails. - $this->setExpectedException(FileExistsException::class); + $this->expectException(FileExistsException::class); $new_filepath = $file_system->copy($uri, $uri, FileSystemInterface::EXISTS_ERROR); $this->assertFalse($new_filepath, 'Copying onto itself without renaming fails.'); $this->assertTrue(file_exists($uri), 'File exists after copying onto itself.'); diff --git a/core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php b/core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php index a2592417e50f..226903c55ecb 100644 --- a/core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php @@ -53,7 +53,7 @@ class FileMoveTest extends FileTestBase { */ public function testMissing() { // Move non-existent file. - $this->setExpectedException(FileNotExistsException::class); + $this->expectException(FileNotExistsException::class); \Drupal::service('file_system')->move($this->randomMachineName(), $this->randomMachineName()); } @@ -67,7 +67,7 @@ class FileMoveTest extends FileTestBase { // Move the file onto itself without renaming shouldn't make changes. /** @var \Drupal\Core\File\FileSystemInterface $file_system */ $file_system = \Drupal::service('file_system'); - $this->setExpectedException(FileException::class); + $this->expectException(FileException::class); $new_filepath = $file_system->move($uri, $uri, FileSystemInterface::EXISTS_REPLACE); $this->assertFalse($new_filepath, 'Moving onto itself without renaming fails.'); $this->assertTrue(file_exists($uri), 'File exists after moving onto itself.'); diff --git a/core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php b/core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php index 354a1b55ff73..a69cb1d4d4a7 100644 --- a/core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php @@ -41,10 +41,8 @@ class FileSystemTest extends KernelTestBase { public function testEnsureFileExistsBeforeCopy() { // We need to compute the exception message here because it will include // the 'real' path to the file, which varies with $this->siteDirectory. - $this->setExpectedException( - FileNotExistsException::class, - "File 'public://test.txt' ('{$this->siteDirectory}/files/test.txt') could not be copied because it does not exist" - ); + $this->expectException(FileNotExistsException::class); + $this->expectExceptionMessage("File 'public://test.txt' ('{$this->siteDirectory}/files/test.txt') could not be copied because it does not exist"); $this->fileSystem->copy('public://test.txt', 'public://test-copy.txt'); } @@ -53,7 +51,8 @@ class FileSystemTest extends KernelTestBase { * @covers ::copy */ public function testDestinationDirectoryFailureOnCopy() { - $this->setExpectedException(DirectoryNotReadyException::class, "The specified file 'public://test.txt' could not be copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions"); + $this->expectException(DirectoryNotReadyException::class); + $this->expectExceptionMessage("The specified file 'public://test.txt' could not be copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions"); touch('public://test.txt'); // public://subdirectory has not been created, so \Drupal::service('file_system')->prepareDirectory() // will fail, causing copy() to throw DirectoryNotReadyException. @@ -64,7 +63,8 @@ class FileSystemTest extends KernelTestBase { * @covers ::copy */ public function testCopyFailureIfFileAlreadyExists() { - $this->setExpectedException(FileExistsException::class, "File 'public://test.txt' could not be copied because a file by that name already exists in the destination directory ('')"); + $this->expectException(FileExistsException::class); + $this->expectExceptionMessage("File 'public://test.txt' could not be copied because a file by that name already exists in the destination directory ('')"); $uri = 'public://test.txt'; touch($uri); $this->fileSystem->copy($uri, $uri, FileSystemInterface::EXISTS_ERROR); @@ -74,7 +74,8 @@ class FileSystemTest extends KernelTestBase { * @covers ::copy */ public function testCopyFailureIfSelfOverwrite() { - $this->setExpectedException(FileException::class, "'public://test.txt' could not be copied because it would overwrite itself"); + $this->expectException(FileException::class); + $this->expectExceptionMessage("'public://test.txt' could not be copied because it would overwrite itself"); $uri = 'public://test.txt'; touch($uri); $this->fileSystem->copy($uri, $uri, FileSystemInterface::EXISTS_REPLACE); diff --git a/core/tests/Drupal/KernelTests/Core/File/PharWrapperTest.php b/core/tests/Drupal/KernelTests/Core/File/PharWrapperTest.php index 2cd2ab1ea949..535f30ffccf3 100644 --- a/core/tests/Drupal/KernelTests/Core/File/PharWrapperTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/PharWrapperTest.php @@ -26,7 +26,7 @@ class PharWrapperTest extends KernelTestBase { // Ensure that file operations via the phar:// stream wrapper throw an // exception for files without the .phar extension. - $this->setExpectedException('TYPO3\PharStreamWrapper\Exception'); + $this->expectException('TYPO3\PharStreamWrapper\Exception'); file_exists("phar://$base/image-2.jpg/index.php"); } diff --git a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php index 8bcc3c4bc98c..8d51d254375a 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php @@ -84,7 +84,7 @@ class ThemeRenderAndAutoescapeTest extends KernelTestBase { * Ensures invalid content is handled correctly. */ public function testThemeEscapeAndRenderNotPrintable() { - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); theme_render_and_autoescape(new NonPrintable()); } diff --git a/core/tests/Drupal/KernelTests/Core/TypedData/AllowedValuesConstraintValidatorTest.php b/core/tests/Drupal/KernelTests/Core/TypedData/AllowedValuesConstraintValidatorTest.php index 5dcbfccddcd9..24c62cacb7f5 100644 --- a/core/tests/Drupal/KernelTests/Core/TypedData/AllowedValuesConstraintValidatorTest.php +++ b/core/tests/Drupal/KernelTests/Core/TypedData/AllowedValuesConstraintValidatorTest.php @@ -108,7 +108,8 @@ class AllowedValuesConstraintValidatorTest extends KernelTestBase { ->addConstraint('AllowedValues', ['choices' => [1, 2, 3], 'callback' => [static::class, 'doesNotExist']]); $typed_data = $this->typedData->create($definition, 1); - $this->setExpectedException(ConstraintDefinitionException::class, 'The AllowedValuesConstraint constraint expects a valid callback'); + $this->expectException(ConstraintDefinitionException::class); + $this->expectExceptionMessage('The AllowedValuesConstraint constraint expects a valid callback'); $typed_data->validate(); } diff --git a/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php b/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php index 191b006e49d9..d89290e01e30 100644 --- a/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php +++ b/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php @@ -63,7 +63,8 @@ class ZfExtensionManagerSfContainerTest extends TestCase { $this->expectExceptionMessage('Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface'); } else { - $this->setExpectedException(\RuntimeException::class, 'Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface'); } $bridge = new ZfExtensionManagerSfContainer(); $bridge->setStandalone(static::class); @@ -78,7 +79,8 @@ class ZfExtensionManagerSfContainerTest extends TestCase { $this->expectExceptionMessage('You have requested a non-existent service "test.foo".'); } else { - $this->setExpectedException(ServiceNotFoundException::class, 'You have requested a non-existent service "test.foo".'); + $this->expectException(ServiceNotFoundException::class); + $this->expectExceptionMessage('You have requested a non-existent service "test.foo".'); } $container = new ContainerBuilder(); $bridge = new ZfExtensionManagerSfContainer('test.'); diff --git a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php index b29f94647a52..eac4743b8fc5 100644 --- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php +++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php @@ -92,7 +92,8 @@ class DateTimePlusTest extends TestCase { $this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); } else { - $this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); } $interval = $input1->diff($input2, $absolute); } @@ -114,7 +115,7 @@ class DateTimePlusTest extends TestCase { $this->expectException($class); } else { - $this->setExpectedException($class); + $this->expectException($class); } $this->assertInstanceOf( '\Drupal\Component\DateTimePlus', @@ -257,7 +258,7 @@ class DateTimePlusTest extends TestCase { $this->expectException($class); } else { - $this->setExpectedException($class); + $this->expectException($class); } DateTimePlus::createFromFormat($format, $input, $timezone); } @@ -820,7 +821,7 @@ class DateTimePlusTest extends TestCase { $this->expectException(\UnexpectedValueException::class); } else { - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); } $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]); } @@ -885,7 +886,8 @@ class DateTimePlusTest extends TestCase { $this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); } else { - $this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); } $date = new DateTimePlus('now', 'Australia/Sydney'); $date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent(); diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index 577bb8baffd1..b1ef367136ea 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -74,7 +74,7 @@ class ContainerTest extends TestCase { $this->expectException(InvalidArgumentException::class); } else { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); } $container = new $this->containerClass($container_definition); } @@ -102,7 +102,7 @@ class ContainerTest extends TestCase { $this->expectException(ParameterNotFoundException::class); } else { - $this->setExpectedException(ParameterNotFoundException::class); + $this->expectException(ParameterNotFoundException::class); } $this->container->getParameter('parameter_that_does_not_exist'); } @@ -117,7 +117,7 @@ class ContainerTest extends TestCase { $this->expectException(ParameterNotFoundException::class); } else { - $this->setExpectedException(ParameterNotFoundException::class); + $this->expectException(ParameterNotFoundException::class); } $this->container->getParameter(NULL); } @@ -156,7 +156,7 @@ class ContainerTest extends TestCase { $this->expectException(LogicException::class); } else { - $this->setExpectedException(LogicException::class); + $this->expectException(LogicException::class); } $this->container->setParameter('some_config', 'new_value'); } @@ -266,7 +266,7 @@ class ContainerTest extends TestCase { $this->expectException(ServiceCircularReferenceException::class); } else { - $this->setExpectedException(ServiceCircularReferenceException::class); + $this->expectException(ServiceCircularReferenceException::class); } $this->container->get('circular_dependency'); } @@ -284,7 +284,7 @@ class ContainerTest extends TestCase { $this->expectException(ServiceNotFoundException::class); } else { - $this->setExpectedException(ServiceNotFoundException::class); + $this->expectException(ServiceNotFoundException::class); } $this->container->get('service_not_exists'); } @@ -338,7 +338,7 @@ class ContainerTest extends TestCase { $this->expectException(InvalidArgumentException::class); } else { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); } $this->container->get('service_parameter_not_exists'); } @@ -355,7 +355,7 @@ class ContainerTest extends TestCase { $this->expectException(InvalidArgumentException::class); } else { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); } $this->container->get('service_parameter_not_exists'); } @@ -385,7 +385,7 @@ class ContainerTest extends TestCase { $this->expectException(ServiceNotFoundException::class); } else { - $this->setExpectedException(ServiceNotFoundException::class); + $this->expectException(ServiceNotFoundException::class); } $this->container->get('service_dependency_not_exists'); } @@ -410,7 +410,7 @@ class ContainerTest extends TestCase { $this->expectException(ServiceNotFoundException::class); } else { - $this->setExpectedException(ServiceNotFoundException::class); + $this->expectException(ServiceNotFoundException::class); } $this->container->get(NULL); } @@ -441,7 +441,7 @@ class ContainerTest extends TestCase { $this->expectException(ServiceNotFoundException::class); } else { - $this->setExpectedException(ServiceNotFoundException::class); + $this->expectException(ServiceNotFoundException::class); } $this->container->get('service_not_exists'); } @@ -482,7 +482,7 @@ class ContainerTest extends TestCase { $this->expectException(RuntimeException::class); } else { - $this->setExpectedException(RuntimeException::class); + $this->expectException(RuntimeException::class); } $this->container->get('synthetic'); } @@ -526,7 +526,7 @@ class ContainerTest extends TestCase { $this->expectException(RuntimeException::class); } else { - $this->setExpectedException(RuntimeException::class); + $this->expectException(RuntimeException::class); } $this->container->get('wrong_factory'); } @@ -569,7 +569,7 @@ class ContainerTest extends TestCase { $this->expectException(InvalidArgumentException::class); } else { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); } $this->container->get('configurable_service_exception'); } @@ -672,7 +672,7 @@ class ContainerTest extends TestCase { $this->expectException(InvalidArgumentException::class); } else { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); } $this->container->get('invalid_argument_service'); } @@ -691,7 +691,7 @@ class ContainerTest extends TestCase { $this->expectException(InvalidArgumentException::class); } else { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); } if (!$this->machineFormat) { throw new InvalidArgumentException('Simulating the test failure.'); diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 2ed2e74158e9..ddfb60d0616f 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -549,7 +549,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->expectException(InvalidArgumentException::class); } else { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); } $this->dumper->getArray(); } @@ -571,7 +571,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->expectException(RuntimeException::class); } else { - $this->setExpectedException(RuntimeException::class); + $this->expectException(RuntimeException::class); } $this->dumper->getArray(); } @@ -593,7 +593,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->expectException(RuntimeException::class); } else { - $this->setExpectedException(RuntimeException::class); + $this->expectException(RuntimeException::class); } $this->dumper->getArray(); } @@ -615,7 +615,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { $this->expectException(RuntimeException::class); } else { - $this->setExpectedException(RuntimeException::class); + $this->expectException(RuntimeException::class); } $this->dumper->getArray(); } diff --git a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php index dbbb6ec08176..f7f17f39c6fa 100644 --- a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php +++ b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php @@ -29,7 +29,7 @@ class DiffOpTest extends TestCase { $this->expectException(Error::class); } else { - $this->setExpectedException(\PHPUnit_Framework_Error::class); + $this->expectException(\PHPUnit_Framework_Error::class); } $op = new DiffOp(); $result = $op->reverse(); diff --git a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php index 9ac807d744d0..b68f5db6a33e 100644 --- a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php @@ -129,7 +129,8 @@ class YamlDirectoryDiscoveryTest extends TestCase { $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\''); } else { - $this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\''); + $this->expectException(DiscoveryException::class); + $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\''); } vfsStream::setup('modules', NULL, [ 'test_1' => [ @@ -155,7 +156,8 @@ class YamlDirectoryDiscoveryTest extends TestCase { $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains invalid YAML'); } else { - $this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains invalid YAML'); + $this->expectException(DiscoveryException::class); + $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains invalid YAML'); } vfsStream::setup('modules', NULL, [ 'test_1' => [ diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php index f9195984341a..caee00b053cb 100644 --- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php @@ -64,7 +64,8 @@ class FileCacheFactoryTest extends TestCase { $this->expectExceptionMessage('Required prefix configuration is missing'); } else { - $this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Required prefix configuration is missing'); } FileCacheFactory::get('test_foo_settings', []); } diff --git a/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php b/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php index 7f636c10866f..ccf1b68813b0 100644 --- a/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php +++ b/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php @@ -49,7 +49,8 @@ class PoStreamWriterTest extends TestCase { $this->expectException(\Exception::class, 'No URI set.'); } else { - $this->setExpectedException(\Exception::class, 'No URI set.'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('No URI set.'); } $this->poWriter->getURI(); @@ -65,7 +66,8 @@ class PoStreamWriterTest extends TestCase { $this->expectException(\Exception::class, 'Unable to write data:'); } else { - $this->setExpectedException(\Exception::class, 'Unable to write data:'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unable to write data:'); } } @@ -109,7 +111,8 @@ class PoStreamWriterTest extends TestCase { $this->expectException(\Exception::class, 'Cannot close stream that is not open.'); } else { - $this->setExpectedException(\Exception::class, 'Cannot close stream that is not open.'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Cannot close stream that is not open.'); } $this->poWriter->close(); diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php index 168d1603e3ce..357f4e05f4ea 100644 --- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php +++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php @@ -104,7 +104,8 @@ class FileStorageTest extends PhpStorageTestBase { $this->expectExceptionMessage('mkdir(): Permission Denied'); } else { - $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'mkdir(): Permission Denied'); + $this->expectException(\PHPUnit_Framework_Error_Warning::class); + $this->expectExceptionMessage('mkdir(): Permission Denied'); } $storage->save('subdirectory/foo.php', $code); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php index aee8d0931893..0d17487165bf 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php @@ -76,10 +76,8 @@ class ContextTest extends TestCase { $this->expectExceptionMessage(sprintf("The %s context is required and not present.", $data_type)); } else { - $this->setExpectedException( - 'Drupal\Component\Plugin\Exception\ContextException', - sprintf("The %s context is required and not present.", $data_type) - ); + $this->expectException('Drupal\Component\Plugin\Exception\ContextException'); + $this->expectExceptionMessage(sprintf("The %s context is required and not present.", $data_type)); } } diff --git a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php index 760c0a9151eb..01dbe12adb98 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php @@ -55,7 +55,8 @@ class DefaultFactoryTest extends TestCase { $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); } else { - $this->setExpectedException(PluginException::class, 'The plugin (corn) did not specify an instance class.'); + $this->expectException(PluginException::class); + $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); } DefaultFactory::getPluginClass('corn', []); } @@ -72,7 +73,8 @@ class DefaultFactoryTest extends TestCase { $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); } else { - $this->setExpectedException(PluginException::class, 'The plugin (corn) did not specify an instance class.'); + $this->expectException(PluginException::class); + $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); } DefaultFactory::getPluginClass('corn', $plugin_definition); } @@ -88,7 +90,8 @@ class DefaultFactoryTest extends TestCase { $this->expectExceptionMessage('Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.'); } else { - $this->setExpectedException(PluginException::class, 'Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.'); + $this->expectException(PluginException::class); + $this->expectExceptionMessage('Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.'); } DefaultFactory::getPluginClass('carrot', ['class' => 'Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot']); } @@ -108,7 +111,7 @@ class DefaultFactoryTest extends TestCase { $this->expectException(PluginException::class); } else { - $this->setExpectedException(PluginException::class); + $this->expectException(PluginException::class); } DefaultFactory::getPluginClass('carrot', $plugin_definition); } @@ -152,7 +155,8 @@ class DefaultFactoryTest extends TestCase { $this->expectExceptionMessage('Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.'); } else { - $this->setExpectedException(PluginException::class, 'Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.'); + $this->expectException(PluginException::class); + $this->expectExceptionMessage('Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.'); } DefaultFactory::getPluginClass('corn', ['class' => Broccoli::class], VegetableInterface::class); } @@ -172,7 +176,7 @@ class DefaultFactoryTest extends TestCase { $this->expectException(PluginException::class); } else { - $this->setExpectedException(PluginException::class); + $this->expectException(PluginException::class); } DefaultFactory::getPluginClass('corn', $plugin_definition, VegetableInterface::class); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php index 1a5c36e7b854..e713ecc73829 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php @@ -73,7 +73,7 @@ class DiscoveryTraitTest extends TestCase { $this->expectException(PluginNotFoundException::class); } else { - $this->setExpectedException(PluginNotFoundException::class); + $this->expectException(PluginNotFoundException::class); } $method_ref->invoke($trait, $definitions, $plugin_id, TRUE); } @@ -115,7 +115,7 @@ class DiscoveryTraitTest extends TestCase { $this->expectException(PluginNotFoundException::class); } else { - $this->setExpectedException(PluginNotFoundException::class); + $this->expectException(PluginNotFoundException::class); } $trait->getDefinition($plugin_id, TRUE); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php index 5b010930922a..268bf0f58b14 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php @@ -104,7 +104,7 @@ class StaticDiscoveryDecoratorTest extends TestCase { $this->expectException('Drupal\Component\Plugin\Exception\PluginNotFoundException'); } else { - $this->setExpectedException('Drupal\Component\Plugin\Exception\PluginNotFoundException'); + $this->expectException('Drupal\Component\Plugin\Exception\PluginNotFoundException'); } } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php index 20d2f76edfc5..d57ffcfc64ca 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php @@ -127,7 +127,7 @@ class ReflectionFactoryTest extends TestCase { $this->expectException('\ReflectionException'); } else { - $this->setExpectedException('\ReflectionException'); + $this->expectException('\ReflectionException'); } } diff --git a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php index 2bad780dbcab..3d9692b45259 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php @@ -126,7 +126,8 @@ class PluginManagerBaseTest extends TestCase { $this->expectExceptionMessage(sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager))); } else { - $this->setExpectedException(\BadMethodCallException::class, sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager))); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage(sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager))); } $manager->getInstance($options); } diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php index 5a71f4838101..910a6356b86b 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php @@ -91,7 +91,7 @@ foo: $this->expectException(InvalidDataTypeException::class); } else { - $this->setExpectedException(InvalidDataTypeException::class); + $this->expectException(InvalidDataTypeException::class); } 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 d857d097a525..eeedf538d6a5 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php @@ -63,7 +63,7 @@ class YamlSymfonyTest extends YamlTestBase { $this->expectException(InvalidDataTypeException::class); } else { - $this->setExpectedException(InvalidDataTypeException::class); + $this->expectException(InvalidDataTypeException::class); } YamlSymfony::decode('foo: [ads'); } @@ -79,7 +79,8 @@ class YamlSymfonyTest extends YamlTestBase { $this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.'); } else { - $this->setExpectedException(InvalidDataTypeException::class, 'Object support when dumping a YAML file has been disabled.'); + $this->expectException(InvalidDataTypeException::class); + $this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.'); } $object = new \stdClass(); $object->foo = 'bar'; diff --git a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php index 7a56abb52899..b6aad1759b5c 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php @@ -133,7 +133,8 @@ class ArgumentsResolverTest extends TestCase { $this->expectExceptionMessage('requires a value for the "$route" argument.'); } else { - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$route" argument.'); } $resolver->getArguments($callable); } @@ -167,7 +168,8 @@ class ArgumentsResolverTest extends TestCase { $this->expectExceptionMessage('requires a value for the "$foo" argument.'); } else { - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$foo" argument.'); } $resolver->getArguments($callable); } @@ -184,7 +186,8 @@ class ArgumentsResolverTest extends TestCase { $this->expectExceptionMessage('requires a value for the "$foo" argument.'); } else { - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$foo" argument.'); } $resolver->getArguments($callable); } diff --git a/core/tests/Drupal/Tests/Component/Utility/ColorTest.php b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php index 02a4ed5f15b1..588af9499baa 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ColorTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php @@ -30,7 +30,7 @@ class ColorTest extends TestCase { $this->expectException('InvalidArgumentException'); } else { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException('InvalidArgumentException'); } } $this->assertSame($expected, Color::hexToRgb($value)); diff --git a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php index 6147c05d37ec..14fdb8407b96 100644 --- a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php @@ -75,7 +75,7 @@ class CryptTest extends TestCase { $this->expectException('InvalidArgumentException'); } else { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException('InvalidArgumentException'); } Crypt::hmacBase64($data, $key); } diff --git a/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php b/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php index 9185d01f32cb..8fd53b6933ee 100644 --- a/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php @@ -37,7 +37,8 @@ class EmailValidatorTest extends TestCase { $this->expectExceptionMessage('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); } else { - $this->setExpectedException(\BadMethodCallException::class, 'Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); } $validator->isValid('example@example.com', (new RFCValidation())); } diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php index a8a8af0e6c35..327287bb695a 100644 --- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php @@ -347,7 +347,7 @@ class HtmlTest extends TestCase { $this->expectException(\AssertionError::class); } else { - $this->setExpectedException(\AssertionError::class); + $this->expectException(\AssertionError::class); } 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 7523c8be0670..88a16bbb2801 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -66,7 +66,7 @@ class RandomTest extends TestCase { $this->expectException(\RuntimeException::class); } else { - $this->setExpectedException(\RuntimeException::class); + $this->expectException(\RuntimeException::class); } for ($i = 0; $i <= 100; $i++) { $str = $random->name(1, TRUE); @@ -87,7 +87,7 @@ class RandomTest extends TestCase { $this->expectException(\RuntimeException::class); } else { - $this->setExpectedException(\RuntimeException::class); + $this->expectException(\RuntimeException::class); } for ($i = 0; $i <= 100; $i++) { $str = $random->string(1, TRUE); diff --git a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php index ef46b7963af3..1cd7f387eeea 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php @@ -21,7 +21,7 @@ class RectangleTest extends TestCase { $this->expectException(\InvalidArgumentException::class); } else { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); } $rect = new Rectangle(-40, 20); } @@ -36,7 +36,7 @@ class RectangleTest extends TestCase { $this->expectException(\InvalidArgumentException::class); } else { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); } $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 beaa472c26b2..ff1b42308490 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -586,7 +586,7 @@ class UrlHelperTest extends TestCase { $this->expectException(\InvalidArgumentException::class); } else { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); } 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 3d34851c5072..1eb3d97121af 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -514,7 +514,7 @@ class AccessManagerTest extends UnitTestCase { $this->checkProvider->setContainer($container); $this->checkProvider->addCheckService('test_incorrect_value', 'access'); - $this->setExpectedException(AccessException::class); + $this->expectException(AccessException::class); $access_manager->checkNamedRoute('test_incorrect_value', [], $this->account); } diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php index 5b7ae314a3d2..7b95e45c8f85 100644 --- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php @@ -177,7 +177,7 @@ class CsrfTokenGeneratorTest extends UnitTestCase { public function testInvalidParameterTypes($token, $value = '') { $this->setupDefaultExpectations(); - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->generator->validate($token, $value); } @@ -205,7 +205,7 @@ class CsrfTokenGeneratorTest extends UnitTestCase { // Update settings with no hash salt. new Settings([]); $generator = new CsrfTokenGenerator($this->privateKey, $this->sessionMetadata); - $this->setExpectedException(\RuntimeException::class); + $this->expectException(\RuntimeException::class); $generator->get(); } diff --git a/core/tests/Drupal/Tests/Core/Access/CustomAccessCheckTest.php b/core/tests/Drupal/Tests/Core/Access/CustomAccessCheckTest.php index af2d65ef5ded..35380024f07d 100644 --- a/core/tests/Drupal/Tests/Core/Access/CustomAccessCheckTest.php +++ b/core/tests/Drupal/Tests/Core/Access/CustomAccessCheckTest.php @@ -133,7 +133,8 @@ class CustomAccessCheckTest extends UnitTestCase { $route_match = $this->createMock(RouteMatchInterface::class); $account = $this->createMock(AccountInterface::class); - $this->setExpectedException(\BadMethodCallException::class, 'The "\Drupal\Tests\Core\Access\NonExistentController::nonExistentMethod" method is not callable as a _custom_access callback in route "/test-route"'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('The "\Drupal\Tests\Core\Access\NonExistentController::nonExistentMethod" method is not callable as a _custom_access callback in route "/test-route"'); // Run the access check. $this->accessChecker->access($route, $route_match, $account); diff --git a/core/tests/Drupal/Tests/Core/Annotation/PluralTranslationTest.php b/core/tests/Drupal/Tests/Core/Annotation/PluralTranslationTest.php index 91d90791a917..93225ece7e65 100644 --- a/core/tests/Drupal/Tests/Core/Annotation/PluralTranslationTest.php +++ b/core/tests/Drupal/Tests/Core/Annotation/PluralTranslationTest.php @@ -51,7 +51,7 @@ class PluralTranslationTest extends UnitTestCase { * @dataProvider providerTestMissingData */ public function testMissingData($data) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); new PluralTranslation($data); } diff --git a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php index 4b8bf94a95d7..ec01d4e26f96 100644 --- a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php @@ -66,7 +66,7 @@ class AssertLegacyTraitTest extends UnitTestCase { */ public function testAssertUniqueTextFail() { $this->page->getText()->willReturn('foo bar bar'); - $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); $this->assertUniqueText('bar'); } @@ -75,7 +75,7 @@ class AssertLegacyTraitTest extends UnitTestCase { */ public function testAssertUniqueTextUnknown() { $this->page->getText()->willReturn('foo bar bar'); - $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); $this->assertUniqueText('alice'); } @@ -102,7 +102,7 @@ class AssertLegacyTraitTest extends UnitTestCase { */ public function testAssertNoUniqueTextFail() { $this->page->getText()->willReturn('foo bar bar'); - $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); $this->assertNoUniqueText('foo'); } @@ -111,7 +111,7 @@ class AssertLegacyTraitTest extends UnitTestCase { */ public function testAssertNoUniqueTextUnknown() { $this->page->getText()->willReturn('foo bar bar'); - $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); $this->assertNoUniqueText('alice'); } @@ -150,7 +150,7 @@ class AssertLegacyTraitTest extends UnitTestCase { ->optionExists('myselect', 'two') ->willReturn($option_field->reveal()); - $this->setExpectedException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); $this->assertOptionSelected('myselect', 'two'); } diff --git a/core/tests/Drupal/Tests/Core/Asset/CssCollectionRendererUnitTest.php b/core/tests/Drupal/Tests/Core/Asset/CssCollectionRendererUnitTest.php index b9d557771b96..eeccea18d6a0 100644 --- a/core/tests/Drupal/Tests/Core/Asset/CssCollectionRendererUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/CssCollectionRendererUnitTest.php @@ -279,7 +279,8 @@ class CssCollectionRendererUnitTest extends UnitTestCase { ->method('get') ->with('system.css_js_query_string') ->will($this->returnValue(NULL)); - $this->setExpectedException('Exception', 'Invalid CSS asset type.'); + $this->expectException('Exception'); + $this->expectExceptionMessage('Invalid CSS asset type.'); $css_group = [ 'group' => 0, diff --git a/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php b/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php index f39a93862d0b..606cddb23b25 100644 --- a/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php @@ -227,7 +227,8 @@ class CssOptimizerUnitTest extends UnitTestCase { * Tests a file CSS asset with preprocessing disabled. */ public function testTypeFilePreprocessingDisabled() { - $this->setExpectedException('Exception', 'Only file CSS assets with preprocessing enabled can be optimized.'); + $this->expectException('Exception'); + $this->expectExceptionMessage('Only file CSS assets with preprocessing enabled can be optimized.'); $css_asset = [ 'group' => -100, @@ -247,7 +248,8 @@ class CssOptimizerUnitTest extends UnitTestCase { * Tests a CSS asset with 'type' => 'external'. */ public function testTypeExternal() { - $this->setExpectedException('Exception', 'Only file CSS assets can be optimized.'); + $this->expectException('Exception'); + $this->expectExceptionMessage('Only file CSS assets can be optimized.'); $css_asset = [ 'group' => -100, diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php index bbd55a64beda..c735de88f8ba 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php @@ -172,7 +172,8 @@ class LibraryDependencyResolverTest extends UnitTestCase { * @covers ::getMinimalRepresentativeSubset */ public function testGetMinimalRepresentativeSubsetInvalidInput() { - $this->setExpectedException(\AssertionError::class, '$libraries can\'t contain duplicate items.'); + $this->expectException(\AssertionError::class); + $this->expectExceptionMessage('$libraries can\'t contain duplicate items.'); $this->libraryDependencyResolver->getMinimalRepresentativeSubset(['test/no_deps_a', 'test/no_deps_a']); } diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index 3dfb89c90976..70fb040df975 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -167,7 +167,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'invalid_file', $path); - $this->setExpectedException(InvalidLibraryFileException::class); + $this->expectException(InvalidLibraryFileException::class); $this->libraryDiscoveryParser->buildByExtension('invalid_file'); } @@ -186,7 +186,8 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'example_module_missing_information', $path); - $this->setExpectedException(IncompleteLibraryDefinitionException::class, "Incomplete library definition for definition 'example' in extension 'example_module_missing_information'"); + $this->expectException(IncompleteLibraryDefinitionException::class); + $this->expectExceptionMessage("Incomplete library definition for definition 'example' in extension 'example_module_missing_information'"); $this->libraryDiscoveryParser->buildByExtension('example_module_missing_information'); } @@ -296,7 +297,7 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'js_positive_weight', $path); - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $this->libraryDiscoveryParser->buildByExtension('js_positive_weight'); } @@ -426,7 +427,8 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'licenses_missing_information', $path); - $this->setExpectedException(LibraryDefinitionMissingLicenseException::class, "Missing license information in library definition for definition 'no-license-info-but-remote' extension 'licenses_missing_information': it has a remote, but no license."); + $this->expectException(LibraryDefinitionMissingLicenseException::class); + $this->expectExceptionMessage("Missing license information in library definition for definition 'no-license-info-but-remote' extension 'licenses_missing_information': it has a remote, but no license."); $this->libraryDiscoveryParser->buildByExtension('licenses_missing_information'); } @@ -540,7 +542,8 @@ class LibraryDiscoveryParserTest extends UnitTestCase { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', $extension, $path); - $this->setExpectedException(\AssertionError::class, $exception_message); + $this->expectException(\AssertionError::class); + $this->expectExceptionMessage($exception_message); $this->libraryDiscoveryParser->buildByExtension($extension); } diff --git a/core/tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php b/core/tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php index 47ac481617ae..c812485b52d1 100644 --- a/core/tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php @@ -176,7 +176,8 @@ class BatchBuilderTest extends UnitTestCase { */ public function testQueueExists() { $batch_builder = (new BatchBuilder()); - $this->setExpectedException(\InvalidArgumentException::class, 'Class \ThisIsNotAClass does not exist.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Class \ThisIsNotAClass does not exist.'); $batch_builder->setQueue('BatchName', '\ThisIsNotAClass'); } @@ -187,7 +188,8 @@ class BatchBuilderTest extends UnitTestCase { */ public function testQueueImplements() { $batch_builder = (new BatchBuilder()); - $this->setExpectedException(\InvalidArgumentException::class, 'Class Exception does not implement \Drupal\Core\Queue\QueueInterface.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Class Exception does not implement \Drupal\Core\Queue\QueueInterface.'); $batch_builder->setQueue('BatchName', \Exception::class); } diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php index db1406bb97aa..eac22bc607ee 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php @@ -194,7 +194,7 @@ class BreadcrumbManagerTest extends UnitTestCase { ->will($this->returnValue('invalid_result')); $this->breadcrumbManager->addBuilder($builder, 0); - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $this->breadcrumbManager->build($this->createMock('Drupal\Core\Routing\RouteMatchInterface')); } diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php index 67c7d9820560..f578301941c8 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php @@ -19,7 +19,8 @@ class BreadcrumbTest extends UnitTestCase { public function testSetLinks() { $breadcrumb = new Breadcrumb(); $breadcrumb->setLinks([new Link('Home', Url::fromRoute(''))]); - $this->setExpectedException(\LogicException::class, 'Once breadcrumb links are set, only additional breadcrumb links can be added.'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Once breadcrumb links are set, only additional breadcrumb links can be added.'); $breadcrumb->setLinks([new Link('None', Url::fromRoute(''))]); } diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php index 2175192ebf54..a9600c2bb197 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php @@ -17,7 +17,7 @@ class CacheTagsInvalidatorTest extends UnitTestCase { */ public function testInvalidateTagsWithInvalidTags() { $cache_tags_invalidator = new CacheTagsInvalidator(); - $this->setExpectedException(\AssertionError::class); + $this->expectException(\AssertionError::class); $cache_tags_invalidator->invalidateTags(['node' => [2, 3, 5, 8, 13]]); } diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTest.php index 5d7f26948741..e0dacf07c0d9 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheTest.php @@ -47,7 +47,8 @@ class CacheTest extends UnitTestCase { */ public function testValidateTags(array $tags, $expected_exception_message) { if ($expected_exception_message !== FALSE) { - $this->setExpectedException('LogicException', $expected_exception_message); + $this->expectException('LogicException'); + $this->expectExceptionMessage($expected_exception_message); } // If it doesn't throw an exception, validateTags() returns NULL. $this->assertNull(Cache::validateTags($tags)); diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php index 8b0b7598165d..5827622f2287 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php @@ -111,7 +111,7 @@ class CacheableMetadataTest extends UnitTestCase { public function testSetCacheMaxAge($data, $expect_exception) { $metadata = new CacheableMetadata(); if ($expect_exception) { - $this->setExpectedException('\InvalidArgumentException'); + $this->expectException('\InvalidArgumentException'); } $metadata->setCacheMaxAge($data); $this->assertEquals($data, $metadata->getCacheMaxAge()); diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php index f89e639cc730..7b5768d3fc68 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -110,7 +110,7 @@ class CacheContextsManagerTest extends UnitTestCase { $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); - $this->setExpectedException(\AssertionError::class); + $this->expectException(\AssertionError::class); $cache_contexts_manager->convertTokensToKeys(["non-cache-context"]); } @@ -123,7 +123,7 @@ class CacheContextsManagerTest extends UnitTestCase { $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $cache_contexts_manager->convertTokensToKeys([$context_token]); } @@ -209,7 +209,8 @@ class CacheContextsManagerTest extends UnitTestCase { $container = new ContainerBuilder(); $cache_contexts_manager = new CacheContextsManager($container, ['foo', 'foo.bar', 'baz']); if ($expected_exception_message !== FALSE) { - $this->setExpectedException('LogicException', $expected_exception_message); + $this->expectException('LogicException'); + $this->expectExceptionMessage($expected_exception_message); } // If it doesn't throw an exception, validateTokens() returns NULL. $this->assertNull($cache_contexts_manager->validateTokens($contexts)); diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index 8b9b6a6e653d..fb620f4ade0d 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -257,7 +257,7 @@ class ConfigTest extends UnitTestCase { * @covers ::set */ public function testSetValidation() { - $this->setExpectedException(ConfigValueException::class); + $this->expectException(ConfigValueException::class); $this->config->set('testData', ['dot.key' => 1]); } @@ -269,7 +269,7 @@ class ConfigTest extends UnitTestCase { $this->config->set('testData', 1); // Attempt to treat the single value as a nested item. - $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class); + $this->expectException(\PHPUnit_Framework_Error_Warning::class); $this->config->set('testData.illegalOffset', 1); } @@ -411,7 +411,8 @@ class ConfigTest extends UnitTestCase { * @dataProvider validateNameProvider */ public function testValidateNameException($name, $exception_message) { - $this->setExpectedException('\Drupal\Core\Config\ConfigNameException', $exception_message); + $this->expectException('\Drupal\Core\Config\ConfigNameException'); + $this->expectExceptionMessage($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 f68e45a87417..5f5f76c7a6f9 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -635,7 +635,8 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { $this->entityType->expects($this->any()) ->method('getPropertiesToExport') ->willReturn(NULL); - $this->setExpectedException(SchemaIncompleteException::class, 'Incomplete or missing schema for test_provider.'); + $this->expectException(SchemaIncompleteException::class); + $this->expectExceptionMessage('Incomplete or missing schema for test_provider.'); $this->entity->toArray(); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index be0ae4d1fef9..e21ae9661da8 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -410,7 +410,8 @@ class ConfigEntityStorageTest extends UnitTestCase { ->shouldNotBeCalled(); $entity = $this->getMockEntity(); - $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); + $this->expectException(EntityMalformedException::class); + $this->expectExceptionMessage('The entity does not have an ID.'); $this->entityStorage->save($entity); } @@ -431,7 +432,7 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity = $this->getMockEntity(['id' => 'foo']); $entity->enforceIsNew(); - $this->setExpectedException(EntityStorageException::class); + $this->expectException(EntityStorageException::class); $this->entityStorage->save($entity); } @@ -453,7 +454,8 @@ class ConfigEntityStorageTest extends UnitTestCase { $this->entityQuery->execute()->willReturn(['baz']); $entity = $this->getMockEntity(['id' => 'foo']); - $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this UUID is already used for'); + $this->expectException(ConfigDuplicateUUIDException::class); + $this->expectExceptionMessage('when this UUID is already used for'); $this->entityStorage->save($entity); } @@ -531,7 +533,8 @@ class ConfigEntityStorageTest extends UnitTestCase { $entity = $this->getMockEntity(['id' => 'foo']); $entity->set('uuid', 'baz'); - $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this entity already exists with UUID'); + $this->expectException(ConfigDuplicateUUIDException::class); + $this->expectExceptionMessage('when this entity already exists with UUID'); $this->entityStorage->save($entity); } @@ -560,7 +563,8 @@ class ConfigEntityStorageTest extends UnitTestCase { $this->assertInstanceOf(EntityInterface::class, $entity); $this->assertSame('foo', $entity->id()); - $this->setExpectedException(\AssertionError::class, 'Cannot load a NULL ID.'); + $this->expectException(\AssertionError::class); + $this->expectExceptionMessage('Cannot load a NULL ID.'); $this->entityStorage->load(NULL); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php index 2b1df3751672..39611431e1ab 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -62,10 +62,8 @@ class ConfigEntityTypeTest extends UnitTestCase { 'config_prefix' => $this->randomMachineName(59), ]; $config_entity = $this->setUpConfigEntityType($definition); - $this->setExpectedException( - '\Drupal\Core\Config\ConfigPrefixLengthException', - "The configuration file name prefix {$definition['provider']}.{$definition['config_prefix']} exceeds the maximum character limit of " . ConfigEntityType::PREFIX_LENGTH - ); + $this->expectException('\Drupal\Core\Config\ConfigPrefixLengthException'); + $this->expectExceptionMessage("The configuration file name prefix {$definition['provider']}.{$definition['config_prefix']} exceeds the maximum character limit of " . ConfigEntityType::PREFIX_LENGTH); $this->assertEmpty($config_entity->getConfigPrefix()); } @@ -101,7 +99,8 @@ class ConfigEntityTypeTest extends UnitTestCase { * @covers ::__construct */ public function testConstructBadStorage() { - $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); + $this->expectException(ConfigEntityStorageClassException::class); + $this->expectExceptionMessage('\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'], @@ -113,7 +112,8 @@ class ConfigEntityTypeTest extends UnitTestCase { */ public function testSetStorageClass() { $config_entity = $this->setUpConfigEntityType([]); - $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); + $this->expectException(ConfigEntityStorageClassException::class); + $this->expectExceptionMessage('\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it'); $config_entity->setStorageClass('\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage'); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php index 43e3f6263e38..bc39a2ecdde3 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php @@ -111,7 +111,8 @@ class QueryFactoryTest extends UnitTestCase { $method = new \ReflectionMethod($query_factory, 'getKeys'); $method->setAccessible(TRUE); - $this->setExpectedException(\LogicException::class, 'test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup'); $method->invoke($query_factory, $this->getConfigObject('test'), 'test.*', 'get', $config_entity_type); } diff --git a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php index d9c8c2c8597c..3b3c9752c859 100644 --- a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php @@ -31,7 +31,8 @@ class ImmutableConfigTest extends UnitTestCase { * @covers ::set */ public function testSet() { - $this->setExpectedException(ImmutableConfigException::class, 'Can not set values on immutable configuration test:name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); + $this->expectException(ImmutableConfigException::class); + $this->expectExceptionMessage('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'); } @@ -39,7 +40,8 @@ class ImmutableConfigTest extends UnitTestCase { * @covers ::clear */ public function testClear() { - $this->setExpectedException(ImmutableConfigException::class, 'Can not clear name key in immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); + $this->expectException(ImmutableConfigException::class); + $this->expectExceptionMessage('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'); } @@ -47,7 +49,8 @@ class ImmutableConfigTest extends UnitTestCase { * @covers ::save */ public function testSave() { - $this->setExpectedException(ImmutableConfigException::class, 'Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); + $this->expectException(ImmutableConfigException::class); + $this->expectExceptionMessage('Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); $this->config->save(); } @@ -55,7 +58,8 @@ class ImmutableConfigTest extends UnitTestCase { * @covers ::delete */ public function testDelete() { - $this->setExpectedException(ImmutableConfigException::class, 'Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object'); + $this->expectException(ImmutableConfigException::class); + $this->expectExceptionMessage('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 84266b41c1c5..745c4f357349 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php @@ -128,7 +128,7 @@ class ControllerResolverTest extends UnitTestCase { * Tests createController() with a non-existent class. */ public function testCreateControllerNonExistentClass() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->controllerResolver->getControllerFromDefinition('Class::method'); } @@ -136,7 +136,7 @@ class ControllerResolverTest extends UnitTestCase { * Tests createController() with an invalid name. */ public function testCreateControllerInvalidName() { - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); $this->controllerResolver->getControllerFromDefinition('ClassWithoutMethod'); } @@ -201,7 +201,7 @@ class ControllerResolverTest extends UnitTestCase { * Tests getControllerFromDefinition() without a callable. */ public function testGetControllerFromDefinitionNotCallable() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $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 db2c89d1e770..29a5aabfa85a 100644 --- a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php @@ -161,7 +161,7 @@ class ConditionTest extends UnitTestCase { $condition = new Condition('AND'); $condition->condition('name', 'value', $operator); - $this->setExpectedException(\PHPUnit_Framework_Error::class); + $this->expectException(\PHPUnit_Framework_Error::class); $condition->compile($connection, $query_placeholder); } diff --git a/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php b/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php index af16ef6adc76..b48e5c05146b 100644 --- a/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php @@ -136,7 +136,8 @@ class UrlConversionTest extends UnitTestCase { * @dataProvider providerInvalidArgumentsUrlConversion */ public function testGetInvalidArgumentExceptionInUrlConversion($url, $root, $expected_exception_message) { - $this->setExpectedException(\InvalidArgumentException::class, $expected_exception_message); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage($expected_exception_message); Database::convertDbUrlToConnectionInfo($url, $root); } @@ -239,7 +240,8 @@ class UrlConversionTest extends UnitTestCase { */ public function testGetInvalidArgumentGetConnectionInfoAsUrl(array $connection_options, $expected_exception_message) { Database::addConnectionInfo('default', 'default', $connection_options); - $this->setExpectedException(\InvalidArgumentException::class, $expected_exception_message); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage($expected_exception_message); $url = Database::getConnectionInfoAsUrl(); } diff --git a/core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php b/core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php index 4e915f772b8c..2809db08b936 100644 --- a/core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php +++ b/core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php @@ -43,7 +43,8 @@ class DrupalDateTimeTest extends UnitTestCase { * @dataProvider providerTestInvalidDateDiff */ public function testInvalidDateDiff($input1, $input2, $absolute) { - $this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); $interval = $input1->diff($input2, $absolute); } @@ -206,7 +207,8 @@ class DrupalDateTimeTest extends UnitTestCase { * @covers ::__call */ public function testChainableNonCallable() { - $this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Core\Datetime\DrupalDateTime::nonexistent()'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Call to undefined method Drupal\Core\Datetime\DrupalDateTime::nonexistent()'); $tz = new \DateTimeZone(date_default_timezone_get()); $date = new DrupalDateTime('now', $tz, ['langcode' => 'en']); $date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent(); diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php index 44d45fba915c..63b94ff4638d 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php @@ -70,7 +70,7 @@ class ProxyServicesPassTest extends UnitTestCase { $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist') ->setLazy(TRUE); - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->proxyServicesPass->process($container); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php index 76ab32e331de..f5b5e84851d6 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -56,7 +56,8 @@ class TaggedHandlersPassTest extends UnitTestCase { ]); $handler_pass = new TaggedHandlersPass(); - $this->setExpectedException(LogicException::class, "At least one service tagged with 'consumer_id' is required."); + $this->expectException(LogicException::class); + $this->expectExceptionMessage("At least one service tagged with 'consumer_id' is required."); $handler_pass->process($container); } @@ -67,7 +68,8 @@ class TaggedHandlersPassTest extends UnitTestCase { * @covers ::processServiceIdCollectorPass */ public function testIdCollectorProcessRequiredHandlers() { - $this->setExpectedException(LogicException::class, "At least one service tagged with 'consumer_id' is required."); + $this->expectException(LogicException::class); + $this->expectExceptionMessage("At least one service tagged with 'consumer_id' is required."); $container = $this->buildContainer(); $container ->register('consumer_id', __NAMESPACE__ . '\ValidConsumer') @@ -94,7 +96,8 @@ class TaggedHandlersPassTest extends UnitTestCase { ->addTag('service_collector'); $handler_pass = new TaggedHandlersPass(); - $this->setExpectedException(LogicException::class, "Service consumer 'consumer_id1' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface."); + $this->expectException(LogicException::class); + $this->expectExceptionMessage("Service consumer 'consumer_id1' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface."); $handler_pass->process($container); } @@ -302,7 +305,7 @@ class TaggedHandlersPassTest extends UnitTestCase { ]); $handler_pass = new TaggedHandlersPass(); - $this->setExpectedException(LogicException::class); + $this->expectException(LogicException::class); $handler_pass->process($container); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php index e8de5ecf59ac..6b075ed6b48a 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php @@ -40,7 +40,8 @@ class ContainerBuilderTest extends UnitTestCase { public function testSetException() { $container = new ContainerBuilder(); $class = new BarClass(); - $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Service ID names must be lowercase: Bar'); $container->set('Bar', $class); } @@ -49,7 +50,8 @@ class ContainerBuilderTest extends UnitTestCase { */ public function testSetParameterException() { $container = new ContainerBuilder(); - $this->setExpectedException(\InvalidArgumentException::class, 'Parameter names must be lowercase: Buzz'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Parameter names must be lowercase: Buzz'); $container->setParameter('Buzz', 'buzz'); } @@ -58,7 +60,8 @@ class ContainerBuilderTest extends UnitTestCase { */ public function testRegisterException() { $container = new ContainerBuilder(); - $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Service ID names must be lowercase: Bar'); $container->register('Bar'); } @@ -114,7 +117,7 @@ class ContainerBuilderTest extends UnitTestCase { */ public function testSerialize() { $container = new ContainerBuilder(); - $this->setExpectedException(\AssertionError::class); + $this->expectException(\AssertionError::class); serialize($container); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php index 46f00bd2a5e2..df86cddc0f05 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php @@ -17,7 +17,7 @@ class ContainerTest extends UnitTestCase { */ public function testSerialize() { $container = new Container(); - $this->setExpectedException(\AssertionError::class); + $this->expectException(\AssertionError::class); serialize($container); } diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php index ac748fbf4bd1..210d8a92439f 100644 --- a/core/tests/Drupal/Tests/Core/DrupalTest.php +++ b/core/tests/Drupal/Tests/Core/DrupalTest.php @@ -51,7 +51,8 @@ class DrupalTest extends UnitTestCase { * @covers ::getContainer */ public function testGetContainerException() { - $this->setExpectedException(ContainerNotInitializedException::class, '\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.'); + $this->expectException(ContainerNotInitializedException::class); + $this->expectExceptionMessage('\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 50da19f06b73..87a511cfddc4 100644 --- a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php @@ -366,7 +366,7 @@ class BaseFieldDefinitionTest extends UnitTestCase { public function testInvalidDefaultValueCallback() { $definition = BaseFieldDefinition::create($this->fieldType); // setDefaultValueCallback returns $this. - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $definition->setDefaultValueCallback([get_class($this), 'mockDefaultValueCallback']); } diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index f18fdbfd68db..02c7a371e227 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -273,7 +273,8 @@ class ContentEntityBaseUnitTest extends UnitTestCase { ->method('hasKey') ->with('revision') ->will($this->returnValue(FALSE)); - $this->setExpectedException('LogicException', 'Entity type ' . $this->entityTypeId . ' does not support revisions.'); + $this->expectException('LogicException'); + $this->expectExceptionMessage('Entity type ' . $this->entityTypeId . ' does not support revisions.'); $this->entity->setNewRevision(); } @@ -427,7 +428,8 @@ class ContentEntityBaseUnitTest extends UnitTestCase { // that trying to save a non-validated entity when validation is required // results in an exception. $this->assertTrue($this->entity->isValidationRequired()); - $this->setExpectedException(\LogicException::class, 'Entity validation was skipped.'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Entity validation was skipped.'); $this->entity->save(); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php index e5c07af5ac9e..1ef003cb7470 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php @@ -330,7 +330,8 @@ class EntityFieldManagerTest extends UnitTestCase { $this->entityType->isTranslatable()->willReturn(TRUE); $this->entityType->getLabel()->willReturn('Test'); - $this->setExpectedException(\LogicException::class, 'The Test entity type cannot be translatable as it does not define a translatable "langcode" field.'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The Test entity type cannot be translatable as it does not define a translatable "langcode" field.'); $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type'); } @@ -456,7 +457,7 @@ class EntityFieldManagerTest extends UnitTestCase { $this->entityType->isTranslatable()->willReturn(TRUE); $this->entityType->getLabel()->willReturn('the_label'); - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php index 70cac6001184..98dd1733c896 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php @@ -268,7 +268,7 @@ class EntityTypeManagerTest extends UnitTestCase { $entity->getFormClass('edit')->willReturn(''); $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]); - $this->setExpectedException(InvalidPluginDefinitionException::class); + $this->expectException(InvalidPluginDefinitionException::class); $this->entityTypeManager->getFormObject('test_entity_type', 'edit'); } @@ -301,7 +301,7 @@ class EntityTypeManagerTest extends UnitTestCase { $entity = $this->prophesize(EntityTypeInterface::class); $entity->getHandlerClass('storage')->willReturn(''); $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]); - $this->setExpectedException(InvalidPluginDefinitionException::class); + $this->expectException(InvalidPluginDefinitionException::class); $this->entityTypeManager->getHandler('test_entity_type', 'storage'); } @@ -334,7 +334,8 @@ class EntityTypeManagerTest extends UnitTestCase { $apple->getLinkTemplates()->willReturn(['canonical' => 'path/to/apple']); $definition = $apple->reveal(); - $this->setExpectedException(InvalidLinkTemplateException::class, "Link template 'canonical' for entity type 'apple' must start with a leading slash, the current link template is 'path/to/apple'"); + $this->expectException(InvalidLinkTemplateException::class); + $this->expectExceptionMessage("Link template 'canonical' for entity type 'apple' must start with a leading slash, the current link template is 'path/to/apple'"); $this->entityTypeManager->processDefinition($definition, 'apple'); } @@ -384,7 +385,8 @@ class EntityTypeManagerTest extends UnitTestCase { public function testGetDefinitionInvalidException() { $this->setUpEntityTypeDefinitions(); - $this->setExpectedException(PluginNotFoundException::class, 'The "pear" entity type does not exist.'); + $this->expectException(PluginNotFoundException::class); + $this->expectExceptionMessage('The "pear" entity type does not exist.'); $this->entityTypeManager->getDefinition('pear', TRUE); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php index b9554e337099..c047f63a27ce 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php @@ -147,7 +147,8 @@ class EntityTypeRepositoryTest extends UnitTestCase { $apple->getOriginalClass()->willReturn('\Drupal\apple\Entity\Apple'); $banana->getOriginalClass()->willReturn('\Drupal\banana\Entity\Banana'); - $this->setExpectedException(NoCorrespondingEntityClassException::class, 'The \Drupal\pear\Entity\Pear class does not correspond to an entity type.'); + $this->expectException(NoCorrespondingEntityClassException::class); + $this->expectExceptionMessage('The \Drupal\pear\Entity\Pear class does not correspond to an entity type.'); $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\pear\Entity\Pear'); } @@ -168,7 +169,8 @@ class EntityTypeRepositoryTest extends UnitTestCase { 'gala' => $gala, ]); - $this->setExpectedException(AmbiguousEntityClassException::class, 'Multiple entity types found for \Drupal\apple\Entity\Apple.'); + $this->expectException(AmbiguousEntityClassException::class); + $this->expectExceptionMessage('Multiple entity types found for \Drupal\apple\Entity\Apple.'); $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\apple\Entity\Apple'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index 4027647abfd2..f787a720db8b 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -272,7 +272,8 @@ class EntityTypeTest extends UnitTestCase { public function testIdExceedsMaxLength() { $id = $this->randomMachineName(33); $message = 'Attempt to create an entity type with an ID longer than 32 characters: ' . $id; - $this->setExpectedException('Drupal\Core\Entity\Exception\EntityTypeIdLengthException', $message); + $this->expectException('Drupal\Core\Entity\Exception\EntityTypeIdLengthException'); + $this->expectExceptionMessage($message); $this->setUpEntityType(['id' => $id]); } @@ -442,7 +443,7 @@ class EntityTypeTest extends UnitTestCase { */ public function testSetLinkTemplateWithInvalidPath() { $entity_type = $this->setUpEntityType(['id' => $this->randomMachineName()]); - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $entity_type->setLinkTemplate('test', 'invalid-path'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php index dfb3f1681d5b..a4c3018012b9 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php @@ -103,7 +103,8 @@ class EntityUrlTest extends UnitTestCase { public function testToUrlNoId() { $entity = $this->getEntity(EntityBase::class, []); - $this->setExpectedException(EntityMalformedException::class, 'The "' . $this->entityTypeId . '" entity cannot have a URI as it does not have an ID'); + $this->expectException(EntityMalformedException::class); + $this->expectExceptionMessage('The "' . $this->entityTypeId . '" entity cannot have a URI as it does not have an ID'); $entity->toUrl(); } @@ -314,7 +315,8 @@ class EntityUrlTest extends UnitTestCase { $this->entityType->getUriCallback()->willReturn($uri_callback); $link_template = 'canonical'; - $this->setExpectedException(UndefinedLinkTemplateException::class, "No link template '$link_template' found for the '$this->entityTypeId' entity type"); + $this->expectException(UndefinedLinkTemplateException::class); + $this->expectExceptionMessage("No link template '$link_template' found for the '$this->entityTypeId' entity type"); $entity->toUrl($link_template); } diff --git a/core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php b/core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php index 6545542afca0..b74fd60d3ad0 100644 --- a/core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php @@ -285,7 +285,7 @@ class FieldDefinitionTest extends UnitTestCase { public function testInvalidDefaultValueCallback($factory_name) { $definition = $this->initializeFieldUsingFactory($factory_name); // setDefaultValueCallback returns $this. - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $definition->setDefaultValueCallback([get_class($this), 'mockDefaultValueCallback']); } diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 71a0a8246465..6c54cdce5016 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -465,7 +465,8 @@ class KeyValueEntityStorageTest extends UnitTestCase { ->method('set'); $this->keyValueStore->expects($this->never()) ->method('delete'); - $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.'); + $this->expectException(EntityMalformedException::class); + $this->expectExceptionMessage('The entity does not have an ID.'); $this->entityStorage->save($entity); } @@ -485,7 +486,8 @@ class KeyValueEntityStorageTest extends UnitTestCase { ->method('set'); $this->keyValueStore->expects($this->never()) ->method('delete'); - $this->setExpectedException(EntityStorageException::class, "'test_entity_type' entity with ID 'foo' already exists"); + $this->expectException(EntityStorageException::class); + $this->expectExceptionMessage("'test_entity_type' entity with ID 'foo' already exists"); $this->entityStorage->save($entity); } 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 850e4b41107a..aa4929e3dc50 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php @@ -39,7 +39,8 @@ class QueryTest extends UnitTestCase { * @covers ::prepare */ public function testNoBaseTable() { - $this->setExpectedException(QueryException::class, 'No base table for example_entity_query, invalid query.'); + $this->expectException(QueryException::class); + $this->expectExceptionMessage('No base table for example_entity_query, invalid query.'); $this->query->execute(); } @@ -49,7 +50,8 @@ class QueryTest extends UnitTestCase { * @covers ::prepare */ public function testNoRevisionTable() { - $this->setExpectedException(QueryException::class, 'No revision table for example_entity_query, invalid query.'); + $this->expectException(QueryException::class); + $this->expectExceptionMessage('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 5f25ce25f853..04aa9f919827 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php @@ -309,7 +309,8 @@ class DefaultTableMappingTest extends UnitTestCase { ->willReturn(TRUE); $table_mapping = new DefaultTableMapping($this->entityType, $definitions); - $this->setExpectedException(SqlContentEntityStorageException::class, "Column information not available for the 'test' field."); + $this->expectException(SqlContentEntityStorageException::class); + $this->expectExceptionMessage("Column information not available for the 'test' field."); $table_mapping->getFieldColumnName($definitions['test'], $column); } @@ -441,7 +442,8 @@ class DefaultTableMappingTest extends UnitTestCase { */ public function testGetFieldTableNameInvalid() { $table_mapping = new DefaultTableMapping($this->entityType, []); - $this->setExpectedException(SqlContentEntityStorageException::class, "Table information not available for the 'invalid_field_name' field."); + $this->expectException(SqlContentEntityStorageException::class); + $this->expectExceptionMessage("Table information not available for the 'invalid_field_name' field."); $table_mapping->getFieldTableName('invalid_field_name'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php index 5a2eac47f6b0..b81e75e4f9bd 100644 --- a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php @@ -296,7 +296,7 @@ class EntityAdapterUnitTest extends UnitTestCase { * @covers ::get */ public function testGetInvalidField() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->entityAdapter->get('invalid'); } @@ -305,7 +305,7 @@ class EntityAdapterUnitTest extends UnitTestCase { */ public function testGetWithoutData() { $this->entityAdapter->setValue(NULL); - $this->setExpectedException(MissingDataException::class); + $this->expectException(MissingDataException::class); $this->entityAdapter->get('id'); } @@ -328,7 +328,7 @@ class EntityAdapterUnitTest extends UnitTestCase { public function testSetWithoutData() { $this->entityAdapter->setValue(NULL); $id_items = [['value' => $this->id + 1]]; - $this->setExpectedException(MissingDataException::class); + $this->expectException(MissingDataException::class); $this->entityAdapter->set('id', $id_items); } @@ -357,7 +357,7 @@ class EntityAdapterUnitTest extends UnitTestCase { */ public function testToArrayWithoutData() { $this->entityAdapter->setValue(NULL); - $this->setExpectedException(MissingDataException::class); + $this->expectException(MissingDataException::class); $this->entityAdapter->toArray(); } diff --git a/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php b/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php index d2672b344bea..92eeb87a0d5e 100644 --- a/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php +++ b/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php @@ -22,7 +22,8 @@ class EntityReferenceSelectionUnitTest extends UnitTestCase { * @covers ::resolveBackwardCompatibilityConfiguration */ public function testInvalidDefaultConfiguration() { - $this->setExpectedException(\InvalidArgumentException::class, "TestSelectionWithInvalidDefaultConfiguration::defaultConfiguration() should not contain a 'handler_settings' key. All settings should be placed in the root level."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("TestSelectionWithInvalidDefaultConfiguration::defaultConfiguration() should not contain a 'handler_settings' key. All settings should be placed in the root level."); new TestSelectionWithInvalidDefaultConfiguration( [], 'test_selector', @@ -37,7 +38,8 @@ class EntityReferenceSelectionUnitTest extends UnitTestCase { * @covers ::resolveBackwardCompatibilityConfiguration */ public function testMalformedHandlerSettingsValue() { - $this->setExpectedException(\InvalidArgumentException::class, "The setting 'handler_settings' is reserved and cannot be used."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The setting 'handler_settings' is reserved and cannot be used."); new TestSelection( // The deprecated 'handler_setting' should be an array. ['handler_settings' => FALSE], diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php index b86760c25bbe..2c582d0c123a 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php @@ -123,7 +123,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase { $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); - $this->setExpectedException(\PHPUnit_Framework_Error::class); + $this->expectException(\PHPUnit_Framework_Error::class); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); } @@ -171,7 +171,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase { $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); - $this->setExpectedException(\PHPUnit_Framework_Error::class); + $this->expectException(\PHPUnit_Framework_Error::class); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index 0228b1cb32a9..aee20d08b3fa 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -98,7 +98,8 @@ class SpecialAttributesRouteSubscriberTest extends UnitTestCase { $event = new RouteBuildEvent($route_collection, 'test'); $subscriber = new SpecialAttributesRouteSubscriber(); - $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'uses reserved variable names'); + $this->expectException(\PHPUnit_Framework_Error_Warning::class); + $this->expectExceptionMessage('uses reserved variable names'); $subscriber->onAlterRoutes($event); } diff --git a/core/tests/Drupal/Tests/Core/Extension/DependencyTest.php b/core/tests/Drupal/Tests/Core/Extension/DependencyTest.php index d1d403f04d8b..6551aaf58db9 100644 --- a/core/tests/Drupal/Tests/Core/Extension/DependencyTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/DependencyTest.php @@ -77,7 +77,8 @@ class DependencyTest extends UnitTestCase { */ public function testOffsetGetException() { $dependency = new Dependency('views', 'drupal', '>8.x-1.1'); - $this->setExpectedException(\InvalidArgumentException::class, 'The does_not_exist key is not supported'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The does_not_exist key is not supported'); $dependency['does_not_exist']; } @@ -87,7 +88,8 @@ class DependencyTest extends UnitTestCase { */ public function testOffsetUnset() { $dependency = new Dependency('views', 'drupal', '>8.x-1.1'); - $this->setExpectedException(\BadMethodCallException::class, 'Drupal\Core\Extension\Dependency::offsetUnset() is not supported'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Drupal\Core\Extension\Dependency::offsetUnset() is not supported'); unset($dependency['name']); } @@ -97,7 +99,8 @@ class DependencyTest extends UnitTestCase { */ public function testOffsetSet() { $dependency = new Dependency('views', 'drupal', '>8.x-1.1'); - $this->setExpectedException(\BadMethodCallException::class, 'Drupal\Core\Extension\Dependency::offsetSet() is not supported'); + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Drupal\Core\Extension\Dependency::offsetSet() is not supported'); $dependency['name'] = 'foo'; } diff --git a/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php b/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php index 7f73fe27ea7f..fcea71b3da0e 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php @@ -32,7 +32,7 @@ class ExtensionListTest extends UnitTestCase { $extension_discovery->scan('test_extension')->willReturn([]); $test_extension_list->setExtensionDiscovery($extension_discovery->reveal()); - $this->setExpectedException(UnknownExtensionException::class); + $this->expectException(UnknownExtensionException::class); $test_extension_list->getName('test_name'); } @@ -56,7 +56,7 @@ class ExtensionListTest extends UnitTestCase { $extension_discovery->scan('test_extension')->willReturn([]); $test_extension_list->setExtensionDiscovery($extension_discovery->reveal()); - $this->setExpectedException(UnknownExtensionException::class); + $this->expectException(UnknownExtensionException::class); $test_extension_list->get('test_name'); } diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php index 796a916db9b6..ee8a45e90048 100644 --- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -71,7 +71,8 @@ BROKEN_INFO; ], ]); $filename = vfsStream::url('modules/fixtures/broken.info.txt'); - $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'broken.info.txt'); + $this->expectException('\Drupal\Core\Extension\InfoParserException'); + $this->expectExceptionMessage('broken.info.txt'); $this->infoParser->parse($filename); } @@ -96,7 +97,8 @@ MISSINGKEYS; ], ]); $filename = vfsStream::url('modules/fixtures/missing_keys.info.txt'); - $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'Missing required keys (type, core, name) in vfs://modules/fixtures/missing_keys.info.txt'); + $this->expectException('\Drupal\Core\Extension\InfoParserException'); + $this->expectExceptionMessage('Missing required keys (type, core, name) in vfs://modules/fixtures/missing_keys.info.txt'); $this->infoParser->parse($filename); } @@ -124,7 +126,8 @@ MISSINGKEY; ], ]); $filename = vfsStream::url('modules/fixtures/missing_key.info.txt'); - $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'Missing required keys (type) in vfs://modules/fixtures/missing_key.info.txt'); + $this->expectException('\Drupal\Core\Extension\InfoParserException'); + $this->expectExceptionMessage('Missing required keys (type) in vfs://modules/fixtures/missing_key.info.txt'); $this->infoParser->parse($filename); } diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php index 134032bbb1e0..36973a8b2a67 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php @@ -165,7 +165,7 @@ class ModuleHandlerTest extends UnitTestCase { * @covers ::getModule */ public function testGetModuleWithNonExistingModule() { - $this->setExpectedException(UnknownExtensionException::class); + $this->expectException(UnknownExtensionException::class); $this->getModuleHandler()->getModule('claire_alice_watch_my_little_pony_module_that_does_not_exist'); } diff --git a/core/tests/Drupal/Tests/Core/Field/FieldInputValueNormalizerTraitTest.php b/core/tests/Drupal/Tests/Core/Field/FieldInputValueNormalizerTraitTest.php index 2d85b3aac73b..b6bc4dbf7f9c 100644 --- a/core/tests/Drupal/Tests/Core/Field/FieldInputValueNormalizerTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Field/FieldInputValueNormalizerTraitTest.php @@ -84,7 +84,8 @@ class FieldInputValueNormalizerTraitTest extends UnitTestCase { * @covers ::normalizeValue */ public function testScalarWithNoMainProperty() { - $this->setExpectedException(\InvalidArgumentException::class, 'A main property is required when normalizing scalar field values.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('A main property is required when normalizing scalar field values.'); $value = 'foo'; $this->normalizeValue($value, NULL); } diff --git a/core/tests/Drupal/Tests/Core/File/FileSystemTest.php b/core/tests/Drupal/Tests/Core/File/FileSystemTest.php index 46ece839f612..fe69183a8567 100644 --- a/core/tests/Drupal/Tests/Core/File/FileSystemTest.php +++ b/core/tests/Drupal/Tests/Core/File/FileSystemTest.php @@ -162,7 +162,8 @@ class FileSystemTest extends UnitTestCase { public function testInvalidUTF8() { vfsStream::setup('dir'); $filename = "a\xFFsdf\x80€" . '.txt'; - $this->setExpectedException(FileException::class, "Invalid filename '$filename'"); + $this->expectException(FileException::class); + $this->expectExceptionMessage("Invalid filename '$filename'"); $this->fileSystem->createFilename($filename, 'vfs://dir'); } diff --git a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php index 4d95e0b0bcca..3c11f43a381a 100644 --- a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php @@ -48,7 +48,8 @@ class ConfigFormBaseTraitTest extends UnitTestCase { $config_method->setAccessible(TRUE); // There is no config factory available this should result in an exception. - $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('No config factory available for ConfigFormBaseTrait'); $config_method->invoke($trait, 'editable.config'); } @@ -62,7 +63,8 @@ class ConfigFormBaseTraitTest extends UnitTestCase { $config_method->setAccessible(TRUE); // There is no config factory available this should result in an exception. - $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('No config factory available for ConfigFormBaseTrait'); $config_method->invoke($trait, 'editable.config'); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php index a6bde06aa7ce..48a6ea4a0c01 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php @@ -55,7 +55,7 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { $commands = []; $expected = []; - $this->setExpectedException(HttpException::class); + $this->expectException(HttpException::class); $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands); } @@ -74,7 +74,7 @@ class FormAjaxResponseBuilderTest extends UnitTestCase { $commands = []; $expected = []; - $this->setExpectedException(HttpException::class); + $this->expectException(HttpException::class); $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index c22f1886940a..a21ec29b9873 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -57,7 +57,8 @@ class FormBuilderTest extends FormTestBase { public function testGetFormIdWithString() { $form_arg = 'foo'; $form_state = new FormState(); - $this->setExpectedException(\InvalidArgumentException::class, 'The form argument foo is not a valid form.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The form argument foo is not a valid form.'); $this->formBuilder->getFormId($form_arg, $form_state); } @@ -215,7 +216,8 @@ class FormBuilderTest extends FormTestBase { */ public function testGetFormWithString() { $form_id = 'test_form_id'; - $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The form argument test_form_id is not a valid form.'); $this->formBuilder->getForm($form_id); } @@ -253,7 +255,8 @@ class FormBuilderTest extends FormTestBase { */ public function testBuildFormWithString() { $form_id = 'test_form_id'; - $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The form argument test_form_id is not a valid form.'); $this->formBuilder->getForm($form_id); } @@ -545,7 +548,7 @@ class FormBuilderTest extends FormTestBase { $form_arg = $this->getMockForm('test_form_id'); $form_state = new FormState(); - $this->setExpectedException(BrokenPostRequestException::class); + $this->expectException(BrokenPostRequestException::class); $this->formBuilder->buildForm($form_arg, $form_state); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php index 8d5f97c6c7d2..4fd1e15a4b35 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php @@ -162,7 +162,7 @@ class FormStateDecoratorBaseTest extends UnitTestCase { public function testSetCachedWithLogicException($cache) { $this->decoratedFormState->setCached($cache) ->willThrow(\LogicException::class); - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); $this->formStateDecoratorBase->setCached($cache); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php index aa60d61006ad..0a5e627a19fb 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php @@ -136,7 +136,8 @@ class FormStateTest extends UnitTestCase { public function testFormErrorsDuringSubmission() { $form_state = new FormState(); $form_state->setValidationComplete(); - $this->setExpectedException(\LogicException::class, 'Form errors cannot be set after form validation has finished.'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Form errors cannot be set after form validation has finished.'); $form_state->setErrorByName('test', 'message'); } @@ -317,7 +318,8 @@ class FormStateTest extends UnitTestCase { public function testSetCachedGet() { $form_state = new FormState(); $form_state->setRequestMethod('GET'); - $this->setExpectedException(\LogicException::class, 'Form state caching on GET requests is not allowed.'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Form state caching on GET requests is not allowed.'); $form_state->setCached(); } diff --git a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php index 50124d01f709..f78ec5bc9a15 100644 --- a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php @@ -101,7 +101,7 @@ class SubformStateTest extends UnitTestCase { * @param string $expected */ public function testGetValuesBroken(array $parents, $expected) { - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $this->testGetValues($parents, $expected); } @@ -162,7 +162,7 @@ class SubformStateTest extends UnitTestCase { * @dataProvider providerTestGetValueBroken */ public function testGetValueBroken(array $parents, $key, $expected, $default = NULL) { - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $this->testGetValue($parents, $key, $expected, $default); } @@ -217,7 +217,7 @@ class SubformStateTest extends UnitTestCase { * @dataProvider providerTestSetValuesBroken */ public function testSetValuesBroken($parents, $new_values, $expected) { - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $this->testSetValues($parents, $new_values, $expected); } diff --git a/core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php index 139200cabeab..a6717326b9cb 100644 --- a/core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php @@ -204,7 +204,8 @@ class LayoutPluginManagerTest extends UnitTestCase { */ public function testProcessDefinition() { $this->moduleHandler->alter('layout', Argument::type('array'))->shouldNotBeCalled(); - $this->setExpectedException(InvalidPluginDefinitionException::class, 'The "module_a_derived_layout:array_based" layout definition must extend ' . LayoutDefinition::class); + $this->expectException(InvalidPluginDefinitionException::class); + $this->expectExceptionMessage('The "module_a_derived_layout:array_based" layout definition must extend ' . LayoutDefinition::class); $module_a_provided_layout = <<<'EOS' module_a_derived_layout: deriver: \Drupal\Tests\Core\Layout\LayoutDeriver diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index 094318c018b3..bb5e98ee9074 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -212,7 +212,7 @@ class ContextualLinkManagerTest extends UnitTestCase { 'group' => 'example', 'id' => 'test_plugin', ]; - $this->setExpectedException(PluginException::class); + $this->expectException(PluginException::class); $this->contextualLinkManager->processDefinition($definition, 'test_plugin'); } @@ -227,7 +227,7 @@ class ContextualLinkManagerTest extends UnitTestCase { 'route_name' => 'example', 'id' => 'test_plugin', ]; - $this->setExpectedException(PluginException::class); + $this->expectException(PluginException::class); $this->contextualLinkManager->processDefinition($definition, 'test_plugin'); } diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php index a887cd6aa30e..1d804cd1cdf4 100644 --- a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php +++ b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php @@ -75,7 +75,7 @@ class ChainRequestPolicyTest extends UnitTestCase { $this->policy->addPolicy($rule); - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $this->policy->check($this->request); } diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php index 8e98e8f3dd63..051f2c2f1c43 100644 --- a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php +++ b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php @@ -84,7 +84,7 @@ class ChainResponsePolicyTest extends UnitTestCase { $this->policy->addPolicy($rule); - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $this->policy->check($this->response, $this->request); } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php index 8480c969df98..365b6c200065 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php @@ -333,7 +333,7 @@ class EntityConverterTest extends UnitTestCase { ->with($plugin_id, 'id', $contexts) ->willThrowException(new PluginNotFoundException($plugin_id)); - $this->setExpectedException(PluginNotFoundException::class); + $this->expectException(PluginNotFoundException::class); $this->entityConverter->convert('id', ['type' => 'entity:' . $plugin_id], 'foo', ['foo' => 'id']); } @@ -342,7 +342,8 @@ class EntityConverterTest extends UnitTestCase { * Tests the convert() method with an invalid dynamic entity type. */ public function testConvertWithInvalidDynamicEntityType() { - $this->setExpectedException(ParamNotConvertedException::class, 'The "foo" parameter was not converted because the "invalid_id" parameter is missing.'); + $this->expectException(ParamNotConvertedException::class); + $this->expectExceptionMessage('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/EntityRevisionParamConverterTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/EntityRevisionParamConverterTest.php index f9f68fe77095..212b53344115 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/EntityRevisionParamConverterTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/EntityRevisionParamConverterTest.php @@ -109,7 +109,7 @@ class EntityRevisionParamConverterTest extends UnitTestCase { $entity_repository = $this->prophesize(EntityRepositoryInterface::class); $converter = new EntityRevisionParamConverter($entity_type_manager->reveal(), $entity_repository->reveal()); - $this->setExpectedException(InvalidPluginDefinitionException::class); + $this->expectException(InvalidPluginDefinitionException::class); $converter->convert('valid_id', ['type' => 'entity_revision:invalid_entity_type_id'], 'foo', ['foo' => 'valid_id']); } @@ -119,7 +119,8 @@ class EntityRevisionParamConverterTest extends UnitTestCase { * @covers ::convert */ public function testConvertWithInvalidType() { - $this->setExpectedException(ParamNotConvertedException::class, 'The type definition "entity_revision_{entity_type_id}" is invalid. The expected format is "entity_revision:".'); + $this->expectException(ParamNotConvertedException::class); + $this->expectExceptionMessage('The type definition "entity_revision_{entity_type_id}" is invalid. The expected format is "entity_revision:".'); $this->converter->convert('valid_id', ['type' => 'entity_revision_{entity_type_id}'], 'foo', ['foo' => 'valid_id']); } @@ -129,7 +130,8 @@ class EntityRevisionParamConverterTest extends UnitTestCase { * @covers ::convert */ public function testConvertWithInvalidDynamicEntityType() { - $this->setExpectedException(ParamNotConvertedException::class, 'The "foo" parameter was not converted because the "invalid_entity_type_id" parameter is missing.'); + $this->expectException(ParamNotConvertedException::class); + $this->expectExceptionMessage('The "foo" parameter was not converted because the "invalid_entity_type_id" parameter is missing.'); $this->converter->convert('valid_id', ['type' => 'entity_revision:{invalid_entity_type_id}'], 'foo', ['foo' => 'valid_id']); } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php index b6bd316e7556..f6f2767516c8 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php @@ -54,7 +54,7 @@ class ParamConverterManagerTest extends UnitTestCase { * @covers ::getConverter */ public function testGetConverterException() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->manager->getConverter('undefined.converter'); } @@ -243,7 +243,8 @@ class ParamConverterManagerTest extends UnitTestCase { ->will($this->returnValue(NULL)); $this->manager->addConverter($converter, 'test_convert'); - $this->setExpectedException(ParamNotConvertedException::class, 'The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")'); + $this->expectException(ParamNotConvertedException::class); + $this->expectExceptionMessage('The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")'); $this->manager->convert($defaults); } diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php index 267947419953..606ffae69894 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php @@ -64,7 +64,7 @@ class PathProcessorFrontTest extends UnitTestCase { $config->get('page.front') ->willReturn(''); $processor = new PathProcessorFront($config_factory->reveal()); - $this->setExpectedException(NotFoundHttpException::class); + $this->expectException(NotFoundHttpException::class); $processor->processInbound('/', new Request()); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextAwarePluginBaseTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextAwarePluginBaseTest.php index 66e54b215759..b3c0d694e874 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextAwarePluginBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextAwarePluginBaseTest.php @@ -48,7 +48,8 @@ class ContextAwarePluginBaseTest extends UnitTestCase { */ public function testGetContextDefinition() { // The context is not defined, so an exception will be thrown. - $this->setExpectedException(ContextException::class, 'The person context is not a valid context.'); + $this->expectException(ContextException::class); + $this->expectExceptionMessage('The person context is not a valid context.'); $this->plugin->getContextDefinition('person'); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php index 72dfc3cf9d9f..d0ddc85b46f9 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php @@ -153,7 +153,7 @@ class ContextDefinitionTest extends UnitTestCase { ->method('getDataType') ->willReturn($data_type); - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $mock_context_definition->getDataDefinition(); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php index 6fe21c18e9d5..dfdd12753d17 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php @@ -69,7 +69,8 @@ class LazyContextRepositoryTest extends UnitTestCase { */ public function testInvalidContextId() { $lazy_context_repository = new LazyContextRepository($this->container, ['test_provider']); - $this->setExpectedException(\InvalidArgumentException::class, 'You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); $lazy_context_repository->getRuntimeContexts(['test_context', '@test_provider:test_context1']); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php index 3d28eea9374b..713ab526d9aa 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php @@ -382,7 +382,8 @@ class ContextHandlerTest extends UnitTestCase { ->method('getContext') ->willThrowException(new ContextException()); - $this->setExpectedException(MissingValueContextException::class, 'Required contexts without a value: hit'); + $this->expectException(MissingValueContextException::class); + $this->expectExceptionMessage('Required contexts without a value: hit'); $this->contextHandler->applyContextMapping($plugin, $contexts); } @@ -451,7 +452,8 @@ class ContextHandlerTest extends UnitTestCase { $plugin->expects($this->never()) ->method('setContext'); - $this->setExpectedException(MissingValueContextException::class, 'Required contexts without a value: hit'); + $this->expectException(MissingValueContextException::class); + $this->expectExceptionMessage('Required contexts without a value: hit'); $this->contextHandler->applyContextMapping($plugin, $contexts); } @@ -551,7 +553,8 @@ class ContextHandlerTest extends UnitTestCase { $plugin->expects($this->never()) ->method('setContext'); - $this->setExpectedException(ContextException::class, 'Assigned contexts were not satisfied: miss'); + $this->expectException(ContextException::class); + $this->expectExceptionMessage('Assigned contexts were not satisfied: miss'); $this->contextHandler->applyContextMapping($plugin, $contexts, ['miss' => 'name']); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php index 7cc4db008e3e..363c9afc3271 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php @@ -51,7 +51,8 @@ class DefaultLazyPluginCollectionTest extends LazyPluginCollectionTestBase { */ public function testGetNotExistingPlugin() { $this->setupPluginCollection(); - $this->setExpectedException(PluginNotFoundException::class, "Plugin ID 'pear' was not found."); + $this->expectException(PluginNotFoundException::class); + $this->expectExceptionMessage("Plugin ID 'pear' was not found."); $this->defaultPluginCollection->get('pear'); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 3f21a2aedd72..7f5ca701456e 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -139,7 +139,8 @@ class DefaultPluginManagerTest extends UnitTestCase { public function testGetDefinitionPluginNotFoundException() { $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions); - $this->setExpectedException(PluginNotFoundException::class, 'The "missing" plugin does not exist. Valid plugin IDs for Drupal\Tests\Core\Plugin\TestPluginManager are: apple, banana'); + $this->expectException(PluginNotFoundException::class); + $this->expectExceptionMessage('The "missing" plugin does not exist. Valid plugin IDs for Drupal\Tests\Core\Plugin\TestPluginManager are: apple, banana'); $plugin_manager->getDefinition('missing'); } @@ -304,7 +305,8 @@ class DefaultPluginManagerTest extends UnitTestCase { $this->expectedDefinitions['banana']['provider'] = 'plugin_test'; $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); - $this->setExpectedException(PluginException::class, 'Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); + $this->expectException(PluginException::class); + $this->expectExceptionMessage('Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); $plugin_manager->createInstance('kale'); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php index 90c7ab772b2e..e5d18c0d8e9a 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php @@ -126,7 +126,8 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); - $this->setExpectedException(InvalidDeriverException::class, 'Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); + $this->expectException(InvalidDeriverException::class); + $this->expectExceptionMessage('Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); $discovery->getDefinitions(); } @@ -147,7 +148,8 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { ->will($this->returnValue($definitions)); $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); - $this->setExpectedException(InvalidDeriverException::class, 'Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); + $this->expectException(InvalidDeriverException::class); + $this->expectExceptionMessage('Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.'); $discovery->getDefinitions(); } @@ -168,7 +170,8 @@ class DerivativeDiscoveryDecoratorTest extends UnitTestCase { ->will($this->returnValue($definitions)); $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain); - $this->setExpectedException(InvalidDeriverException::class, 'Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.'); + $this->expectException(InvalidDeriverException::class); + $this->expectExceptionMessage('Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.'); $discovery->getDefinitions(); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php index 844eb7b007ec..bce9ec8cb6df 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php @@ -125,7 +125,7 @@ class HookDiscoveryTest extends UnitTestCase { ->method('getImplementations') ->will($this->returnValue([])); - $this->setExpectedException(PluginNotFoundException::class); + $this->expectException(PluginNotFoundException::class); $this->hookDiscovery->getDefinition('test_non_existant', TRUE); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php b/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php index fc4b77aebe17..fbe886a77379 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php @@ -125,7 +125,8 @@ class PluginFormFactoryTest extends UnitTestCase { * @covers ::createInstance */ public function testCreateInstanceDefinitionException() { - $this->setExpectedException(InvalidPluginDefinitionException::class, 'The "the_plugin_id" plugin did not specify a "anything" form class'); + $this->expectException(InvalidPluginDefinitionException::class); + $this->expectExceptionMessage('The "the_plugin_id" plugin did not specify a "anything" form class'); $plugin = $this->prophesize(PluginWithFormsInterface::class); $plugin->getPluginId()->willReturn('the_plugin_id'); @@ -139,7 +140,8 @@ class PluginFormFactoryTest extends UnitTestCase { * @covers ::createInstance */ public function testCreateInstanceInvalidException() { - $this->setExpectedException(InvalidPluginDefinitionException::class, 'The "the_plugin_id" plugin did not specify a valid "invalid" form class, must implement \Drupal\Core\Plugin\PluginFormInterface'); + $this->expectException(InvalidPluginDefinitionException::class); + $this->expectExceptionMessage('The "the_plugin_id" plugin did not specify a valid "invalid" form class, must implement \Drupal\Core\Plugin\PluginFormInterface'); $expected = new \stdClass(); $this->classResolver->getInstanceFromDefinition(get_class($expected))->willReturn($expected); diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php index 818244832485..9d4342d1d731 100644 --- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php +++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php @@ -106,7 +106,8 @@ class ElementTest extends UnitTestCase { $element = [ 'foo' => 'bar', ]; - $this->setExpectedException(\PHPUnit_Framework_Error::class, '"foo" is an invalid render array key'); + $this->expectException(\PHPUnit_Framework_Error::class); + $this->expectExceptionMessage('"foo" is an invalid render array key'); Element::children($element); } diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php index 776b79446dfa..00e5d8b2589b 100644 --- a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php @@ -128,7 +128,8 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { ]; $chained_placeholder_strategy = new ChainedPlaceholderStrategy(); - $this->setExpectedException(\AssertionError::class, 'At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.'); + $this->expectException(\AssertionError::class); + $this->expectExceptionMessage('At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.'); $chained_placeholder_strategy->processPlaceholders($placeholders); } @@ -152,7 +153,8 @@ class ChainedPlaceholderStrategyTest extends UnitTestCase { $chained_placeholder_strategy = new ChainedPlaceholderStrategy(); $chained_placeholder_strategy->addPlaceholderStrategy($rogue_strategy); - $this->setExpectedException(\AssertionError::class, 'Processed placeholders must be a subset of all placeholders.'); + $this->expectException(\AssertionError::class); + $this->expectExceptionMessage('Processed placeholders must be a subset of all placeholders.'); $chained_placeholder_strategy->processPlaceholders($placeholders); } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php index 202c9efa7160..1c7fd44693de 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php @@ -624,7 +624,8 @@ class RendererBubblingTest extends RendererTestBase { ], '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingCacheOverwritePrerender'], ]; - $this->setExpectedException(\LogicException::class, 'Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.'); $this->renderer->renderRoot($data); } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php index 36137b4a00d0..d53fba091440 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php @@ -852,7 +852,8 @@ class RendererPlaceholdersTest extends RendererTestBase { $element = []; $element['#lazy_builder'] = '\Drupal\Tests\Core\Render\PlaceholdersTest::callback'; - $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value.'); + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('The #lazy_builder property must have an array as a value.'); $this->renderer->renderRoot($element); } @@ -864,7 +865,8 @@ class RendererPlaceholdersTest extends RendererTestBase { $element = []; $element['#lazy_builder'] = ['\Drupal\Tests\Core\Render\PlaceholdersTest::callback', 'arg1', 'arg2']; - $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback.'); + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback.'); $this->renderer->renderRoot($element); } @@ -911,7 +913,8 @@ class RendererPlaceholdersTest extends RendererTestBase { ], ]; - $this->setExpectedException(\DomainException::class, "A #lazy_builder callback's context may only contain scalar values or NULL."); + $this->expectException(\DomainException::class); + $this->expectExceptionMessage("A #lazy_builder callback's context may only contain scalar values or NULL."); $this->renderer->renderRoot($element); } @@ -925,7 +928,8 @@ class RendererPlaceholdersTest extends RendererTestBase { $element['child_a']['#markup'] = 'Oh hai!'; $element['child_b']['#markup'] = 'kthxbai'; - $this->setExpectedException(\DomainException::class, 'When a #lazy_builder callback is specified, no children can exist; all children must be generated by the #lazy_builder callback. You specified the following children: child_a, child_b.'); + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('When a #lazy_builder callback is specified, no children can exist; all children must be generated by the #lazy_builder callback. You specified the following children: child_a, child_b.'); $this->renderer->renderRoot($element); } @@ -939,7 +943,8 @@ class RendererPlaceholdersTest extends RendererTestBase { $element['#llama'] = '#awesome'; $element['#piglet'] = '#cute'; - $this->setExpectedException(\DomainException::class, 'When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #llama, #piglet.'); + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #llama, #piglet.'); $this->renderer->renderRoot($element); } @@ -951,7 +956,8 @@ class RendererPlaceholdersTest extends RendererTestBase { $element = []; $element['#create_placeholder'] = TRUE; - $this->setExpectedException(\LogicException::class, 'When #create_placeholder is set, a #lazy_builder callback must be present as well.'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('When #create_placeholder is set, a #lazy_builder callback must be present as well.'); $this->renderer->renderRoot($element); } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php index 7e4b83345eb9..0517e659c4f3 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php @@ -39,7 +39,7 @@ class RendererRecursionTest extends RendererTestBase { $complex_child = $complex_child_template; $callable = function () use ($renderer, $complex_child) { - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); $renderer->renderRoot($complex_child); }; diff --git a/core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php b/core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php index 8d6bf813828c..595501727d06 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php @@ -98,7 +98,8 @@ class AcceptHeaderMatcherTest extends UnitTestCase { $request = Request::create('path/two', 'GET'); $request->headers->set('Accept', 'application/json, text/xml;q=0.9'); $request->setRequestFormat('json'); - $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified formats application/json text/xml'); + $this->expectException(NotAcceptableHttpException::class); + $this->expectExceptionMessage('No route found for the specified formats application/json text/xml'); $this->matcher->filter($routes, $request); } diff --git a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php index 204c18468bb2..735b3ea3a5fc 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php @@ -96,7 +96,7 @@ class AccessAwareRouterTest extends UnitTestCase { ->method('checkRequest') ->with($request) ->willReturn($access_result); - $this->setExpectedException(AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $this->router->matchRequest($request); } @@ -112,7 +112,8 @@ class AccessAwareRouterTest extends UnitTestCase { ->method('checkRequest') ->with($request) ->willReturn($access_result); - $this->setExpectedException(AccessDeniedHttpException::class, $reason); + $this->expectException(AccessDeniedHttpException::class); + $this->expectExceptionMessage($reason); $this->router->matchRequest($request); } diff --git a/core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php b/core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php index 777073ed03bc..1ae593bfda70 100644 --- a/core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php @@ -112,7 +112,8 @@ class ContentTypeHeaderMatcherTest extends UnitTestCase { $routes = $this->fixtures->contentRouteCollection(); $request = Request::create('path/two', 'POST'); $request->headers->set('Content-type', 'application/hal+json'); - $this->setExpectedException(UnsupportedMediaTypeHttpException::class, 'No route found that matches "Content-Type: application/hal+json"'); + $this->expectException(UnsupportedMediaTypeHttpException::class); + $this->expectExceptionMessage('No route found that matches "Content-Type: application/hal+json"'); $matcher->filter($routes, $request); } @@ -128,7 +129,8 @@ class ContentTypeHeaderMatcherTest extends UnitTestCase { $request = Request::create('path/two', 'POST'); // Delete all request headers that Request::create() sets by default. $request->headers = new ParameterBag(); - $this->setExpectedException(UnsupportedMediaTypeHttpException::class, 'No "Content-Type" request header specified'); + $this->expectException(UnsupportedMediaTypeHttpException::class); + $this->expectExceptionMessage('No "Content-Type" request header specified'); $matcher->filter($routes, $request); } diff --git a/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php index 2e411b2b8545..563d6065a4de 100644 --- a/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php @@ -56,7 +56,7 @@ class MethodFilterTest extends UnitTestCase { $collection = new RouteCollection(); $collection->add('test_route.get', new Route('/test', [], [], [], '', [], ['GET'])); - $this->setExpectedException(MethodNotAllowedException::class); + $this->expectException(MethodNotAllowedException::class); $method_filter = new MethodFilter(); $method_filter->filter($collection, $request); @@ -72,7 +72,7 @@ class MethodFilterTest extends UnitTestCase { $collection->add('test_route2.get', new Route('/test', [], [], [], '', [], ['GET'])); $collection->add('test_route3.get', new Route('/test', [], [], [], '', [], ['GET'])); - $this->setExpectedException(MethodNotAllowedException::class); + $this->expectException(MethodNotAllowedException::class); $method_filter = new MethodFilter(); $method_filter->filter($collection, $request); diff --git a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php index 83d0505f15c7..6eec8fdf9262 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php @@ -79,7 +79,8 @@ class RequestFormatRouteFilterTest extends UnitTestCase { $request = Request::create('test?_format=xml', 'GET'); $request->setRequestFormat('xml'); $route_filter = new RequestFormatRouteFilter(); - $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified format xml.'); + $this->expectException(NotAcceptableHttpException::class); + $this->expectExceptionMessage('No route found for the specified format xml.'); $route_filter->filter($collection, $request); } @@ -87,7 +88,8 @@ class RequestFormatRouteFilterTest extends UnitTestCase { * @covers ::filter */ public function testNoRouteFoundWhenNoRequestFormatAndSingleRouteWithMultipleFormats() { - $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified format html.'); + $this->expectException(NotAcceptableHttpException::class); + $this->expectExceptionMessage('No route found for the specified format html.'); $url = $this->prophesize(GeneratedUrl::class); $url_assembler = $this->prophesize(UnroutedUrlAssemblerInterface::class); diff --git a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php index ded951b2d654..cb491441a030 100644 --- a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php @@ -39,7 +39,7 @@ class TrustedRedirectResponseTest extends UnitTestCase { $redirect_response = new TrustedRedirectResponse('/example'); - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $redirect_response->setTargetUrl('http://evil-url.com/example'); } diff --git a/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php b/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php index 3e6d501723d5..d793524c333a 100644 --- a/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php +++ b/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php @@ -35,7 +35,7 @@ class AccountProxyTest extends UnitTestCase { * @covers ::setInitialAccountId */ public function testSetInitialAccountIdException() { - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); $account_proxy = new AccountProxy(); $current_user = $this->prophesize(AccountInterface::class); $account_proxy->setAccount($current_user->reveal()); diff --git a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php index f72e4ce9f0e7..82f98f5dcc1f 100644 --- a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php +++ b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php @@ -84,7 +84,7 @@ class SettingsTest extends UnitTestCase { public function testGetHashSaltEmpty(array $config) { // Re-create settings with no 'hash_salt' key. $settings = new Settings($config); - $this->setExpectedException(\RuntimeException::class); + $this->expectException(\RuntimeException::class); $settings->getHashSalt(); } @@ -107,7 +107,7 @@ class SettingsTest extends UnitTestCase { * @covers ::__sleep */ public function testSerialize() { - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); serialize(new Settings([])); } @@ -137,7 +137,7 @@ class SettingsTest extends UnitTestCase { $instace_property->setAccessible(TRUE); $instace_property->setValue(NULL); - $this->setExpectedException(\BadMethodCallException::class); + $this->expectException(\BadMethodCallException::class); $settings->getInstance(); } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php index fe77a4e7d9ec..29720cd2b2aa 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php @@ -86,7 +86,8 @@ class TranslatableMarkupTest extends UnitTestCase { */ public function testIsStringAssertion() { $translation = $this->getStringTranslationStub(); - $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('$string ("foo") must be a string.'); new TranslatableMarkup(new TranslatableMarkup('foo', [], [], $translation)); } @@ -95,7 +96,8 @@ class TranslatableMarkupTest extends UnitTestCase { */ public function testIsStringAssertionWithFormattableMarkup() { $formattable_string = new FormattableMarkup('@bar', ['@bar' => 'foo']); - $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('$string ("foo") must be a string.'); new TranslatableMarkup($formattable_string); } diff --git a/core/tests/Drupal/Tests/Core/TempStore/PrivateTempStoreTest.php b/core/tests/Drupal/Tests/Core/TempStore/PrivateTempStoreTest.php index 5a44e39bfbb1..a6173d9ac62d 100644 --- a/core/tests/Drupal/Tests/Core/TempStore/PrivateTempStoreTest.php +++ b/core/tests/Drupal/Tests/Core/TempStore/PrivateTempStoreTest.php @@ -139,7 +139,7 @@ class PrivateTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); + $this->expectException(TempStoreException::class); $this->tempStore->set('test', 'value'); } @@ -274,7 +274,7 @@ class PrivateTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); + $this->expectException(TempStoreException::class); $this->tempStore->delete('test'); } diff --git a/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php b/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php index 38f712de6b73..37dce4bfca91 100644 --- a/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php +++ b/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php @@ -152,7 +152,7 @@ class SharedTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); + $this->expectException(TempStoreException::class); $this->tempStore->set('test', 'value'); } @@ -347,7 +347,7 @@ class SharedTempStoreTest extends UnitTestCase { $this->keyValue->expects($this->once()) ->method('getCollectionName'); - $this->setExpectedException(TempStoreException::class); + $this->expectException(TempStoreException::class); $this->tempStore->delete('test'); } diff --git a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php index 21b1f778d0af..019acbe1dcad 100644 --- a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php +++ b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php @@ -48,7 +48,7 @@ class TwigSandboxTest extends UnitTestCase { */ public function testEntityDangerousMethods($template) { $entity = $this->createMock('Drupal\Core\Entity\EntityInterface'); - $this->setExpectedException(\Twig_Sandbox_SecurityError::class); + $this->expectException(\Twig_Sandbox_SecurityError::class); $this->twig->render($template, ['entity' => $entity]); } diff --git a/core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php b/core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php index e130e07dba9d..b0708408b5c5 100644 --- a/core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php @@ -75,7 +75,8 @@ class BrowserTestBaseTest extends UnitTestCase { $ref_gethttpclient = new \ReflectionMethod($btb, 'getHttpClient'); $ref_gethttpclient->setAccessible(TRUE); - $this->setExpectedException(\RuntimeException::class, 'The Mink client type stdClass does not support getHttpClient().'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The Mink client type stdClass does not support getHttpClient().'); $ref_gethttpclient->invoke($btb); } diff --git a/core/tests/Drupal/Tests/Core/Test/TestDatabaseTest.php b/core/tests/Drupal/Tests/Core/Test/TestDatabaseTest.php index 8a6fdc83193c..6e9e63ddc357 100644 --- a/core/tests/Drupal/Tests/Core/Test/TestDatabaseTest.php +++ b/core/tests/Drupal/Tests/Core/Test/TestDatabaseTest.php @@ -15,7 +15,8 @@ class TestDatabaseTest extends UnitTestCase { * @covers ::__construct */ public function testConstructorException() { - $this->setExpectedException(\InvalidArgumentException::class, "Invalid database prefix: blah1253"); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Invalid database prefix: blah1253"); new TestDatabase('blah1253'); } diff --git a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php index 44292471120a..f355f794b1ec 100644 --- a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php @@ -97,7 +97,7 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * @covers ::validate */ public function testValidateWithGroups() { - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); $this->recursiveValidator->validate('test', NULL, 'test group'); } @@ -107,7 +107,7 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * @covers ::validate */ public function testValidateWithoutTypedData() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->recursiveValidator->validate('test'); } @@ -235,7 +235,7 @@ class RecursiveContextualValidatorTest extends UnitTestCase { ], ]; $typed_data = $this->setupTypedData($tree, 'test_name'); - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); $this->recursiveValidator->validateProperty($typed_data, 'key1', 'test group'); } @@ -245,7 +245,7 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * @dataProvider providerTestValidatePropertyWithInvalidObjects */ public function testValidatePropertyWithInvalidObjects($object) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->recursiveValidator->validateProperty($object, 'key1', NULL); } @@ -287,7 +287,7 @@ class RecursiveContextualValidatorTest extends UnitTestCase { * @dataProvider providerTestValidatePropertyWithInvalidObjects */ public function testValidatePropertyValueWithInvalidObjects($object) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $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 d1219da001af..cf78e76a1312 100644 --- a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php +++ b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php @@ -103,7 +103,7 @@ class UnroutedUrlTest extends UnitTestCase { * @dataProvider providerFromInvalidUri */ public function testFromInvalidUri($uri) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $url = Url::fromUri($uri); } @@ -141,7 +141,7 @@ class UnroutedUrlTest extends UnitTestCase { ->with($request) ->will($this->throwException(new ResourceNotFoundException())); - $this->setExpectedException(ResourceNotFoundException::class); + $this->expectException(ResourceNotFoundException::class); Url::createFromRequest($request); } @@ -181,7 +181,7 @@ class UnroutedUrlTest extends UnitTestCase { */ public function testGetRouteName($uri) { $url = Url::fromUri($uri); - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $url->getRouteName(); } @@ -195,7 +195,7 @@ class UnroutedUrlTest extends UnitTestCase { */ public function testGetRouteParameters($uri) { $url = Url::fromUri($uri); - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $url->getRouteParameters(); } @@ -209,7 +209,7 @@ class UnroutedUrlTest extends UnitTestCase { */ public function testGetInternalPath($uri) { $url = Url::fromUri($uri); - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $url->getInternalPath(); } diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index d42cd7dc4e5a..dcdee870a1e0 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -218,7 +218,7 @@ class UrlTest extends UnitTestCase { * @dataProvider providerFromInvalidInternalUri */ public function testFromInvalidUserInput($path) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $url = Url::fromUserInput($path); } @@ -289,7 +289,7 @@ class UrlTest extends UnitTestCase { ->with($request) ->will($this->throwException(new ResourceNotFoundException())); - $this->setExpectedException(ResourceNotFoundException::class); + $this->expectException(ResourceNotFoundException::class); Url::createFromRequest($request); } @@ -317,7 +317,7 @@ class UrlTest extends UnitTestCase { * @covers ::getUri */ public function testGetUriForInternalUrl($urls) { - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); foreach ($urls as $url) { $url->getUri(); } @@ -419,7 +419,7 @@ class UrlTest extends UnitTestCase { */ public function testGetRouteNameWithExternalUrl() { $url = Url::fromUri('http://example.com'); - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $url->getRouteName(); } @@ -446,7 +446,7 @@ class UrlTest extends UnitTestCase { */ public function testGetRouteParametersWithExternalUrl() { $url = Url::fromUri('http://example.com'); - $this->setExpectedException(\UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $url->getRouteParameters(); } @@ -636,7 +636,7 @@ class UrlTest extends UnitTestCase { ->with('entity.test_entity.canonical', ['test_entity' => '1/blah']) ->willThrowException(new InvalidParameterException('Parameter "test_entity" for route "/test_entity/{test_entity}" must match "[^/]++" ("1/blah" given) to generate a corresponding URL..')); - $this->setExpectedException(InvalidParameterException::class); + $this->expectException(InvalidParameterException::class); Url::fromUri('entity:test_entity/1/blah')->toString(); } @@ -755,7 +755,7 @@ class UrlTest extends UnitTestCase { * @dataProvider providerFromInvalidInternalUri */ public function testFromInvalidInternalUri($path) { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); Url::fromUri('internal:' . $path); } @@ -827,7 +827,8 @@ class UrlTest extends UnitTestCase { * @covers ::fromUri */ public function testFromRouteUriWithMissingRouteName() { - $this->setExpectedException(\InvalidArgumentException::class, "The route URI 'route:' is invalid."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("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 4a0554936213..c023feaeb00b 100644 --- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -58,7 +58,7 @@ class UnroutedUrlAssemblerTest extends UnitTestCase { * @covers ::assemble */ public function testAssembleWithNeitherExternalNorDomainLocalUri() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->unroutedUrlAssembler->assemble('wrong-url'); } @@ -66,7 +66,7 @@ class UnroutedUrlAssemblerTest extends UnitTestCase { * @covers ::assemble */ public function testAssembleWithLeadingSlash() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->unroutedUrlAssembler->assemble('/drupal.org'); } diff --git a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php index 9a84c92fdcb7..f7972e1d39b7 100644 --- a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php +++ b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php @@ -97,8 +97,14 @@ trait PhpunitCompatibilityTrait { * The expected exception message. * @param int $exception_code * The expected exception code. + * + * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. + * Backward compatibility for PHPUnit 4 will no longer be supported. + * + * @see https://www.drupal.org/node/3056869 */ public function setExpectedException($class, $message = '', $exception_code = NULL) { + @trigger_error('\Drupal\Tests\PhpunitCompatibilityTrait:setExpectedException() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Backward compatibility for PHPUnit 4 will no longer be supported. See https://www.drupal.org/node/3056869', E_USER_DEPRECATED); $this->expectException($class); if (!empty($message)) { $this->expectExceptionMessage($message); diff --git a/core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php b/core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php index 4454a3b37433..03a25656ebef 100644 --- a/core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php +++ b/core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php @@ -21,6 +21,20 @@ class PhpunitCompatibilityTraitTest extends UnitTestCase { $this->assertInstanceOf('\Drupal\Tests\MockTestClassInterface', $this->getMock(MockTestClassInterface::class)); } + /** + * Tests that setExpectedException is available. + * + * @covers ::setExpectedException + * @group legacy + * @expectedDeprecation \Drupal\Tests\PhpunitCompatibilityTrait:setExpectedException() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Backward compatibility for PHPUnit 4 will no longer be supported. See https://www.drupal.org/node/3056869 + */ + public function testSetExpectedException() { + $expectedMessage = "Expected message"; + $expectedCode = 100; + $this->setExpectedException(\Exception::class, $expectedMessage, $expectedCode); + throw new \Exception($expectedMessage, $expectedCode); + } + } interface MockTestClassInterface {