Skip to content

Commit 63946c6

Browse files
committed
Fixed failing unit tests
1 parent a0eaf60 commit 63946c6

19 files changed

+126
-84
lines changed

.ci/Jenkinsfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ pipeline {
7979
buildWithGitHubNotification('8.0-alpine')
8080
}
8181
}
82+
stage('on PHP 8.1') {
83+
agent { label 'linux && immutable' }
84+
steps {
85+
buildWithGitHubNotification('8.1-alpine')
86+
}
87+
}
88+
stage('on PHP 8.2') {
89+
agent { label 'linux && immutable' }
90+
steps {
91+
buildWithGitHubNotification('8.2-alpine')
92+
}
93+
}
8294
}
8395
}
8496
stage('Release') {

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ tab_width = 4
1313
indent_size = 4
1414
indent_style = tab
1515

16-
[*.{dtd,html,inc,php,phpt,rng,wsdl,xml,xsd,xsl}]
16+
[*.{dtd,html,inc,php,phpt,rng,wsdl,xml,xml.dist,xsd,xsl}]
1717
indent_size = 4
1818
indent_style = space
1919

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"ext-json": "*"
2323
},
2424
"require-dev": {
25-
"php-parallel-lint/php-parallel-lint": "^1.3.0",
25+
"php-parallel-lint/php-parallel-lint": "^1.3.2",
2626
"squizlabs/php_codesniffer": "3.*",
27-
"brianium/paratest": "^3.1",
28-
"monolog/monolog": "^2.0"
27+
"monolog/monolog": "^2.0",
28+
"phpunit/phpunit": "^8.5||^9.5||^10"
2929
},
3030
"autoload": {
3131
"psr-4": {"Elastic\\": "src/Elastic"}
@@ -41,7 +41,7 @@
4141
"parallel-lint . --exclude vendor",
4242
"phpcs --standard=phpcs.xml --extensions=php --encoding=utf-8 --tab-width=4 -sp src/Elastic",
4343
"phpcs --standard=phpcs.xml --extensions=php --encoding=utf-8 --tab-width=4 -sp tests/Elastic",
44-
"paratest -c phpunit.xml.dist --bootstrap tests/bootstrap.php --log-junit=junit-${VERSION}.xml"
44+
"phpunit --log-junit=junit-${VERSION}.xml"
4545
]
4646
},
4747
"config": {

phpunit.xml.dist

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<phpunit
4-
bootstrap="tests/bootstrap.php"
5-
colors="true"
6-
verbose= "true"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
74
beStrictAboutTestsThatDoNotTestAnything="true"
8-
beStrictAboutOutputDuringTests= "true"
5+
beStrictAboutOutputDuringTests="true"
6+
bootstrap="./tests/bootstrap.php"
7+
colors="true"
8+
failOnRisky="true"
9+
stopOnDefect="true"
10+
stopOnError="true"
11+
stopOnFailure="true"
12+
stopOnIncomplete="true"
13+
stopOnRisky="true"
14+
stopOnWarning="true"
15+
testdox="true"
16+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
17+
cacheDirectory="_GENERATED/phpunit_cache"
918
>
19+
<coverage>
20+
<include>
21+
<directory suffix=".php">./src/Elastic</directory>
22+
</include>
23+
</coverage>
24+
1025
<testsuites>
1126
<testsuite name="ECS Logging Frameworks Test Suite">
12-
<directory>tests/Elastic/</directory>
27+
<directory>./tests/Elastic</directory>
1328
</testsuite>
1429
</testsuites>
15-
<filter>
16-
<whitelist>
17-
<directory suffix=".php">src/Elastic/</directory>
18-
</whitelist>
19-
</filter>
30+
2031
<php>
2132
<ini name="date.timezone" value="UTC"/>
2233
</php>

src/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatter.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ private function formatContext(array $inContext, array &$outRecord): void
154154
}
155155
}
156156

157+
/**
158+
* Skip 'callType' key. The value is the same as 'type' in the frame returned by debug_backtrace().
159+
*
160+
* @See https://www.php.net/manual/en/function.debug-backtrace.php
161+
*/
162+
if ($contextKey === 'callType') {
163+
continue;
164+
}
165+
157166
$outRecord[$contextKey] = $contextVal;
158167
}
159168

