Skip to content

Commit

Permalink
Add additional context tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevay committed Sep 13, 2022
1 parent f319f52 commit 3fc150f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Unit/Context/ContextKeysTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Tests\Unit\Context;

use OpenTelemetry\Context\ContextKeys;
use PHPUnit\Framework\TestCase;

/**
* @covers \OpenTelemetry\Context\ContextKeys
*/
final class ContextKeysTest extends TestCase
{
public function test_span_context_key(): void
{
$this->assertSame(ContextKeys::span(), ContextKeys::span());
}

public function test_baggage_context_key(): void
{
$this->assertSame(ContextKeys::baggage(), ContextKeys::baggage());
}
}
29 changes: 29 additions & 0 deletions tests/Unit/Context/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

use OpenTelemetry\Context\Context;
use OpenTelemetry\Context\ContextKey;
use OpenTelemetry\Context\ContextKeys;
use OpenTelemetry\Context\ImplicitContextKeyedInterface;
use PHPUnit\Framework\TestCase;
use stdClass;

/**
* @covers \OpenTelemetry\Context\Context
Expand Down Expand Up @@ -134,6 +137,32 @@ public function test_ctx_value_not_found_returns_null(): void
$this->assertNull($ctx->get(new ContextKey('baz')));
}

public function test_ctx_value_overwrite_null_returns_null(): void
{
$key = Context::createKey('-');
$ctx = Context::getRoot()->with($key, 'val')->with($key, null);

$this->assertNull($ctx->get($key));
}

public function test_set_get_span_key(): void
{
$key = ContextKeys::span();
$span = new stdClass();

$ctx = Context::getRoot()->with($key, $span);
$this->assertSame($span, $ctx->get($key));
}

public function test_with_context_value_calls_store_in_context(): void
{
$ctx = Context::getRoot();
$value = $this->createMock(ImplicitContextKeyedInterface::class);
$value->expects($this->once())->method('storeInContext')->with($ctx)->willReturn($ctx);

$ctx->withContextValue($value);
}

public function test_attach_and_detach_set_current_ctx(): void
{
$key = new ContextKey();
Expand Down

0 comments on commit 3fc150f

Please sign in to comment.