Skip to content

Commit

Permalink
Polyfill PHPUnit methods not available in old versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Sep 20, 2023
1 parent a06f598 commit cf1792d
Show file tree
Hide file tree
Showing 37 changed files with 184 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**"
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-${{ matrix.setup }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-
${{ runner.os }}-${{ matrix.setup }}-php-${{ matrix.php }}-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
"require-dev": {
"cebe/markdown": "^1.1",
"js-phpize/js-phpize-phug": "^1.2 || ^2.2.1",
"kylekatarnls/multi-tester": "^2.5.2",
"nodejs-php-fallback/coffeescript": "^1.0.1",
"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",
"phpunit/php-invoker": "^1.1.4 || ^3.1.1",
"pug-php/pug": "^2.7.3 || ^3.4.1",
"pug-php/pug-filter-coffee-script": "^1.3.1",
"squizlabs/php_codesniffer": "^3.7.2"
Expand Down
33 changes: 33 additions & 0 deletions src/Phug/Util/CompatibilityUtil/TestCaseTyped.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 33 additions & 0 deletions src/Phug/Util/CompatibilityUtil/TestCaseUntyped.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions tests/Phug/CliTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -259,7 +259,7 @@ public function testCacheDirectory()

$this->removeFile($expected);

self::assertRegExp('/Inconsistent indentation./', $text);
self::assertMatchesRegularExpression('/Inconsistent indentation./', $text);
}

/**
Expand Down Expand Up @@ -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";

Expand Down
5 changes: 4 additions & 1 deletion tests/Phug/DependencyInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
use Phug\Test\Utils\ClockInterface;
use Phug\Util\UnorderedArguments;

/**
* @coversDefaultClass \Phug\DependencyInjection
*/
class DependencyInjectionTest extends AbstractDependencyInjectionTest
{
/**
* @covers \Phug\DependencyInjection::<public>
* @covers ::<public>
* @covers \Phug\DependencyInjection\Dependency::<public>
* @covers \Phug\DependencyInjection\Requirement::<public>
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Phug/Element/MixinCallElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function testPhpUnwrap()
eval('?>'.$php);
ob_get_clean();

self::assertRegExp('/echo\s1;\s+\}/', $php);
self::assertMatchesRegularExpression('/echo\s1;\s+\}/', $php);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Phug/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion tests/Phug/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
/**
Expand Down
5 changes: 5 additions & 0 deletions tests/Phug/Lexer/Scanner/AssignmentScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function testScan()
self::assertSame('test', $tok->getName());
}

/**
* @coversNothing
*/
public function testScanWithAttributes()
{
/** @var AssignmentToken $tok */
Expand All @@ -42,6 +45,8 @@ public function testScanWithAttributes()

/**
* @see https://github.com/phug-php/phug/issues/22
*
* @coversNothing
*/
public function testObjectInTernary()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Phug/OptimizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit cf1792d

Please sign in to comment.