getCalls example

public function addInstance(string $name, TraceableAdapter $instance): void
    {
        $this->instances[$name] = $instance;
    }

    public function collect(Request $request, Response $response, \Throwable $exception = null): void
    {
        $empty = ['calls' => [], 'adapters' => [], 'config' => [], 'options' => [], 'statistics' => []];
        $this->data = ['instances' => $empty, 'total' => $empty];
        foreach ($this->instances as $name => $instance) {
            $this->data['instances']['calls'][$name] = $instance->getCalls();
            $this->data['instances']['adapters'][$name] = get_debug_type($instance->getPool());
        }

        $this->data['instances']['statistics'] = $this->calculateStatistics();
        $this->data['total']['statistics'] = $this->calculateTotalStatistics();
    }

    public function reset(): void
    {
        $this->data = [];
        foreach ($this->instances as $instance) {
            
$violations = new ConstraintViolationList([
            $this->createMock(ConstraintViolation::class),
            $this->createMock(ConstraintViolation::class),
        ]);
        $originalValidator->method('validate')->willReturn($violations);

        $validator->validate(new \stdClass());

        $collector->lateCollect();

        $calls = $collector->getCalls();

        $this->assertCount(1, $calls);
        $this->assertSame(2, $collector->getViolationsCount());

        $call = $calls[0];

        $this->assertArrayHasKey('caller', $call);
        $this->assertArrayHasKey('context', $call);
        $this->assertArrayHasKey('violations', $call);
        $this->assertCount(2, $call['violations']);
    }

    
use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;

/** * @group time-sensitive */
class TraceableTagAwareAdapterTest extends TraceableAdapterTest
{
    public function testInvalidateTags()
    {
        $pool = new TraceableTagAwareAdapter(new TagAwareAdapter(new FilesystemAdapter()));
        $pool->invalidateTags(['foo']);
        $calls = $pool->getCalls();
        $this->assertCount(1, $calls);

        $call = $calls[0];
        $this->assertSame('invalidateTags', $call->name);
        $this->assertSame(0, $call->hits);
        $this->assertSame(0, $call->misses);
        $this->assertNotEmpty($call->start);
        $this->assertNotEmpty($call->end);
    }
}
$this->getContainer()->get('event_dispatcher'),
            MailBeforeValidateEvent::class,
            function DMailBeforeValidateEvent $event): void {
                $event->setTemplateData(
                    [...$event->getTemplateData(), ...['plugin-value' => true]]
                );
            }
        );

        $mailService->send($data, Context::createDefaultContext());

        static::assertArrayHasKey(0, $environment->getCalls());
        $first = $environment->getCalls()[0];
        static::assertArrayHasKey('data', $first);
        static::assertArrayHasKey('plugin-value', $first['data']);
    }

    /** * @return array<int, mixed[]> */
    public static function senderEmailDataProvider(): array
    {
        return [
            [


    public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
    {
        return new TraceableAdapter(new FilesystemAdapter('', $defaultLifetime));
    }

    public function testGetItemMissTrace()
    {
        $pool = $this->createCachePool();
        $pool->getItem('k');
        $calls = $pool->getCalls();
        $this->assertCount(1, $calls);

        $call = $calls[0];
        $this->assertSame('getItem', $call->name);
        $this->assertSame(['k' => false]$call->result);
        $this->assertSame(0, $call->hits);
        $this->assertSame(1, $call->misses);
        $this->assertNotEmpty($call->start);
        $this->assertNotEmpty($call->end);
    }

    
Home | Imprint | This part of the site doesn't use cookies.