|
8 | 8 | use OpenTelemetry\API\Trace\TracerInterface; |
9 | 9 | use OpenTelemetry\Aws\Xray\Propagator; |
10 | 10 | use OpenTelemetry\Instrumentation\AwsSdk\AwsSdkInstrumentation; |
11 | | -use OpenTelemetry\SDK\Trace\TracerProvider; |
12 | 11 | use OpenTelemetry\SDK\Trace\TracerProviderInterface; |
13 | 12 | use PHPUnit\Framework\TestCase; |
14 | 13 |
|
15 | 14 | class AwsSdkInstrumentationTest extends TestCase |
16 | 15 | { |
17 | | - private TracerProvider $tracerProvider; |
18 | 16 | private AwsSdkInstrumentation $awsSdkInstrumentation; |
19 | 17 |
|
20 | 18 | protected function setUp(): void |
21 | 19 | { |
22 | 20 | BypassFinals::enable(); |
23 | | - $this->tracerProvider = $this->createMock(TracerProvider::class); |
24 | | - $this->provider = $this->createMock(TracerProviderInterface::class); |
25 | | - $this->tracer = $this->createMock(TracerInterface::class); |
26 | | - |
27 | 21 | $this->awsSdkInstrumentation = new AwsSdkInstrumentation(); |
28 | | - $this->awsSdkInstrumentation->setTracerProvider($this->tracerProvider); |
29 | 22 | } |
30 | 23 |
|
31 | 24 | public function testInstrumentationClassName() |
@@ -69,17 +62,25 @@ public function testGetXrayPropagator() |
69 | 62 |
|
70 | 63 | public function testGetTracerProvider() |
71 | 64 | { |
| 65 | + $tracerProvider = $this->createMock(TracerProviderInterface::class); |
| 66 | + $this->awsSdkInstrumentation->setTracerProvider($tracerProvider); |
| 67 | + |
72 | 68 | $this->assertSame( |
73 | 69 | $this->awsSdkInstrumentation->getTracerProvider(), |
74 | | - $this->tracerProvider |
| 70 | + $tracerProvider |
75 | 71 | ); |
76 | 72 | } |
77 | 73 |
|
78 | 74 | public function testGetTracer() |
79 | 75 | { |
80 | | - $this->provider->method('getTracer')->willReturn($this->tracer); |
81 | | - $this->awsSdkInstrumentation->setTracerProvider($this->provider); |
82 | | - $this->assertSame($this->tracer, $this->awsSdkInstrumentation->getTracer()); |
| 76 | + $tracer = $this->createMock(TracerInterface::class); |
| 77 | + $tracerProvider = $this->createMock(TracerProviderInterface::class); |
| 78 | + $tracerProvider->expects($this->once()) |
| 79 | + ->method('getTracer') |
| 80 | + ->willReturn($tracer); |
| 81 | + |
| 82 | + $this->awsSdkInstrumentation->setTracerProvider($tracerProvider); |
| 83 | + $this->assertSame($tracer, $this->awsSdkInstrumentation->getTracer()); |
83 | 84 | } |
84 | 85 |
|
85 | 86 | public function testInstrumentationActivated() |
|
0 commit comments