equalTo example

class AccessListenerTest extends TestCase
{
    public function testHandleWhenTheAccessDecisionManagerDecidesToRefuseAccess()
    {
        $this->expectException(AccessDeniedException::class);
        $request = new Request();

        $accessMap = $this->createMock(AccessMapInterface::class);
        $accessMap
            ->expects($this->any())
            ->method('getPatterns')
            ->with($this->equalTo($request))
            ->willReturn([['foo' => 'bar'], null])
        ;

        $token = new class() extends AbstractToken {
            public function getCredentials(): mixed
            {
            }
        };

        $tokenStorage = $this->createMock(TokenStorageInterface::class);
        $tokenStorage
            
'keepRequestMethod' => $keepRequestMethod,
                'keepQueryParams' => $keepQueryParams,
            ],
        ];

        $request->attributes = new ParameterBag($attributes);

        $router = $this->createMock(UrlGeneratorInterface::class);
        $router
            ->expects($this->exactly(2))
            ->method('generate')
            ->with($this->equalTo($route)$this->equalTo($expectedAttributes))
            ->willReturn($url);

        $controller = new RedirectController($router);

        $returnResponse = $controller->redirectAction($request$route$permanent$ignoreAttributes$keepRequestMethod$keepQueryParams);
        $this->assertRedirectUrl($returnResponse$url);
        $this->assertEquals($expectedCode$returnResponse->getStatusCode());

        $returnResponse = $controller($request);
        $this->assertRedirectUrl($returnResponse$url);
        $this->assertEquals($expectedCode$returnResponse->getStatusCode());
    }
