Skip to content

Commit

Permalink
Support PHP 8.1 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m authored Mar 7, 2023
1 parent 024b762 commit 63c2a31
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 22 deletions.
180 changes: 180 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# PHPUnit Composer min/max test.
# TODO: Make our own orb out of this.

version: 2.1
orbs:
php: circleci/php@1.1.0

commands:
update-packages:
description: |
Update your composer packages with automated caching and best practices applied.
parameters:
app-dir:
default: ~/project
description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root.
type: string
cache-files-dir:
default: /home/circleci/.composer/cache/files
description: Absolute path to the file cache folder. This should be inline with "composer global config cache-files-dir --absolute".
type: string
cache-key:
default: composer.lock
description: If this file is updated a new cache bucket will be created. Recommended to use composer.lock. Use composer.json when composer.lock is absent.
type: string
cache-version:
default: v1
description: Change the default cache version if you need to clear the cache for any reason.
type: string
install-flags:
default: --no-interaction --prefer-dist
description: |
By default, packages will be installed with "composer install --no-interaction --prefer-dist", use this to override the standard install flags.
type: string
vendor-dir:
default: vendor
description: Relative path to the vendor folder. Relative to "app-dir". This should be inline with "composer config vendor-dir".
type: string
with-cache:
default: true
description: Enable automatic caching of your dependencies for increased speed.
type: boolean
steps:
- when:
condition: << parameters.with-cache >>
steps:
- restore_cache:
keys:
- composer-deps-<<parameters.cache-version>>-{{ checksum "<<parameters.app-dir>>/<<parameters.cache-key>>" }}
- run:
command: |
if [ ! -f "composer.json" ] && [ ! -f "composer.lock" ]; then
echo
echo "---"
echo "Unable to find your composer.json and composer.lock files. Did you forget to set the app-dir parameter?"
echo "---"
echo
echo "Current directory: $(pwd)"
echo
echo
echo "List directory: "
echo
ls
exit 1
fi
name: Verify composer.json and/or composer.lock exist
working_directory: <<parameters.app-dir>>
- run:
command: composer update <<parameters.install-flags>>
name: Updating Composer Packages
working_directory: <<parameters.app-dir>>
- when:
condition: << parameters.with-cache >>
steps:
- save_cache:
key: composer-deps-<<parameters.cache-version>>-{{ checksum "<<parameters.app-dir>>/<<parameters.cache-key>>" }}
paths:
- <<parameters.app-dir>>/<<parameters.vendor-dir>>
- <<parameters.cache-files-dir>>
install-xdebug:
steps:
- run:
name: Install XDebug
command: sudo -E install-php-extensions xdebug && sudo -E docker-php-ext-enable xdebug

install-cc-test-reporter:
# TODO: Parameterize location.
steps:
- run:
name: Install Codeclimate test reporter
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
run-phpunit-tests:
description: |
Run PHPUnit tests.
parameters:
app-dir:
default: ~/project
description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root.
type: string
install-flags:
default: ""
description: Arguments to `composer update`.
type: string
test-command:
default: test
description: The name of the script within your composer.json which will run your tests.
type: string
report-to-codeclimate:
type: boolean
default: false
description: Report coverage info to Codeclimate.
steps:
- checkout
- update-packages:
app-dir: <<parameters.app-dir>>
cache-key: composer.json
install-flags: <<parameters.install-flags>>
- when:
condition: <<parameters.report-to-codeclimate>>
steps:
- install-xdebug
- install-cc-test-reporter
- run: |
./cc-test-reporter before-build
XDEBUG_MODE=coverage composer <<parameters.test-command>> -- --coverage-clover clover.xml
./cc-test-reporter after-build --coverage-input-type clover --exit-code $?
- when:
condition:
not: <<parameters.report-to-codeclimate>>
steps:
- run: |
XDEBUG_MODE=off composer <<parameters.test-command>>
jobs:
matrix-conditions:
environment:
CC_TEST_REPORTER_ID: 9a881d202df999a0be1604b97a1c0fc504bb10145446f7a2c5d84601f83a251d
description: Run tests for matrix
executor:
name: php/default
tag: << parameters.version >>
parameters:
version:
default: "7.4"
description: The `cimg/php` Docker image version tag.
type: string
install-flags:
default: ""
description: Arguments to `composer update`.
type: string
steps:
- when:
condition:
and:
- equal: [ "8.1", <<parameters.version>> ]
- equal: [ "", <<parameters.install-flags>> ]
steps:
- run-phpunit-tests:
report-to-codeclimate: true
install-flags: << parameters.install-flags >>
- when:
condition:
not:
and:
- equal: [ "8.1", <<parameters.version>> ]
- equal: [ "", <<parameters.install-flags>> ]
steps:
- run-phpunit-tests:
install-flags: << parameters.install-flags >>

