diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7047d97f2..0d2e11684 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,13 +7,43 @@ on: branches: [ master ] jobs: - tests: + outdated: + runs-on: ubuntu-latest + container: setupphp/node@sha256:9271c0a914deb70c1717ec113410c9d43e48123d0ed398bb696f00f4f0ef15ba + + strategy: + matrix: + php-version: + - "8.1" + + steps: + - uses: "actions/checkout@v3" + - uses: "shivammathur/setup-php@v2" + with: + php-version: ${{ matrix.php-version }} + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: php-outdated + + - name: Install Composer dependencies + run: composer install --prefer-dist --no-progress + + - name: Run test suite + run: composer run-script test + + current: runs-on: ubuntu-latest strategy: matrix: php-version: - "8.1" + - "8.2" - "8.3" + - "8.4" steps: - uses: "actions/checkout@v3" @@ -29,7 +59,7 @@ jobs: uses: actions/cache@v3 with: path: vendor - key: php-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }} + key: php-${{ matrix.php-version }} - name: Install Composer dependencies run: composer install --prefer-dist --no-progress diff --git a/composer.json b/composer.json index 2c9305dbb..85232092d 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,13 @@ "keywords": ["bbcode","bbcodes","blog","censor","embed","emoji","emoticons","engine","forum","html","markdown","markup","media","parser","shortcodes"], "license": "MIT", "require": { - "php": "~8.1.22 || ~8.2.9 || ^8.3", + "php": "^8.1", "ext-dom": "*", "ext-filter": "*", "lib-pcre": ">=8.13", "s9e/regexp-builder": "^1.4", - "s9e/sweetdom": "^3.0" + "s9e/sweetdom": "^3.3" }, "require-dev": { "code-lts/doctum": "*", diff --git a/src/Utils/ParsedDOM/Document.php b/src/Utils/ParsedDOM/Document.php index 1ebf02453..f984641cc 100644 --- a/src/Utils/ParsedDOM/Document.php +++ b/src/Utils/ParsedDOM/Document.php @@ -8,7 +8,7 @@ namespace s9e\TextFormatter\Utils\ParsedDOM; use const LIBXML_NSCLEAN, SORT_STRING, false; -use function ksort, substr, strpos; +use function class_alias, class_exists, ksort, substr, strpos; use s9e\SweetDOM\Document as SweetDocument; use s9e\TextFormatter\Configurator\Validators\TagName; use s9e\TextFormatter\Configurator\Validators\AttributeName; @@ -26,6 +26,11 @@ public function __construct(string $version = '1.0', string $encoding = 'utf-8') { parent::__construct($version, $encoding); + // Create an alias to whichever SweetDOM\Element subclass is used on current PHP version + if (!class_exists(SweetElement::class, false)) + { + class_alias($this->getNodesNamespace() . '\\Element', SweetElement::class, false); + } $this->registerNodeClass('DOMElement', Element::class); } diff --git a/src/Utils/ParsedDOM/Element.php b/src/Utils/ParsedDOM/Element.php index 8751611cc..54f88dd6b 100644 --- a/src/Utils/ParsedDOM/Element.php +++ b/src/Utils/ParsedDOM/Element.php @@ -10,8 +10,8 @@ use DOMNode; use const SORT_STRING; use function count, ksort, preg_match; -use s9e\SweetDOM\Element as SweetElement; +// This requires the SweetElement class to be aliased to the correct s9e\SweetDOM\Element subclass class Element extends SweetElement { /** diff --git a/tests/Configurator/Helpers/TemplateModifierTest.php b/tests/Configurator/Helpers/TemplateModifierTest.php index 75b165035..e578854c9 100644 --- a/tests/Configurator/Helpers/TemplateModifierTest.php +++ b/tests/Configurator/Helpers/TemplateModifierTest.php @@ -122,7 +122,7 @@ function ($m) '/\\$[0-9]+/', function ($m, $node) { - return ['literal', get_class($node)]; + return ['literal', preg_replace('(SweetDOM\\\\\\K.*\\\\)', '', get_class($node))]; }, 's9e\\SweetDOM\\Text' ],