Skip to content

Commit

Permalink
Merge pull request #111 from phug-php/feature/multi-tester-3
Browse files Browse the repository at this point in the history
Use multi-tester 2.5
  • Loading branch information
kylekatarnls authored Sep 21, 2023
2 parents d8e0a30 + 355aeef commit 44978d6
Show file tree
Hide file tree
Showing 95 changed files with 796 additions and 95 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/**"
14 changes: 8 additions & 6 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4']
php: ['8.2']
setup: ['stable']

name: PHP
Expand All @@ -25,17 +25,19 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: memory_limit=-1, zend.enable_gc=0, xdebug.mode="coverage,develop"
tools: composer:v2
extensions: pcntl
coverage: xdebug

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-${{ matrix.setup }}-coverage-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-
${{ runner.os }}-${{ matrix.setup }}-coverage-${{ matrix.php }}-
- name: Code Climate Test Reporter Preparation
run: |
Expand All @@ -49,11 +51,11 @@ jobs:
if: steps.composer-cache.outputs.cache-hit != 'true'
run: |
composer config version 1.9.0
${{ matrix.php >= 8 && 'composer require --no-update phpunit/phpunit:^8.5.14 --no-interaction;' || '' }}
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress ${{ matrix.php >= 8.1 && '--ignore-platform-req=php' || '' }}
composer require --no-update phpunit/phpunit:^9.6.12 phpunit/php-code-coverage:^9.2.28 --dev --no-interaction
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress --no-interaction
- name: Run test suite
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml --default-time-limit=3

- name: Code Climate Test Reporter
if: ${{ env.CC_TEST_REPORTER_ID != '' }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Multitest
name: Multi-test

on:
push:
Expand All @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
php: ['7.4', '8.0']
php: ['7.4', '8.2']
setup: ['stable']

name: PHP ${{ matrix.php }}
Expand All @@ -31,15 +31,15 @@ jobs:
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-multi-v2-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-multi-test-v2-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-multi-v2-${{ matrix.php }}-
${{ runner.os }}-multi-test-v2-${{ matrix.php }}-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: |
composer config version 1.9.0
composer require kylekatarnls/multi-tester:^2.3 --no-update --no-interaction
composer require kylekatarnls/multi-tester:^2.5.2 --dev --no-update --no-interaction
composer update --prefer-dist --prefer-${{ matrix.setup }} --no-progress --no-interaction
- name: Run test suites
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: php-${{ matrix.php }}-${{ runner.os }}-${{ matrix.setup }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-
php-${{ matrix.php }}-${{ runner.os }}-${{ matrix.setup }}-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
Expand Down
19 changes: 12 additions & 7 deletions .multi-tester.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
pug-php/pug:
install:
- composer config --no-plugins allow-plugins.nodejs-php-fallback/nodejs-php-fallback true
- composer install --no-interaction
source:
success_only: true
url: https://github.com/pug-php/pug.git
reference: master
install: github
script: github

pug/bemto:
autoload:
Expand Down Expand Up @@ -39,10 +42,12 @@ ci-pug/ci-pug:
- composer install --no-interaction

bkwld/laravel-pug:
install:
- composer config --no-plugins allow-plugins.pug/installer true
- composer config --no-plugins allow-plugins.nodejs-php-fallback/nodejs-php-fallback true
- composer install --no-interaction
source:
success_only: true
url: https://github.com/BKWLD/laravel-pug.git
reference: master
install: github
script: github

pug/yii2:
install:
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"symfony/var-dumper": "^3.4 || ^4.0 || ^5.0 || ^6.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.14",
"phpunit/php-code-coverage": "^2.2 || ^4.0 || ^5.2 || ^6.0 || ^7.0",
"squizlabs/php_codesniffer": "~3.4.2",
"cebe/markdown": "^1.1",
"js-phpize/js-phpize-phug": "^1.2 || ^2.2.1",
"pug-php/pug": "^2.7.3 || ^3.4.1",
"pug-php/pug-filter-coffee-script": "^1.3.1",
"nodejs-php-fallback/coffeescript": "^1.0.1",
"nodejs-php-fallback/less": "^1.0.5",
"nodejs-php-fallback/uglify": "^1.0.4",
"nodejs-php-fallback/stylus": "^1.0.4",
"cebe/markdown": "^1.1",
"kylekatarnls/multi-tester": "^2.3"
"nodejs-php-fallback/uglify": "^1.0.4",
"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": "^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"
},
"replace": {
"phug/ast": "self.version",
Expand Down
2 changes: 1 addition & 1 deletion release.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* php release.php minor stable message.md
* ```.
*
* Put release notes in message.md as markdown format.
* Put release notes in message.md as Markdown format.
*/
$settings = parse_ini_file('.env');

