willReturnSelf example

private array $registeredHandlers = [];

    private readonly Connection $connection;

    private readonly IdsCollection $ids;

    protected function setUp(): void
    {
        $this->ids = new IdsCollection();

        $qb = $this->createMock(QueryBuilder::class);
        $qb->method('select')->willReturnSelf();
        $qb->method('from')->willReturnSelf();
        $qb->method('leftJoin')->willReturnSelf();
        $qb->method('andWhere')->willReturnSelf();

        $qb
            ->method('setParameter')
            ->willReturnCallback(function Dstring $key, string $paymentMethodId): QueryBuilder {
                static::assertSame('paymentMethodId', $key);

                if (\array_key_exists($paymentMethodId$this->registeredHandlers)) {
                    $handler = $this->registeredHandlers[$paymentMethodId];

                    
$mock_data_definition = $this->getMockBuilder(ContextDefinitionInterface::class)
      ->onlyMethods([
        'getConstraints',
        'setLabel',
        'setDescription',
        'setRequired',
        'setConstraints',
      ])
      ->getMockForAbstractClass();
    $mock_data_definition->expects($this->once())
      ->method('setLabel')
      ->willReturnSelf();
    $mock_data_definition->expects($this->once())
      ->method('setDescription')
      ->willReturnSelf();
    $mock_data_definition->expects($this->once())
      ->method('setRequired')
      ->willReturnSelf();
    $mock_data_definition->expects($this->once())
      ->method('getConstraints')
      ->willReturn([]);
    $mock_data_definition->expects($this->once())
      ->method('setConstraints')
      

  public function testCall() {
    $mock_router = $this->createMock(RouterInterface::class);

    $this->router = $this->getMockBuilder(MockRouterInterface::class)
      ->disableOriginalConstructor()
      ->onlyMethods(['getRouteCollection', 'match', 'getContext', 'setContext', 'generate', 'add'])
      ->getMock();
    $this->router->expects($this->once())
      ->method('add')
      ->with($mock_router)
      ->willReturnSelf();
    $this->accessAwareRouter = new AccessAwareRouter($this->router, $this->accessManager, $this->currentUser);

    $this->accessAwareRouter->add($mock_router);
  }

}

/** * Interface used in the mocking process of this test. */
interface MockRouterInterface extends RouterInterface {

  
// Type D intentionally doesn't exist.         'type_d' => [
          'display_plugin' => 'type_d',
          'display_options' => [],
        ],
      ],
    ], 'view');

    $query = $this->createMock('Drupal\Core\Entity\Query\QueryInterface');
    $query->expects($this->exactly(2))
      ->method('condition')
      ->willReturnSelf();
    $query->expects($this->once())
      ->method('execute')
      ->willReturn(['test_view_1', 'test_view_2', 'test_view_3']);

    $view_storage = $this->getMockBuilder('Drupal\Core\Config\Entity\ConfigEntityStorage')
      ->disableOriginalConstructor()
      ->getMock();
    $view_storage->expects($this->once())
      ->method('getQuery')
      ->willReturn($query);

    
$childA = new ChildA();
        $childB = new ChildB();
        $childA->name = false;
        $childB->name = 'fake';
        $entity->childA = [$childA];
        $entity->childB = [$childB];
        $validatorContext = $this->createMock(ContextualValidatorInterface::class);
        $validatorContext
            ->expects($this->once())
            ->method('validate')
            ->with($entity, null, [])
            ->willReturnSelf();

        $validator = $this
            ->getMockBuilder(RecursiveValidator::class)
            ->disableOriginalConstructor()
            ->onlyMethods(['startContext'])
            ->getMock();
        $validator
            ->expects($this->once())
            ->method('startContext')
            ->willReturn($validatorContext);

        
\Drupal::setContainer($container);
  }

  /** * Tests rebuilding the theme data. * * @see \Drupal\Core\Extension\ThemeHandler::rebuildThemeData() */
  public function testRebuildThemeData() {
    $this->themeList->expects($this->once())
      ->method('reset')
      ->willReturnSelf();
    $this->themeList->expects($this->once())
      ->method('getList')
      ->willReturn([
        'stark' => new Extension($this->root, 'theme', 'core/themes/stark/stark.info.yml', 'stark.theme'),
      ]);

    $theme_data = $this->themeHandler->rebuildThemeData();
    $this->assertCount(1, $theme_data);
    $info = $theme_data['stark'];

    // Ensure some basic properties.
Home | Imprint | This part of the site doesn't use cookies.