Skip to content

Commit

Permalink
fix #25
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaguerre committed Nov 14, 2022
1 parent c0ee06d commit 1fac67a
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions spec/Tracing/Propagation/Doctrine/TraceContextInfoProviderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/*
* This file is part of the worldia/instrumentation-bundle package.
* (c) Worldia <[email protected]>
*/

namespace spec\Instrumentation\Tracing\Propagation\Doctrine;

use Composer\InstalledVersions;
use Instrumentation\Tracing\Propagation\Doctrine\TraceContextInfoProviderInterface;
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SemConv\ResourceAttributes;
use PhpSpec\ObjectBehavior;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Kernel;

class TraceContextInfoProviderSpec extends ObjectBehavior
{
public function let(ResourceInfo $info, AttributesInterface $attributes): void
{
$attributes->has(ResourceAttributes::SERVICE_NAME)->willReturn(false);
$info->getAttributes()->willReturn($attributes);

$this->beConstructedWith($info);
}

public function it_implements_interface(): void
{
$this->shouldBeAnInstanceOf(TraceContextInfoProviderInterface::class);
}

public function it_gets_trace_context(): void
{
$this->getTraceContext()->shouldBeLike($this->getMinimalInfo());
}

public function it_gets_service_name(ResourceInfo $info, AttributesInterface $attributes, RequestStack $requestStack, Request $request, ParameterBag $requestParameters): void
{
$attributes->has(ResourceAttributes::SERVICE_NAME)->willReturn(true);
$attributes->get(ResourceAttributes::SERVICE_NAME)->willReturn('dummy-app');
$info->getAttributes()->willReturn($attributes);

$this->beConstructedWith($info);

$this->getTraceContext()->shouldBeLike(array_merge($this->getMinimalInfo(), [
'application' => 'dummy-app',
]));
}

public function it_gets_controller_and_route(ResourceInfo $info, AttributesInterface $attributes, RequestStack $requestStack, Request $request, ParameterBag $requestParameters): void
{
$info->getAttributes()->willReturn($attributes);

$this->beConstructedWith($info, null, $requestStack);

$requestStack->getCurrentRequest()->willReturn($request);
$request->attributes = $requestParameters;
$requestParameters->get('_route')->willReturn('some_route');
$requestParameters->get('_controller')->willReturn('Some\Controller');

$this->getTraceContext()->shouldBeLike(array_merge($this->getMinimalInfo(), [
'controller' => 'Some\\\\Controller',
'route' => 'some_route',
]));
}

private function getMinimalInfo(): array
{
return [
'db_driver' => sprintf('doctrine/dbal-%s', InstalledVersions::getVersion('doctrine/dbal')),
'framework' => sprintf('symfony-%s', Kernel::VERSION),
];
}
}

0 comments on commit 1fac67a

Please sign in to comment.