diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..29cc548 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +export XDEBUG_MODE=coverage diff --git a/.gitattributes b/.gitattributes index 6efd584..37e903a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ /tests export-ignore /.github export-ignore /resources/pp/*.pp export-ignore +.envrc export-ignore phpunit.xml.dist export-ignore psalm.xml export-ignore phpcs.xml export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f635610..70f8c20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Psalm uses: docker://vimeo/psalm-github-actions @@ -18,7 +18,7 @@ jobs: composer_ignore_platform_reqs: true - name: Upload Security Analysis results to GitHub - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@v4 with: sarif_file: results.sarif @@ -40,21 +40,15 @@ jobs: strategy: matrix: php: - - version: 7.4 - coverage: false - - version: 8.0 - coverage: false - - version: 8.1 - coverage: false - - version: 8.2 - coverage: false - version: 8.3 coverage: true - version: 8.4 coverage: false + - version: 8.5 + coverage: false prefer-lowest: ['', '--prefer-lowest'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -67,7 +61,7 @@ jobs: - name: Cache Composer packages id: composer-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: vendor key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} diff --git a/.gitignore b/.gitignore index e16dfc7..5175100 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ !/tests/log/.gitkeep .phpunit.result.cache .phpcs-cache +.phpunit.cache/ phpunit.xml -composer.lock \ No newline at end of file +composer.lock +*.bak diff --git a/composer.json b/composer.json index fc06b27..0e501d9 100644 --- a/composer.json +++ b/composer.json @@ -1,36 +1,37 @@ { "name": "fabiang/dateparser", - "description": "Parser for date strings", + "description": "Date parsing library supporting the full format RFC3339", "type": "library", "license": "BSD-2-Clause", "keywords": ["rfc3339", "dateparser", "date", "datetime", "parser"], "authors": [ { "name": "Fabian Grutschus", - "email": "fabian.grutschus@invitel.de" + "email": "github@lubyte.de" } ], "minimum-stability": "stable", "require": { - "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", + "php": "~8.3.0 || ~8.4.0 || ~8.5.0", "phplrt/runtime": "^3.2" }, + "require-dev": { + "phpunit/phpunit": "^12.0", + "squizlabs/php_codesniffer": "*", + "vimeo/psalm": "*", + "laminas/laminas-coding-standard": "*", + "phplrt/compiler": "^3.2", + "mikey179/vfsstream": "^1.6.12" + }, "autoload": { "psr-4": { "Fabiang\\Dateparser\\": "src/" } }, - "require-dev": { - "phpunit/phpunit": "^9.5.16 || ^10.0", - "squizlabs/php_codesniffer": "^3.7", - "vimeo/psalm": "^4.23", - "laminas/laminas-coding-standard": "^2.3", - "phplrt/compiler": "^3.2" - }, "scripts": { - "phpcs": "phpcs", + "phpcs": "phpcs --colors", "psalm": "psalm", - "phpunit": "phpunit", + "phpunit": "phpunit --colors --coverage-text", "test": [ "@phpcs", "@psalm", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 26e075e..56e7af9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,26 +1,18 @@ - - + + tests/src/ - - - src/ - - - @@ -28,5 +20,11 @@ - + + + + + src/ + + diff --git a/src/AbstractParser.php b/src/AbstractParser.php index 419a4fc..1a8aa0f 100644 --- a/src/AbstractParser.php +++ b/src/AbstractParser.php @@ -5,6 +5,7 @@ namespace Fabiang\Dateparser; use Fabiang\Dateparser\Exception\LoadDefinitionException; +use Override; use Phplrt\Lexer\Lexer; use Phplrt\Lexer\Multistate; use Phplrt\Parser\BuilderInterface; @@ -67,6 +68,7 @@ public function __construct(array $reducers) /** * {@inheritDoc} */ + #[Override] public function build(ContextInterface $context, $result) { $state = $context->getState(); diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php deleted file mode 100644 index 124e8a1..0000000 --- a/src/Exception/UnexpectedValueException.php +++ /dev/null @@ -1,14 +0,0 @@ -baseParse('RFC3339', $string); diff --git a/tests/src/AbstractParserTest.php b/tests/src/AbstractParserTest.php new file mode 100644 index 0000000..fdef666 --- /dev/null +++ b/tests/src/AbstractParserTest.php @@ -0,0 +1,58 @@ +expectException(LoadDefinitionException::class); + $this->expectExceptionMessageMatches('/^Unable to load definition file/'); + + $underTest = new class extends AbstractParser { + #[Override] + public function parse(string $string): DateTime + { + $this->load('UNKNOWN'); + } + }; + $underTest->parse('unrelevant'); + } + + public function testLoadNotReadable() + { + $this->expectException(LoadDefinitionException::class); + $this->expectExceptionMessageMatches('/^Definition file \'.*NOT_READABLE.php\' is not readable/'); + + $underTest = new class extends AbstractParser { + public function __construct() + { + $path = vfsStream::setup(); + $file = $path->url() . '/NOT_READABLE.php'; + file_put_contents($file, 'url()); + } + + #[Override] + public function parse(string $string): DateTime + { + $this->load('NOT_READABLE'); + } + }; + $underTest->parse('unrelevant'); + } +} diff --git a/tests/src/RFC3339Test.php b/tests/src/RFC3339Test.php index 85cd121..838da1b 100644 --- a/tests/src/RFC3339Test.php +++ b/tests/src/RFC3339Test.php @@ -5,34 +5,25 @@ namespace Fabiang\Dateparser; use DateTime; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use function intval; -/** - * Generated by PHPUnit_SkeletonGenerator on 2017-07-25 at 17:34:16. - * - * @coversDefaultClass \Fabiang\Dateparser\RFC3339 - */ +#[CoversClass(RFC3339::class)] +#[UsesClass(AbstractParser::class)] final class RFC3339Test extends TestCase { private RFC3339 $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ protected function setUp(): void { $this->object = new RFC3339(); } - /** - * @covers ::parse - * @covers ::getTimezoneValue - * @covers \Fabiang\Dateparser\AbstractParser - * @dataProvider provideValidDateStrings - */ + #[DataProvider('provideValidDateStrings')] public function testParse( string $date, string $year, @@ -56,7 +47,7 @@ public function testParse( $this->assertSame($microseconds, intval($dateObject->format('u'))); } - public function provideValidDateStrings(): array + public static function provideValidDateStrings(): array { return [ [