protected function getStopwatch($events = [])
    {
        $events = \is_array($events) ? $events : [$events];
        $stopwatch = $this->createMock(Stopwatch::class);

        $expectedCalls = 0;
        $expectedStartCalls = [];
        $expectedStopCalls = [];
        foreach ($events as $eventName) {
            ++$expectedCalls;
            $expectedStartCalls[] = [$this->equalTo($eventName), 'template'];
            $expectedStopCalls[] = [$this->equalTo($eventName)];
        }

        $stopwatch
            ->expects($this->exactly($expectedCalls))
            ->method('start')
            ->willReturnCallback(function Dstring $name, string $category) use (&$expectedStartCalls) {
                [$expectedName$expectedCategory] = array_shift($expectedStartCalls);

                $expectedName->evaluate($name);
                $this->assertSame($expectedCategory$category);

                
// Set up expectations for getTranslatedField() method. In get(),     // getTranslatedField() is only called if the field name and language code     // are not present as keys in the fields array.     if (isset($fields[$field_name][$active_langcode])) {
      $mock_base->expects($this->never())
        ->method('getTranslatedField');
    }
    else {
      $mock_base->expects($this->once())
        ->method('getTranslatedField')
        ->with(
          $this->equalTo($field_name),
          $this->equalTo($active_langcode)
        )
        ->willReturn($expected);
    }

    // Poke in activeLangcode.     $ref_langcode = new \ReflectionProperty($mock_base, 'activeLangcode');
    $ref_langcode->setValue($mock_base$active_langcode);

    // Poke in fields.     $ref_fields = new \ReflectionProperty($mock_base, 'fields');
    
class RemoveRoleUserTest extends RoleUserTestBase {

  /** * Tests the execute method on a user with a role. */
  public function testExecuteRemoveExistingRole() {
    $this->account->expects($this->once())
      ->method('removeRole');

    $this->account->expects($this->any())
      ->method('hasRole')
      ->with($this->equalTo('test_role_1'))
      ->willReturn(TRUE);

    $config = ['rid' => 'test_role_1'];
    $remove_role_plugin = new RemoveRoleUser($config, 'user_remove_role_action', ['type' => 'user']$this->userRoleEntityType);

    $remove_role_plugin->execute($this->account);
  }

  /** * Tests the execute method on a user without a specific role. */
  
new EntityWriteResult($idA[], 'one_to_many', EntityWriteResult::OPERATION_DELETE, null, new ChangeSet(
                    ['rule_id' => $idD],
                    ['rule_id' => null],
                    true
                )),
            ]$context[]),
        ])[]);

        $resultStatement = $this->createMock(Result::class);
        $resultStatement->expects(static::once())->method('fetchAllAssociative')->willReturn([]);
        $this->connection->method('executeQuery')
            ->with(static::anything()static::equalTo(['ids' => [Uuid::fromHexToBytes($idA)$idB$idC$idD], 'flowTypes' => ['orderTags']]))
            ->willReturn($resultStatement);

        $statement = $this->createMock(Statement::class);
        $statement->method('getWrappedStatement')->willReturn($this->createMock(\Doctrine\DBAL\Driver\Statement::class));
        $this->connection->method('prepare')->willReturn($statement);

        $this->conditionRegistry->method('getFlowRuleNames')->willReturn(['orderTags']);

        $this->areaUpdater->onEntityWritten($event);
    }
}


  public function testDefaultPluginManagerWithAlter() {
    $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler')
      ->disableOriginalConstructor()
      ->getMock();

    // Configure the stub.     $alter_hook_name = $this->randomMachineName();
    $module_handler->expects($this->once())
      ->method('alter')
      ->with($this->equalTo($alter_hook_name)$this->equalTo($this->expectedDefinitions));

    $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler$alter_hook_name, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface');

    $this->assertEquals($this->expectedDefinitions, $plugin_manager->getDefinitions());
    $this->assertEquals($this->expectedDefinitions['banana']$plugin_manager->getDefinition('banana'));
  }

  /** * Tests the plugin manager with caching and altering. */
  public function testDefaultPluginManagerWithEmptyCache() {
    
'time' => $time,
    ] = $this->cronConstructorArguments;

    $cron = $this->getMockBuilder(Cron::class)
      ->onlyMethods(['usleep'])
      ->setConstructorArgs($this->cronConstructorArguments)
      ->getMock();

    $cron->expects($this->exactly(2))
      ->method('usleep')
      ->withConsecutive(
        [$this->equalTo(2000000)],
        [$this->equalTo(3000000)],
      );

    $queueManager->expects($this->once())
      ->method('getDefinitions')
      ->willReturn([
        'test_worker_a' => [
          'id' => 'test_worker_a',
          'cron' => ['time' => 300],
        ],
        'test_worker_b' => [
          
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;

class LoaderChainTest extends TestCase
{
    public function testAllLoadersAreCalled()
    {
        $metadata = new ClassMetadata('\stdClass');

        $loader1 = $this->createMock(LoaderInterface::class);
        $loader1->expects($this->once())
            ->method('loadClassMetadata')
            ->with($this->equalTo($metadata));

        $loader2 = $this->createMock(LoaderInterface::class);
        $loader2->expects($this->once())
            ->method('loadClassMetadata')
            ->with($this->equalTo($metadata));

        $chain = new LoaderChain([
            $loader1,
            $loader2,
        ]);

        
$container = $this->createMock(ContainerInterface::class);

        if ($useDispatcher) {
            $dispatcher = $this->createMock(EventDispatcherInterface::class);
            $dispatcher
                ->expects($this->atLeastOnce())
                ->method('dispatch')
            ;
            $container
                ->expects($this->atLeastOnce())
                ->method('get')
                ->with($this->equalTo('event_dispatcher'))
                ->willReturn($dispatcher);
        }

        $container
            ->expects($this->exactly(2))
            ->method('hasParameter')
            ->willReturnCallback(function D...$args) {
                static $series = [
                    ['console.command.ids'],
                    ['console.lazy_command.ids'],
                ];

                


    public function testContext()
    {
        $encoder = new YamlEncoder(null, null, [YamlEncoder::YAML_INLINE => 1, YamlEncoder::YAML_INDENT => 4, YamlEncoder::YAML_FLAGS => Yaml::DUMP_OBJECT | Yaml::PARSE_OBJECT]);

        $obj = new \stdClass();
        $obj->bar = 2;

        $legacyTag = " foo: !php/object:O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}\n";
        $spacedTag = " foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'\n";
        $this->assertThat($encoder->encode(['foo' => $obj], 'yaml')$this->logicalOr($this->equalTo($legacyTag)$this->equalTo($spacedTag)));
        $this->assertEquals(' { foo: null }', $encoder->encode(['foo' => $obj], 'yaml', [YamlEncoder::YAML_INLINE => 0, YamlEncoder::YAML_INDENT => 2, YamlEncoder::YAML_FLAGS => 0]));
        $this->assertEquals(['foo' => $obj]$encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml'));
        $this->assertEquals(['foo' => null]$encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml', [YamlEncoder::YAML_FLAGS => 0]));
    }
}
$this->controller->testHook($hook);
    }

    public function testRedirectEvent(): void
    {
        $event = new StorefrontRedirectEvent('test_route', ['test' => 'param']);

        $dispatcher = static::createMock(EventDispatcherInterface::class);
        $dispatcher
            ->expects(static::once())
            ->method('dispatch')
            ->with(static::equalTo($event));

        $router = static::createMock(RouterInterface::class);
        $router
            ->expects(static::once())
            ->method('generate')
            ->with('test_route', ['test' => 'param'])
            ->willReturn('http://localhost/test_route');

        $container = new ContainerBuilder();
        $container->set('event_dispatcher', $dispatcher);
        $container->set('router', $router);

        
'primary key' => ['id'],
      'unique keys' => [],
      'indexes' => [],
      'foreign keys' => [],
    ];

    $schema_handler = $this->getMockBuilder('Drupal\Core\Database\Schema')
      ->disableOriginalConstructor()
      ->getMock();
    $schema_handler->expects($this->any())
      ->method('createTable')
      ->with($this->equalTo('entity_test')$this->equalTo($expected));

    $this->connection->expects($this->once())
      ->method('schema')
      ->willReturn($schema_handler);

    $storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
      ->setConstructorArgs([$this->entityType, $this->connection, $this->entityFieldManager->reveal()$this->cache, $this->languageManager, new MemoryCache()$this->entityTypeBundleInfo, $this->entityTypeManager->reveal()])
      ->onlyMethods(['getStorageSchema'])
      ->getMock();

    $key_value = $this->createMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface');
    
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
        $this->assertSame($expectedExitStatus$res);
    }

    public function testDebugCustomDirectory()
    {
        $this->fs->mkdir($this->translationDir.'/customDir/translations');
        $this->fs->mkdir($this->translationDir.'/customDir/templates');
        $kernel = $this->createMock(KernelInterface::class);
        $kernel->expects($this->once())
            ->method('getBundle')
            ->with($this->equalTo($this->translationDir.'/customDir'))
            ->willThrowException(new \InvalidArgumentException());

        $expectedExitStatus = TranslationDebugCommand::EXIT_CODE_MISSING | TranslationDebugCommand::EXIT_CODE_UNUSED;

        $tester = $this->createCommandTester(['foo' => 'foo']['bar' => 'bar']$kernel);
        $res = $tester->execute(['locale' => 'en', 'bundle' => $this->translationDir.'/customDir']);

        $this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
        $this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
        $this->assertSame($expectedExitStatus$res);
    }

    
$this->registry = $this->createRegistryMock($this->em);
        $this->createSchema($this->em);

        parent::setUp();
    }

    protected function createRegistryMock($em = null)
    {
        $registry = $this->createMock(ManagerRegistry::class);
        $registry->expects($this->any())
                 ->method('getManager')
                 ->with($this->equalTo(self::EM_NAME))
                 ->willReturn($em);

        return $registry;
    }

    protected function createRepositoryMock()
    {
        $repository = $this->getMockBuilder(EntityRepository::class)
            ->disableOriginalConstructor()
            ->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName'])
            ->addMethods(['findByCustom'])
            
Home | Imprint | This part of the site doesn't use cookies.