From aaf05fded2379c7c6db9a8fa11be75a371166b9f Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 27 Oct 2020 08:27:43 +0100 Subject: add upstream patch for PHP 8 add patch for Xdebug 3 from https://github.com/theseer/Autoload/pull/97 --- Autoload-php8.patch | 362 ++++++++++++++++++++++++++++++++++++++++++++++ Autoload-xdebug3.patch | 24 +++ php-theseer-autoload.spec | 49 ++++--- 3 files changed, 415 insertions(+), 20 deletions(-) create mode 100644 Autoload-php8.patch create mode 100644 Autoload-xdebug3.patch diff --git a/Autoload-php8.patch b/Autoload-php8.patch new file mode 100644 index 0000000..11923cb --- /dev/null +++ b/Autoload-php8.patch @@ -0,0 +1,362 @@ +From 3b4082f059fb9e2d8b7039ea51b554427336af67 Mon Sep 17 00:00:00 2001 +From: Arne Blankerts +Date: Sun, 23 Aug 2020 23:54:20 +0200 +Subject: [PATCH] Close #95 + +--- + CHANGELOG.md | 6 +++- + composer.json | 3 +- + composer.lock | 8 +++-- + phive.xml | 4 +-- + phpunit.xml.dist | 46 ++++++++++++------------ + src/Parser.php | 19 +++++++++- + tests/AutoloadRendererTest.php | 28 ++++++--------- + tests/FactoryTest.php | 2 +- + tests/ParserTest.php | 55 +++++++++++------------------ + tests/_data/parser/relative.php | 4 +++ + tests/classdependencysorterTest.php | 5 ++- + 11 files changed, 93 insertions(+), 87 deletions(-) + create mode 100644 tests/_data/parser/relative.php + +diff --git a/src/Parser.php b/src/Parser.php +index c658b28..3d50bbf 100644 +--- a/src/Parser.php ++++ b/src/Parser.php +@@ -43,6 +43,12 @@ + define('T_TRAIT', -1); + } + ++ // PHP 8.0 forward compat ++ if (!defined('T_NAME_FULLY_QUALIFIED')) { ++ define('T_NAME_FULLY_QUALIFIED', -1); ++ define('T_NAME_QUALIFIED', -1); ++ } ++ + /** + * Namespace aware parser to find and extract defined classes within php source files + * +@@ -168,6 +174,9 @@ private function processClass($pos) { + case T_WHITESPACE: { + break; + } ++ ++ case T_NAME_FULLY_QUALIFIED: ++ case T_NAME_QUALIFIED: + case T_STRING: { + $$mode .= $tok[1]; + break; +@@ -186,6 +195,7 @@ private function processClass($pos) { + $mode = 'implements'; + break; + } ++ + case ',': { + if ($mode === 'implements') { + $implementsList[] = $this->resolveDependencyName($implements); +@@ -195,7 +205,8 @@ private function processClass($pos) { + } + default: { + throw new ParserException(sprintf( +- 'Parse error while trying to process class definition (unexpected token in name).' ++ 'Parse error while trying to process class definition (unexpected token "%s" in name).', ++ \token_name($tok[0]) + ), ParserException::ParseError + ); + } +@@ -237,6 +248,8 @@ private function processInterface($pos) { + foreach(array_slice($stack, 1, -1) as $tok) { + switch ($tok[0]) { + case T_NS_SEPARATOR: ++ case T_NAME_QUALIFIED: ++ case T_NAME_FULLY_QUALIFIED: + case T_STRING: { + $$mode .= $tok[1]; + break; +@@ -406,6 +419,8 @@ private function parseUseOfTrait($stackSize, $stack) { + break; + } + case T_NS_SEPARATOR: ++ case T_NAME_QUALIFIED: ++ case T_NAME_FULLY_QUALIFIED: + case T_STRING: { + $use .= $current[1]; + break; +@@ -458,6 +473,8 @@ private function parseUseAsImport($stack) { + break; + } + case T_NS_SEPARATOR: ++ case T_NAME_QUALIFIED: ++ case T_NAME_FULLY_QUALIFIED: + case T_STRING: { + $$mode .= $current[1]; + break; +diff --git a/tests/AutoloadRendererTest.php b/tests/AutoloadRendererTest.php +index fcf0d0e..c1dd00f 100644 +--- a/tests/AutoloadRendererTest.php ++++ b/tests/AutoloadRendererTest.php +@@ -37,12 +37,10 @@ + + namespace TheSeer\Autoload\Tests { + +- use TheSeer\Autoload\Parser; ++ use TheSeer\Autoload\AutoloadBuilderException; + use TheSeer\Autoload\AutoloadRenderer; + + /** +- * Unit tests for PHPFilter iterator class +- * + * @author Arne Blankerts + * @copyright Arne Blankerts , All rights reserved. + */ +@@ -51,7 +49,7 @@ class AutoloadRendererTest extends \PHPUnit\Framework\TestCase { + private $classlist; + private $template; + +- public function setUp() { ++ public function setUp(): void { + $this->classlist = array(); + $this->classlist['demo1'] = realpath(__DIR__ . '/_data/parser/class.php'); + $this->classlist['demo2'] = realpath(__DIR__ . '/_data/parser/class.php'); +@@ -59,7 +57,6 @@ public function setUp() { + } + + /** +- * + * @covers \TheSeer\Autoload\AutoloadRenderer::__construct + * @covers \TheSeer\Autoload\AutoloadRenderer::render + */ +@@ -67,9 +64,9 @@ public function testDefaultRendering() { + $ab = new \TheSeer\Autoload\AutoloadRenderer($this->classlist); + $expected = " \$classes = array(\n 'demo1' => '".__DIR__."/_data/parser/class.php',\n"; + $expected = strtr($expected, '\\', '/'); +- $this->assertContains($expected, $ab->render($this->template)); ++ $this->assertStringContainsString($expected, $ab->render($this->template)); + $expected = "require \$classes[\$cn]"; +- $this->assertContains($expected, $ab->render($this->template)); ++ $this->assertStringContainsString($expected, $ab->render($this->template)); + } + + /** +@@ -81,7 +78,7 @@ public function testWindowsLFRendering() { + $ab = new \TheSeer\Autoload\AutoloadRenderer($this->classlist); + $ab->setLineBreak("\r\n"); + $expected = "_data/parser/class.php',\r\n"; +- $this->assertContains($expected, $ab->render($this->template)); ++ $this->assertStringContainsString($expected, $ab->render($this->template)); + } + + /** +@@ -104,7 +101,7 @@ public function testIndentWithTabsRendering() { + $ab = new \TheSeer\Autoload\AutoloadRenderer($this->classlist); + $ab->setIndent("\t"); + $expected = "\t'demo2'"; +- $this->assertContains($expected, $ab->render($this->template)); ++ $this->assertStringContainsString($expected, $ab->render($this->template)); + } + + +@@ -120,10 +117,10 @@ public function testSetBaseDirRendering() { + + $expected = "require __DIR__ . \$classes[\$cn];"; + $expected = strtr($expected, '\\', '/'); +- $this->assertContains($expected, $result); ++ $this->assertStringContainsString($expected, $result); + + $expected = " \$classes = array(\n 'demo1' => '/tests/_data/parser/class.php',\n"; +- $this->assertContains($expected, $result); ++ $this->assertStringContainsString($expected, $result); + } + + /** +@@ -135,7 +132,7 @@ public function testRenderingInCompatMode() { + $ab->setCompat(true); + $ab->setBaseDir(realpath(__DIR__)); + $expected = "require dirname(__FILE__) . \$classes[\$cn];"; +- $this->assertContains($expected, $ab->render($this->template)); ++ $this->assertStringContainsString($expected, $ab->render($this->template)); + + } + +@@ -146,15 +143,12 @@ public function testRelativeSubBaseDirRendering() { + $ab = new \TheSeer\Autoload\AutoloadRenderer($this->classlist); + $ab->setBaseDir(realpath(__DIR__.'/_data/dependency')); + $expected = "'demo1' => '/../parser/class.php'"; +- $this->assertContains($expected, $ab->render($this->template)); ++ $this->assertStringContainsString($expected, $ab->render($this->template)); + } + +- /** +- * +- * @expectedException \TheSeer\Autoload\AutoloadBuilderException +- */ + public function testSettingInvalidTimestamp() { + $ab = new \TheSeer\Autoload\AutoloadRenderer($this->classlist); ++ $this->expectException(AutoloadBuilderException::class); + $ab->setTimestamp('Bad'); + } + +diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php +index df2978d..1e36a86 100644 +--- a/tests/FactoryTest.php ++++ b/tests/FactoryTest.php +@@ -44,7 +44,7 @@ + + class FactoryTest extends \PHPUnit\Framework\TestCase { + +- public function setUp() { ++ public function setUp(): void { + $this->factory = new Factory(); + $this->config = new Config(array()); + $this->factory->setConfig($this->config); +diff --git a/tests/ParserTest.php b/tests/ParserTest.php +index f28f16f..3b3f27d 100644 +--- a/tests/ParserTest.php ++++ b/tests/ParserTest.php +@@ -38,14 +38,9 @@ + namespace TheSeer\Autoload\Tests { + + use TheSeer\Autoload\Parser; ++ use TheSeer\Autoload\ParserException; + use TheSeer\Autoload\SourceFile; + +- /** +- * Unit tests for ClassFinder class +- * +- * @author Arne Blankerts +- * @copyright Arne Blankerts , All rights reserved. +- */ + class ParserTest extends \PHPUnit\Framework\TestCase { + + public function testNoClassDefined() { +@@ -84,66 +79,52 @@ public function testRedeclaringThrowsException() { + $this->assertContains('demo', $rc->getRedeclarations()); + } + +- /** +- * @expectedException \TheSeer\Autoload\ParserException +- * @expectedExceptionCode \TheSeer\Autoload\ParserException::ParseError +- */ + public function testInvalidClassnameThrowsException() { + $parser = new \TheSeer\Autoload\Parser; ++ $this->expectException(ParserException::class); ++ $this->expectExceptionCode(ParserException::ParseError); + $parser->parse(new SourceFile((__DIR__.'/_data/parser/parseerror1.php'))); + } + +- /** +- * @expectedException \TheSeer\Autoload\ParserException +- * @expectedExceptionCode \TheSeer\Autoload\ParserException::ParseError +- */ + public function testInvalidClassnameWithExtendsThrowsException() { + $parser = new \TheSeer\Autoload\Parser; ++ $this->expectException(ParserException::class); ++ $this->expectExceptionCode(ParserException::ParseError); + $parser->parse(new SourceFile((__DIR__.'/_data/parser/parseerror2.php'))); + } + +- /** +- * @expectedException \TheSeer\Autoload\ParserException +- * @expectedExceptionCode \TheSeer\Autoload\ParserException::ParseError +- */ + public function testInvalidClassnameForExtendsThrowsException() { + $parser = new \TheSeer\Autoload\Parser(true); ++ $this->expectException(ParserException::class); ++ $this->expectExceptionCode(ParserException::ParseError); + $parser->parse(new SourceFile((__DIR__.'/_data/parser/parseerror3.php'))); + } + +- /** +- * @expectedException \TheSeer\Autoload\ParserException +- * @expectedExceptionCode \TheSeer\Autoload\ParserException::ParseError +- */ + public function testInvalidClassnameForImplementsThrowsException() { + $parser = new \TheSeer\Autoload\Parser(true); ++ $this->expectException(ParserException::class); ++ $this->expectExceptionCode(ParserException::ParseError); + $parser->parse(new SourceFile((__DIR__.'/_data/parser/parseerror4.php'))); + } + +- /** +- * @expectedException \TheSeer\Autoload\ParserException +- * @expectedExceptionCode \TheSeer\Autoload\ParserException::ParseError +- */ + public function testSyntacticallyInvalidClassnameThrowsException() { + $parser = new \TheSeer\Autoload\Parser; ++ $this->expectException(ParserException::class); ++ $this->expectExceptionCode(ParserException::ParseError); + $parser->parse(new SourceFile((__DIR__.'/_data/parser/invalid1.php'))); + } + +- /** +- * @expectedException \TheSeer\Autoload\ParserException +- * @expectedExceptionCode \TheSeer\Autoload\ParserException::ParseError +- */ + public function testInvalidTokenInClassnameThrowsException() { + $parser = new \TheSeer\Autoload\Parser; ++ $this->expectException(ParserException::class); ++ $this->expectExceptionCode(ParserException::ParseError); + $parser->parse(new SourceFile((__DIR__.'/_data/parser/invalid2.php'))); + } + +- /** +- * @expectedException \TheSeer\Autoload\ParserException +- * @expectedExceptionCode \TheSeer\Autoload\ParserException::ParseError +- */ + public function testInvalidTokenInClassnameWithinNamespaceThrowsException() { + $parser = new \TheSeer\Autoload\Parser; ++ $this->expectException(ParserException::class); ++ $this->expectExceptionCode(ParserException::ParseError); + $parser->parse(new SourceFile((__DIR__.'/_data/parser/invalid3.php'))); + } + +@@ -542,6 +523,12 @@ public function testInlineUseOfKeywordTraitGetsIgnored() { + $this->assertEquals(array('demo'), $rc->getUnits()); + } + ++ public function testPHP80Relative() { ++ $parser = new Parser(); ++ $rc = $parser->parse(new SourceFile((__DIR__.'/_data/parser/relative.php'))); ++ $this->assertEquals(array('foo\\demo'), $rc->getUnits()); ++ } ++ + } + + } +diff --git a/tests/_data/parser/relative.php b/tests/_data/parser/relative.php +new file mode 100644 +index 0000000..6e3c185 +--- /dev/null ++++ b/tests/_data/parser/relative.php +@@ -0,0 +1,4 @@ ++assertEquals($expectFilesOrder, array_unique(array_values($r))); + } + +- /** +- * @expectedException \TheSeer\Autoload\ClassDependencySorterException +- */ + public function testRecusriveDependencyThrowsException() { + $classes=array('test1' => 'file1'); + $dependency=array('test1' => array('test1')); + + $x = new ClassDependencySorter($classes, $dependency); ++ $this->expectException(ClassDependencySorterException::class); + $r = $x->process(); + + } diff --git a/Autoload-xdebug3.patch b/Autoload-xdebug3.patch new file mode 100644 index 0000000..0034c90 --- /dev/null +++ b/Autoload-xdebug3.patch @@ -0,0 +1,24 @@ +From cd91e690190551adb068ba0e968ca9673daf419b Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Tue, 27 Oct 2020 07:32:44 +0100 +Subject: [PATCH] fix for xdebug v3 + +--- + src/CLI.php | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/src/CLI.php b/src/CLI.php +index 3c78ce8..5c87b3b 100644 +--- a/src/CLI.php ++++ b/src/CLI.php +@@ -591,7 +591,9 @@ private function preBootstrap() { + ini_set('xdebug.scream', 0); + ini_set('xdebug.max_nesting_level', 8192); + ini_set('xdebug.show_exception_trace', 0); +- xdebug_disable(); ++ if (function_exists('xdebug_disable')) { // Xdebug v2 ++ xdebug_disable(); ++ } + } + + } diff --git a/php-theseer-autoload.spec b/php-theseer-autoload.spec index 1059dc2..e857e94 100644 --- a/php-theseer-autoload.spec +++ b/php-theseer-autoload.spec @@ -1,6 +1,6 @@ # remirepo/fedora spec file for php-theseer-autoload # -# Copyright (c) 2014-2019 Remi Collet +# Copyright (c) 2014-2020 Remi Collet # License: CC-BY-SA # http://creativecommons.org/licenses/by-sa/4.0/ # @@ -20,7 +20,7 @@ Name: php-theseer-autoload Version: 1.25.9 -Release: 1%{?dist} +Release: 3%{?dist} Summary: A tool and library to generate autoload code License: BSD @@ -29,19 +29,24 @@ Source0: https://github.com/%{gh_owner}/%{gh_project}/archive/%{gh_commit # Autoloader path Patch0: %{gh_project}-rpm.patch +# PHP 8 compatibility +Patch1: %{gh_project}-php8.patch +# Xdebug 3 compatibility +Patch2: %{gh_project}-xdebug3.patch BuildArch: noarch -BuildRequires: php(language) >= 5.3.1 +BuildRequires: php(language) >= 7.2 +%if 0%{?fedora} >= 31 || 0%{?rhel} >= 9 +%global phpunit %{_bindir}/phpunit9 +%else +%global phpunit %{_bindir}/phpunit8 +%endif %if 0%{?fedora} >= 27 || 0%{?rhel} >= 8 -BuildRequires: (php-composer(theseer/directoryscanner) >= 1.3 with php-composer(theseer/directoryscanner) < 2) -BuildRequires: (php-composer(zetacomponents/console-tools) >= 1.7 with php-composer(zetacomponents/console-tools) < 2) -%global phpunit %{_bindir}/phpunit7 +BuildRequires: (php-composer(theseer/directoryscanner) >= 1.3 with php-composer(theseer/directoryscanner) < 2) +BuildRequires: (php-composer(zetacomponents/console-tools) >= 1.7.1 with php-composer(zetacomponents/console-tools) < 2) %else -BuildRequires: php-composer(theseer/directoryscanner) < 2 -BuildRequires: php-composer(theseer/directoryscanner) >= 1.3 -BuildRequires: php-composer(zetacomponents/console-tools) < 2 -BuildRequires: php-composer(zetacomponents/console-tools) >= 1.7 -%global phpunit %{_bindir}/phpunit +BuildRequires: php-theseer-directoryscanner >= 1.3 +BuildRequires: php-zetacomponents-console-tools >= 1.7.1 %endif BuildRequires: %{phpunit} @@ -50,13 +55,11 @@ BuildRequires: %{phpunit} # "zetacomponents/console-tools": "^1.7.1" Requires: php(language) >= 5.3.1 %if 0%{?fedora} >= 27 || 0%{?rhel} >= 8 -Requires: (php-composer(theseer/directoryscanner) >= 1.3 with php-composer(theseer/directoryscanner) < 2) -Requires: (php-composer(zetacomponents/console-tools) >= 1.7 with php-composer(zetacomponents/console-tools) < 2) +Requires: (php-composer(theseer/directoryscanner) >= 1.3 with php-composer(theseer/directoryscanner) < 2) +Requires: (php-composer(zetacomponents/console-tools) >= 1.7.1 with php-composer(zetacomponents/console-tools) < 2) %else -Requires: php-composer(theseer/directoryscanner) < 2 -Requires: php-composer(theseer/directoryscanner) >= 1.3 -Requires: php-composer(zetacomponents/console-tools) < 2 -Requires: php-composer(zetacomponents/console-tools) >= 1.7 +Requires: php-theseer-directoryscanner >= 1.3 +Requires: php-zetacomponents-console-tools >= 1.7.1 %endif # From phpcompatinfo report for version 1.25.0 Requires: php-cli @@ -82,6 +85,8 @@ the option of creating static require lists as well as phar archives. %setup -q -n %{gh_project}-%{gh_commit} %patch0 -p0 -b .rpm +%patch1 -p1 +%patch2 -p1 : drop composer dependencies sed -e '\:../vendor/:d' -i src/autoload.php @@ -119,14 +124,13 @@ php t.php --output foo.php src cat < - 1.25.9-3 +- add upstream patch for PHP 8 +- add patch for Xdebug 3 from + https://github.com/theseer/Autoload/pull/97 + * Fri Mar 20 2020 Remi Collet - 1.25.9-1 - update to 1.25.9 -- cgit