diff --git a/.gitattributes b/.gitattributes
index 62bc288..1b422fb 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -9,4 +9,4 @@
phpunit.xml.dist export-ignore
tests export-ignore
docs export-ignore
-
+.phpunit.result.cache
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index f77afc4..3d951c7 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -16,9 +16,8 @@ jobs:
strategy:
matrix:
include:
- - php-version: '8.1'
- main: true
- php-version: '8.2'
+ main: true
- php-version: '8.3'
- php-version: '8.4'
nightly: true
@@ -44,7 +43,7 @@ jobs:
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
- run: composer install --prefer-dist --dev
+ run: composer install --prefer-dist
- name: Run tests
continue-on-error: ${{ matrix.nightly }}
diff --git a/.idea/ElementFinder.iml b/.idea/ElementFinder.iml
index e0fcf0b..c7bb0ea 100644
--- a/.idea/ElementFinder.iml
+++ b/.idea/ElementFinder.iml
@@ -3,28 +3,20 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/php.xml b/.idea/php.xml
index 5bbce04..be54721 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -75,6 +75,17 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6159742..22c0122 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
# Changelog
All Notable changes to `ElementFinder` will be documented in this file
+## 3.0 [Unreleased]
+- Move to php 8.2
## 2.0.0 [2023-01-11]
- Move to php 8.1
diff --git a/composer.json b/composer.json
index b29bd23..87ebca7 100644
--- a/composer.json
+++ b/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^8.1",
+ "php": "^8.2",
"ext-dom": "*",
"ext-libxml": "*",
"symfony/css-selector": "^7.1"
@@ -35,7 +35,7 @@
},
"autoload-dev": {
"psr-4": {
- "Test\\Xparse\\ElementFinder\\": "tests"
+ "Test\\Xparse\\ElementFinder\\": "./tests"
}
},
"config": {
diff --git a/ecs.php b/ecs.php
index b3c703e..3b67e58 100644
--- a/ecs.php
+++ b/ecs.php
@@ -4,6 +4,7 @@
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
+use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
@@ -14,7 +15,11 @@
__FILE__,
]);
- $ecsConfig->rules([NoUnusedImportsFixer::class, VoidReturnFixer::class]);
+ $ecsConfig->rules([
+ NoUnusedImportsFixer::class,
+ VoidReturnFixer::class,
+ DeclareStrictTypesFixer::class,
+ ]);
// this way you can add sets - group of rules
$ecsConfig->sets([SetList::SPACES, SetList::ARRAY, SetList::DOCBLOCK, SetList::NAMESPACES, SetList::COMMENTS, SetList::PSR_12]);
diff --git a/phpunit.xml b/phpunit.xml
index 00edbe1..0eef20b 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -2,19 +2,25 @@
-
- src/
-
- tests
+ ./tests
+
+
+ ./src
+
+
diff --git a/src/ElementFinder.php b/src/ElementFinder.php
index 80c022e..41f91c7 100644
--- a/src/ElementFinder.php
+++ b/src/ElementFinder.php
@@ -214,7 +214,19 @@ private function setData(string $data): self
if (static::DOCUMENT_HTML === $this->type) {
$data = StringHelper::safeEncodeStr($data);
- $data = mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8');
+
+ //Analogue of mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8')
+ //Usage of mb_convert_encoding with encoding to HTML_ENTITIES is deprecated since php version 8.2
+ //When passing data to ElementFinder in an encoding other than UTF-8, any unrecognized characters will be ignored
+ $data = mb_encode_numericentity(
+ htmlspecialchars_decode(
+ htmlentities($data, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8', false),
+ ENT_NOQUOTES
+ ),
+ [0x80, 0x10FFFF, 0, ~0],
+ 'UTF-8'
+ );
+
$this->dom->loadHTML($data, LIBXML_NOCDATA & LIBXML_NOERROR);
} elseif (static::DOCUMENT_XML === $this->type) {
$this->dom->loadXML($data, LIBXML_NOCDATA & LIBXML_NOERROR);
diff --git a/tests/Collection/Filters/StringFilter/RegexStringFilterTest.php b/tests/Collection/Filters/StringFilter/RegexStringFilterTest.php
index d3e100c..c28cc54 100644
--- a/tests/Collection/Filters/StringFilter/RegexStringFilterTest.php
+++ b/tests/Collection/Filters/StringFilter/RegexStringFilterTest.php
@@ -1,11 +1,13 @@
*/
-class StringCollectionTest extends TestCase
+final class StringCollectionTest extends TestCase
{
public function testInvalidObjectIndex(): void
{
@@ -87,10 +88,12 @@ public function testMergeWithPartialItems(): void
{
$collection = (new StringCollection([
1 => 'a',
- ]))->merge(new StringCollection([
- 1 => 'b',
- 'c',
- ]));
+ ]))->merge(
+ new StringCollection([
+ 1 => 'b',
+ 'c',
+ ])
+ );
self::assertSame(['a', 'b', 'c'], $collection->all());
}
@@ -128,7 +131,8 @@ public function testFilter(): void
self::assertSame(
[
- 'bar', 'baz',
+ 'bar',
+ 'baz',
],
$collection->all()
);
@@ -148,9 +152,7 @@ public function testMap(): void
);
}
- /**
- * @dataProvider lastDataProvider
- */
+ #[DataProvider('lastDataProvider')]
public function testLast(array $items, mixed $expected): void
{
$collection = new StringCollection($items);
diff --git a/tests/CssExpressionTranslator/CssExpressionTranslatorTest.php b/tests/CssExpressionTranslator/CssExpressionTranslatorTest.php
index 32f651a..6204fc8 100644
--- a/tests/CssExpressionTranslator/CssExpressionTranslatorTest.php
+++ b/tests/CssExpressionTranslator/CssExpressionTranslatorTest.php
@@ -2,8 +2,9 @@
declare(strict_types=1);
-namespace Xparse\ElementFinder\CssExpressionTranslator\Test;
+namespace Test\Xparse\ElementFinder\CssExpressionTranslator;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Xparse\ElementFinder\CssExpressionTranslator\CssExpressionTranslator;
@@ -15,7 +16,7 @@ class CssExpressionTranslatorTest extends TestCase
/**
* @return string[][]
*/
- final public function getConvertWithAttributesDataProvider(): array
+ final public static function getConvertWithAttributesDataProvider(): array
{
return [
['a', 'descendant-or-self::a'],
@@ -26,9 +27,7 @@ final public function getConvertWithAttributesDataProvider(): array
];
}
- /**
- * @dataProvider getConvertWithAttributesDataProvider
- */
+ #[DataProvider('getConvertWithAttributesDataProvider')]
final public function testConvertWithAttributes(string $input, string $expect): void
{
self::assertSame(
diff --git a/tests/CssExpressionTranslator/CssOrXpathExpressionTranslatorTest.php b/tests/CssExpressionTranslator/CssOrXpathExpressionTranslatorTest.php
index 7b82ab2..87619f3 100644
--- a/tests/CssExpressionTranslator/CssOrXpathExpressionTranslatorTest.php
+++ b/tests/CssExpressionTranslator/CssOrXpathExpressionTranslatorTest.php
@@ -5,6 +5,7 @@
namespace Test\Xparse\ElementFinder\CssExpressionTranslator;
use InvalidArgumentException;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Xparse\ElementFinder\CssExpressionTranslator\CssOrXpathExpressionTranslator;
@@ -16,7 +17,7 @@ final class CssOrXpathExpressionTranslatorTest extends TestCase
/**
* @return string[][]
*/
- public function getQueriesDataProvider(): array
+ public static function getQueriesDataProvider(): array
{
return [
[
@@ -90,9 +91,7 @@ public function getQueriesDataProvider(): array
];
}
- /**
- * @dataProvider getQueriesDataProvider
- */
+ #[DataProvider('getQueriesDataProvider')]
public function testQueries(string $input, string $expect): void
{
$output = (new CssOrXpathExpressionTranslator())
diff --git a/tests/Dummy/ItemsByClassExpressionTranslator.php b/tests/Dummy/ItemsByClassExpressionTranslator.php
index e29230d..d94a449 100644
--- a/tests/Dummy/ItemsByClassExpressionTranslator.php
+++ b/tests/Dummy/ItemsByClassExpressionTranslator.php
@@ -1,5 +1,7 @@
';
}
+
+ /**
+ * @return string[][]
+ */
+ public static function getDifferentEncodingsSupportDataProvider(): array
+ {
+ return [
+ [
+ 'Текст текст text',
+ 'Текст текст text',
+ ],
+ [
+ ' text',
+ ' text',
+ ],
+ ];
+ }
+
+ #[DataProvider('getDifferentEncodingsSupportDataProvider')]
+ public function testDifferentEncodingsSupport(string $html, string $bodyText): void
+ {
+ $page = new ElementFinder($html);
+ $pageBodyText = $page->content('//body')->first();
+ self::assertInstanceOf(ElementFinder::class, $page);
+ self::assertEquals($bodyText, $pageBodyText);
+ }
}
diff --git a/tests/Helper/FormHelperTest.php b/tests/Helper/FormHelperTest.php
index cea4a47..3c408b6 100644
--- a/tests/Helper/FormHelperTest.php
+++ b/tests/Helper/FormHelperTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Xparse\ElementFinder\Helper;
+namespace Test\Xparse\ElementFinder\Helper;
use Exception;
use PHPUnit\Framework\TestCase;
diff --git a/tests/Helper/NodeHelperTest.php b/tests/Helper/NodeHelperTest.php
index 1aeba01..61766d9 100644
--- a/tests/Helper/NodeHelperTest.php
+++ b/tests/Helper/NodeHelperTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Xparse\ElementFinder\Helper;
+namespace Test\Xparse\ElementFinder\Helper;
use DOMDocument;
use PHPUnit\Framework\TestCase;
diff --git a/tests/Helper/StringHelperTest.php b/tests/Helper/StringHelperTest.php
index 27b9d05..aa0130f 100644
--- a/tests/Helper/StringHelperTest.php
+++ b/tests/Helper/StringHelperTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Tests\Xparse\ElementFinder\Helper;
+namespace Test\Xparse\ElementFinder\Helper;
use PHPUnit\Framework\TestCase;
use Xparse\ElementFinder\Helper\StringHelper;
@@ -10,7 +10,7 @@
/**
* @author Ivan Shcherbak
*/
-class StringHelperTest extends TestCase
+final class StringHelperTest extends TestCase
{
public function testEncode(): void
{