Commit 3c7ffa19 authored by catch's avatar catch
Browse files

Issue #3354382 by mondrake: [PHPUnit 10] Provide a static viable alternative...

Issue #3354382 by mondrake: [PHPUnit 10] Provide a static viable alternative to $this->prophesize() in data providers

(cherry picked from commit 6ef863a2)
parent fbec11ff
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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())],
    ];
  }

+2 −2
Original line number Diff line number Diff line
@@ -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()),
          ],
        ],
      ],
+4 −4
Original line number Diff line number Diff line
@@ -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);
+3 −3
Original line number Diff line number Diff line
@@ -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.
+15 −13
Original line number Diff line number Diff line
@@ -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 [
Loading