Skip to content

Commit f72c2e2

Browse files
committed
Drop performance tests
1 parent b6ff76f commit f72c2e2

10 files changed

Lines changed: 551 additions & 402 deletions

File tree

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343
"scripts": {
4444
"test": "php ./vendor/phpunit/phpunit/phpunit --configuration ./continuous-integration/phpunit/phpunit.xml --testdox --colors=always",
4545
"test-coverage": "php -d xdebug.mode=coverage ./vendor/phpunit/phpunit/phpunit --configuration ./continuous-integration/phpunit/phpunit.xml --testdox --colors=always --coverage-html ./continuous-integration/autotests-coverage-report --coverage-filter ./src",
46+
"check-style": "php ./vendor/bin/phpcs --standard=continuous-integration/phpcs/phpcs.xml -v",
4647
"fix-style": "php ./vendor/bin/phpcbf --standard=continuous-integration/phpcs/phpcs.xml -v"
4748
},
4849
"require-dev": {
49-
"phpunit/phpunit": "^11.5",
50-
"squizlabs/php_codesniffer": "^4.0",
50+
"phpunit/phpunit": "^9.6",
51+
"squizlabs/php_codesniffer": "^3.13",
5152
"sbwerewolf/json-serialize-trait": "^1"
5253
},
5354
"require": {
54-
"php": ">=8.3",
55+
"php": ">=8.0 <8.3",
5556
"ext-xmlreader": "*",
5657
"ext-libxml": "*"
57-
},
58-
"config": {}
58+
}
5959
}

composer.lock

Lines changed: 377 additions & 361 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

continuous-integration/phpunit/phpunit.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd"
55
bootstrap="../../vendor/autoload.php"
6-
cacheDirectory=".phpunit.cache"
7-
executionOrder="depends,defects"
8-
shortenArraysForExportThreshold="10"
96
beStrictAboutOutputDuringTests="true"
10-
displayDetailsOnPhpunitDeprecations="true"
11-
failOnPhpunitDeprecation="true"
127
failOnRisky="true"
138
failOnWarning="true">
149
<testsuites>
@@ -20,9 +15,9 @@
2015
</testsuite>
2116
</testsuites>
2217

23-
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
18+
<coverage processUncoveredFiles="true">
2419
<include>
2520
<directory>../../src</directory>
2621
</include>
27-
</source>
22+
</coverage>
2823
</phpunit>

src/SbWereWolf/XmlNavigator/Extraction/PrettyPrintComposer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private static function appendChild(
183183
if (
184184
is_array($target[$childName])
185185
&& $target[$childName] !== []
186-
&& array_is_list($target[$childName])
186+
&& self::isList($target[$childName])
187187
) {
188188
$target[$childName][] = $childValue;
189189
return;
@@ -256,4 +256,9 @@ private static function collectAttributes(XMLReader $reader): array
256256

257257
return $attributes;
258258
}
259+
260+
private static function isList(array $value): bool
261+
{
262+
return $value === array_values($value);
263+
}
259264
}

src/SbWereWolf/XmlNavigator/Navigation/XmlElement.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private static function isXmlAttributes(mixed $value): bool
246246
*/
247247
private static function isHierarchySequence(mixed $value): bool
248248
{
249-
if (!is_array($value) || !array_is_list($value)) {
249+
if (!is_array($value) || !self::isList($value)) {
250250
return false;
251251
}
252252

@@ -258,4 +258,9 @@ private static function isHierarchySequence(mixed $value): bool
258258

259259
return true;
260260
}
261+
262+
private static function isList(array $value): bool
263+
{
264+
return $value === array_values($value);
265+
}
261266
}

tests/Compat/docker/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ARG PHP_IMAGE=php:8.0-cli
2+
FROM ${PHP_IMAGE}
3+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
4+
5+
ENV COMPOSER_ALLOW_SUPERUSER=1
6+
7+
ARG XDEBUG_VERSION=
8+
9+
RUN apt-get update \
10+
&& apt-get install -y --no-install-recommends \
11+
git \
12+
unzip \
13+
libxml2-dev \
14+
$PHPIZE_DEPS \
15+
&& docker-php-ext-install xml \
16+
&& if [ -n "$XDEBUG_VERSION" ]; then \
17+
pecl install xdebug-"$XDEBUG_VERSION"; \
18+
else \
19+
pecl install xdebug; \
20+
fi \
21+
&& docker-php-ext-enable xdebug \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
WORKDIR /app

tests/Compat/docker/run-compat.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [ "$#" -lt 3 ]; then
5+
echo "usage: $0 <php-image> <xdebug-version> <command...>" >&2
6+
exit 2
7+
fi
8+
9+
php_image="$1"
10+
shift
11+
xdebug_version="$1"
12+
shift
13+
14+
image_tag="xml-browser-compat:${php_image//[:\/]/-}"
15+
16+
docker build \
17+
--build-arg "PHP_IMAGE=$php_image" \
18+
--build-arg "XDEBUG_VERSION=$xdebug_version" \
19+
-t "$image_tag" \
20+
-f tests/Compat/docker/Dockerfile \
21+
.
22+
23+
docker run --rm \
24+
-v "$PWD:/app" \
25+
-w /app \
26+
"$image_tag" \
27+
bash -lc "$*"

tests/Unit/Conversion/FastXmlToArrayTest.php

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace SbWereWolf\XmlNavigator\Test\Unit\Conversion;
66

77
use InvalidArgumentException;
8-
use PHPUnit\Framework\Attributes\DataProvider;
98
use PHPUnit\Framework\TestCase;
109
use ReflectionMethod;
1110
use SbWereWolf\XmlNavigator\Conversion\FastXmlToArray;
@@ -113,7 +112,9 @@ public function testPrettyPrintSupportsXmlTextAndXmlFile(): void
113112
self::assertSame($expected, FastXmlToArray::prettyPrint('', $xmlFile));
114113
}
115114

