Skip to content

Commit

Permalink
Update test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-novotny committed Nov 20, 2024
1 parent ecf93a2 commit 528a26f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
"inspirum/arrayable": "^1.2"
},
"require-dev": {
"inspirum/coding-standard": "^1.5",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.5",
"shipmonk/composer-dependency-analyser": "^1.5",
"squizlabs/php_codesniffer": "^3.9"
"ext-simplexml": "*",
"inspirum/coding-standard": "^1.6",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^11.0",
"shipmonk/composer-dependency-analyser": "^1.8",
"squizlabs/php_codesniffer": "^3.11"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions src/Reader/DefaultReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,16 @@ private function createNode(string $name, mixed $text, array $attributes, array
{
$usedNamespaces = $this->getUsedNamespaces($name, $attributes);

$namespaces = array_merge($namespaces, ...array_map(static fn(ReadResult $element) => $element->namespaces, $elements));
$usedNamespaces = array_merge($usedNamespaces, ...array_map(static fn(ReadResult $element) => $element->usedNamespaces, $elements));
$namespaces = array_merge($namespaces, ...array_map(static fn (ReadResult $element) => $element->namespaces, $elements));
$usedNamespaces = array_merge($usedNamespaces, ...array_map(static fn (ReadResult $element) => $element->usedNamespaces, $elements));

$withNamespace = $rootNamespaces !== null;

if ($withNamespace) {
$namespaceAttributes = $this->namespacesToAttributes($namespaces, $rootNamespaces);
$namespaceAttributes = array_filter(
$namespaceAttributes,
static fn($namespaceLocalName) => in_array(Parser::getLocalName($namespaceLocalName), $usedNamespaces),
static fn ($namespaceLocalName) => in_array(Parser::getLocalName($namespaceLocalName), $usedNamespaces),
ARRAY_FILTER_USE_KEY,
);

Expand All @@ -208,8 +208,8 @@ private function getUsedNamespaces(string $name, array $attributes): array
{
return array_values(array_filter([
Parser::getNamespacePrefix($name),
...array_map(static fn($attributeName) => Parser::getNamespacePrefix($attributeName), array_keys($attributes)),
], static fn($ns) => $ns !== null && $ns !== 'xmlns'));
...array_map(static fn ($attributeName) => Parser::getNamespacePrefix($attributeName), array_keys($attributes)),
], static fn ($ns) => $ns !== null && $ns !== 'xmlns'));
}

/**
Expand All @@ -231,7 +231,7 @@ private function namespacesToAttributes(array $namespaces, array $rootNamespaces
*/
private function read(): bool
{
return Handler::withErrorHandlerForXMLReader(fn(): bool => $this->reader->read());
return Handler::withErrorHandlerForXMLReader(fn (): bool => $this->reader->read());
}

private function next(?string $name = null): bool
Expand Down
4 changes: 2 additions & 2 deletions tests/Reader/DefaultReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function testIterateWithSimpleLoadString(string $file, bool $withNamespac
throw $exception;
}

self::assertSame($expectedItem, array_map(static fn(SimpleXMLElement $element): string => trim((string) preg_replace('/<\?xml[^>]*\?>/', '', (string) $element->asXML(), 1)), $elements));
self::assertSame($expectedItem, array_map(static fn (SimpleXMLElement $element): string => trim((string) preg_replace('/<\?xml[^>]*\?>/', '', (string) $element->asXML(), 1)), $elements));
}
}

Expand Down Expand Up @@ -428,7 +428,7 @@ public function testIterateWithXpath(string $file, bool $withNamespaces, string
throw $exception;
}

self::assertSame($expected[$i], array_map(static fn(Node $element): string => $element->toString(), $elements));
self::assertSame($expected[$i], array_map(static fn (Node $element): string => $element->toString(), $elements));
}
}

Expand Down

0 comments on commit 528a26f

Please sign in to comment.