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 e23ff8d06c30c7c25dbe1409d9c6e30da8b8ba4c..32ddc51fc29701296286f8b3794c43468661dbc3 100644 --- a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php +++ b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php @@ -18,6 +18,7 @@ use Drupal\TestTools\Random; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; +use Prophecy\Prophet; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -39,10 +40,10 @@ public function testNonHtmlResponse($response_class) { $big_pipe_response_attachments_processor->processAttachments($non_html_response); } - public function nonHtmlResponseProvider() { + public static function nonHtmlResponseProvider() { return [ 'AjaxResponse, which implements AttachmentsInterface' => [AjaxResponse::class], - 'A dummy that implements AttachmentsInterface' => [get_class($this->prophesize(AttachmentsInterface::class)->reveal())], + 'A dummy that implements AttachmentsInterface' => [get_class((new Prophet())->prophesize(AttachmentsInterface::class)->reveal())], ]; } diff --git a/core/modules/ckeditor5/tests/src/Unit/LanguagePluginTest.php b/core/modules/ckeditor5/tests/src/Unit/LanguagePluginTest.php index 162e759786597c9894bfaabe744cc74a7e49e41b..395004ecec5d21489279fb10c65c5ff50ef1132d 100644 --- a/core/modules/ckeditor5/tests/src/Unit/LanguagePluginTest.php +++ b/core/modules/ckeditor5/tests/src/Unit/LanguagePluginTest.php @@ -19,7 +19,7 @@ class LanguagePluginTest extends UnitTestCase { /** * Provides a list of configs to test. */ - public function providerGetDynamicPluginConfig(): array { + public static function providerGetDynamicPluginConfig(): array { $un_expected_output = [ 'language' => [ 'textPartLanguage' => [ @@ -60,7 +60,7 @@ public function providerGetDynamicPluginConfig(): array { ['language_list' => 'all'], [ 'language' => [ - 'textPartLanguage' => $this->buildExpectedDynamicConfig(LanguageManager::getStandardLanguageList()), + 'textPartLanguage' => static::buildExpectedDynamicConfig(LanguageManager::getStandardLanguageList()), ], ], ], diff --git a/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php b/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php index 15c522abd1809955f60504fe5b097000703f70df..a2fb19c5f86ad50510e911e282ed9300bfd38204 100644 --- a/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php +++ b/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php @@ -192,8 +192,8 @@ public function validateResponseProvider() { $test_cases = array_map(function ($input) use ($defaults) { [$json, $expected, $description, $route_name, $resource_type] = array_values($input + $defaults); return [ - $this->createRequest($route_name, $resource_type), - $this->createResponse($json), + static::createRequest($route_name, $resource_type), + static::createResponse($json), $expected, $description, ]; @@ -213,7 +213,7 @@ public function validateResponseProvider() { * @return \Symfony\Component\HttpFoundation\Request * The mock request object. */ - protected function createRequest($route_name, ResourceType $resource_type) { + protected static function createRequest(string $route_name, ResourceType $resource_type): Request { $request = new Request(); $request->attributes->set(RouteObjectInterface::ROUTE_NAME, $route_name); $request->attributes->set(Routes::RESOURCE_TYPE_KEY, $resource_type); @@ -229,7 +229,7 @@ protected function createRequest($route_name, ResourceType $resource_type) { * @return \Drupal\rest\ResourceResponse * The mock response object. */ - protected function createResponse($json = NULL) { + protected static function createResponse(?string $json = NULL): ResourceResponse { $response = new ResourceResponse(); if ($json) { $response->setContent($json); diff --git a/core/modules/jsonapi/tests/src/Unit/JsonApiSpecTest.php b/core/modules/jsonapi/tests/src/Unit/JsonApiSpecTest.php index a55c09641de35138f44d1b20b3d08e2a6d6ad8e5..3f425360ebe48f0c9b9922379ea74a61db58cd5b 100644 --- a/core/modules/jsonapi/tests/src/Unit/JsonApiSpecTest.php +++ b/core/modules/jsonapi/tests/src/Unit/JsonApiSpecTest.php @@ -26,7 +26,7 @@ public function testIsValidMemberName($member_name, $expected) { /** * Data provider for testIsValidMemberName. */ - public function providerTestIsValidMemberName() { + public static function providerTestIsValidMemberName() { // Copied from http://jsonapi.org/format/upcoming/#document-member-names. $data = []; $data['alphanumeric-lowercase'] = ['12kittens', TRUE]; @@ -107,8 +107,8 @@ public function testIsValidCustomQueryParameter($custom_query_parameter, $expect /** * Data provider for testIsValidCustomQueryParameter. */ - public function providerTestIsValidCustomQueryParameter() { - $data = $this->providerTestIsValidMemberName(); + public static function providerTestIsValidCustomQueryParameter() { + $data = static::providerTestIsValidMemberName(); // All valid member names are also valid custom query parameters, except for // single-character ones. diff --git a/core/modules/layout_builder/tests/src/Unit/LayoutEntityHelperTraitTest.php b/core/modules/layout_builder/tests/src/Unit/LayoutEntityHelperTraitTest.php index 2f43967eb98fe19f0b7d59f7628a8827d330644c..15cbb2dd144657923420ec62fbdb56d1843d90a5 100644 --- a/core/modules/layout_builder/tests/src/Unit/LayoutEntityHelperTraitTest.php +++ b/core/modules/layout_builder/tests/src/Unit/LayoutEntityHelperTraitTest.php @@ -9,6 +9,7 @@ use Drupal\layout_builder\Section; use Drupal\layout_builder\SectionComponent; use Drupal\Tests\UnitTestCase; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\layout_builder\LayoutEntityHelperTrait @@ -20,24 +21,25 @@ class LayoutEntityHelperTraitTest extends UnitTestCase { /** * Data provider method for tests that need sections with inline blocks. */ - public function providerSectionsWithInlineComponents() { + public static function providerSectionsWithInlineComponents() { + $prophet = new Prophet(); $components = []; // Ensure a non-derivative component is not returned. - $non_derivative_component = $this->prophesize(SectionComponent::class); - $non_derivative_component->getPlugin()->willReturn($this->prophesize(PluginInspectionInterface::class)->reveal()); + $non_derivative_component = $prophet->prophesize(SectionComponent::class); + $non_derivative_component->getPlugin()->willReturn($prophet->prophesize(PluginInspectionInterface::class)->reveal()); $components[] = $non_derivative_component->reveal(); // Ensure a derivative component with a different base Id is not returned. - $derivative_non_inline_component = $this->prophesize(SectionComponent::class); - $plugin = $this->prophesize(DerivativeInspectionInterface::class); + $derivative_non_inline_component = $prophet->prophesize(SectionComponent::class); + $plugin = $prophet->prophesize(DerivativeInspectionInterface::class); $plugin->getBaseId()->willReturn('some_other_base_id_which_we_do_not_care_about_but_it_is_nothing_personal'); $derivative_non_inline_component->getPlugin()->willReturn($plugin); $components[] = $derivative_non_inline_component->reveal(); // Ensure that inline block component is returned. - $inline_component = $this->prophesize(SectionComponent::class); - $inline_plugin = $this->prophesize(DerivativeInspectionInterface::class)->willImplement(ConfigurableInterface::class); + $inline_component = $prophet->prophesize(SectionComponent::class); + $inline_plugin = $prophet->prophesize(DerivativeInspectionInterface::class)->willImplement(ConfigurableInterface::class); $inline_plugin->getBaseId()->willReturn('inline_block'); $inline_plugin->getConfiguration()->willReturn(['block_revision_id' => 'the_revision_id']); $inline_component->getPlugin()->willReturn($inline_plugin->reveal()); @@ -45,28 +47,28 @@ public function providerSectionsWithInlineComponents() { $components[] = $inline_component; // Ensure that inline block component without revision is returned. - $inline_component_without_revision_id = $this->prophesize(SectionComponent::class); - $inline_plugin_without_revision_id = $this->prophesize(DerivativeInspectionInterface::class)->willImplement(ConfigurableInterface::class); + $inline_component_without_revision_id = $prophet->prophesize(SectionComponent::class); + $inline_plugin_without_revision_id = $prophet->prophesize(DerivativeInspectionInterface::class)->willImplement(ConfigurableInterface::class); $inline_plugin_without_revision_id->getBaseId()->willReturn('inline_block'); $inline_plugin_without_revision_id->getConfiguration()->willReturn(['other_key' => 'other_value']); $inline_component_without_revision_id->getPlugin()->willReturn($inline_plugin_without_revision_id->reveal()); $inline_component_without_revision_id = $inline_component_without_revision_id->reveal(); $components[] = $inline_component_without_revision_id; - $section = $this->prophesize(Section::class); + $section = $prophet->prophesize(Section::class); $section->getComponents()->willReturn($components); $components = []; // Ensure that inline block components in all sections are returned. - $inline_component2 = $this->prophesize(SectionComponent::class); - $inline_plugin2 = $this->prophesize(DerivativeInspectionInterface::class)->willImplement(ConfigurableInterface::class); + $inline_component2 = $prophet->prophesize(SectionComponent::class); + $inline_plugin2 = $prophet->prophesize(DerivativeInspectionInterface::class)->willImplement(ConfigurableInterface::class); $inline_plugin2->getBaseId()->willReturn('inline_block'); $inline_plugin2->getConfiguration()->willReturn(['block_revision_id' => 'the_other_revision_id']); $inline_component2->getPlugin()->willReturn($inline_plugin2->reveal()); $inline_component2 = $inline_component2->reveal(); $components[] = $inline_component2; - $section2 = $this->prophesize(Section::class); + $section2 = $prophet->prophesize(Section::class); $section2->getComponents()->willReturn($components); return [ diff --git a/core/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php b/core/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php index 54307f3a0cc36908d906ea2eb6cf6abef752af24..47275a0ba4832f258b6cd0abe79c6f4b51ba158b 100644 --- a/core/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php +++ b/core/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php @@ -11,14 +11,14 @@ */ class RequirementsExceptionTest extends UnitTestCase { - protected $missingRequirements = ['random_jackson_pivot', '51_Eridani_b']; + protected const MISSING_REQUIREMENTS = ['random_jackson_pivot', '51_Eridani_b']; /** * @covers ::getRequirements */ public function testGetRequirements() { - $exception = new RequirementsException('Missing requirements ', ['requirements' => $this->missingRequirements]); - $this->assertEquals(['requirements' => $this->missingRequirements], $exception->getRequirements()); + $exception = new RequirementsException('Missing requirements ', ['requirements' => static::MISSING_REQUIREMENTS]); + $this->assertEquals(['requirements' => static::MISSING_REQUIREMENTS], $exception->getRequirements()); } /** @@ -33,17 +33,17 @@ public function testGetExceptionString($expected, $message, $requirements) { /** * Provides a list of requirements to test. */ - public function getRequirementsProvider() { + public static function getRequirementsProvider() { return [ [ 'requirements: random_jackson_pivot.', 'Single Requirement', - ['requirements' => $this->missingRequirements[0]], + ['requirements' => static::MISSING_REQUIREMENTS[0]], ], [ 'requirements: random_jackson_pivot. requirements: 51_Eridani_b.', 'Multiple Requirements', - ['requirements' => $this->missingRequirements], + ['requirements' => static::MISSING_REQUIREMENTS], ], ]; } diff --git a/core/modules/system/tests/src/Kernel/DateFormatAccessControlHandlerTest.php b/core/modules/system/tests/src/Kernel/DateFormatAccessControlHandlerTest.php index dd1c96b020099e6050afb464c4ddc739292a069a..3dbc8d8ccaae1e86e0810369a2007e4594865f51 100644 --- a/core/modules/system/tests/src/Kernel/DateFormatAccessControlHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/DateFormatAccessControlHandlerTest.php @@ -8,6 +8,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\user\Traits\UserCreationTrait; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\system\DateFormatAccessControlHandler @@ -81,7 +82,7 @@ public function testAccess($which_user, $which_entity, $view_label_access_result public function testAccessProvider() { $c = new ContainerBuilder(); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); + $cache_contexts_manager = (new Prophet())->prophesize(CacheContextsManager::class); $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); $cache_contexts_manager->reveal(); $c->set('cache_contexts_manager', $cache_contexts_manager); diff --git a/core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php b/core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php index b1ec10022fdb606880e15cf20c4f1183e8ae1831..1dcc91fbbb4927a7ac57f356346a9b0e52c9783b 100644 --- a/core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php +++ b/core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php @@ -12,6 +12,7 @@ use Drupal\user\Plugin\Validation\Constraint\UserMailRequiredValidator; use Drupal\user\UserInterface; use Drupal\user\UserStorageInterface; +use Prophecy\Prophet; use Symfony\Component\Validator\Context\ExecutionContextInterface; /** @@ -77,20 +78,21 @@ public function testValidate($items, $expected_violation, $is_admin = FALSE) { /** * Data provider for ::testValidate(). */ - public function providerTestValidate() { + public static function providerTestValidate() { + $prophet = new Prophet(); $cases = []; // Case 1: Empty user should be ignored. - $items = $this->prophesize(FieldItemListInterface::class); + $items = $prophet->prophesize(FieldItemListInterface::class); $items->getEntity()->willReturn(NULL)->shouldBeCalledTimes(1); $cases['Empty user should be ignored'] = [$items->reveal(), FALSE]; // Case 2: New users without an email should add a violation. - $items = $this->prophesize(FieldItemListInterface::class); - $account = $this->prophesize(UserInterface::class); + $items = $prophet->prophesize(FieldItemListInterface::class); + $account = $prophet->prophesize(UserInterface::class); $account->isNew()->willReturn(TRUE); $account->id()->shouldNotBeCalled(); - $field_definition = $this->prophesize(FieldDefinitionInterface::class); + $field_definition = $prophet->prophesize(FieldDefinitionInterface::class); $field_definition->getLabel()->willReturn('Email'); $account->getFieldDefinition("mail")->willReturn($field_definition->reveal())->shouldBeCalledTimes(1); $items->getEntity()->willReturn($account->reveal())->shouldBeCalledTimes(1); @@ -98,11 +100,11 @@ public function providerTestValidate() { $cases['New users without an email should add a violation'] = [$items->reveal(), TRUE]; // Case 3: Existing users without an email should add a violation. - $items = $this->prophesize(FieldItemListInterface::class); - $account = $this->prophesize(UserInterface::class); + $items = $prophet->prophesize(FieldItemListInterface::class); + $account = $prophet->prophesize(UserInterface::class); $account->isNew()->willReturn(FALSE); $account->id()->willReturn(3); - $field_definition = $this->prophesize(FieldDefinitionInterface::class); + $field_definition = $prophet->prophesize(FieldDefinitionInterface::class); $field_definition->getLabel()->willReturn('Email'); $account->getFieldDefinition("mail")->willReturn($field_definition->reveal())->shouldBeCalledTimes(1); $items->getEntity()->willReturn($account->reveal())->shouldBeCalledTimes(1); @@ -110,11 +112,11 @@ public function providerTestValidate() { $cases['Existing users without an email should add a violation'] = [$items->reveal(), TRUE]; // Case 4: New user with an e-mail is valid. - $items = $this->prophesize(FieldItemListInterface::class); - $account = $this->prophesize(UserInterface::class); + $items = $prophet->prophesize(FieldItemListInterface::class); + $account = $prophet->prophesize(UserInterface::class); $account->isNew()->willReturn(TRUE); $account->id()->shouldNotBeCalled(); - $field_definition = $this->prophesize(FieldDefinitionInterface::class); + $field_definition = $prophet->prophesize(FieldDefinitionInterface::class); $field_definition->getLabel()->willReturn('Email'); $account->getFieldDefinition("mail")->willReturn($field_definition->reveal())->shouldBeCalledTimes(1); $items->getEntity()->willReturn($account->reveal())->shouldBeCalledTimes(1); @@ -122,11 +124,11 @@ public function providerTestValidate() { $cases['New user with an e-mail is valid'] = [$items->reveal(), FALSE]; // Case 5: Existing users with an email should be ignored. - $items = $this->prophesize(FieldItemListInterface::class); - $account = $this->prophesize(UserInterface::class); + $items = $prophet->prophesize(FieldItemListInterface::class); + $account = $prophet->prophesize(UserInterface::class); $account->isNew()->willReturn(FALSE); $account->id()->willReturn(3); - $field_definition = $this->prophesize(FieldDefinitionInterface::class); + $field_definition = $prophet->prophesize(FieldDefinitionInterface::class); $field_definition->getLabel()->willReturn('Email'); $account->getFieldDefinition("mail")->willReturn($field_definition->reveal())->shouldBeCalledTimes(1); $items->getEntity()->willReturn($account->reveal())->shouldBeCalledTimes(1); @@ -135,11 +137,11 @@ public function providerTestValidate() { // Case 6: Existing users without an email should be ignored if the current // user is an administrator. - $items = $this->prophesize(FieldItemListInterface::class); - $account = $this->prophesize(UserInterface::class); + $items = $prophet->prophesize(FieldItemListInterface::class); + $account = $prophet->prophesize(UserInterface::class); $account->isNew()->willReturn(FALSE); $account->id()->willReturn(3); - $field_definition = $this->prophesize(FieldDefinitionInterface::class); + $field_definition = $prophet->prophesize(FieldDefinitionInterface::class); $field_definition->getLabel()->willReturn('Email'); $account->getFieldDefinition("mail")->willReturn($field_definition->reveal())->shouldBeCalledTimes(1); $items->getEntity()->willReturn($account->reveal())->shouldBeCalledTimes(1); diff --git a/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php index 8e50cc08f19096ae414e4c05b0df1e50bb57d105..a02816727a31f301dc2060e0d518e0feff0d18e2 100644 --- a/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\views\Unit\Plugin\field; use Drupal\Core\GeneratedUrl; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; use Drupal\Core\Render\Markup; use Drupal\Core\Url; @@ -21,6 +22,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Route; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\views\Plugin\views\field\FieldPluginBase @@ -51,10 +53,8 @@ class FieldPluginBaseTest extends UnitTestCase { /** * Default configuration for URL output. - * - * @var array */ - protected $defaultUrlOptions = [ + protected const DEFAULT_URL_OPTIONS = [ 'absolute' => FALSE, 'alias' => FALSE, 'entity' => NULL, @@ -406,7 +406,7 @@ public function testRenderAsLinkWithUrlAndOptions(Url $url, $alter, Url $expecte $field->field_alias = 'key'; $row = new ResultRow(['key' => 'value']); - $expected_url->setOptions($expected_url->getOptions() + $this->defaultUrlOptions); + $expected_url->setOptions($expected_url->getOptions() + static::DEFAULT_URL_OPTIONS); $expected_link_url->setUrlGenerator($this->urlGenerator); $expected_url_options = $expected_url->getOptions(); @@ -427,7 +427,7 @@ public function testRenderAsLinkWithUrlAndOptions(Url $url, $alter, Url $expecte * @return array * Array of test data. */ - public function providerTestRenderAsLinkWithUrlAndOptions() { + public static function providerTestRenderAsLinkWithUrlAndOptions() { $data = []; // Simple path with default options. @@ -441,35 +441,35 @@ public function providerTestRenderAsLinkWithUrlAndOptions() { // Add a fragment. $url = Url::fromRoute('test_route'); $url_with_fragment = Url::fromRoute('test_route'); - $options = ['fragment' => 'test'] + $this->defaultUrlOptions; + $options = ['fragment' => 'test'] + static::DEFAULT_URL_OPTIONS; $url_with_fragment->setOptions($options); $data[] = [$url, ['fragment' => 'test'], $url_with_fragment, '/test-path#test', clone $url_with_fragment, '<a href="/test-path#test">value</a>']; // Rel attributes. $url = Url::fromRoute('test_route'); $url_with_rel = Url::fromRoute('test_route'); - $options = ['attributes' => ['rel' => 'up']] + $this->defaultUrlOptions; + $options = ['attributes' => ['rel' => 'up']] + static::DEFAULT_URL_OPTIONS; $url_with_rel->setOptions($options); $data[] = [$url, ['rel' => 'up'], clone $url, '/test-path', $url_with_rel, '<a href="/test-path" rel="up">value</a>']; // Target attributes. $url = Url::fromRoute('test_route'); $url_with_target = Url::fromRoute('test_route'); - $options = ['attributes' => ['target' => '_blank']] + $this->defaultUrlOptions; + $options = ['attributes' => ['target' => '_blank']] + static::DEFAULT_URL_OPTIONS; $url_with_target->setOptions($options); $data[] = [$url, ['target' => '_blank'], $url_with_target, '/test-path', clone $url_with_target, '<a href="/test-path" target="_blank">value</a>']; // Link attributes. $url = Url::fromRoute('test_route'); $url_with_link_attributes = Url::fromRoute('test_route'); - $options = ['attributes' => ['foo' => 'bar']] + $this->defaultUrlOptions; + $options = ['attributes' => ['foo' => 'bar']] + static::DEFAULT_URL_OPTIONS; $url_with_link_attributes->setOptions($options); $data[] = [$url, ['link_attributes' => ['foo' => 'bar']], clone $url, '/test-path', $url_with_link_attributes, '<a href="/test-path" foo="bar">value</a>']; // Manual specified query. $url = Url::fromRoute('test_route'); $url_with_query = Url::fromRoute('test_route'); - $options = ['query' => ['foo' => 'bar']] + $this->defaultUrlOptions; + $options = ['query' => ['foo' => 'bar']] + static::DEFAULT_URL_OPTIONS; $url_with_query->setOptions($options); $data[] = [$url, ['query' => ['foo' => 'bar']], clone $url_with_query, '/test-path?foo=bar', $url_with_query, '<a href="/test-path?foo=bar">value</a>']; @@ -482,14 +482,14 @@ public function providerTestRenderAsLinkWithUrlAndOptions() { // Query specified as option and path. $url = Url::fromRoute('test_route')->setOption('query', ['foo' => 'bar']); $url_with_query = Url::fromRoute('test_route'); - $options = ['query' => ['key' => 'value']] + $this->defaultUrlOptions; + $options = ['query' => ['key' => 'value']] + static::DEFAULT_URL_OPTIONS; $url_with_query->setOptions($options); $data[] = [$url, ['query' => ['key' => 'value']], $url_with_query, '/test-path?key=value', clone $url_with_query, '<a href="/test-path?key=value">value</a>']; // Alias flag. $url = Url::fromRoute('test_route'); $url_without_alias = Url::fromRoute('test_route'); - $options = ['alias' => TRUE] + $this->defaultUrlOptions; + $options = ['alias' => TRUE] + static::DEFAULT_URL_OPTIONS; $url_without_alias->setOptions($options); $data[] = [$url, ['alias' => TRUE], $url_without_alias, '/test-path', clone $url_without_alias, '<a href="/test-path">value</a>']; @@ -497,15 +497,15 @@ public function providerTestRenderAsLinkWithUrlAndOptions() { $language = new Language(['id' => 'fr']); $url = Url::fromRoute('test_route'); $url_with_language = Url::fromRoute('test_route'); - $options = ['language' => $language] + $this->defaultUrlOptions; + $options = ['language' => $language] + static::DEFAULT_URL_OPTIONS; $url_with_language->setOptions($options); $data[] = [$url, ['language' => $language], $url_with_language, '/fr/test-path', clone $url_with_language, '<a href="/fr/test-path" hreflang="fr">value</a>']; // Entity flag. - $entity = $this->createMock('Drupal\Core\Entity\EntityInterface'); + $entity = (new Prophet())->prophesize(EntityInterface::class)->reveal(); $url = Url::fromRoute('test_route'); $url_with_entity = Url::fromRoute('test_route'); - $options = ['entity' => $entity] + $this->defaultUrlOptions; + $options = ['entity' => $entity] + static::DEFAULT_URL_OPTIONS; $url_with_entity->setOptions($options); $data[] = [$url, ['entity' => $entity], $url_with_entity, '/test-path', clone $url_with_entity, '<a href="/test-path">value</a>']; @@ -513,7 +513,7 @@ public function providerTestRenderAsLinkWithUrlAndOptions() { $entity_type_id = 'node'; $url = Url::fromRoute('test_route'); $url_with_entity_type = Url::fromRoute('test_route'); - $options = ['entity_type' => $entity_type_id] + $this->defaultUrlOptions; + $options = ['entity_type' => $entity_type_id] + static::DEFAULT_URL_OPTIONS; $url_with_entity_type->setOptions($options); $data[] = [$url, ['entity_type' => $entity_type_id], $url_with_entity_type, '/test-path', clone $url_with_entity_type, '<a href="/test-path">value</a>']; diff --git a/core/modules/workflows/tests/src/Kernel/WorkflowAccessControlHandlerTest.php b/core/modules/workflows/tests/src/Kernel/WorkflowAccessControlHandlerTest.php index 836735692606c10b588a5bdd0517f9fccd306568..c65e49dd0a4acb06d61c4220946112a5bcd53c10 100644 --- a/core/modules/workflows/tests/src/Kernel/WorkflowAccessControlHandlerTest.php +++ b/core/modules/workflows/tests/src/Kernel/WorkflowAccessControlHandlerTest.php @@ -8,6 +8,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\workflows\Entity\Workflow; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\workflows\WorkflowAccessControlHandler @@ -119,7 +120,7 @@ public function testCheckAccess($user, $operation, $result, $states_to_create = */ public function checkAccessProvider() { $container = new ContainerBuilder(); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); + $cache_contexts_manager = (new Prophet())->prophesize(CacheContextsManager::class); $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); $cache_contexts_manager->reveal(); $container->set('cache_contexts_manager', $cache_contexts_manager); diff --git a/core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php b/core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php index 3a474f3d8e89587120bd8e9746746e2723066255..958dc61324090291a8e6a3e989ea7aea4487d46c 100644 --- a/core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php +++ b/core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php @@ -52,7 +52,7 @@ public function datetimeDateCallbackTrusted(array &$element, FormStateInterface /** * {@inheritdoc} */ - public function datetimeDateCallback(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) { + public static function datetimeDateCallback(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) { $element['datetimeDateCallbackExecuted'] = [ '#value' => TRUE, ]; @@ -72,7 +72,7 @@ public function datetimeTimeCallbackTrusted(array &$element, FormStateInterface /** * {@inheritdoc} */ - public function datetimeTimeCallback(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) { + public static function datetimeTimeCallback(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) { $element['timeCallbackExecuted'] = [ '#value' => TRUE, ]; @@ -180,12 +180,12 @@ public function providerUntrusted() : array { 'untrusted date' => [ 'datetimeDateCallback', 'datetimeTimeCallbackTrusted', - sprintf('DateTime element #date_date_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString([$this, 'datetimeDateCallback'])), + sprintf('DateTime element #date_date_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString([static::class, 'datetimeDateCallback'])), ], 'untrusted time' => [ 'datetimeDateCallbackTrusted', 'datetimeTimeCallback', - sprintf('DateTime element #date_time_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString([$this, 'datetimeTimeCallback'])), + sprintf('DateTime element #date_time_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString([static::class, 'datetimeTimeCallback'])), ], ]; } diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index a026d89aacc7e129b0eb85506d7854975f470bd7..5cd26aa6fff1cfeddf28cd34356fc7488581ba9f 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\Crypt; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; + use Prophecy\Prophet; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -234,7 +235,7 @@ public function testGetServiceDefinitions($services, $definition_services) { * - parameters as expected in the container definition. * - frozen value */ - public function getDefinitionsDataProvider() { + public static function getDefinitionsDataProvider() { $base_service_definition = [ 'class' => '\stdClass', 'public' => TRUE, @@ -277,7 +278,7 @@ public function getDefinitionsDataProvider() { $service_definitions[] = [ 'arguments' => ['foo', new Reference('bar')], 'arguments_count' => 2, - 'arguments_expected' => $this->getCollection(['foo', $this->getServiceCall('bar')]), + 'arguments_expected' => static::getCollection(['foo', static::getServiceCall('bar')]), ] + $base_service_definition; // Test a public reference that should not throw an Exception. @@ -285,7 +286,7 @@ public function getDefinitionsDataProvider() { $service_definitions[] = [ 'arguments' => [$reference], 'arguments_count' => 1, - 'arguments_expected' => $this->getCollection([$this->getServiceCall('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)]), + 'arguments_expected' => static::getCollection([static::getServiceCall('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)]), ] + $base_service_definition; // Test a private shared service, denoted by having a Reference. @@ -298,9 +299,9 @@ public function getDefinitionsDataProvider() { $service_definitions[] = [ 'arguments' => ['foo', new Reference('private_definition')], 'arguments_count' => 2, - 'arguments_expected' => $this->getCollection([ + 'arguments_expected' => static::getCollection([ 'foo', - $this->getPrivateServiceCall('private_definition', $private_definition, TRUE), + static::getPrivateServiceCall('private_definition', $private_definition, TRUE), ]), ] + $base_service_definition; @@ -311,9 +312,9 @@ public function getDefinitionsDataProvider() { $service_definitions[] = [ 'arguments' => ['foo', $private_definition_object], 'arguments_count' => 2, - 'arguments_expected' => $this->getCollection([ + 'arguments_expected' => static::getCollection([ 'foo', - $this->getPrivateServiceCall(NULL, $private_definition), + static::getPrivateServiceCall(NULL, $private_definition), ]), ] + $base_service_definition; @@ -327,20 +328,20 @@ public function getDefinitionsDataProvider() { $service_definitions[] = [ 'arguments' => [[new Reference('bar')]], 'arguments_count' => 1, - 'arguments_expected' => $this->getCollection([$this->getCollection([$this->getServiceCall('bar')])]), + 'arguments_expected' => static::getCollection([static::getCollection([static::getServiceCall('bar')])]), ] + $base_service_definition; // Test a collection with a variable to resolve. $service_definitions[] = [ 'arguments' => [new Parameter('llama_parameter')], 'arguments_count' => 1, - 'arguments_expected' => $this->getCollection([$this->getParameterCall('llama_parameter')]), + 'arguments_expected' => static::getCollection([static::getParameterCall('llama_parameter')]), ] + $base_service_definition; // Test getMethodCalls. $calls = [ - ['method', $this->getCollection([])], - ['method2', $this->getCollection([])], + ['method', static::getCollection([])], + ['method2', static::getCollection([])], ]; $service_definitions[] = [ 'calls' => $calls, @@ -353,7 +354,7 @@ public function getDefinitionsDataProvider() { // Test factory. $service_definitions[] = [ 'factory' => [new Reference('bar'), 'factoryMethod'], - 'factory_expected' => [$this->getServiceCall('bar'), 'factoryMethod'], + 'factory_expected' => [static::getServiceCall('bar'), 'factoryMethod'], ] + $base_service_definition; // Test invalid factory - needed to test deep dumpValue(). @@ -369,7 +370,7 @@ public function getDefinitionsDataProvider() { // Test configurator. $service_definitions[] = [ 'configurator' => [new Reference('bar'), 'configureService'], - 'configurator_expected' => [$this->getServiceCall('bar'), 'configureService'], + 'configurator_expected' => [static::getServiceCall('bar'), 'configureService'], ] + $base_service_definition; $services_provided = []; @@ -379,7 +380,7 @@ public function getDefinitionsDataProvider() { ]; foreach ($service_definitions as $service_definition) { - $definition = $this->prophesize('\Symfony\Component\DependencyInjection\Definition'); + $definition = (new Prophet())->prophesize('\Symfony\Component\DependencyInjection\Definition'); $definition->getClass()->willReturn($service_definition['class']); $definition->isPublic()->willReturn($service_definition['public']); $definition->getFile()->willReturn($service_definition['file']); @@ -430,7 +431,7 @@ public function getDefinitionsDataProvider() { $services_provided[] = [ ['foo_service' => $definition->reveal()], - ['foo_service' => $this->serializeDefinition($filtered_service_definition)], + ['foo_service' => static::serializeDefinition($filtered_service_definition)], ]; } @@ -442,14 +443,14 @@ public function getDefinitionsDataProvider() { * * Used to override serialization. */ - protected function serializeDefinition(array $service_definition) { + protected static function serializeDefinition(array $service_definition) { return serialize($service_definition); } /** * Helper function to return a service definition. */ - protected function getServiceCall($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { + protected static function getServiceCall($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { return (object) [ 'type' => 'service', 'id' => $id, @@ -493,19 +494,19 @@ public function testGetServiceDefinitionWithReferenceToAlias($public) { $this->containerBuilder->getDefinition('bar')->willReturn($bar_definition); $dump = $this->dumper->getArray(); if ($public) { - $service_definition = $this->getServiceCall('bar'); + $service_definition = static::getServiceCall('bar'); } else { - $service_definition = $this->getPrivateServiceCall('bar', $bar_definition_php_array, TRUE); + $service_definition = static::getPrivateServiceCall('bar', $bar_definition_php_array, TRUE); } $data = [ 'class' => '\stdClass', - 'arguments' => $this->getCollection([ + 'arguments' => static::getCollection([ $service_definition, ]), 'arguments_count' => 1, ]; - $this->assertEquals($this->serializeDefinition($data), $dump['services']['foo'], 'Expected definition matches dump.'); + $this->assertEquals(static::serializeDefinition($data), $dump['services']['foo'], 'Expected definition matches dump.'); } public function publicPrivateDataProvider() { @@ -593,10 +594,10 @@ public function testGetServiceDefinitionForObjectServiceId() { $this->expectDeprecation('_serviceId is deprecated in drupal:9.5.0 and is removed from drupal:11.0.0. Use \Drupal\Core\DrupalKernelInterface::getServiceIdMapping() instead. See https://www.drupal.org/node/3292540'); $a = $this->dumper->getArray(); $this->assertEquals( - $this->serializeDefinition([ + static::serializeDefinition([ 'class' => '\stdClass', // Legacy code takes care of converting _serviceId into this. - 'arguments' => $this->getCollection([$this->getServiceCall('foo')]), + 'arguments' => static::getCollection([static::getServiceCall('foo')]), 'arguments_count' => 1, ]), $a['services']['bar']); } @@ -633,9 +634,9 @@ public function testPercentsEscape($expected, $argument) { $dump = $this->dumper->getArray(); - $this->assertEquals($this->serializeDefinition([ + $this->assertEquals(static::serializeDefinition([ 'class' => '\stdClass', - 'arguments' => $this->getCollection([ + 'arguments' => static::getCollection([ $this->getRaw($expected), ]), 'arguments_count' => 1, @@ -665,7 +666,7 @@ public function percentsEscapeProvider() { /** * Helper function to return a private service definition. */ - protected function getPrivateServiceCall($id, $service_definition, $shared = FALSE) { + protected static function getPrivateServiceCall($id, $service_definition, $shared = FALSE) { if (!$id) { $hash = Crypt::hashBase64(serialize($service_definition)); $id = 'private__' . $hash; @@ -681,7 +682,7 @@ protected function getPrivateServiceCall($id, $service_definition, $shared = FAL /** * Helper function to return a machine-optimized collection. */ - protected function getCollection($collection, $resolve = TRUE) { + protected static function getCollection($collection, $resolve = TRUE) { return (object) [ 'type' => 'collection', 'value' => $collection, @@ -692,7 +693,7 @@ protected function getCollection($collection, $resolve = TRUE) { /** * Helper function to return a parameter definition. */ - protected function getParameterCall($name) { + protected static function getParameterCall($name) { return (object) [ 'type' => 'parameter', 'name' => $name, diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/PhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/PhpArrayDumperTest.php index 4271f50c18617567a7b2222be4b741fb08827645..91abfe4fc64f430d07e17acb41da42178e7333fc 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/PhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/PhpArrayDumperTest.php @@ -22,14 +22,14 @@ protected function setUp(): void { /** * {@inheritdoc} */ - protected function serializeDefinition(array $service_definition) { + protected static function serializeDefinition(array $service_definition) { return $service_definition; } /** * {@inheritdoc} */ - protected function getServiceCall($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { + protected static function getServiceCall($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { if ($invalid_behavior !== ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { return sprintf('@?%s', $id); } @@ -40,14 +40,14 @@ protected function getServiceCall($id, $invalid_behavior = ContainerInterface::E /** * {@inheritdoc} */ - protected function getParameterCall($name) { + protected static function getParameterCall($name) { return '%' . $name . '%'; } /** * {@inheritdoc} */ - protected function getCollection($collection, $resolve = TRUE) { + protected static function getCollection($collection, $resolve = TRUE) { return $collection; } diff --git a/core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php b/core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php index e7dc72e5b7fd5374719761e1a2099a42df788a1a..0bbb799268ca8d7e6d8ba8fc9b94689c85ec18a1 100644 --- a/core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php +++ b/core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php @@ -5,6 +5,7 @@ use Drupal\Component\Render\HtmlEscapedText; use Drupal\Component\Render\MarkupInterface; use PHPUnit\Framework\TestCase; +use Prophecy\Prophet; /** * Tests the HtmlEscapedText class. @@ -31,20 +32,22 @@ public function testToString($text, $expected, $message) { * * @see testToString() */ - public function providerToString() { + public static function providerToString() { + $prophet = new Prophet(); + // Checks that invalid multi-byte sequences are escaped. $tests[] = ["Foo\xC0bar", 'Foo�bar', 'Escapes invalid sequence "Foo\xC0bar"']; $tests[] = ["\xc2\"", '�"', 'Escapes invalid sequence "\xc2\""']; $tests[] = ["Foo ÿñ", "Foo ÿñ", 'Does not escape valid sequence "Foo ÿñ"']; // Checks that special characters are escaped. - $script_tag = $this->prophesize(MarkupInterface::class); + $script_tag = $prophet->prophesize(MarkupInterface::class); $script_tag->__toString()->willReturn('<script>'); $script_tag = $script_tag->reveal(); $tests[] = [$script_tag, '<script>', 'Escapes <script> even inside an object that implements MarkupInterface.']; $tests[] = ["<script>", '<script>', 'Escapes <script>']; $tests[] = ['<>&"\'', '<>&"'', 'Escapes reserved HTML characters.']; - $specialchars = $this->prophesize(MarkupInterface::class); + $specialchars = $prophet->prophesize(MarkupInterface::class); $specialchars->__toString()->willReturn('<>&"\''); $specialchars = $specialchars->reveal(); $tests[] = [$specialchars, '<>&"'', 'Escapes reserved HTML characters even inside an object that implements MarkupInterface.']; diff --git a/core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php b/core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php index c73ed8dbb9b7cdeaea5af4c9b2e7411e2fb8685f..d68e03521b8347fb6ba2f6d277ae17f957eca288 100644 --- a/core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php +++ b/core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php @@ -6,6 +6,7 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\MarkupInterface; use PHPUnit\Framework\TestCase; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\Component\Render\PlainTextOutput @@ -36,7 +37,8 @@ public function testRenderFromHtml($expected, $string, $args = []) { /** * Data provider for ::testRenderFromHtml() */ - public function providerRenderFromHtml() { + public static function providerRenderFromHtml() { + $prophet = new Prophet(); $data = []; $data['simple-text'] = ['Giraffes and wombats', 'Giraffes and wombats']; @@ -47,12 +49,12 @@ public function providerRenderFromHtml() { $string = 'The <em> tag makes your text look like <em>"this"</em>.'; $data['escaped-html-with-quotes'] = [$expected, $string]; - $safe_string = $this->prophesize(MarkupInterface::class); + $safe_string = $prophet->prophesize(MarkupInterface::class); $safe_string->__toString()->willReturn('<em>"this"</em>'); $safe_string = $safe_string->reveal(); $data['escaped-html-with-quotes-and-placeholders'] = [$expected, 'The @tag tag makes your text look like @result.', ['@tag' => '<em>', '@result' => $safe_string]]; - $safe_string = $this->prophesize(MarkupInterface::class); + $safe_string = $prophet->prophesize(MarkupInterface::class); $safe_string->__toString()->willReturn($string); $safe_string = $safe_string->reveal(); $data['safe-string'] = [$expected, $safe_string]; diff --git a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php index 3ec83076c03e484d1e5c39fc39d061101c7c4f7f..9c8e310cef9e5d0ab988b7bf21db29c79f8767e8 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php @@ -18,6 +18,7 @@ use Drupal\Tests\UnitTestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; +use Prophecy\Prophet; use Symfony\Component\Routing\Route; /** @@ -68,19 +69,19 @@ public function testGetAddPageRoute(Route $expected = NULL, EntityTypeInterface $this->assertEquals($expected, $route); } - public function providerTestGetAddPageRoute() { + public static function providerTestGetAddPageRoute() { $data = []; - $entity_type1 = $this->getEntityType(); + $entity_type1 = static::getEntityType(); $entity_type1->hasLinkTemplate('add-page')->willReturn(FALSE); $data['no_add_page_link_template'] = [NULL, $entity_type1->reveal()]; - $entity_type2 = $this->getEntityType(); + $entity_type2 = static::getEntityType(); $entity_type2->hasLinkTemplate('add-page')->willReturn(TRUE); $entity_type2->getKey('bundle')->willReturn(NULL); $data['no_bundle'] = [NULL, $entity_type2->reveal()]; - $entity_type3 = $this->getEntityType(); + $entity_type3 = static::getEntityType(); $entity_type3->hasLinkTemplate('add-page')->willReturn(TRUE); $entity_type3->getLinkTemplate('add-page')->willReturn('/the/add/page/link/template'); $entity_type3->id()->willReturn('the_entity_type_id'); @@ -115,15 +116,16 @@ public function testGetAddFormRoute(Route $expected = NULL, EntityTypeInterface $this->assertEquals($expected, $route); } - public function providerTestGetAddFormRoute() { + public static function providerTestGetAddFormRoute() { + $prophet = new Prophet(); $data = []; - $entity_type1 = $this->getEntityType(); + $entity_type1 = static::getEntityType(); $entity_type1->hasLinkTemplate('add-form')->willReturn(FALSE); $data['no_add_form_link_template'] = [NULL, $entity_type1->reveal()]; - $entity_type2 = $this->getEntityType(); + $entity_type2 = static::getEntityType(); $entity_type2->getBundleEntityType()->willReturn(NULL); $entity_type2->hasLinkTemplate('add-form')->willReturn(TRUE); $entity_type2->id()->willReturn('the_entity_type_id'); @@ -139,12 +141,12 @@ public function providerTestGetAddFormRoute() { ->setRequirement('_entity_create_access', 'the_entity_type_id'); $data['no_add_form_no_bundle'] = [clone $route, $entity_type2->reveal()]; - $entity_type3 = $this->getEntityType($entity_type2); + $entity_type3 = static::getEntityType($entity_type2); $entity_type3->getFormClass('add')->willReturn('Drupal\Core\Entity\EntityForm'); $route->setDefault('_entity_form', 'the_entity_type_id.add'); $data['add_form_no_bundle'] = [clone $route, $entity_type3->reveal()]; - $entity_type4 = $this->getEntityType($entity_type3); + $entity_type4 = static::getEntityType($entity_type3); $entity_type4->getKey('bundle')->willReturn('the_bundle_key'); $entity_type4->getBundleEntityType()->willReturn(NULL); $entity_type4->getLinkTemplate('add-form')->willReturn('/the/add/form/link/template/{the_bundle_key}'); @@ -155,10 +157,10 @@ public function providerTestGetAddFormRoute() { ->setRequirement('_entity_create_access', 'the_entity_type_id:{the_bundle_key}'); $data['add_form_bundle_static'] = [clone $route, $entity_type4->reveal()]; - $entity_type5 = $this->getEntityType($entity_type4); + $entity_type5 = static::getEntityType($entity_type4); $entity_type5->getBundleEntityType()->willReturn('the_bundle_entity_type_id'); $entity_type5->getLinkTemplate('add-form')->willReturn('/the/add/form/link/template/{the_bundle_entity_type_id}'); - $bundle_entity_type = $this->getEntityType(); + $bundle_entity_type = static::getEntityType(); $bundle_entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); $route->setPath('/the/add/form/link/template/{the_bundle_entity_type_id}'); $route @@ -171,18 +173,18 @@ public function providerTestGetAddFormRoute() { ]); $data['add_form_bundle_entity_id_key_type_null'] = [clone $route, $entity_type5->reveal(), $bundle_entity_type->reveal()]; - $entity_type6 = $this->getEntityType($entity_type5); - $bundle_entity_type = $this->getEntityType(); + $entity_type6 = static::getEntityType($entity_type5); + $bundle_entity_type = static::getEntityType(); $bundle_entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE); - $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); + $field_storage_definition = $prophet->prophesize(FieldStorageDefinitionInterface::class); $field_storage_definition->getType()->willReturn('integer'); $route->setRequirement('the_entity_type_id', '\d+'); $data['add_form_bundle_entity_id_key_type_integer'] = [clone $route, $entity_type6->reveal(), $bundle_entity_type->reveal(), $field_storage_definition->reveal()]; - $entity_type7 = $this->getEntityType($entity_type6); - $bundle_entity_type = $this->prophesize(ConfigEntityTypeInterface::class); + $entity_type7 = static::getEntityType($entity_type6); + $bundle_entity_type = $prophet->prophesize(ConfigEntityTypeInterface::class); $bundle_entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE); - $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); + $field_storage_definition = $prophet->prophesize(FieldStorageDefinitionInterface::class); $route // Unset the 'the_entity_type_id' requirement. ->setRequirements(['_entity_create_access' => $route->getRequirement('_entity_create_access')]) @@ -211,19 +213,20 @@ public function testGetCanonicalRoute(Route $expected = NULL, EntityTypeInterfac $this->assertEquals($expected, $route); } - public function providerTestGetCanonicalRoute() { + public static function providerTestGetCanonicalRoute() { + $prophet = new Prophet(); $data = []; - $entity_type1 = $this->getEntityType(); + $entity_type1 = static::getEntityType(); $entity_type1->hasLinkTemplate('canonical')->willReturn(FALSE); $data['no_canonical_link_template'] = [NULL, $entity_type1->reveal()]; - $entity_type2 = $this->getEntityType(); + $entity_type2 = static::getEntityType(); $entity_type2->hasLinkTemplate('canonical')->willReturn(TRUE); $entity_type2->hasViewBuilderClass()->willReturn(FALSE); $data['no_view_builder'] = [NULL, $entity_type2->reveal()]; - $entity_type3 = $this->getEntityType($entity_type2); + $entity_type3 = static::getEntityType($entity_type2); $entity_type3->hasViewBuilderClass()->willReturn(TRUE); $entity_type3->id()->willReturn('the_entity_type_id'); $entity_type3->getLinkTemplate('canonical')->willReturn('/the/canonical/link/template'); @@ -245,11 +248,11 @@ public function providerTestGetCanonicalRoute() { ]); $data['id_key_type_null'] = [clone $route, $entity_type3->reveal()]; - $entity_type4 = $this->getEntityType($entity_type3); + $entity_type4 = static::getEntityType($entity_type3); $entity_type4->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE); $entity_type4->getKey('id')->willReturn('id'); $route->setRequirement('the_entity_type_id', '\d+'); - $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class); + $field_storage_definition = $prophet->prophesize(FieldStorageDefinitionInterface::class); $field_storage_definition->getType()->willReturn('integer'); $data['id_key_type_integer'] = [clone $route, $entity_type4->reveal(), $field_storage_definition->reveal()]; @@ -265,24 +268,24 @@ public function testGetCollectionRoute(Route $expected = NULL, EntityTypeInterfa $this->assertEquals($expected, $route); } - public function providerTestGetCollectionRoute() { + public static function providerTestGetCollectionRoute() { $data = []; - $entity_type1 = $this->getEntityType(); + $entity_type1 = static::getEntityType(); $entity_type1->hasLinkTemplate('collection')->willReturn(FALSE); $data['no_collection_link_template'] = [NULL, $entity_type1->reveal()]; - $entity_type2 = $this->getEntityType(); + $entity_type2 = static::getEntityType(); $entity_type2->hasLinkTemplate('collection')->willReturn(TRUE); $entity_type2->hasListBuilderClass()->willReturn(FALSE); $data['no_list_builder'] = [NULL, $entity_type2->reveal()]; - $entity_type3 = $this->getEntityType($entity_type2); + $entity_type3 = static::getEntityType($entity_type2); $entity_type3->hasListBuilderClass()->willReturn(TRUE); $entity_type3->getAdminPermission()->willReturn(FALSE); $data['no_admin_permission'] = [NULL, $entity_type3->reveal()]; - $entity_type4 = $this->getEntityType($entity_type3); + $entity_type4 = static::getEntityType($entity_type3); $entity_type4->getAdminPermission()->willReturn('administer the entity type'); $entity_type4->id()->willReturn('the_entity_type_id'); $entity_type4->getLabel()->willReturn('The entity type'); @@ -339,8 +342,8 @@ public function testGetEntityTypeIdKeyTypeNotFieldable() { * * @return \Prophecy\Prophecy\ObjectProphecy */ - protected function getEntityType(ObjectProphecy $base_entity_type = NULL) { - $entity_type = $this->prophesize(EntityTypeInterface::class); + protected static function getEntityType(ObjectProphecy $base_entity_type = NULL) { + $entity_type = (new Prophet())->prophesize(EntityTypeInterface::class); if ($base_entity_type) { foreach ($base_entity_type->getMethodProphecies() as $method => $prophecies) { foreach ($prophecies as $prophecy) { diff --git a/core/tests/Drupal/Tests/Core/Field/FieldFilteredMarkupTest.php b/core/tests/Drupal/Tests/Core/Field/FieldFilteredMarkupTest.php index b4b2ed07ecfa3a5d7220e56c25144e02461440bf..ffe6e4470376871a0b78c4a630ae0b8980b97d55 100644 --- a/core/tests/Drupal/Tests/Core/Field/FieldFilteredMarkupTest.php +++ b/core/tests/Drupal/Tests/Core/Field/FieldFilteredMarkupTest.php @@ -5,6 +5,7 @@ use Drupal\Tests\UnitTestCase; use Drupal\Core\Field\FieldFilteredMarkup; use Drupal\Component\Render\MarkupInterface; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\Core\Field\FieldFilteredMarkup @@ -28,7 +29,7 @@ public function testCreate($string, $expected, $instance_of_check) { /** * Provides data for testCreate(). */ - public function providerTestCreate() { + public static function providerTestCreate() { $data = []; $data[] = ['', '', FALSE]; // Certain tags are filtered. @@ -39,7 +40,7 @@ public function providerTestCreate() { $data[] = ['<em>teststring', '<em>teststring</em>', TRUE]; // Even safe strings will be escaped. - $safe_string = $this->prophesize(MarkupInterface::class); + $safe_string = (new Prophet())->prophesize(MarkupInterface::class); $safe_string->__toString()->willReturn('<script>teststring</script>'); $data[] = [$safe_string->reveal(), 'teststring', TRUE]; diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php index 664f423f39d9880e2a25ae8340d8fdd9f818b4d6..11c845484b94aa55600b59e51a3e2c914bbad230 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php @@ -23,6 +23,7 @@ use Drupal\Core\Url; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; +use Prophecy\Prophet; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; @@ -195,8 +196,8 @@ public function testGetActionsForRoute($route_appears, array $plugin_definitions $this->assertEquals($expected_actions, $this->localActionManager->getActionsForRoute($route_appears)); } - public function getActionsForRouteProvider() { - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); + public static function getActionsForRouteProvider() { + $cache_contexts_manager = (new Prophet())->prophesize(CacheContextsManager::class); $cache_contexts_manager->assertValidTokens(Argument::any()) ->willReturn(TRUE); diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionIsSatisfiedTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionIsSatisfiedTest.php index 7f9a23df2221611cf22f21d5c5a6e8f62397ad8a..0a8a50a67c3037ba35be29b0a1256473f65c1a63 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionIsSatisfiedTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionIsSatisfiedTest.php @@ -21,6 +21,7 @@ use Drupal\Core\Validation\ConstraintManager; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\Core\Plugin\Context\EntityContextDefinition @@ -133,7 +134,7 @@ public function testIsSatisfiedBy($expected, ContextDefinition $requirement, Con /** * Provides test data for ::testIsSatisfiedBy(). */ - public function providerTestIsSatisfiedBy() { + public static function providerTestIsSatisfiedBy() { $data = []; $content = new EntityType(['id' => 'test_content']); @@ -145,7 +146,7 @@ public function providerTestIsSatisfiedBy() { EntityContextDefinition::fromEntityType($content), EntityContextDefinition::fromEntityType($content), ]; - $entity = $this->prophesize(ContentEntityInterface::class)->willImplement(\IteratorAggregate::class); + $entity = (new Prophet())->prophesize(ContentEntityInterface::class)->willImplement(\IteratorAggregate::class); $entity->getIterator()->willReturn(new \ArrayIterator([])); $entity->getCacheContexts()->willReturn([]); $entity->getCacheTags()->willReturn([]); diff --git a/core/tests/Drupal/Tests/Core/Plugin/PluginDependencyTraitTest.php b/core/tests/Drupal/Tests/Core/Plugin/PluginDependencyTraitTest.php index 81aa44d01e990188116f215f2e26a978d5c02442..b5998c1f4d635052749394165e70bc43493c5855 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/PluginDependencyTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/PluginDependencyTraitTest.php @@ -11,6 +11,7 @@ use Drupal\Core\Plugin\PluginDependencyTrait; use Drupal\Tests\UnitTestCase; use Prophecy\Prophecy\ProphecyInterface; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\Core\Plugin\PluginDependencyTrait @@ -77,12 +78,13 @@ public function testCalculatePluginDependencies(ProphecyInterface $plugin, $defi /** * Provides test data for plugin dependencies. */ - public function providerTestPluginDependencies() { + public static function providerTestPluginDependencies() { + $prophet = new Prophet(); $data = []; - $plugin = $this->prophesize(PluginInspectionInterface::class); + $plugin = $prophet->prophesize(PluginInspectionInterface::class); - $dependent_plugin = $this->prophesize(PluginInspectionInterface::class)->willImplement(DependentPluginInterface::class); + $dependent_plugin = $prophet->prophesize(PluginInspectionInterface::class)->willImplement(DependentPluginInterface::class); $dependent_plugin->calculateDependencies()->willReturn([ 'module' => ['test_module2'], ]); @@ -136,7 +138,7 @@ public function providerTestPluginDependencies() { ], ]; - $definition = $this->prophesize(PluginDefinitionInterface::class); + $definition = $prophet->prophesize(PluginDefinitionInterface::class); $definition->getProvider()->willReturn('test_module1'); $data['object_definition'] = [ $plugin, @@ -148,7 +150,7 @@ public function providerTestPluginDependencies() { ], ]; - $dependent_definition = $this->prophesize(PluginDefinitionInterface::class)->willImplement(DependentPluginDefinitionInterface::class); + $dependent_definition = $prophet->prophesize(PluginDefinitionInterface::class)->willImplement(DependentPluginDefinitionInterface::class); $dependent_definition->getProvider()->willReturn('test_module1'); $dependent_definition->getConfigDependencies()->willReturn(['module' => ['test_module2']]); $data['dependent_object_definition'] = [ diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php index 00e5d8b2589b781bc5ea1b226643e3d8c5531528..bbffcd04fd9c6b8a8e449edd774a1d828636ffc5 100644 --- a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy; use Drupal\Tests\UnitTestCase; +use Prophecy\Prophet; /** * @coversDefaultClass \Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy @@ -32,7 +33,8 @@ public function testProcessPlaceholders($strategies, $placeholders, $result) { * * @return array */ - public function providerProcessPlaceholders() { + public static function providerProcessPlaceholders() { + $prophet = new Prophet(); $data = []; // Empty placeholders. @@ -43,7 +45,7 @@ public function providerProcessPlaceholders() { 'remove-me' => ['#markup' => 'I-am-a-llama-that-will-be-removed-sad-face.'], ]; - $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); + $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn([]); $dev_null_strategy = $prophecy->reveal(); @@ -54,7 +56,7 @@ public function providerProcessPlaceholders() { '67890' => ['#markup' => 'special-placeholder'], ]; - $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); + $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn($placeholders); $single_flush_strategy = $prophecy->reveal(); @@ -68,18 +70,18 @@ public function providerProcessPlaceholders() { '12345' => ['#markup' => '<esi:include src="/fragment/12345" />'], ]; - $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); + $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn($result); $esi_strategy = $prophecy->reveal(); $data['fake esi strategy'] = [[$esi_strategy], $placeholders, $result]; // ESI + SingleFlush strategy (ESI replaces all). - $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); + $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn($result); $esi_strategy = $prophecy->reveal(); - $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); + $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->shouldNotBeCalled(); $prophecy->processPlaceholders($result)->shouldNotBeCalled(); $prophecy->processPlaceholders([])->shouldNotBeCalled(); @@ -105,11 +107,11 @@ public function providerProcessPlaceholders() { $result = $esi_result + $normal_result; - $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); + $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn($esi_result); $esi_strategy = $prophecy->reveal(); - $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); + $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($normal_result)->willReturn($normal_result); $single_flush_strategy = $prophecy->reveal(); diff --git a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php index 32e93c07196d82fdbc7745de715d71c921c3ab6e..1aa2da366a1cca8fc61463dd3e4483f6869e4bfb 100644 --- a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php +++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php @@ -15,6 +15,7 @@ use Drupal\Core\Template\TwigExtension; use Drupal\Core\Url; use Drupal\Tests\UnitTestCase; +use Prophecy\Prophet; use Twig\Environment; use Twig\Loader\ArrayLoader; use Twig\Loader\FilesystemLoader; @@ -293,10 +294,10 @@ public function testRenderVar($result, $input) { $this->assertEquals('Rendered output', $this->systemUnderTest->renderVar($input)); } - public function providerTestRenderVar() { + public static function providerTestRenderVar() { $data = []; - $renderable = $this->prophesize(RenderableInterface::class); + $renderable = (new Prophet())->prophesize(RenderableInterface::class); $render_array = ['#type' => 'test', '#var' => 'giraffe']; $renderable->toRenderable()->willReturn($render_array); $data['renderable'] = [$render_array, $renderable->reveal()];