Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/analyzers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2', '8.3', '8.4']
php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
Expand All @@ -29,3 +29,4 @@ jobs:
run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }}
- name: Run the tests
run: composer run psalm
continue-on-error: ${{ matrix.php-versions == '8.5' }}
2 changes: 1 addition & 1 deletion .github/workflows/autoloader.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2', '8.3', '8.4']
php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2', '8.3', '8.4']
php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2', '8.3', '8.4']
php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2', '8.3', '8.4']
php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
Expand All @@ -32,4 +32,3 @@ jobs:
run: composer run tests
- name: Check tests quality
run: composer run testquality
continue-on-error: ${{ matrix.php-versions == '8.4' }} # Infection is not ready yet.
6 changes: 0 additions & 6 deletions .phive/phars.xml

This file was deleted.

22 changes: 13 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
],
"type": "library",
"require": {
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
"php": "~8.3.0 || ~8.4.0 || ~8.5.0",
"ext-dom": "*",
"ext-libxml": "*",
"ext-xml": "*",
"ext-xsl": "*",
"ext-xmlreader": "*",
"ext-xmlwriter": "*",
"azjezz/psl": "^3.0",
"azjezz/psl": "^3.0 || ^4.0",
"webmozart/assert": "^1.10"
},
"require-dev": {
"symfony/finder": "^6.1 || ^7.0",
"veewee/composer-run-parallel": "^1.0.0",
"vimeo/psalm": "^5.4",
"phpunit/phpunit": "~12.3",
"vimeo/psalm": "~6.13",
"php-cs-fixer/shim": "~3.88",
"infection/infection": "^0.31.7",
"php-standard-library/psalm-plugin": "^2.2"
},
"license": "MIT",
Expand All @@ -47,19 +50,19 @@
"autoload": [
"@php build/bootstrap.php"
],
"cs": "PHP_CS_FIXER_IGNORE_ENV=1 php ./tools/php-cs-fixer.phar fix --dry-run",
"cs:fix": "PHP_CS_FIXER_IGNORE_ENV=1 php ./tools/php-cs-fixer.phar fix",
"cs": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --dry-run",
"cs:fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix",
"psalm": "./vendor/bin/psalm --no-cache --stats",
"tests": "./tools/phpunit.phar --coverage-text --color",
"tests": "./vendor/bin/phpunit --coverage-text --color",
"stress": [
"Composer\\Config::disableProcessTimeout",
"@php -c stress.ini ./tools/phpunit.phar --configuration phpunit.stress.xml --no-coverage"
"@php -c stress.ini ./vendor/bin/phpunit --configuration phpunit.stress.xml --no-coverage"
],
"testquality": "@parallel coverage infection",
"coverage": "@php ./tools/full-coverage-check.php .phpunit.cache/clover/clover.xml",
"infection": [
"Composer\\Config::disableProcessTimeout",
"./tools/infection.phar --show-mutations -v"
"./vendor/bin/infection --show-mutations -v"
],
"ci": [
"@autoload",
Expand All @@ -69,7 +72,8 @@
},
"config": {
"allow-plugins": {
"veewee/composer-run-parallel": true
"veewee/composer-run-parallel": true,
"infection/extension-installer": true
}
}
}
10 changes: 7 additions & 3 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
},
"minMsi": 100,
"minCoveredMsi": 100,
"phpUnit": {
"customPath": ".\/tools\/phpunit.phar"
},
"logs": {
"text": ".phpunit.cache/infection.log",
"html": ".phpunit.cache/infection"
},
"mutators": {
"@default": true,
"ReturnRemoval": {
"ignore": [
"VeeWee\\Xml\\Dom\\Traverser\\Visitor\\RemoveNamespaces::onNodeLeave",
"VeeWee\\Xml\\Dom\\Traverser\\Visitor\\SortAttributes::onNodeEnter",
"VeeWee\\Xml\\Reader\\Reader::provide",
]
},
"CastInt": {
"ignore": [
"VeeWee\\Xml\\*Exception::__construct"
Expand Down
57 changes: 30 additions & 27 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="tests/bootstrap.php"
executionOrder="random"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
executionOrder="random"
beStrictAboutCoverageMetadata="false"
beStrictAboutOutputDuringTests="true"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnWarning="true"
failOnPhpunitWarning="true"
>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<file>src/bootstrap.php</file>
</exclude>
<report>
<clover outputFile=".phpunit.cache/clover/clover.xml" />
<html outputDirectory=".phpunit.cache/report" lowUpperBound="99" highLowerBound="99" />
</report>
</coverage>
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests/Xml</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<file>src/bootstrap.php</file>
</exclude>
</source>

<coverage includeUncoveredFiles="true">
<report>
<clover outputFile=".phpunit.cache/clover/clover.xml"/>
<html outputDirectory=".phpunit.cache/report" lowUpperBound="99" highLowerBound="99"/>
</report>
</coverage>

<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests/Xml</directory>
</testsuite>
</testsuites>
</phpunit>
20 changes: 4 additions & 16 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,21 @@
skipChecksOnUnresolvableIncludes="false"
checkForThrowsDocblock="true"
checkForThrowsInGlobalScope="true"
findUnusedCode="false"
ensureOverrideAttribute="false"
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"
>
<projectFiles>
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="tests" />
<directory name="vendor" />
<file name="src/bootstrap.php"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MissingConstructor>
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</MissingConstructor>
<UndefinedClass>
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</UndefinedClass>
<MissingDependency>
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</MissingDependency>
<MixedArgumentTypeCoercion>
<errorLevel type="suppress">
<directory name="src/Xml/Encoding/Internal/Encoder/Builder" />
Expand All @@ -47,6 +34,7 @@
<file name="stubs/DOM.phpstub" />
<file name="stubs/XMLReader.phpstub" />
<file name="stubs/XMLWriter.phpstub" />
<file name="stubs/XSLTProcessor.phpstub" />
</stubs>
<plugins>
<pluginClass class="Psl\Psalm\Plugin" />
Expand Down
4 changes: 3 additions & 1 deletion src/Xml/Dom/Xpath/Locator/query_single.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ static function (DOMXPath $xpath) use ($query, $node): DOMNode {
1,
format('Expected to find only one node that matches %s. Got %s', $query, count($list))
);
$node = $list->item(0);
Assert::notNull($node);

return $list->item(0);
return $node;
};
}
2 changes: 1 addition & 1 deletion src/Xml/Reader/Configurator/xsd_schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function xsd_schema(string $schemaFile): Closure
Assert::fileExists($schemaFile);

disallow_libxml_false_returns(
$reader->setSchema($schemaFile),
@$reader->setSchema($schemaFile),

Copilot AI Oct 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the @ error suppression operator can hide important errors and make debugging difficult. Consider using proper error handling instead of suppressing errors.

Suggested change
@$reader->setSchema($schemaFile),
$reader->setSchema($schemaFile),

Copilot uses AI. Check for mistakes.
'Unable to apply XSD schema to the XML Reader.'
);

Expand Down
21 changes: 14 additions & 7 deletions src/Xml/Xslt/Configurator/security_preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
namespace VeeWee\Xml\Xslt\Configurator;

use Closure;
use XSL_SECPREF_CREATE_DIRECTORY;
use XSL_SECPREF_DEFAULT;
use XSL_SECPREF_NONE;
use XSL_SECPREF_READ_FILE;
use XSL_SECPREF_READ_NETWORK;
use XSL_SECPREF_WRITE_FILE;
use XSL_SECPREF_WRITE_NETWORK;
use XSLTProcessor;

/**
* @see https://www.php.net/manual/en/xsltprocessor.setsecurityprefs.php
*
* @param int-mask<
* \XSL_SECPREF_NONE,
* \XSL_SECPREF_READ_FILE,
* \XSL_SECPREF_WRITE_FILE,
* \XSL_SECPREF_CREATE_DIRECTORY,
* \XSL_SECPREF_READ_NETWORK,
* \XSL_SECPREF_WRITE_NETWORK,
* \XSL_SECPREF_DEFAULT
* XSL_SECPREF_NONE,
* XSL_SECPREF_READ_FILE,
* XSL_SECPREF_WRITE_FILE,
* XSL_SECPREF_CREATE_DIRECTORY,
* XSL_SECPREF_READ_NETWORK,
* XSL_SECPREF_WRITE_NETWORK,
* XSL_SECPREF_DEFAULT
* > $preferences
*
* @return Closure(XSLTProcessor): XSLTProcessor
Expand Down
1 change: 0 additions & 1 deletion src/Xml/Xslt/Transformer/document_to_string.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function document_to_string(Document $document): Closure
{
return static fn (XSLTProcessor $processor): string => disallow_issues(
static function () use ($document, $processor): string {
// Result can also be null ... undocumentedly!
return (string) disallow_libxml_false_returns(
$processor->transformToXML($document->toUnsafeDocument()),
'Unable to apply the XSLT template'
Expand Down
14 changes: 14 additions & 0 deletions stubs/XSLTProcessor.phpstub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
class XSLTProcessor
{
/**
* Transform to XML
* @link https://php.net/manual/en/xsltprocessor.transformtoxml.php
* @param DOMDocument|SimpleXMLElement $document <p>
* The transformed document.
* </p>
* @return string|false|null The result of the transformation as a string or <b>FALSE</b> on error.
*/
public function transformToXml($document): string|false|null {}

}
44 changes: 44 additions & 0 deletions tests/Xml/Dom/Assert/AssertAttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace VeeWee\Tests\Xml\Dom\Assert;

use DOMNode;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psl\Type\Exception\AssertException;
use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Assert\assert_attribute;

final class AssertAttributeTest extends TestCase
{
#[DataProvider('provideTestCases')]
public function test_it_knows_attributes(?DOMNode $node, bool $expected): void
{
if (!$expected) {
$this->expectException(AssertException::class);
}

$actual = assert_attribute($node);
static::assertSame($node, $actual);
}

public static function provideTestCases()
{
$doc = Document::fromXmlString(
<<<EOXML
<doc>
<item attr="val">Hello</item>
</doc>
EOXML
)->toUnsafeDocument();

yield [$doc, false];
yield [$doc->documentElement, false];
yield [$doc->documentElement->firstElementChild, false];
yield [$doc->documentElement->firstElementChild->attributes->getNamedItem('attr'), true];
yield [$doc->documentElement->firstElementChild->firstChild, false];
yield [null, false];
}
}
Loading
Loading