Verified Commit 4869fb9a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3433086 by mondrake: Method addMethods() of class...

Issue #3433086 by mondrake: Method addMethods() of class PHPUnit\Framework\MockObject\MockBuilder is deprecated in PHPUnit 10

(cherry picked from commit b73c68de)
parent 5e5839ab
Loading
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

namespace Drupal\Tests\block\Unit\Plugin\DisplayVariant;

use Drupal\block\Plugin\DisplayVariant\BlockPageVariant;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\DependencyInjection\Container;
use Drupal\Tests\UnitTestCase;
@@ -43,8 +44,8 @@ class BlockPageVariantTest extends UnitTestCase {
   * @param array $definition
   *   The plugin definition array.
   *
   * @return \Drupal\block\Plugin\DisplayVariant\BlockPageVariant|\PHPUnit\Framework\MockObject\MockObject
   *   A mocked display variant plugin.
   * @return \Drupal\block\Plugin\DisplayVariant\BlockPageVariant
   *   A test display variant plugin.
   */
  public function setUpDisplayVariant($configuration = [], $definition = []) {

@@ -62,10 +63,7 @@ public function setUpDisplayVariant($configuration = [], $definition = []) {
    $this->blockRepository = $this->createMock('Drupal\block\BlockRepositoryInterface');
    $this->blockViewBuilder = $this->createMock('Drupal\Core\Entity\EntityViewBuilderInterface');

    return $this->getMockBuilder('Drupal\block\Plugin\DisplayVariant\BlockPageVariant')
      ->setConstructorArgs([$configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, ['config:block_list']])
      ->addMethods(['getRegionNames'])
      ->getMock();
    return new BlockPageVariant($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, ['config:block_list']);
  }

  public static function providerBuild() {
+2 −4
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\Tests\UnitTestCase;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\rest\Plugin\views\display\RestExport;
use Drupal\views\Entity\View;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

@@ -41,10 +42,7 @@ protected function setUp(): void {
      ->disableOriginalConstructor()
      ->getMock();

    $view = $this->getMockBuilder('\Drupal\views\Entity\View')
      ->addMethods(['initHandlers'])
      ->setConstructorArgs([['id' => 'test_view'], 'view'])
      ->getMock();
    $view = new View(['id' => 'test_view'], 'view');

    $view_executable = $this->getMockBuilder('\Drupal\views\ViewExecutable')
      ->onlyMethods(['initHandlers', 'getTitle'])
+4 −9
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@

namespace Drupal\Tests\views\Unit\Plugin\field;

use Drupal\Core\GeneratedUrl;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\GeneratedUrl;
use Drupal\Core\Language\Language;
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
@@ -15,11 +15,11 @@
use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Prophecy\Prophet;
use Symfony\Component\DependencyInjection\ContainerBuilder;
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
@@ -640,18 +640,13 @@ public static function providerTestRenderAsExternalLinkWithPathAndTokens() {
  /**
   * Sets up a test field.
   *
   * @return \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTestField|\PHPUnit\Framework\MockObject\MockObject
   * @return \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTestField
   *   The test field.
   */
  protected function setupTestField(array $options = []) {
    /** @var \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTestField $field */
    $field = $this->getMockBuilder('Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTestField')
      ->addMethods(['l'])
      ->setConstructorArgs([$this->configuration, $this->pluginId, $this->pluginDefinition])
      ->getMock();
    $field = new FieldPluginBaseTestField($this->configuration, $this->pluginId, $this->pluginDefinition);
    $field->init($this->executable, $this->display, $options);
    $field->setLinkGenerator($this->linkGenerator);

    return $field;
  }

+32 −16
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@

namespace Drupal\Tests\Component\Plugin\Discovery;

use Drupal\Component\Plugin\Discovery\StaticDiscovery;
use Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator;
use PHPUnit\Framework\TestCase;

/**
@@ -62,9 +64,9 @@ public static function providerGetDefinition() {
   */
  public function testGetDefinition($expected, $has_register_definitions, $exception_on_invalid, $definitions, $base_plugin_id) {
    // Mock our StaticDiscoveryDecorator.
    $mock_decorator = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator')
    $mock_decorator = $this->getMockBuilder(StaticDiscoveryDecorator::class)
      ->disableOriginalConstructor()
      ->addMethods(['registeredDefinitionCallback'])
      ->onlyMethods([])
      ->getMock();

    // Set up the ::$registerDefinitions property.
@@ -129,9 +131,9 @@ public static function providerGetDefinitions() {
   */
  public function testGetDefinitions($has_register_definitions, $definitions) {
    // Mock our StaticDiscoveryDecorator.
    $mock_decorator = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator')
    $mock_decorator = $this->getMockBuilder(StaticDiscoveryDecorator::class)
      ->disableOriginalConstructor()
      ->addMethods(['registeredDefinitionCallback'])
      ->onlyMethods([])
      ->getMock();

    // Set up the ::$registerDefinitions property.
@@ -194,9 +196,9 @@ public static function providerCall() {
   */
  public function testCall($method, $args) {
    // Mock a decorated object.
    $mock_decorated = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryInterface')
      ->addMethods([$method])
      ->getMockForAbstractClass();
    $mock_decorated = $this->getMockBuilder(StaticDiscoveryTestDecoratedClass::class)
      ->onlyMethods([$method])
      ->getMock();
    // Our mocked method will return any arguments sent to it.
    $mock_decorated->expects($this->once())
      ->method($method)
@@ -206,18 +208,13 @@ function () {
        }
      );

    // Create a mock decorator.
    $mock_decorator = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator')
      ->disableOriginalConstructor()
      ->getMock();
    // Poke the decorated object into our decorator.
    $ref_decorated = new \ReflectionProperty($mock_decorator, 'decorated');
    $ref_decorated->setValue($mock_decorator, $mock_decorated);
    // Create the decorator.
    $decorator = new StaticDiscoveryDecorator($mock_decorated);

    // Exercise __call.
    // Exercise __call on the decorator.
    $this->assertEquals(
      $args,
      \call_user_func_array([$mock_decorated, $method], $args)
      \call_user_func_array([$decorator, $method], $args)
    );
  }

@@ -234,3 +231,22 @@ interface StaticDiscoveryDecoratorTestMockInterface {
  public function registerDefinitionsCallback();

}

/**
 * A class extending StaticDiscovery for testing purposes.
 */
class StaticDiscoveryTestDecoratedClass extends StaticDiscovery {

  public function getDefinitions(): array {
    return [];
  }

  public function complexArguments(mixed ...$args): array {
    return $args;
  }

  public function noArguments(): array {
    return [];
  }

}
+8 −5
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
namespace Drupal\Tests\Core\Config\Entity;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityDisplayModeBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;

@@ -92,11 +93,7 @@ public function testCalculateDependencies() {
        [$this->entityType, TRUE, $this->entityInfo],
      ]);

    $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\EntityDisplayModeBase')
      ->setConstructorArgs([$values, $this->entityType])
      ->addMethods(['getFilterFormat'])
      ->getMock();

    $this->entity = new EntityDisplayModeBaseTestableClass($values, $this->entityType);
    $dependencies = $this->entity->calculateDependencies()->getDependencies();
    $this->assertContains('test_module', $dependencies['module']);
  }
@@ -154,3 +151,9 @@ public function testGetTargetType() {
  }

}

/**
 * A class extending EntityDisplayModeBase for testing purposes.
 */
class EntityDisplayModeBaseTestableClass extends EntityDisplayModeBase {
}
Loading