From 9089fbff67ef455a2493dbab639ba80b456143ff Mon Sep 17 00:00:00 2001 From: kylekatarnls Date: Wed, 20 Sep 2023 15:19:55 +0200 Subject: [PATCH] Polyfill PHPUnit methods not available in old versions --- .codeclimate.yml | 2 + .github/workflows/coverage.yml | 2 +- composer.json | 2 +- .../Util/CompatibilityUtil/TestCaseTyped.php | 33 ++++++++++++ .../CompatibilityUtil/TestCaseUntyped.php | 33 ++++++++++++ tests/Phug/CliTest.php | 6 +-- tests/Phug/DependencyInjectionTest.php | 5 +- tests/Phug/Element/MixinCallElementTest.php | 2 +- tests/Phug/EventTest.php | 2 +- tests/Phug/FormatterTest.php | 2 +- .../Lexer/Scanner/AssignmentScannerTest.php | 5 ++ tests/Phug/OptimizerTest.php | 2 +- .../AssignmentTokenHandlerTest.php | 3 ++ .../AttributeEndTokenHandlerTest.php | 3 ++ .../TokenHandler/BlockTokenHandlerTest.php | 3 ++ .../TokenHandler/CodeTokenHandlerTest.php | 3 ++ .../ConditionalTokenHandlerTest.php | 3 ++ .../TokenHandler/DoTokenHandlerTest.php | 3 ++ .../ExpansionTokenHandlerTest.php | 3 ++ .../ExpressionTokenHandlerTest.php | 3 ++ .../TokenHandler/FilterTokenHandlerTest.php | 3 ++ .../TokenHandler/ForTokenHandlerTest.php | 3 ++ .../TokenHandler/IdTokenHandlerTest.php | 3 ++ .../TokenHandler/ImportTokenHandlerTest.php | 3 ++ .../InterpolationEndTokenHandlerTest.php | 3 ++ .../InterpolationStartTokenHandlerTest.php | 3 ++ .../TokenHandler/KeywordTokenHandlerTest.php | 3 ++ .../TagInterpolationEndTokenHandlerTest.php | 3 ++ .../TokenHandler/TextTokenHandlerTest.php | 3 ++ .../TokenHandler/VariableTokenHandlerTest.php | 3 ++ .../TokenHandler/WhileTokenHandlerTest.php | 3 ++ .../TokenHandler/YieldTokenHandlerTest.php | 3 ++ tests/Phug/ProfilerModuleTest.php | 54 +++++++++++-------- tests/Phug/RendererTest.php | 2 +- tests/Phug/Util/ModuleTest.php | 2 +- tests/Phug/Util/TestCaseTest.php | 2 +- 36 files changed, 181 insertions(+), 35 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index a613eb4c..2440c014 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -37,5 +37,7 @@ plugins: enabled: true exclude_patterns: - "src/Phug/Phug/Phug/Optimizer.php" + - "src/Phug/Util/CompatibilityUtil/TestCaseTyped.php" + - "src/Phug/Util/CompatibilityUtil/TestCaseUntyped.php" exclude_patterns: - "**/tests/**" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 2c15e1f7..3592beb3 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -25,7 +25,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - ini-values: memory_limit=-1, zend.enable_gc=0, xdebug.mode=coverage + ini-values: memory_limit=-1, zend.enable_gc=0, xdebug.mode="coverage,develop" tools: composer:v2 extensions: pcntl coverage: xdebug diff --git a/composer.json b/composer.json index 39c76862..65639b50 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "nodejs-php-fallback/less": "^1.0.5", "nodejs-php-fallback/stylus": "^1.0.4", "nodejs-php-fallback/uglify": "^1.0.4", - "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.34 || ^9.6.13", + "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^8.5.34 || ^9.6.13", "phpunit/php-code-coverage": "^2.2.4 || ^4.0.8 || ^5.3.2 || ^6.1.4 || ^7.0.15 || ^9.2.28", "phpunit/php-invoker": "^3.1.1", "pug-php/pug": "^2.7.3 || ^3.4.1", diff --git a/src/Phug/Util/CompatibilityUtil/TestCaseTyped.php b/src/Phug/Util/CompatibilityUtil/TestCaseTyped.php index ff3b9868..233f5e2e 100644 --- a/src/Phug/Util/CompatibilityUtil/TestCaseTyped.php +++ b/src/Phug/Util/CompatibilityUtil/TestCaseTyped.php @@ -30,5 +30,38 @@ protected function tearDown(): void { $this->finishTest(); } + + public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void + { + if (!method_exists(parent::class, 'assertMatchesRegularExpression')) { + self::assertRegExp($pattern, $string, $message); + + return; + } + + parent::assertMatchesRegularExpression($pattern, $string, $message); + } + + public static function assertFileDoesNotExist(string $filename, string $message = ''): void + { + if (!method_exists(parent::class, 'assertFileDoesNotExist')) { + self::assertFileNotExists($filename, $message); + + return; + } + + parent::assertFileDoesNotExist($filename, $message); + } + + public static function assertIsArray($actual, string $message = ''): void + { + if (!method_exists(parent::class, 'assertIsArray')) { + self::assertSame('array', gettype($actual)); + + return; + } + + parent::assertIsArray($actual, $message); + } } // @codeCoverageIgnoreEnd diff --git a/src/Phug/Util/CompatibilityUtil/TestCaseUntyped.php b/src/Phug/Util/CompatibilityUtil/TestCaseUntyped.php index dcfcc170..0fad46d0 100644 --- a/src/Phug/Util/CompatibilityUtil/TestCaseUntyped.php +++ b/src/Phug/Util/CompatibilityUtil/TestCaseUntyped.php @@ -30,5 +30,38 @@ protected function tearDown() { $this->finishTest(); } + + public static function assertMatchesRegularExpression($pattern, $string, $message = '') + { + if (!method_exists(parent::class, 'assertMatchesRegularExpression')) { + self::assertRegExp($pattern, $string, $message); + + return; + } + + parent::assertMatchesRegularExpression($pattern, $string, $message); + } + + public static function assertFileDoesNotExist($filename, $message = '') + { + if (!method_exists(parent::class, 'assertFileDoesNotExist')) { + self::assertFileNotExists($filename, $message); + + return; + } + + parent::assertFileDoesNotExist($filename, $message); + } + + public static function assertIsArray($actual, $message = '') + { + if (!method_exists(parent::class, 'assertIsArray')) { + self::assertSame('array', gettype($actual)); + + return; + } + + parent::assertIsArray($actual, $message); + } } // @codeCoverageIgnoreEnd diff --git a/tests/Phug/CliTest.php b/tests/Phug/CliTest.php index fe5d98e7..ffd5dcab 100644 --- a/tests/Phug/CliTest.php +++ b/tests/Phug/CliTest.php @@ -224,7 +224,7 @@ public function testCacheDirectory() ob_end_clean(); self::assertFileExists($expected); - self::assertFileNotExists("$expected/junk"); + self::assertFileDoesNotExist("$expected/junk"); $registryFile = "$expected/registry.php"; @@ -259,7 +259,7 @@ public function testCacheDirectory() $this->removeFile($expected); - self::assertRegExp('/Inconsistent indentation./', $text); + self::assertMatchesRegularExpression('/Inconsistent indentation./', $text); } /** @@ -328,7 +328,7 @@ public function testCacheDirectoryWithViewsDirInOptions() ob_end_clean(); self::assertFileExists($expected); - self::assertFileNotExists("$expected/junk"); + self::assertFileDoesNotExist("$expected/junk"); $registryFile = "$expected/registry.php"; diff --git a/tests/Phug/DependencyInjectionTest.php b/tests/Phug/DependencyInjectionTest.php index 25712a6c..a3680e1e 100644 --- a/tests/Phug/DependencyInjectionTest.php +++ b/tests/Phug/DependencyInjectionTest.php @@ -11,10 +11,13 @@ use Phug\Test\Utils\ClockInterface; use Phug\Util\UnorderedArguments; +/** + * @coversDefaultClass \Phug\DependencyInjection + */ class DependencyInjectionTest extends AbstractDependencyInjectionTest { /** - * @covers \Phug\DependencyInjection:: + * @covers :: * @covers \Phug\DependencyInjection\Dependency:: * @covers \Phug\DependencyInjection\Requirement:: */ diff --git a/tests/Phug/Element/MixinCallElementTest.php b/tests/Phug/Element/MixinCallElementTest.php index c6156e68..3fabd9c5 100644 --- a/tests/Phug/Element/MixinCallElementTest.php +++ b/tests/Phug/Element/MixinCallElementTest.php @@ -360,7 +360,7 @@ public function testPhpUnwrap() eval('?>'.$php); ob_get_clean(); - self::assertRegExp('/echo\s1;\s+\}/', $php); + self::assertMatchesRegularExpression('/echo\s1;\s+\}/', $php); } /** diff --git a/tests/Phug/EventTest.php b/tests/Phug/EventTest.php index 5ac5f058..326f86b0 100644 --- a/tests/Phug/EventTest.php +++ b/tests/Phug/EventTest.php @@ -56,7 +56,7 @@ public function testGetSetTarget() public function testGetSetParams() { $event = new Event('test.event'); - self::assertInternalType('array', $event->getParams()); + self::assertIsArray($event->getParams()); self::assertCount(0, $event->getParams(), 'params are empty when not passed'); $params = ['test_key' => 'test value']; diff --git a/tests/Phug/FormatterTest.php b/tests/Phug/FormatterTest.php index e1f838e2..574109f2 100644 --- a/tests/Phug/FormatterTest.php +++ b/tests/Phug/FormatterTest.php @@ -300,7 +300,7 @@ public function testFormat() $exp = new ExpressionElement('foreach ($tabs as $key => $tab)'); $code = $formatter->format($exp); - self::assertRegExp('/as\s\$key\s=>\s\$tab/', $code); + self::assertMatchesRegularExpression('/as\s\$key\s=>\s\$tab/', $code); } /** diff --git a/tests/Phug/Lexer/Scanner/AssignmentScannerTest.php b/tests/Phug/Lexer/Scanner/AssignmentScannerTest.php index d9029677..893386c6 100644 --- a/tests/Phug/Lexer/Scanner/AssignmentScannerTest.php +++ b/tests/Phug/Lexer/Scanner/AssignmentScannerTest.php @@ -25,6 +25,9 @@ public function testScan() self::assertSame('test', $tok->getName()); } + /** + * @coversNothing + */ public function testScanWithAttributes() { /** @var AssignmentToken $tok */ @@ -42,6 +45,8 @@ public function testScanWithAttributes() /** * @see https://github.com/phug-php/phug/issues/22 + * + * @coversNothing */ public function testObjectInTernary() { diff --git a/tests/Phug/OptimizerTest.php b/tests/Phug/OptimizerTest.php index f4673b53..dffe0375 100644 --- a/tests/Phug/OptimizerTest.php +++ b/tests/Phug/OptimizerTest.php @@ -174,7 +174,7 @@ public function testUpToDateCheckCachePath() $cachePath = null; self::assertFalse($optimizer->isExpired('file2', $cachePath)); - self::assertFileNotExists($cachePath); + self::assertFileDoesNotExist($cachePath); rename(__DIR__.'/file2.pug', __DIR__.'/../views/dir2/file2.pug'); $options['up_to_date_check'] = true; diff --git a/tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php index 81c1e691..63219569 100644 --- a/tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php @@ -14,6 +14,7 @@ use Phug\Parser\TokenHandler\AttributeEndTokenHandler; use Phug\Parser\TokenHandler\AttributeStartTokenHandler; use Phug\Parser\TokenHandler\AttributeTokenHandler; +use Phug\Test\Utils\ExceptionAnnotationReader; use Phug\Util\TestCase; /** @@ -81,6 +82,8 @@ public function testHandleTokenWithNothingNext() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div')); $handler = new AssignmentTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/AttributeEndTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/AttributeEndTokenHandlerTest.php index 91c74c96..552ede35 100644 --- a/tests/Phug/Parser/TokenHandler/AttributeEndTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/AttributeEndTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser; use Phug\Parser\State; use Phug\Parser\TokenHandler\AttributeEndTokenHandler; +use Phug\Test\Utils\ExceptionAnnotationReader; use Phug\Util\TestCase; /** @@ -37,6 +38,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div')); $handler = new AttributeEndTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php index d6fc48a9..7c98c846 100644 --- a/tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\BlockTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\BlockTokenHandler @@ -34,6 +35,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div')); $handler = new BlockTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php index ecb124fb..654cc68f 100644 --- a/tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php @@ -9,6 +9,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\CodeTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\CodeTokenHandler @@ -105,6 +106,8 @@ public function testHandleCodeValue() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div- do_something()')); $handler = new CodeTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/ConditionalTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ConditionalTokenHandlerTest.php index 828cc3ff..d5a6377b 100644 --- a/tests/Phug/Parser/TokenHandler/ConditionalTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ConditionalTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\ConditionalTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\ConditionalTokenHandler @@ -35,6 +36,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new ConditionalTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php index e2c2ff81..9adb2b7a 100644 --- a/tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\DoTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\DoTokenHandler @@ -39,6 +40,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new DoTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php index a25bd394..72dd2724 100644 --- a/tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\ExpansionTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\ExpansionTokenHandler @@ -81,6 +82,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new ExpansionTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php index bc22f470..412b48e8 100644 --- a/tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\ExpressionTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\ExpressionTokenHandler @@ -40,6 +41,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new ExpressionTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php index ae4b3434..70eda749 100644 --- a/tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php @@ -11,6 +11,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\FilterTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\FilterTokenHandler @@ -96,6 +97,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new FilterTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php index 1f3fc174..5ba3182f 100644 --- a/tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\ForTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\ForTokenHandler @@ -36,6 +37,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new ForTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/IdTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/IdTokenHandlerTest.php index e9d17fa4..63a3e2a3 100644 --- a/tests/Phug/Parser/TokenHandler/IdTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/IdTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\IdTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\IdTokenHandler @@ -45,6 +46,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new IdTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/ImportTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ImportTokenHandlerTest.php index 8a6e2e40..1f0fb85b 100644 --- a/tests/Phug/Parser/TokenHandler/ImportTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ImportTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\ImportTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\ImportTokenHandler @@ -45,6 +46,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new ImportTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/InterpolationEndTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/InterpolationEndTokenHandlerTest.php index 91361746..53417622 100644 --- a/tests/Phug/Parser/TokenHandler/InterpolationEndTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/InterpolationEndTokenHandlerTest.php @@ -7,6 +7,7 @@ use Phug\Parser; use Phug\Parser\State; use Phug\Parser\TokenHandler\InterpolationEndTokenHandler; +use Phug\Test\Utils\ExceptionAnnotationReader; use Phug\Util\TestCase; /** @@ -23,6 +24,8 @@ class InterpolationEndTokenHandlerTest extends TestCase */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div')); $handler = new InterpolationEndTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/InterpolationStartTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/InterpolationStartTokenHandlerTest.php index 841c1130..1fe417b5 100644 --- a/tests/Phug/Parser/TokenHandler/InterpolationStartTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/InterpolationStartTokenHandlerTest.php @@ -10,6 +10,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\InterpolationStartTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\InterpolationStartTokenHandler @@ -137,6 +138,8 @@ public function testInterpolationInNestedBlock() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div')); $handler = new InterpolationStartTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/KeywordTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/KeywordTokenHandlerTest.php index 746e2c6d..3af58a66 100644 --- a/tests/Phug/Parser/TokenHandler/KeywordTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/KeywordTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\KeywordTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\KeywordTokenHandler @@ -50,6 +51,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div')); $handler = new KeywordTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/TagInterpolationEndTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/TagInterpolationEndTokenHandlerTest.php index 6c013841..a72e76e8 100644 --- a/tests/Phug/Parser/TokenHandler/TagInterpolationEndTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/TagInterpolationEndTokenHandlerTest.php @@ -7,6 +7,7 @@ use Phug\Parser; use Phug\Parser\State; use Phug\Parser\TokenHandler\TagInterpolationEndTokenHandler; +use Phug\Test\Utils\ExceptionAnnotationReader; use Phug\Util\TestCase; /** @@ -23,6 +24,8 @@ class TagInterpolationEndTokenHandlerTest extends TestCase */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div')); $handler = new TagInterpolationEndTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/TextTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/TextTokenHandlerTest.php index 99669233..a1355aef 100644 --- a/tests/Phug/Parser/TokenHandler/TextTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/TextTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\TextTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\TextTokenHandler @@ -67,6 +68,8 @@ public function testHandleMarkup() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new TextTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/VariableTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/VariableTokenHandlerTest.php index 5a18998f..7de36a3d 100644 --- a/tests/Phug/Parser/TokenHandler/VariableTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/VariableTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\VariableTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\VariableTokenHandler @@ -35,6 +36,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new VariableTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/WhileTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/WhileTokenHandlerTest.php index 662740ac..cb74612d 100644 --- a/tests/Phug/Parser/TokenHandler/WhileTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/WhileTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\WhileTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\WhileTokenHandler @@ -52,6 +53,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('')); $handler = new WhileTokenHandler(); diff --git a/tests/Phug/Parser/TokenHandler/YieldTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/YieldTokenHandlerTest.php index 002706c5..d5eb2344 100644 --- a/tests/Phug/Parser/TokenHandler/YieldTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/YieldTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Parser\State; use Phug\Parser\TokenHandler\YieldTokenHandler; use Phug\Test\AbstractParserTest; +use Phug\Test\Utils\ExceptionAnnotationReader; /** * @coversDefaultClass \Phug\Parser\TokenHandler\YieldTokenHandler @@ -34,6 +35,8 @@ public function testHandleToken() */ public function testHandleTokenTokenException() { + ExceptionAnnotationReader::read($this, __METHOD__); + $lexer = new Lexer(); $state = new State(new Parser(), $lexer->lex('div')); $handler = new YieldTokenHandler(); diff --git a/tests/Phug/ProfilerModuleTest.php b/tests/Phug/ProfilerModuleTest.php index 1e2013c8..3945ae36 100644 --- a/tests/Phug/ProfilerModuleTest.php +++ b/tests/Phug/ProfilerModuleTest.php @@ -54,15 +54,15 @@ public function testRenderProfiler() ]); $render = $renderer->render('div'); - self::assertRegExp('/div lexing\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div lexing\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div lexing:', $render); - self::assertRegExp('/div parsing\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div parsing\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div parsing:', $render); - self::assertRegExp('/div compiling\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div compiling\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div compiling:', $render); - self::assertRegExp('/div formatting\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div formatting\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div formatting:', $render); - self::assertRegExp('/div rendering\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div rendering\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div rendering:', $render); $renderer = new Renderer([ @@ -76,9 +76,9 @@ public function testRenderProfiler() ]); $render = $renderer->render("mixin foo\n p&attributes(\$attributes)\n | Hello\n+foo(a='b')"); - self::assertRegExp('/\+foo\s+parsing\s*
\s*[\.\d]+µs/', $render); - self::assertRegExp('/text\s+parsing\s*
\s*[\.\d]+µs/', $render); - self::assertRegExp('/mixin\s+foo\s+parsing\s*
\s*[\.\d]+µs/', $render); + self::assertMatchesRegularExpression('/\+foo\s+parsing\s*
\s*[\.\d]+µs/', $render); + self::assertMatchesRegularExpression('/text\s+parsing\s*
\s*[\.\d]+µs/', $render); + self::assertMatchesRegularExpression('/mixin\s+foo\s+parsing\s*
\s*[\.\d]+µs/', $render); $renderer->reInitOptions([ 'debug' => false, @@ -117,15 +117,15 @@ public function testLogProfiler() $count = count($profiler->getEvents()); $profiler->recordDisplayEvent(1); self::assertCount($count, $profiler->getEvents()); - self::assertRegExp('/div lexing\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div lexing\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div lexing:', $render); - self::assertRegExp('/div parsing\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div parsing\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div parsing:', $render); - self::assertRegExp('/div compiling\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div compiling\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div compiling:', $render); - self::assertRegExp('/div formatting\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div formatting\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div formatting:', $render); - self::assertRegExp('/div rendering\s*
\s*[\.\d]+[µm]?s/', $render); + self::assertMatchesRegularExpression('/div rendering\s*
\s*[\.\d]+[µm]?s/', $render); self::assertStringContains('title="div rendering:', $render); } @@ -341,15 +341,15 @@ public function testDisplayProfiler() $contents = ob_get_contents(); ob_end_clean(); - self::assertRegExp('/div lexing\s*
\s*[\.\d]+[µm]?s/', $contents); + self::assertMatchesRegularExpression('/div lexing\s*
\s*[\.\d]+[µm]?s/', $contents); self::assertStringContains('title="div lexing:', $contents); - self::assertRegExp('/div parsing\s*
\s*[\.\d]+[µm]?s/', $contents); + self::assertMatchesRegularExpression('/div parsing\s*
\s*[\.\d]+[µm]?s/', $contents); self::assertStringContains('title="div parsing:', $contents); - self::assertRegExp('/div compiling\s*
\s*[\.\d]+[µm]?s/', $contents); + self::assertMatchesRegularExpression('/div compiling\s*
\s*[\.\d]+[µm]?s/', $contents); self::assertStringContains('title="div compiling:', $contents); - self::assertRegExp('/div formatting\s*
\s*[+-]?[\.\d]+[µm]?s/', $contents); + self::assertMatchesRegularExpression('/div formatting\s*
\s*[+-]?[\.\d]+[µm]?s/', $contents); self::assertStringContains('title="div formatting:', $contents); - self::assertRegExp('/div rendering\s*
\s*[\.\d]+[µm]?s/', $contents); + self::assertMatchesRegularExpression('/div rendering\s*
\s*[\.\d]+[µm]?s/', $contents); self::assertStringContains('title="div rendering:', $contents); self::assertStringContains('-void-dump-', $contents); } @@ -430,7 +430,14 @@ public function testCustomDump() */ public function testEventVarDump() { - if (!function_exists('xdebug_is_enabled') || !xdebug_is_enabled()) { + $xdebugMode = getenv('XDEBUG_MODE') ?: ini_get('xdebug.mode'); + $xdebugModes = array_map('trim', explode(',', implode(',', (array) $xdebugMode))); + $xdebugSupported = ( + (function_exists('xdebug_is_enabled') && xdebug_is_enabled()) || + in_array('develop', $xdebugModes, true) + ); + + if (!$xdebugSupported) { self::markTestSkipped('var_dump test needs XDebug to be enabled.'); return; @@ -457,7 +464,7 @@ public function testEventVarDump() $render = $renderer->render('div'); - self::assertRegExp('/class\\s+Phug\\\\Parser\\\\Node\\\\DocumentNode#\\d+\\s+\\(\\d+\\)\\s+\\{/', $render); + self::assertMatchesRegularExpression('/class\\s+Phug\\\\Parser\\\\Node\\\\DocumentNode#\\d+\\s+\\(\\d+\\)\\s+\\{/', $render); } /** @@ -481,7 +488,10 @@ public function testEventVarDumpIsolated() $eventDumpProperty->setAccessible(true); $eventDump = $eventDumpProperty->getValue($profiler); - $this->assertRegExp('/(.*ProfilerModule\.php:\d+:\n)?string\(2\) "OK"/', trim($eventDump('OK'))); + self::assertMatchesRegularExpression( + '/(.*ProfilerModule\.php:\d+:\n)?string\(2\) "OK"/', + trim($eventDump('OK')) + ); } /** @@ -516,7 +526,7 @@ public function testGetErrorAsHtml() $renderer = new Renderer(); $error = $getErrorAsHtml->invoke($renderer, (object) [], [], []); - self::assertRegExp('/
Call to undefined method .+::getFile\(\)[\s\S]+<\/pre>/', $error);
+        self::assertMatchesRegularExpression('/
Call to undefined method .+::getFile\(\)[\s\S]+<\/pre>/', $error);
     }
 
     /**
diff --git a/tests/Phug/RendererTest.php b/tests/Phug/RendererTest.php
index c86df0ea..b7d1a0a7 100644
--- a/tests/Phug/RendererTest.php
+++ b/tests/Phug/RendererTest.php
@@ -1067,7 +1067,7 @@ public function testWhiteSpace()
             '| me!',
         ])));
 
-        self::assertRegExp('/^Don\'t\s+