Unverified Commit e82e0c05 authored by alexpott's avatar alexpott
Browse files

Issue #3059090 by clepson, mondrake, alexpott: Deprecate...

Issue #3059090 by clepson, mondrake, alexpott: Deprecate \Drupal\Tests\PhpunitCompatibilityTrait::setExpectedException()
parent 6d3ac6c7
......@@ -33,7 +33,7 @@ public function testNonHtmlResponse($response_class) {
$big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($this->prophesize(AttachmentsResponseProcessorInterface::class));
$non_html_response = new $response_class();
$this->setExpectedException(\AssertionError::class);
$this->expectException(\AssertionError::class);
$big_pipe_response_attachments_processor->processAttachments($non_html_response);
}
......
......@@ -95,7 +95,8 @@ public function testTransformException() {
->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, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
}
......
......@@ -116,7 +116,8 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
*/
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 @@ public function testGet() {
*/
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 @@ public function testPatch() {
*/
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);
......
......@@ -120,7 +120,8 @@ public function testInvalidRecipient() {
$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);
}
......
......@@ -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,
......
......@@ -147,7 +147,7 @@ public function testBasicModeration($entity_type_id) {
}
// Set an invalid moderation state.
$this->setExpectedException(EntityStorageException::class);
$this->expectException(EntityStorageException::class);
$entity->moderation_state->value = 'foobar';
$entity->save();
}
......
......@@ -101,7 +101,7 @@ public function testGetValue() {
*/
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);
}
......
......@@ -255,7 +255,7 @@ public function testSetValueProperty() {
* @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 @@ public function datetimeValidationProvider() {
* @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();
......
......@@ -18,7 +18,8 @@ public function testUnknownDateType($method = 'defineValueProcessPipeline') {
$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']);
}
......
......@@ -35,7 +35,8 @@ protected function setUp() {
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']);
}
......
......@@ -207,7 +207,8 @@ public function testCalculateDependenciesIncorrectBundle() {
'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();
}
......
......@@ -192,7 +192,8 @@ public function testInvalidEnforcedCardinality($enforced_cardinality) {
'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();
}
......
......@@ -63,7 +63,8 @@ public function testTransform($method, $value, $expected_value, $migrate_excepti
$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) {
......
......@@ -47,8 +47,8 @@ public function testDefaults() {
* @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');
}
......
......@@ -86,7 +86,7 @@ public function testTypeHandlingWithInvalidType() {
],
];
$this->setExpectedException(UnexpectedValueException::class);
$this->expectException(UnexpectedValueException::class);
$this->serializer->denormalize($data_with_invalid_type, $this->entityClass, $this->format);
}
......@@ -100,7 +100,7 @@ public function testTypeHandlingWithNoTypes() {
],
];
$this->setExpectedException(UnexpectedValueException::class);
$this->expectException(UnexpectedValueException::class);
$this->serializer->denormalize($data_with_no_types, $this->entityClass, $this->format);
}
......@@ -146,7 +146,8 @@ public function testMarkFieldForDeletion() {
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 @@ public function testDenormalizeInvalidCustomSerializedField() {
$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);
}
......
......@@ -23,7 +23,7 @@ public function testFieldItemNormalizerDenormalizeExceptions($context) {
$field_item_normalizer = new FieldItemNormalizer();
$data = [];
$class = [];
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$field_item_normalizer->denormalize($data, $class, NULL, $context);
}
......
......@@ -23,7 +23,7 @@ public function testFieldNormalizerDenormalizeExceptions($context) {
$field_item_normalizer = new FieldNormalizer();
$data = [];
$class = [];
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$field_item_normalizer->denormalize($data, $class, NULL, $context);
}
......
......@@ -115,7 +115,8 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
*/
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 @@ public function testGetIndividual() {
*/
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 @@ public function testPatchIndividual() {
*/
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 @@ public function testDeleteIndividual() {
*/
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 @@ public function testRelated() {
*/
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 @@ public function testCollection() {
*/
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);
}
......
......@@ -126,7 +126,10 @@ public function resolveInternalIncludePathProvider() {
*/
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 @@ public function resolveInternalEntityQueryPathProvider() {
* @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);
}
......
......@@ -205,7 +205,7 @@ public function testGetIndividualDenied() {
$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 @@ public function testCreateIndividualWithMissingRequiredData() {
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 @@ public function testCreateIndividualDuplicateError() {
],
]);
$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)],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment