ReverseContainer example


class ReverseContainerTest extends TestCase {

  /** * @covers ::getId */
  public function testGetId(): void {
    $container = new ContainerBuilder();
    $service = new \stdClass();
    $container->set('bar', $service);

    $reverse_container = new ReverseContainer($container);

    $this->assertSame('bar', $reverse_container->getId($service));
    $non_service = new \stdClass();
    $this->assertNull($reverse_container->getId($non_service));
    $this->assertSame('service_container', $reverse_container->getId($container));
  }

  /** * @covers ::recordContainer */
  public function testRecordContainer(): void {
    

  public static function setContainerWithKernel() {
    $container = new ContainerBuilder();
    $kernel = new DrupalKernel('test', NULL);
    // Objects of the same type will have access to each others private and     // protected members even though they are not the same instances. This is     // because the implementation specific details are already known when     // inside those objects.     $kernel->container = $container;
    $container->set('kernel', $kernel);
    $container->set(ReverseContainer::classnew ReverseContainer($container));
    \Drupal::setContainer($container);
    return $container;
  }

}
$computationService = new class() {
            public function __invoke(CacheItem $item)
            {
                return 123;
            }
        };

        $container = new Container();
        $container->set('computation_service', $computationService);
        $container->set('cache_pool', $pool);

        $reverseContainer = new ReverseContainer($containernew ServiceLocator([]));

        $msg = EarlyExpirationMessage::create($reverseContainer[$computationService, '__invoke']$item$pool);

        $this->assertSame('cache_pool', $msg->getPool());
        $this->assertSame($pool$msg->findPool($reverseContainer));

        $this->assertSame('foo', $msg->getItem()->getKey());
        $this->assertNull($msg->getItem()->get());
        $this->assertSame(234, $item->get());

        $this->assertSame(['@computation_service', '__invoke']$msg->getCallback());
        
usleep(30000);
                $item->expiresAfter(3600);

                return 123;
            }
        };

        $container = new Container();
        $container->set('computation_service', $computationService);
        $container->set('cache_pool', $pool);

        $reverseContainer = new ReverseContainer($containernew ServiceLocator([]));

        $msg = EarlyExpirationMessage::create($reverseContainer$computationService$item$pool);

        $handler = new EarlyExpirationHandler($reverseContainer);

        $handler($msg);

        $this->assertSame(123, $pool->get('foo', $this->fail(...), 0.0, $metadata));

        $this->assertGreaterThan(25, $metadata['ctime']);
        $this->assertGreaterThan(time()$metadata['expiry']);
    }
$computationService = new class() {
            public function __invoke(CacheItem $item)
            {
                return 123;
            }
        };

        $container = new Container();
        $container->set('computation_service', $computationService);
        $container->set('cache_pool', $pool);

        $reverseContainer = new ReverseContainer($containernew ServiceLocator([]));

        $bus = $this->createMock(MessageBusInterface::class);

        $dispatcher = new EarlyExpirationDispatcher($bus$reverseContainer);

        $saveResult = null;
        $pool->setCallbackWrapper(function Dcallable $callback, CacheItem $item, bool &$save, AdapterInterface $pool, \Closure $setMetadata, ?LoggerInterface $logger) use ($dispatcher, &$saveResult) {
            try {
                return $dispatcher($callback$item$save$pool$setMetadata$logger);
            } finally {
                $saveResult = $save;
            }
Home | Imprint | This part of the site doesn't use cookies.