116-
#[DataProvider('missingSourceProvider')]
115+
/**
116+
* @dataProvider missingSourceProvider
117+
*/
117118
public function testMethodsRejectMissingXmlSource(string $method): void
118119
{
119120
$this->expectException(InvalidArgumentException::class);
@@ -137,7 +138,9 @@ public static function missingSourceProvider(): array
137138
];
138139
}
139140

140-
#[DataProvider('ambiguousSourceProvider')]
141+
/**
142+
* @dataProvider ambiguousSourceProvider
143+
*/
141144
public function testMethodsRejectAmbiguousXmlSource(
142145
string $method,
143146
string $xmlText,
@@ -208,7 +211,9 @@ public function testPrettyPrintRejectsMalformedXmlText(): void
208211
FastXmlToArray::prettyPrint('<broken>');
209212
}
210213

211-
#[DataProvider('malformedUriProvider')]
214+
/**
215+
* @dataProvider malformedUriProvider
216+
*/
212217
public function testMethodsRejectMalformedXmlFile(string $method): void
213218
{
214219
$this->expectException(InvalidArgumentException::class);
@@ -266,28 +271,39 @@ public function testParseRootElementRejectsBufferedLibxmlErrorsAfterParse(): voi
266271
);
267272
/** @noinspection PhpExpressionResultUnusedInspection */
268273
$method->setAccessible(true);
269-
270-
$this->expectException(InvalidArgumentException::class);
271-
$this->expectExceptionCode(-669);
272-
$this->expectExceptionMessage(
273-
'Unable to parse XML from $xmlText. ' .
274-
'Premature end of data in tag broken line 1'
275-
);
276-
277-
$method->invoke(
278-
null,
279-
'<root/>',
280-
'',
281-
null,
282-
LIBXML_BIGLINES | LIBXML_COMPACT,
283-
static function (\XMLReader $reader): array {
284-
$dom = new \DOMDocument();
285-
@$dom->loadXML('<broken>');
286-
287-
return [
288-
'n' => $reader->name,
289-
];
290-
}
291-
);
274+
try {
275+
$method->invoke(
276+
null,
277+
'<root/>',
278+
'',
279+
null,
280+
LIBXML_BIGLINES | LIBXML_COMPACT,
281+
static function (\XMLReader $reader): array {
282+
$dom = new \DOMDocument();
283+
@$dom->loadXML('<broken>');
284+
285+
return [
286+
'n' => $reader->name,
287+
];
288+
}
289+
);
290+
self::fail('Expected parsing exception was not thrown.');
291+
} catch (InvalidArgumentException $exception) {
292+
self::assertSame(-669, $exception->getCode());
293+
self::assertStringContainsString(
294+
'Unable to parse XML from $xmlText.',
295+
$exception->getMessage()
296+
);
297+
self::assertTrue(
298+
strpos(
299+
$exception->getMessage(),
300+
'Premature end of data in tag broken line 1'
301+
) !== false
302+
|| strpos(
303+
$exception->getMessage(),
304+
"EndTag: '</' not found"
305+
) !== false
306+
);
307+
}
292308
}
293309
}

tests/Unit/Extraction/HierarchyComposerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,34 @@ public function testComposeReturnsEmptyArrayWhenReaderIsExhausted(): void
9393
self::assertSame([], HierarchyComposer::compose($reader));
9494
$reader->close();
9595
}
96+
97+
public function testComposeMovesReaderPastTopLevelEmptyElement(): void
98+
{
99+
$reader = XmlFixture::readerFromFixture('empty-elements.xml');
100+
101+
while ($reader->read()) {
102+
if (
103+
$reader->nodeType === \XMLReader::ELEMENT
104+
&& $reader->name === 'root'
105+
) {
106+
break;
107+
}
108+
}
109+
110+
self::assertSame(
111+
[
112+
'n' => 'root',
113+
'a' => [
114+
'attr' => '1',
115+
],
116+
],
117+
HierarchyComposer::compose($reader)
118+
);
119+
120+
while ($reader->nodeType !== \XMLReader::ELEMENT && $reader->read()) {
121+
}
122+
123+
self::assertSame('next', $reader->name);
124+
$reader->close();
125+
}
96126
}

tests/Unit/Extraction/PrettyPrintComposerTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,37 @@ public function testComposeReturnsEmptyArrayWhenReaderIsExhausted(): void
7474
$reader->close();
7575
}
7676

77+
public function testComposeMovesReaderPastTopLevelEmptyElement(): void
78+
{
79+
$reader = XmlFixture::readerFromFixture('empty-elements.xml');
80+
81+
while ($reader->read()) {
82+
if (
83+
$reader->nodeType === \XMLReader::ELEMENT
84+
&& $reader->name === 'root'
85+
) {
86+
break;
87+
}
88+
}
89+
90+
self::assertSame(
91+
[
92+
'root' => [
93+
'@attributes' => [
94+
'attr' => '1',
95+
],
96+
],
97+
],
98+
PrettyPrintComposer::compose($reader)
99+
);
100+
101+
while ($reader->nodeType !== \XMLReader::ELEMENT && $reader->read()) {
102+
}
103+
104+
self::assertSame('next', $reader->name);
105+
$reader->close();
106+
}
107+
77108
public function testComposePreservesMixedContentWithAttributesAndChild(): void
78109
{
79110
$reader = XmlFixture::readerFromFixture('mixed-content.xml');

0 commit comments

Comments
 (0)