Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  remove tests on php 8.3
  CS
  add support for immutable 5
  use blackbox 5
  fix tests
  test against php 8.3
  • Loading branch information
Baptouuuu committed Sep 16, 2023
2 parents 9f2aae9 + a2aa521 commit a02227b
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 82 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.1', '8.2']
php-version: ['8.2']
dependencies: ['lowest', 'highest']
name: 'PHPUnit'
steps:
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1', '8.2']
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'Psalm'
steps:
Expand All @@ -54,7 +54,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1']
php-version: ['8.2']
name: 'CS'
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
vendor
.phpunit.result.cache
.phpunit.cache
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 7.5.0 - 2023-09-16

### Added

- Support for `innmind/immutable:~5.0`

### Removed

- Support for PHP `8.1`

## 7.4.0 - 2023-02-03

### Added
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"issues": "http://github.com/Innmind/XML/issues"
},
"require": {
"php": "~8.1",
"innmind/immutable": "^4.7.1",
"php": "~8.2",
"innmind/immutable": "^4.7.1|~5.0",
"innmind/filesystem": "~5.1|~6.0"
},
"autoload": {
Expand All @@ -30,9 +30,9 @@
}
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"vimeo/psalm": "~4.22",
"phpunit/phpunit": "~10.2",
"vimeo/psalm": "~5.12",
"innmind/coding-standard": "~2.0",
"innmind/black-box": "^4.18"
"innmind/black-box": "~5.5"
}
}
21 changes: 13 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" printerClass="Innmind\BlackBox\PHPUnit\ResultPrinterV9">
<coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache">
<extensions>
<bootstrap class="Innmind\BlackBox\PHPUnit\Extension">
</bootstrap>
</extensions>
<coverage/>
<testsuites>
<testsuite name="XML test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>.</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="XML test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<psalm
errorLevel="1"
resolveFromConfigFile="true"
findUnusedCode="false"
findUnusedBaselineEntry="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
6 changes: 3 additions & 3 deletions src/Element/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ public function asContent(): Content
$this
->children
->flatMap(
static fn($node) => match ($node instanceof AsContent) {
true => $node->asContent()->lines(),
false => Content\Lines::ofContent($node->toString())->lines(),
static fn($node) => match (true) {
$node instanceof AsContent => $node->asContent()->lines(),
default => Content\Lines::ofContent($node->toString())->lines(),
},
)
->map(static fn($line) => $line->map(
Expand Down
6 changes: 3 additions & 3 deletions src/Node/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ public function asContent(): Content
->append(
$this
->children
->flatMap(static fn($node) => match ($node instanceof AsContent) {
true => $node->asContent()->lines(),
false => Content\Lines::ofContent($node->toString())->lines(),
->flatMap(static fn($node) => match (true) {
$node instanceof AsContent => $node->asContent()->lines(),
default => Content\Lines::ofContent($node->toString())->lines(),
}),
),
);
Expand Down
5 changes: 4 additions & 1 deletion src/Translator/NodeTranslator/DocumentTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function of(): self
*/
private function buildVersion(\DOMDocument $document): Maybe
{
[$major, $minor] = \explode('.', $document->xmlVersion);
[$major, $minor] = \explode('.', $document->xmlVersion ?? '');

return Version::maybe(
(int) $major,
Expand All @@ -75,6 +75,7 @@ private function buildVersion(\DOMDocument $document): Maybe
*/
private function buildDoctype(\DOMDocumentType $type): Maybe
{
/** @psalm-suppress MixedArgument */
return Type::maybe(
$type->name,
$type->publicId,
Expand All @@ -92,11 +93,13 @@ private function buildChildren(
/** @var Maybe<Sequence<Node>> */
$children = Maybe::just(Sequence::of());

/** @psalm-suppress ImpureMethodCall */
foreach ($nodes as $child) {
if ($child->nodeType === \XML_DOCUMENT_TYPE_NODE) {
continue;
}

/** @psalm-suppress MixedArgumentTypeCoercion */
$children = $children->flatMap(
static fn($children) => $translate($child)->map(
static fn($node) => ($children)($node),
Expand Down
11 changes: 10 additions & 1 deletion src/Translator/NodeTranslator/Visitor/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ public function __invoke(\DOMNode $node): Maybe
return $attributes;
}

foreach ($node->attributes as $name => $attribute) {
/**
* @psalm-suppress MixedArgument
* @psalm-suppress ImpureMethodCall
*/
foreach ($node->attributes ?? [] as $name => $attribute) {
/**
* @psalm-suppress MixedArgument
* @psalm-suppress MixedPropertyFetch
* @psalm-suppress MixedArgumentTypeCoercion
*/
$attributes = $attributes->flatMap(
static fn($attributes) => Attribute::maybe($name, $attribute->value)->map(
static fn($attribute) => ($attributes)($attribute),
Expand Down
2 changes: 2 additions & 0 deletions src/Translator/NodeTranslator/Visitor/Children.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function __invoke(\DOMNode $node): Maybe
/** @var Maybe<Sequence<Node>> */
$children = Maybe::just(Sequence::of());

/** @psalm-suppress ImpureMethodCall */
foreach ($node->childNodes as $child) {
/** @psalm-suppress MixedArgumentTypeCoercion */
$children = $children->flatMap(
fn($children) => ($this->translate)($child)->map(
static fn($node) => ($children)($node),
Expand Down
2 changes: 1 addition & 1 deletion src/Visitor/PreviousSibling.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __invoke(Node $tree): Maybe
static fn($parent) => $parent->children(),
);

/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress InvalidArgument */
return $children
->flatMap(fn($children) => $children->indexOf($this->node))
->filter(static fn($position) => $position >= 0)
Expand Down
46 changes: 31 additions & 15 deletions tests/Element/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,34 @@ public function testPrependChild()
),
);
$this->assertEquals(
$element->children()->get(0),
$element2->children()->get(1),
$element->children()->get(0)->match(
static fn($value) => $value,
static fn() => null,
),
$element2->children()->get(1)->match(
static fn($value) => $value,
static fn() => null,
),
);
$this->assertEquals(
$element->children()->get(1),
$element2->children()->get(2),
$element->children()->get(1)->match(
static fn($value) => $value,
static fn() => null,
),
$element2->children()->get(2)->match(
static fn($value) => $value,
static fn() => null,
),
);
$this->assertEquals(
$element->children()->get(2),
$element2->children()->get(3),
$element->children()->get(2)->match(
static fn($value) => $value,
static fn() => null,
),
$element2->children()->get(3)->match(
static fn($value) => $value,
static fn() => null,
),
);
}

Expand Down Expand Up @@ -358,14 +376,13 @@ public function testFilterChild()
{
$this
->forAll(
DataSet\Unicode::lengthBetween(1, 255),
DataSet\Strings::madeOf(DataSet\Unicode::any())->between(1, 255),
DataSet\Sequence::of(
DataSet\Decorate::immutable(
static fn($name) => Element::of($name),
DataSet\Unicode::lengthBetween(1, 10),
DataSet\Strings::madeOf(DataSet\Unicode::any())->between(1, 255),
),
DataSet\Integers::between(0, 10),
),
)->between(0, 10),
)
->then(function($name, $children) {
$element = Element::of(
Expand All @@ -388,17 +405,16 @@ public function testMapChild()
{
$this
->forAll(
DataSet\Unicode::lengthBetween(1, 255),
DataSet\Strings::madeOf(DataSet\Unicode::any())->between(1, 255),
DataSet\Sequence::of(
DataSet\Decorate::immutable(
static fn($name) => Element::of($name),
DataSet\Unicode::lengthBetween(1, 10),
DataSet\Strings::madeOf(DataSet\Unicode::any())->between(1, 10),
),
DataSet\Integers::between(1, 10),
),
)->between(1, 10),
DataSet\Decorate::immutable(
static fn($name) => Element::of($name),
DataSet\Unicode::lengthBetween(1, 10),
DataSet\Strings::madeOf(DataSet\Unicode::any())->between(1, 10),
),
)
->then(function($name, $children, $replacement) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Element/SelfClosingElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function testCast()
public function testFilterChild()
{
$this
->forAll(DataSet\Unicode::lengthBetween(1, 255))
->forAll(DataSet\Strings::madeOf(DataSet\Unicode::any())->between(1, 255))
->then(function($name) {
$element = SelfClosingElement::of($name);

Expand All @@ -272,7 +272,7 @@ public function testFilterChild()
public function testMapChild()
{
$this
->forAll(DataSet\Unicode::lengthBetween(1, 255))
->forAll(DataSet\Strings::madeOf(DataSet\Unicode::any())->between(1, 255))
->then(function($name) {
$element = SelfClosingElement::of($name);

Expand Down
4 changes: 2 additions & 2 deletions tests/Node/Document/EncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testThrowWhenInvalidName($name)
Encoding::of($name);
}

public function cases(): array
public static function cases(): array
{
return [
['unicode-1-1'],
Expand All @@ -42,7 +42,7 @@ public function cases(): array
];
}

public function invalid(): array
public static function invalid(): array
{
return [
['@'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Node/Document/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testThrowWhenEmptyName()
Type::of('');
}

public function cases(): array
public static function cases(): array
{
return [
['foo', '', '', '<!DOCTYPE foo>'],
Expand Down
Loading

0 comments on commit a02227b

Please sign in to comment.