Issue #3433086 by mondrake: Method addMethods() of class PHPUnit\Framework\MockObject\MockBuilder is deprecated in PHPUnit 10
(cherry picked from commit b73c68de45
)
merge-requests/7859/head
parent
a44ba4db44
commit
bdcf4705fa
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Drupal\Tests\block\Unit\Plugin\DisplayVariant;
|
namespace Drupal\Tests\block\Unit\Plugin\DisplayVariant;
|
||||||
|
|
||||||
|
use Drupal\block\Plugin\DisplayVariant\BlockPageVariant;
|
||||||
use Drupal\Core\Cache\CacheableMetadata;
|
use Drupal\Core\Cache\CacheableMetadata;
|
||||||
use Drupal\Core\DependencyInjection\Container;
|
use Drupal\Core\DependencyInjection\Container;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
@ -43,8 +44,8 @@ class BlockPageVariantTest extends UnitTestCase {
|
||||||
* @param array $definition
|
* @param array $definition
|
||||||
* The plugin definition array.
|
* The plugin definition array.
|
||||||
*
|
*
|
||||||
* @return \Drupal\block\Plugin\DisplayVariant\BlockPageVariant|\PHPUnit\Framework\MockObject\MockObject
|
* @return \Drupal\block\Plugin\DisplayVariant\BlockPageVariant
|
||||||
* A mocked display variant plugin.
|
* A test display variant plugin.
|
||||||
*/
|
*/
|
||||||
public function setUpDisplayVariant($configuration = [], $definition = []) {
|
public function setUpDisplayVariant($configuration = [], $definition = []) {
|
||||||
|
|
||||||
|
@ -62,10 +63,7 @@ class BlockPageVariantTest extends UnitTestCase {
|
||||||
$this->blockRepository = $this->createMock('Drupal\block\BlockRepositoryInterface');
|
$this->blockRepository = $this->createMock('Drupal\block\BlockRepositoryInterface');
|
||||||
$this->blockViewBuilder = $this->createMock('Drupal\Core\Entity\EntityViewBuilderInterface');
|
$this->blockViewBuilder = $this->createMock('Drupal\Core\Entity\EntityViewBuilderInterface');
|
||||||
|
|
||||||
return $this->getMockBuilder('Drupal\block\Plugin\DisplayVariant\BlockPageVariant')
|
return new BlockPageVariant($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, ['config:block_list']);
|
||||||
->setConstructorArgs([$configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, ['config:block_list']])
|
|
||||||
->addMethods(['getRegionNames'])
|
|
||||||
->getMock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerBuild() {
|
public function providerBuild() {
|
||||||
|
|
|
@ -7,6 +7,7 @@ namespace Drupal\Tests\rest\Unit;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||||
use Drupal\rest\Plugin\views\display\RestExport;
|
use Drupal\rest\Plugin\views\display\RestExport;
|
||||||
|
use Drupal\views\Entity\View;
|
||||||
use Symfony\Component\Routing\Route;
|
use Symfony\Component\Routing\Route;
|
||||||
use Symfony\Component\Routing\RouteCollection;
|
use Symfony\Component\Routing\RouteCollection;
|
||||||
|
|
||||||
|
@ -41,10 +42,7 @@ class CollectRoutesTest extends UnitTestCase {
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$view = $this->getMockBuilder('\Drupal\views\Entity\View')
|
$view = new View(['id' => 'test_view'], 'view');
|
||||||
->addMethods(['initHandlers'])
|
|
||||||
->setConstructorArgs([['id' => 'test_view'], 'view'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$view_executable = $this->getMockBuilder('\Drupal\views\ViewExecutable')
|
$view_executable = $this->getMockBuilder('\Drupal\views\ViewExecutable')
|
||||||
->onlyMethods(['initHandlers', 'getTitle'])
|
->onlyMethods(['initHandlers', 'getTitle'])
|
||||||
|
|
|
@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Drupal\Tests\views\Unit\Plugin\field;
|
namespace Drupal\Tests\views\Unit\Plugin\field;
|
||||||
|
|
||||||
use Drupal\Core\GeneratedUrl;
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
|
use Drupal\Core\GeneratedUrl;
|
||||||
use Drupal\Core\Language\Language;
|
use Drupal\Core\Language\Language;
|
||||||
use Drupal\Core\Render\Markup;
|
use Drupal\Core\Render\Markup;
|
||||||
use Drupal\Core\Url;
|
use Drupal\Core\Url;
|
||||||
|
@ -15,11 +15,11 @@ use Drupal\Core\Utility\UnroutedUrlAssembler;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||||
use Drupal\views\ResultRow;
|
use Drupal\views\ResultRow;
|
||||||
|
use Prophecy\Prophet;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\Routing\Route;
|
use Symfony\Component\Routing\Route;
|
||||||
use Prophecy\Prophet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @coversDefaultClass \Drupal\views\Plugin\views\field\FieldPluginBase
|
* @coversDefaultClass \Drupal\views\Plugin\views\field\FieldPluginBase
|
||||||
|
@ -640,18 +640,13 @@ class FieldPluginBaseTest extends UnitTestCase {
|
||||||
/**
|
/**
|
||||||
* Sets up a test field.
|
* 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.
|
* The test field.
|
||||||
*/
|
*/
|
||||||
protected function setupTestField(array $options = []) {
|
protected function setupTestField(array $options = []) {
|
||||||
/** @var \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTestField $field */
|
$field = new FieldPluginBaseTestField($this->configuration, $this->pluginId, $this->pluginDefinition);
|
||||||
$field = $this->getMockBuilder('Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTestField')
|
|
||||||
->addMethods(['l'])
|
|
||||||
->setConstructorArgs([$this->configuration, $this->pluginId, $this->pluginDefinition])
|
|
||||||
->getMock();
|
|
||||||
$field->init($this->executable, $this->display, $options);
|
$field->init($this->executable, $this->display, $options);
|
||||||
$field->setLinkGenerator($this->linkGenerator);
|
$field->setLinkGenerator($this->linkGenerator);
|
||||||
|
|
||||||
return $field;
|
return $field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Drupal\Tests\Component\Plugin\Discovery;
|
namespace Drupal\Tests\Component\Plugin\Discovery;
|
||||||
|
|
||||||
|
use Drupal\Component\Plugin\Discovery\StaticDiscovery;
|
||||||
|
use Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,9 +64,9 @@ class StaticDiscoveryDecoratorTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public function testGetDefinition($expected, $has_register_definitions, $exception_on_invalid, $definitions, $base_plugin_id) {
|
public function testGetDefinition($expected, $has_register_definitions, $exception_on_invalid, $definitions, $base_plugin_id) {
|
||||||
// Mock our StaticDiscoveryDecorator.
|
// Mock our StaticDiscoveryDecorator.
|
||||||
$mock_decorator = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator')
|
$mock_decorator = $this->getMockBuilder(StaticDiscoveryDecorator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->addMethods(['registeredDefinitionCallback'])
|
->onlyMethods([])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
// Set up the ::$registerDefinitions property.
|
// Set up the ::$registerDefinitions property.
|
||||||
|
@ -129,9 +131,9 @@ class StaticDiscoveryDecoratorTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public function testGetDefinitions($has_register_definitions, $definitions) {
|
public function testGetDefinitions($has_register_definitions, $definitions) {
|
||||||
// Mock our StaticDiscoveryDecorator.
|
// Mock our StaticDiscoveryDecorator.
|
||||||
$mock_decorator = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator')
|
$mock_decorator = $this->getMockBuilder(StaticDiscoveryDecorator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->addMethods(['registeredDefinitionCallback'])
|
->onlyMethods([])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
// Set up the ::$registerDefinitions property.
|
// Set up the ::$registerDefinitions property.
|
||||||
|
@ -194,9 +196,9 @@ class StaticDiscoveryDecoratorTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public function testCall($method, $args) {
|
public function testCall($method, $args) {
|
||||||
// Mock a decorated object.
|
// Mock a decorated object.
|
||||||
$mock_decorated = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryInterface')
|
$mock_decorated = $this->getMockBuilder(StaticDiscoveryTestDecoratedClass::class)
|
||||||
->addMethods([$method])
|
->onlyMethods([$method])
|
||||||
->getMockForAbstractClass();
|
->getMock();
|
||||||
// Our mocked method will return any arguments sent to it.
|
// Our mocked method will return any arguments sent to it.
|
||||||
$mock_decorated->expects($this->once())
|
$mock_decorated->expects($this->once())
|
||||||
->method($method)
|
->method($method)
|
||||||
|
@ -206,18 +208,13 @@ class StaticDiscoveryDecoratorTest extends TestCase {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create a mock decorator.
|
// Create the decorator.
|
||||||
$mock_decorator = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator')
|
$decorator = new StaticDiscoveryDecorator($mock_decorated);
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
// Poke the decorated object into our decorator.
|
|
||||||
$ref_decorated = new \ReflectionProperty($mock_decorator, 'decorated');
|
|
||||||
$ref_decorated->setValue($mock_decorator, $mock_decorated);
|
|
||||||
|
|
||||||
// Exercise __call.
|
// Exercise __call on the decorator.
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$args,
|
$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();
|
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 [];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Drupal\Tests\Core\Config\Entity;
|
namespace Drupal\Tests\Core\Config\Entity;
|
||||||
|
|
||||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||||
|
use Drupal\Core\Entity\EntityDisplayModeBase;
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
|
||||||
|
@ -92,11 +93,7 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
|
||||||
[$this->entityType, TRUE, $this->entityInfo],
|
[$this->entityType, TRUE, $this->entityInfo],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->entity = $this->getMockBuilder('\Drupal\Core\Entity\EntityDisplayModeBase')
|
$this->entity = new EntityDisplayModeBaseTestableClass($values, $this->entityType);
|
||||||
->setConstructorArgs([$values, $this->entityType])
|
|
||||||
->addMethods(['getFilterFormat'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$dependencies = $this->entity->calculateDependencies()->getDependencies();
|
$dependencies = $this->entity->calculateDependencies()->getDependencies();
|
||||||
$this->assertContains('test_module', $dependencies['module']);
|
$this->assertContains('test_module', $dependencies['module']);
|
||||||
}
|
}
|
||||||
|
@ -154,3 +151,9 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class extending EntityDisplayModeBase for testing purposes.
|
||||||
|
*/
|
||||||
|
class EntityDisplayModeBaseTestableClass extends EntityDisplayModeBase {
|
||||||
|
}
|
||||||
|
|
|
@ -373,10 +373,7 @@ class FormValidatorTest extends UnitTestCase {
|
||||||
* @dataProvider providerTestPerformRequiredValidation
|
* @dataProvider providerTestPerformRequiredValidation
|
||||||
*/
|
*/
|
||||||
public function testPerformRequiredValidation($element, $expected_message, $call_watchdog) {
|
public function testPerformRequiredValidation($element, $expected_message, $call_watchdog) {
|
||||||
$form_validator = $this->getMockBuilder('Drupal\Core\Form\FormValidator')
|
$form_validator = new FormValidator(new RequestStack(), $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $this->formErrorHandler);
|
||||||
->setConstructorArgs([new RequestStack(), $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $this->formErrorHandler])
|
|
||||||
->addMethods(['setError'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
if ($call_watchdog) {
|
if ($call_watchdog) {
|
||||||
$this->logger->expects($this->once())
|
$this->logger->expects($this->once())
|
||||||
|
|
Loading…
Reference in New Issue