Verified Commit de4c1e82 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3232714 by paulocs, vsujeetkumar, mondrake, longwave, quietone,...

Issue #3232714 by paulocs, vsujeetkumar, mondrake, longwave, quietone, larowlan: Replace, in tests, mocks that do not configure doubles with their actual objects
parent b6a3c633
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -52,15 +52,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = [])
    $translation_manager = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface');

    // Make an object to test.
    $builder = $this->getMockBuilder('Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder')
      ->setConstructorArgs([
        $entity_type_manager,
        $config_factory,
        $forum_manager,
        $translation_manager,
      ])
      ->onlyMethods([])
      ->getMock();
    $builder = new ForumListingBreadcrumbBuilder($entity_type_manager, $config_factory, $forum_manager, $translation_manager);

    $route_match = $this->createMock('Drupal\Core\Routing\RouteMatchInterface');
    $route_match->expects($this->once())
+1 −11
Original line number Diff line number Diff line
@@ -57,17 +57,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = [])
    $translation_manager = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface');

    // Make an object to test.
    $builder = $this->getMockBuilder('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder')
      ->setConstructorArgs(
        [
          $entity_type_manager,
          $config_factory,
          $forum_manager,
          $translation_manager,
        ]
      )
      ->onlyMethods([])
      ->getMock();
    $builder = new ForumNodeBreadcrumbBuilder($entity_type_manager, $config_factory, $forum_manager, $translation_manager);

    $route_match = $this->createMock('Drupal\Core\Routing\RouteMatchInterface');
    $route_match->expects($this->once())
+4 −7
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\Tests\views\Unit\Controller;

use Drupal\Core\Render\RenderContext;
use Drupal\Core\Render\Renderer;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Ajax\ViewAjaxResponse;
use Drupal\views\Controller\ViewAjaxController;
@@ -94,7 +95,7 @@ protected function setUp(): void {
    $element_info_manager = $this->createMock('\Drupal\Core\Render\ElementInfoManagerInterface');
    $request_stack = new RequestStack();
    $request_stack->push(new Request());
    $args = [
    $this->renderer = new Renderer(
      $this->createMock('\Drupal\Core\Controller\ControllerResolverInterface'),
      $this->createMock('\Drupal\Core\Theme\ThemeManagerInterface'),
      $element_info_manager,
@@ -106,12 +107,8 @@ protected function setUp(): void {
          'languages:language_interface',
          'theme',
        ],
      ],
    ];
    $this->renderer = $this->getMockBuilder('Drupal\Core\Render\Renderer')
      ->setConstructorArgs($args)
      ->onlyMethods([])
      ->getMock();
      ]
    );
    $container = new ContainerBuilder();
    $container->set('renderer', $this->renderer);
    \Drupal::setContainer($container);
+5 −8
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Language\Language;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Validator\ValidatorInterface;

/**
@@ -417,10 +418,8 @@ public function testTypedData(bool $bundle_typed_data_definition, bool $entity_t
   */
  public function testValidate() {
    $validator = $this->createMock(ValidatorInterface::class);
    /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit\Framework\MockObject\MockObject $empty_violation_list */
    $empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList')
      ->onlyMethods([])
      ->getMock();
    /** @var \Symfony\Component\Validator\ConstraintViolationList $empty_violation_list */
    $empty_violation_list = new ConstraintViolationList();
    $non_empty_violation_list = clone $empty_violation_list;
    $violation = $this->createMock('\Symfony\Component\Validator\ConstraintViolationInterface');
    $non_empty_violation_list->add($violation);
@@ -446,10 +445,8 @@ public function testValidate() {
   */
  public function testRequiredValidation() {
    $validator = $this->createMock(ValidatorInterface::class);
    /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit\Framework\MockObject\MockObject $empty_violation_list */
    $empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList')
      ->onlyMethods([])
      ->getMock();
    /** @var \Symfony\Component\Validator\ConstraintViolationList $empty_violation_list */
    $empty_violation_list = new ConstraintViolationList();
    $validator->expects($this->once())
      ->method('validate')
      ->with($this->entity->getTypedData())
+2 −4
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormValidator;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -179,10 +180,7 @@ protected function setUp(): void {
    $this->requestStack->push($this->request);
    $this->logger = $this->createMock('Drupal\Core\Logger\LoggerChannelInterface');
    $form_error_handler = $this->createMock('Drupal\Core\Form\FormErrorHandlerInterface');
    $this->formValidator = $this->getMockBuilder('Drupal\Core\Form\FormValidator')
      ->setConstructorArgs([$this->requestStack, $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $form_error_handler])
      ->onlyMethods([])
      ->getMock();
    $this->formValidator = new FormValidator($this->requestStack, $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $form_error_handler);
    $this->formSubmitter = $this->getMockBuilder('Drupal\Core\Form\FormSubmitter')
      ->setConstructorArgs([$this->requestStack, $this->urlGenerator])
      ->onlyMethods(['batchGet'])
Loading