workflows:
all-tests:
jobs:
- matrix-conditions:
matrix:
parameters:
version: ["7.4", "8.0", "8.1"]
install-flags: ["", "--prefer-lowest"]
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.idea
.ddev
/vendor/
composer.lock
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/e7bf8f7b56a6f1bf4c68/maintainability)](https://codeclimate.com/github/GetDKAN/pdlt/maintainability) | [![Test Coverage](https://api.codeclimate.com/v1/badges/e7bf8f7b56a6f1bf4c68/test_coverage)](https://codeclimate.com/github/GetDKAN/pdlt/test_coverage)

# PHP Date Language Tool

A simple parser generator for reading, processing, or translating regular date language formats.
Expand Down Expand Up @@ -34,4 +36,4 @@ echo $converter->convert('%-m/%-d/%y');

### Supported Output Formats

- [MySQL](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format)
- [MySQL](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format)
38 changes: 31 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,41 @@
"name": "getdkan/pdlt",
"description": "PHP Date Language Tool",
"type": "library",
"autoload": {
"psr-4": {
"PDLT\\": "src/",
"PDLT\\tests\\": "tests/"
}
},
"authors": [
{
"name": "Clayton Liddell",
"email": "clayton.liddell@civicactions.com"
}
],
"require": {}
"require": {
"php": ">=7.4"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"rector/rector": "^0.15.17",
"squizlabs/php_codesniffer": "^3.7",
"drupal/coder": "^8.3.14"
},
"autoload": {
"psr-4": {
"PDLT\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"PDLT\\Tests\\": "tests/"
}
},
"scripts": {
"phpcbf": "./vendor/bin/phpcbf",
"phpcs": "./vendor/bin/phpcs",
"rector": "./vendor/bin/rector process",
"rector-dry-run": "./vendor/bin/rector process --dry-run",
"test": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --testsuite all --coverage-html ./coverage"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
17 changes: 17 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="getdkan">

<arg name="extensions" value="inc,install,module,php,profile,test,theme,yml"/>
<description>PHP CodeSniffer configuration for GetDKAN.</description>

<file>src</file>
<file>tests</file>
<file>rector.php</file>

<rule ref="Drupal">
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
</rule>
<rule ref="DrupalPractice"/>

</ruleset>
14 changes: 14 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="all">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @file
* Rector configuration for PHP 7.4 compatibility.
*/

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
]);
};
2 changes: 1 addition & 1 deletion src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function compileToken(TokenInterface $token): string {
* Compiled token string.
*
* @throws \PDLT\UnsupportedTokenException
* When the supplied token is not supported by the this compiler's
* When the supplied token is not supported by the compiler's
* compilation map.
*/
protected function compileDirective(DirectiveToken $token): string {
Expand Down
44 changes: 44 additions & 0 deletions tests/CompilerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace PDLT\Tests;

use PDLT\Compiler;
use PDLT\CompilationMapInterface;
use PDLT\CompilationMap\MySQL;
use PDLT\DirectiveToken;
use PDLT\TokenInterface;
use PDLT\UnsupportedTokenException;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \PDLT\Compiler
*/
class CompilerTest extends TestCase {

/**
* @covers ::compileToken
*/
public function testCompileTokenException() {
$this->expectException(UnsupportedTokenException::class);
$this->expectExceptionMessage('Unable to compile unsupported token type');

$map_mock = $this->getMockForAbstractClass(CompilationMapInterface::class);
(new Compiler($map_mock))->compile([
// Mock object is never DirectiveToken or LiteralToken.
$this->getMockForAbstractClass(TokenInterface::class),
]);
}

/**
* @covers ::compileDirective
*/
public function testCompileDirectiveException() {
$this->expectException(UnsupportedTokenException::class);
$this->expectExceptionMessage('Unable to compile unsupported directive "this-directive-should-not-exist"; not found in compilation map "PDLT\CompilationMap\MySQL".');

(new Compiler(new MySQL()))->compile([
new DirectiveToken('this-directive-should-not-exist'),
]);
}

}
Loading

0 comments on commit 63c2a31

Please sign in to comment.