-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathTracingTest.php
More file actions
72 lines (60 loc) · 2.07 KB
/
TracingTest.php
File metadata and controls
72 lines (60 loc) · 2.07 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
namespace Elastic\Tests\Types;
use \Elastic\Tests\BaseTestCase;
use Elastic\Types\Tracing;
use Elastic\Types\BaseType;
/**
* Test: Tracing (Type)
*
* @version v1.x
*
* @see Elastic\Types\Tracing
*
* @author Philip Krauss <philip.krauss@elastic.co>
*/
class TracingTest extends BaseTestCase
{
/**
* @covers Elastic\Types\Tracing::__construct
* @covers Elastic\Types\Tracing::jsonSerialize
*/
public function testSerialization()
{
$traceId = $this->generateTraceId();
$trxId = $this->generateTransactionId();
$tracing = new Tracing($traceId, $trxId);
$this->assertInstanceOf(BaseType::class, $tracing);
$json = json_encode($tracing);
// Comply to the ECS format
$decoded = json_decode($json, true);
$this->assertIsArray($decoded);
$this->assertArrayHasKey('trace', $decoded);
$this->assertArrayHasKey('transaction', $decoded);
$this->assertArrayHasKey('id', $decoded['trace']);
$this->assertArrayHasKey('id', $decoded['transaction']);
// Values correctly propagated
$this->assertEquals($traceId, $decoded['trace']['id']);
$this->assertEquals($trxId, $decoded['transaction']['id']);
}
/**
* @depends testSerialization
*
* @covers Elastic\Types\Tracing::__construct
* @covers Elastic\Types\Tracing::jsonSerialize
*/
public function testMvpWithoutTransactionId()
{
$traceId = $this->generateTraceId();
$tracing = new Tracing($traceId);
$json = json_encode($tracing);
$decoded = json_decode($json, true);
$this->assertArrayNotHasKey('transaction', $decoded);
$this->assertArrayHasKey('trace', $decoded);
$this->assertArrayHasKey('id', $decoded['trace']);
$this->assertEquals($traceId, $decoded['trace']['id']);
}
}