Expand Down
6 changes: 6 additions & 0 deletions src/Phug/Formatter/Formatter/Format/XmlFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,23 @@ protected function formatAttributeElement(AttributeElement $element)
$value = $element->getValue();
$name = $element->getName();
$nonEmptyAttribute = ($name === 'class' || $name === 'id');

if ($nonEmptyAttribute && (
!$value ||
($value instanceof TextElement && ((string) $value->getValue()) === '') ||
(is_string($value) && in_array(trim($value), ['', '""', "''"], true))
)) {
return '';
}

if ($value instanceof ExpressionElement) {
if ($nonEmptyAttribute && in_array(trim($value->getValue()), ['', '""', "''"], true)) {
return '';
}

if (strtolower($value->getValue()) === 'true') {
$formattedValue = null;

if ($name instanceof ExpressionElement) {
$bufferVariable = $this->pattern('buffer_variable');
$name = $this->pattern(
Expand All @@ -193,6 +197,7 @@ protected function formatAttributeElement(AttributeElement $element)
$value = new ExpressionElement($bufferVariable);
$formattedValue = $this->format($value);
}

$formattedName = $this->format($name);
$formattedValue = $formattedValue || $formattedValue === '0'
? $formattedValue
Expand All @@ -204,6 +209,7 @@ protected function formatAttributeElement(AttributeElement $element)
$formattedValue
);
}

if (in_array(strtolower($value->getValue()), ['false', 'null', 'undefined'], true)) {
return '';
}
Expand Down
8 changes: 1 addition & 7 deletions src/Phug/Formatter/Formatter/Partial/MagicAccessorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ trait MagicAccessorTrait
{
private function getMethod($prefix, $name)
{
switch ($name) {
case 'nodes':
$name = 'children';
break;
}

return $prefix.ucfirst($name);
return $prefix.ucfirst($name === 'nodes' ? 'children' : $name);
}

public function __get($name)
Expand Down
21 changes: 19 additions & 2 deletions src/Phug/Renderer/Renderer/Adapter/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,35 @@ private function isCacheUpToDate(&$path, $input = null)
return file_exists($path);
}

private function getCacheDirectory()
private function readCacheDirectoryFromOptions()
{
$cacheFolder = $this->hasOption('cache_dir')
? $this->getOption('cache_dir')
: null;

if (!$cacheFolder && $cacheFolder !== false) {
$cacheFolder = $this->getRenderer()->hasOption('cache_dir')
? $this->getRenderer()->getOption('cache_dir')
: null;
}

if ($cacheFolder === true) {
$cacheFolder = $this->getOption('tmp_dir');
return $this->getOption('tmp_dir');
}

return $cacheFolder;
}

private function getCacheDirectory()
{
$cacheFolder = $this->readCacheDirectoryFromOptions();

if ($cacheFolder === null) {
throw new RuntimeException(
'You need to set "cache_dir" option to a writable location in order '.
'to use cache feature.',
7
);
}

if (!is_dir($cacheFolder) && !@mkdir($cacheFolder, 0777, true)) {
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
Loading

0 comments on commit 44978d6

Please sign in to comment.