Verified Commit 1889d623 authored by Jess's avatar Jess
Browse files

Issue #3317230 by mondrake, kim.pepper, longwave: Fix test mock related PHPStan 0 issues

(cherry picked from commit 53803cfb)
parent d8dab58d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -96,8 +96,8 @@ public function testThirdPartySettings() {
    $this->assertSame('value 1', $this->plugin->getThirdPartySetting('the_module', 'the_key'));

    // When the section list is updated, also update the result returned.
    $section_list->setThirdPartySetting('the_module', 'the_key', 'value 2')->shouldBeCalled()->will(function ($args) {
      $this->getThirdPartySetting('the_module', 'the_key', NULL)->willReturn($args[2]);
    $section_list->setThirdPartySetting('the_module', 'the_key', 'value 2')->shouldBeCalled()->will(function (array $args) use ($section_list) {
      $section_list->getThirdPartySetting('the_module', 'the_key', NULL)->willReturn($args[2]);
    });

    // Update the plugin value.
+0 −25
Original line number Diff line number Diff line
@@ -1450,11 +1450,6 @@ parameters:
			count: 1
			path: modules/language/tests/src/Functional/LanguageBreadcrumbTest.php

		-
			message: "#^Call to an undefined method Drupal\\\\Tests\\\\layout_builder\\\\Unit\\\\DefaultsSectionStorageTest\\:\\:getThirdPartySetting\\(\\)\\.$#"
			count: 1
			path: modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php

		-
			message: "#^Constructor of class Drupal\\\\link\\\\Plugin\\\\migrate\\\\process\\\\FieldLink has an unused parameter \\$migration\\.$#"
			count: 1
@@ -2920,16 +2915,6 @@ parameters:
			count: 2
			path: tests/Drupal/KernelTests/Core/Entity/EntityDecoupledTranslationRevisionsTest.php

		-
			message: "#^Call to an undefined method Drupal\\\\KernelTests\\\\Core\\\\Entity\\\\EntityDisplayFormBaseTest\\:\\:getComponent\\(\\)\\.$#"
			count: 3
			path: tests/Drupal/KernelTests/Core/Entity/EntityDisplayFormBaseTest.php

		-
			message: "#^Call to an undefined method Drupal\\\\KernelTests\\\\Core\\\\Entity\\\\EntityDisplayFormBaseTest\\:\\:setComponent\\(\\)\\.$#"
			count: 1
			path: tests/Drupal/KernelTests/Core/Entity/EntityDisplayFormBaseTest.php

		-
			message: "#^Method Drupal\\\\KernelTests\\\\Core\\\\Entity\\\\EntityKernelTestBase\\:\\:createUser\\(\\) invoked with 4 parameters, 0\\-2 required\\.$#"
			count: 3
@@ -3120,16 +3105,6 @@ parameters:
			count: 1
			path: tests/Drupal/Tests/Core/Database/InstallerObjectTest.php

		-
			message: "#^Call to an undefined method Drupal\\\\Tests\\\\Core\\\\Entity\\\\EntityFieldManagerTest\\:\\:get\\(\\)\\.$#"
			count: 3
			path: tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php

		-
			message: "#^Call to an undefined method Drupal\\\\Tests\\\\Core\\\\Entity\\\\EntityTypeBundleInfoTest\\:\\:get\\(\\)\\.$#"
			count: 1
			path: tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php

		-
			message: "#^Call to method getDefinitions\\(\\) on an unknown class Drupal\\\\Core\\\\Plugin\\\\CategorizingPluginManagerTrait\\.$#"
			count: 3
+7 −7
Original line number Diff line number Diff line
@@ -37,9 +37,9 @@ public function testCopyFormValuesToEntity() {
      'region' => 'hidden',
    ];
    $entity->removeComponent('new_field_mismatch_type_visible')
      ->will(function ($args) {
      ->will(function (array $args) use ($entity) {
        // On subsequent calls, getComponent() will return an empty array.
        $this->getComponent($args[0])->willReturn([]);
        $entity->getComponent($args[0])->willReturn([]);
      })
      ->shouldBeCalled();

@@ -76,9 +76,9 @@ public function testCopyFormValuesToEntity() {
      'region' => 'hidden',
    ];
    $entity->removeComponent('field_start_visible_change_region')
      ->will(function ($args) {
      ->will(function (array $args) use ($entity) {
        // On subsequent calls, getComponent() will return an empty array.
        $this->getComponent($args[0])->willReturn([]);
        $entity->getComponent($args[0])->willReturn([]);
      })
      ->shouldBeCalled();

@@ -105,16 +105,16 @@ public function testCopyFormValuesToEntity() {
        'type' => 'textfield',
        'region' => 'content',
      ])
      ->will(function ($args) {
      ->will(function (array $args) use ($entity) {
        // On subsequent calls, getComponent() will return the newly set values.
        $this->getComponent($args[0])->willReturn($args[1]);
        $entity->getComponent($args[0])->willReturn($args[1]);
        $args[1] += [
          'settings' => [],
          'third_party_settings' => [
            'foo' => 'bar',
          ],
        ];
        $this->setComponent($args[0], $args[1])->shouldBeCalled();
        $entity->setComponent($args[0], $args[1])->shouldBeCalled();
      })
      ->shouldBeCalled();

+9 −6
Original line number Diff line number Diff line
@@ -431,13 +431,14 @@ public function testGetBaseFieldDefinitionsWithCaching() {

    $expected = ['id' => $field_definition];

    $cacheBackend = $this->cacheBackend;
    $this->cacheBackend->get('entity_base_field_definitions:test_entity_type:en')
      ->willReturn(FALSE)
      ->shouldBeCalled();
    $this->cacheBackend->set('entity_base_field_definitions:test_entity_type:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_field_info'])
      ->will(function ($args) {
      ->will(function (array $args) use ($cacheBackend) {
        $data = (object) ['data' => $args[1]];
        $this->get('entity_base_field_definitions:test_entity_type:en')
        $cacheBackend->get('entity_base_field_definitions:test_entity_type:en')
          ->willReturn($data)
          ->shouldBeCalled();
      })
@@ -458,6 +459,7 @@ public function testGetFieldDefinitionsWithCaching() {

    $expected = ['id' => $field_definition];

    $cacheBackend = $this->cacheBackend;
    $this->cacheBackend->get('entity_base_field_definitions:test_entity_type:en')
      ->willReturn((object) ['data' => $expected])
      ->shouldBeCalledTimes(2);
@@ -465,9 +467,9 @@ public function testGetFieldDefinitionsWithCaching() {
      ->willReturn(FALSE)
      ->shouldBeCalledTimes(1);
    $this->cacheBackend->set('entity_bundle_field_definitions:test_entity_type:test_bundle:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_field_info'])
      ->will(function ($args) {
      ->will(function (array $args) use ($cacheBackend) {
        $data = (object) ['data' => $args[1]];
        $this->get('entity_bundle_field_definitions:test_entity_type:test_bundle:en')
        $cacheBackend->get('entity_bundle_field_definitions:test_entity_type:test_bundle:en')
          ->willReturn($data)
          ->shouldBeCalled();
      })
@@ -507,14 +509,15 @@ function () use ($definitions) {
      'field_storage' => $field_storage_definition->reveal(),
    ];

    $cacheBackend = $this->cacheBackend;
    $this->cacheBackend->get('entity_base_field_definitions:test_entity_type:en')
      ->willReturn((object) ['data' => ['id' => $expected['id']]])
      ->shouldBeCalledTimes(2);
    $this->cacheBackend->get('entity_field_storage_definitions:test_entity_type:en')->willReturn(FALSE);

    $this->cacheBackend->set('entity_field_storage_definitions:test_entity_type:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_field_info'])
      ->will(function () use ($expected) {
        $this->get('entity_field_storage_definitions:test_entity_type:en')
      ->will(function () use ($expected, $cacheBackend) {
        $cacheBackend->get('entity_field_storage_definitions:test_entity_type:en')
          ->willReturn((object) ['data' => $expected])
          ->shouldBeCalled();
      })
+3 −2
Original line number Diff line number Diff line
@@ -232,10 +232,11 @@ public function testGetAllBundleInfo() {
      'banana' => $banana,
    ]);

    $cacheBackend = $this->cacheBackend;
    $this->cacheBackend->get('entity_bundle_info:en')->willReturn(FALSE);
    $this->cacheBackend->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_bundles'])
      ->will(function () {
        $this->get('entity_bundle_info:en')
      ->will(function () use ($cacheBackend) {
        $cacheBackend->get('entity_bundle_info:en')
          ->willReturn((object) ['data' => 'cached data'])
          ->shouldBeCalled();
      })