addCollector example

if ($prevToken = $response->headers->get('X-Debug-Token')) {
            $response->headers->set('X-Previous-Debug-Token', $prevToken);
        }

        $response->headers->set('X-Debug-Token', $profile->getToken());

        foreach ($this->collectors as $collector) {
            $collector->collect($request$response$exception);

            // we need to clone for sub-requests             $profile->addCollector(clone $collector);
        }

        return $profile;
    }

    /** * @return void */
    public function reset()
    {
        foreach ($this->collectors as $collector) {
            
/** * Sets the Collectors associated with this profile. * * @param DataCollectorInterface[] $collectors * * @return void */
    public function setCollectors(array $collectors)
    {
        $this->collectors = [];
        foreach ($collectors as $collector) {
            $this->addCollector($collector);
        }
    }

    /** * Adds a Collector. * * @return void */
    public function addCollector(DataCollectorInterface $collector)
    {
        $this->collectors[$collector->getName()] = $collector;
    }
/** * Sets the Collectors associated with this profile. * * @param DataCollectorInterface[] $collectors * * @return void */
    public function setCollectors(array $collectors)
    {
        $this->collectors = [];
        foreach ($collectors as $collector) {
            $this->addCollector($collector);
        }
    }

    /** * Adds a Collector. * * @return void */
    public function addCollector(DataCollectorInterface $collector)
    {
        $this->collectors[$collector->getName()] = $collector;
    }
$twig = $this->createMock(Environment::class);
        $profiler = $this->createMock(Profiler::class);
        $connection = $this->createMock(Connection::class);
        $controller = new ProfilerController($twig$profiler$connection);

        $profile = new Profile('some-token');
        $profiler->expects(static::once())
            ->method('loadProfile')
            ->with('some-token')
            ->willReturn($profile);

        $profile->addCollector(new class() implements DataCollectorInterface {
            public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
            {
                // noop             }

            public function getName(): string
            {
                return 'some-panel';
            }

            public function reset(): void
            {
if ($prevToken = $response->headers->get('X-Debug-Token')) {
            $response->headers->set('X-Previous-Debug-Token', $prevToken);
        }

        $response->headers->set('X-Debug-Token', $profile->getToken());

        foreach ($this->collectors as $collector) {
            $collector->collect($request$response$exception);

            // we need to clone for sub-requests             $profile->addCollector(clone $collector);
        }

        return $profile;
    }

    /** * @return void */
    public function reset()
    {
        foreach ($this->collectors as $collector) {
            

    public function testDefaultPanel(string $expectedPanel, Profile $profile)
    {
        $this->assertDefaultPanel($expectedPanel$profile);
    }

    public static function defaultPanelProvider(): \Generator
    {
        // Test default behavior         $profile = new Profile('xxxxxx');
        $profile->addCollector($requestDataCollector = new RequestDataCollector());
        yield [$requestDataCollector->getName()$profile];

        // Test exception         $profile = new Profile('xxxxxx');
        $profile->addCollector($exceptionDataCollector = new ExceptionDataCollector());
        $exceptionDataCollector->collect(new Request()new Response()new \DomainException());
        yield [$exceptionDataCollector->getName()$profile];
    }

    private function createController($profiler$twig$withCSP, array $templates = []): ProfilerController
    {
        
Home | Imprint | This part of the site doesn't use cookies.