summaryrefslogtreecommitdiff
path: root/vendor/opentracing/opentracing/tests/OpenTracing/ReferenceTest.php
blob: cb971a20cb4fb222b6550a30c48e681d27c0caee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

declare(strict_types=1);

namespace OpenTracing\Tests;

use TypeError;
use PHPUnit\Framework\TestCase;
use OpenTracing\Reference;
use OpenTracing\NoopSpanContext;
use OpenTracing\InvalidReferenceArgumentException;

/**
 * @covers Reference
 */
final class ReferenceTest extends TestCase
{
    const REFERENCE_TYPE = 'ref_type';

    public function testCreateAReferenceFailsOnInvalidContext()
    {
        $context = 'invalid_context';

        $this->expectException(TypeError::class);
        new Reference('child_of', $context);
    }

    public function testCreateAReferenceFailsOnEmptyType()
    {
        $context = new NoopSpanContext();

        $this->expectException(InvalidReferenceArgumentException::class);
        $this->expectExceptionMessage('Reference type can not be an empty string');
        new Reference('', $context);
    }

    public function testAReferenceCanBeCreatedAsACustomType()
    {
        $context = new NoopSpanContext();
        $reference = new Reference(self::REFERENCE_TYPE, $context);

        $this->assertSame($context, $reference->getSpanContext());
        $this->assertTrue($reference->isType(self::REFERENCE_TYPE));
    }
}