src/Elastic/Types/BaseType.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class BaseType
1212
{
13-
1413
/**
1514
* Get the Popo as array
1615
*

src/Elastic/Types/Error.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public function __construct(Throwable $throwable)
3535
$this->throwable = $throwable;
3636
}
3737

38+
/**
39+
* @param Throwable $throwable
40+
*
41+
* @return array<string, mixed>
42+
*/
3843
public static function serialize(Throwable $throwable): array
3944
{
4045
return [
@@ -46,8 +51,12 @@ public static function serialize(Throwable $throwable): array
4651
}
4752

4853
/**
49-
* @return array
54+
* @return array<string, mixed>
55+
*
56+
* @noinspection PhpFullyQualifiedNameUsageInspection
57+
* @noinspection PhpLanguageLevelInspection
5058
*/
59+
#[\ReturnTypeWillChange]
5160
public function jsonSerialize(): array
5261
{
5362
return self::serialize($this->throwable);

src/Elastic/Types/Service.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
class Service extends BaseType implements JsonSerializable
2323
{
24-
2524
/**
2625
* @var array
2726
*/
@@ -121,8 +120,12 @@ final public function setVersion(string $version)
121120
}
122121

123122
/**
124-
* @return array
123+
* @return array<string, mixed>
124+
*
125+
* @noinspection PhpFullyQualifiedNameUsageInspection
126+
* @noinspection PhpLanguageLevelInspection
125127
*/
128+
#[\ReturnTypeWillChange]
126129
public function jsonSerialize()
127130
{
128131
return ['service' => $this->data];

src/Elastic/Types/Tracing.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
* @version v1.x
1717
*
1818
* @see https://www.elastic.co/guide/en/ecs/current/ecs-tracing.html
19-
* @see Elastic\Types\TracingTest
19+
* @see \Elastic\Types\TracingTest
2020
*
2121
* @author Philip Krauss <philip.krauss@elastic.co>
2222
*/
2323
class Tracing extends BaseType implements JsonSerializable
2424
{
25-
2625
/**
2726
* Unique identifier of the trace
2827
*
@@ -48,14 +47,19 @@ public function __construct(string $traceId, ?string $transactionId = null)
4847
}
4948

5049
/**
51-
* @return array
50+
* @return array<string, mixed>
51+
*
52+
* @noinspection PhpFullyQualifiedNameUsageInspection
53+
* @noinspection PhpLanguageLevelInspection
5254
*/
53-
public function jsonSerialize()
55+
#[\ReturnTypeWillChange]
56+
public function jsonSerialize(): array
5457
{
55-
$message['trace'] = ['id' => $this->traceId];
58+
$result = [];
59+
$result['trace'] = ['id' => $this->traceId];
5660
if ($this->transactionId !== null) {
57-
$message['transaction'] = ['id' => $this->transactionId];
61+
$result['transaction'] = ['id' => $this->transactionId];
5862
}
59-
return $message;
63+
return $result;
6064
}
6165
}

src/Elastic/Types/User.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
class User extends BaseType implements JsonSerializable
2323
{
24-
2524
/**
2625
* @var array
2726
*/
@@ -94,9 +93,13 @@ final public function setHash(string $hash)
9493
}
9594

9695
/**
97-
* @return array
96+
* @return array<string, mixed>
97+
*
98+
* @noinspection PhpFullyQualifiedNameUsageInspection
99+
* @noinspection PhpLanguageLevelInspection
98100
*/
99-
public function jsonSerialize()
101+
#[\ReturnTypeWillChange]
102+
public function jsonSerialize(): array
100103
{
101104
return ['user' => $this->data];
102105
}

tests/Elastic/BaseTestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
class BaseTestCase extends TestCase
2121
{
22-
2322
/**
2423
* @return string
2524
*/

tests/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function testContextWithUser()
202202
/**
203203
* @return array<array<mixed>>
204204
*/
205-
public function dataProviderForTestContextWithError(): iterable
205+
public static function dataProviderForTestContextWithError(): iterable
206206
{
207207
return [
208208
[self::generateException(), false],
@@ -409,7 +409,7 @@ function ($record) {
409409
/**
410410
* @return array<array<bool>>
411411
*/
412-
public function dataProviderForTestsIntrospectionProcessor(): iterable
412+
public static function dataProviderForTestsIntrospectionProcessor(): iterable
413413
{
414414
return [[false], [true]];
415415
}

tests/Elastic/Monolog/Formatter/TestHelper.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class TestHelper
4141

4242
public function run(Closure $log): array
4343
{
44-
$this->logOriginFunction = __METHOD__;
45-
4644
$logger = new Logger($this->loggerName);
4745
$handler = new MockHandler();
4846

tests/Elastic/Types/BaseTypeTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Elastic\Tests\Types;
1010

11-
use \Elastic\Tests\BaseTestCase;
11+
use Elastic\Tests\BaseTestCase;
1212
use Elastic\Types\Tracing;
1313
use Elastic\Types\BaseType;
1414

@@ -17,15 +17,14 @@
1717
*
1818
* @version v1.x
1919
*
20-
* @see Elastic\Types\BaseType
20+
* @see \Elastic\Types\BaseType
2121
*
2222
* @author Philip Krauss <philip.krauss@elastic.co>
2323
*/
2424
class BaseTypeTest extends BaseTestCase
2525
{
26-
2726
/**
28-
* @covers Elastic\Types\BaseType::toArray
27+
* @covers \Elastic\Types\BaseType::toArray
2928
*/
3029
public function testToArray()
3130
{
@@ -39,7 +38,7 @@ public function testToArray()
3938
}
4039

4140
/**
42-
* @covers Elastic\Types\BaseType::__toString
41+
* @covers \Elastic\Types\BaseType::__toString
4342
*/
4443
public function testToString()
4544
{

tests/Elastic/Types/ErrorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
class ErrorTest extends BaseTestCase
2525
{
26-
2726
/**
2827
* @covers \Elastic\Types\Error::__construct
2928
* @covers \Elastic\Types\Error::jsonSerialize

tests/Elastic/Types/ServiceTest.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Elastic\Tests\Types;
1010

11-
use \Elastic\Tests\BaseTestCase;
11+
use Elastic\Tests\BaseTestCase;
1212
use Elastic\Types\Service;
1313
use Elastic\Types\BaseType;
1414

@@ -17,21 +17,20 @@
1717
*
1818
* @version v1.x
1919
*
20-
* @see Elastic\Types\Service
20+
* @see \Elastic\Types\Service
2121
*
2222
* @author Philip Krauss <philip.krauss@elastic.co>
2323
*/
2424
class ServiceTest extends BaseTestCase
2525
{
26-
2726
/**
28-
* @covers Elastic\Types\Service::__construct
29-
* @covers Elastic\Types\Service::jsonSerialize
30-
* @covers Elastic\Types\Service::setId
31-
* @covers Elastic\Types\Service::setName
32-
* @covers Elastic\Types\Service::setState
33-
* @covers Elastic\Types\Service::setType
34-
* @covers Elastic\Types\Service::setVersion
27+
* @covers \Elastic\Types\Service::__construct
28+
* @covers \Elastic\Types\Service::jsonSerialize
29+
* @covers \Elastic\Types\Service::setId
30+
* @covers \Elastic\Types\Service::setName
31+
* @covers \Elastic\Types\Service::setState
32+
* @covers \Elastic\Types\Service::setType
33+
* @covers \Elastic\Types\Service::setVersion
3534
*/
3635
public function testSerializationOfCoreFields()
3736
{
@@ -74,9 +73,9 @@ public function testSerializationOfCoreFields()
7473
/**
7574
* @depends testSerializationOfCoreFields
7675
*
77-
* @covers Elastic\Types\Service::__construct
78-
* @covers Elastic\Types\Service::jsonSerialize
79-
* @covers Elastic\Types\Service::setEphemeralId
76+
* @covers \Elastic\Types\Service::__construct
77+
* @covers \Elastic\Types\Service::jsonSerialize
78+
* @covers \Elastic\Types\Service::setEphemeralId
8079
*/
8180
public function testSeralizeEphemeralId()
8281
{
@@ -95,9 +94,9 @@ public function testSeralizeEphemeralId()
9594
/**
9695
* @depends testSerializationOfCoreFields
9796
*
98-
* @covers Elastic\Types\Service::__construct
99-
* @covers Elastic\Types\Service::jsonSerialize
100-
* @covers Elastic\Types\Service::setNodeName
97+
* @covers \Elastic\Types\Service::__construct
98+
* @covers \Elastic\Types\Service::jsonSerialize
99+
* @covers \Elastic\Types\Service::setNodeName
101100
*/
102101
public function testSeralizeNodeName()
103102
{

0 commit comments

Comments
 (0)