Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup/fix context package #711

Merged
merged 14 commits into from
Jun 16, 2022
Prev Previous commit
Next Next commit
Fix cannot mock final class Context
Revert after introducing ContextInterface?
  • Loading branch information
Nevay committed Jun 15, 2022
commit 0b5db5fd464aebcecad33bbd787cab4bfca6839a
13 changes: 5 additions & 8 deletions tests/Unit/API/Trace/NoopSpanBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function test_noop_created_span_uses_provided_context(): void
$span = $this->createMock(SpanInterface::class);
$span->method('getContext')->willReturn($spanContext);

$context = $this->createMock(Context::class);
$context->method('get')->with(SpanContextKey::instance())->willReturn($span);
$context = Context::getRoot()->with(SpanContextKey::instance(), $span);

$contextStorage = $this->createMock(ContextStorageInterface::class);

Expand All @@ -59,8 +58,7 @@ public function test_noop_created_span_uses_current_context(): void
$span = $this->createMock(SpanInterface::class);
$span->method('getContext')->willReturn($spanContext);

$context = $this->createMock(Context::class);
$context->method('get')->with(SpanContextKey::instance())->willReturn($span);
$context = Context::getRoot()->with(SpanContextKey::instance(), $span);

$contextStorage = $this->createMock(ContextStorageInterface::class);
$contextStorage->method('current')->willReturn($context);
Expand All @@ -79,8 +77,7 @@ public function test_noop_created_span_doesnt_use_current_context_if_no_parent()
$span = $this->createMock(SpanInterface::class);
$span->method('getContext')->willReturn($spanContext);

$context = $this->createMock(Context::class);
$context->method('get')->with(SpanContextKey::instance())->willReturn($span);
$context = Context::getRoot()->with(SpanContextKey::instance(), $span);

$contextStorage = $this->createMock(ContextStorageInterface::class);
$contextStorage->method('current')->willReturn($context);
Expand All @@ -99,8 +96,7 @@ public function test_noop_created_span_removes_is_recording_flag(): void
$span = $this->createMock(SpanInterface::class);
$span->method('isRecording')->willReturn(true);

$context = $this->createMock(Context::class);
$context->method('get')->with(SpanContextKey::instance())->willReturn($span);
$context = Context::getRoot()->with(SpanContextKey::instance(), $span);

$contextStorage = $this->createMock(ContextStorageInterface::class);

Expand Down Expand Up @@ -179,6 +175,7 @@ public function test_set_span_kind(): void
public function test_start_span(): void
{
$contextStorage = $this->createMock(ContextStorageInterface::class);
$contextStorage->method('current')->willReturn(Context::getRoot());

$this->assertInstanceOf(
NonRecordingSpan::class,
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/SDK/Trace/Sampler/AlwaysOffSamplerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AlwaysOffSamplerTest extends TestCase
*/
public function test_should_sample(): void
{
$parentContext = $this->createMock(Context::class);
$parentContext = Context::getRoot();
$sampler = new AlwaysOffSampler();
$decision = $sampler->shouldSample(
$parentContext,
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/SDK/Trace/Sampler/AlwaysOnSamplerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AlwaysOnSamplerTest extends TestCase
*/
public function test_should_sample(): void
{
$parentContext = $this->createMock(Context::class);
$parentContext = Context::getRoot();
$sampler = new AlwaysOnSampler();
$decision = $sampler->shouldSample(
$parentContext,
Expand Down