Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export XDEBUG_MODE=coverage
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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') }}
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
!/tests/log/.gitkeep
.phpunit.result.cache
.phpcs-cache
.phpunit.cache/
phpunit.xml
composer.lock
composer.lock
*.bak
25 changes: 13 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
34 changes: 16 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
colors="true"
forceCoversAnnotation="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="false"
beStrictAboutResourceUsageDuringSmallTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true">

<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.5/phpunit.xsd"
colors="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="false"
beStrictAboutTestsThatDoNotTestAnything="true"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="true">
<testsuites>
<testsuite name="unit">
<directory>tests/src/</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>src/</directory>
</include>
</coverage>

<php>
<ini name="error_reporting" value="-1"/>
<ini name="display_errors" value="On"/>
<ini name="log_errors" value="0"/>
<ini name="memory_limit" value="-1"/>
</php>

<logging></logging>
<logging/>

<source>
<include>
<directory>src/</directory>
</include>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions src/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,6 +68,7 @@ public function __construct(array $reducers)
/**
* {@inheritDoc}
*/
#[Override]
public function build(ContextInterface $context, $result)
{
$state = $context->getState();
Expand Down
14 changes: 0 additions & 14 deletions src/Exception/UnexpectedValueException.php

This file was deleted.

3 changes: 3 additions & 0 deletions src/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use DateTime;

/**
* @psalm-api
*/
interface ParserInterface
{
public function parse(string $string): DateTime;
Expand Down
5 changes: 5 additions & 0 deletions src/RFC3339.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
namespace Fabiang\Dateparser;

use DateTime;
use Override;

use function sprintf;
use function substr;

/**
* @psalm-api
*/
class RFC3339 extends AbstractParser
{
public const T_YEAR = 'T_YEAR';
Expand All @@ -25,6 +29,7 @@ class RFC3339 extends AbstractParser
public const T_TIMEZONE_LEFT = 'T_TIMEZONE_LEFT';
public const T_TIMEZONE_RIGHT = 'T_TIMEZONE_RIGHT';

#[Override]
public function parse(string $string): DateTime
{
$parsedTokens = $this->baseParse('RFC3339', $string);
Expand Down
58 changes: 58 additions & 0 deletions tests/src/AbstractParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Fabiang\Dateparser;

use DateTime;
use Fabiang\Dateparser\Exception\LoadDefinitionException;
use org\bovigo\vfs\vfsStream;
use Override;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

use function chmod;
use function file_put_contents;

#[CoversClass(AbstractParser::class)]
final class AbstractParserTest extends TestCase
{
public function testLoadFileMissing()
{
$this->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, '<?php return [];');
chmod($file, 0000);
parent::__construct($path->url());
}

#[Override]
public function parse(string $string): DateTime
{
$this->load('NOT_READABLE');
}
};
$underTest->parse('unrelevant');
}
}
23 changes: 7 additions & 16 deletions tests/src/RFC3339Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -56,7 +47,7 @@ public function testParse(
$this->assertSame($microseconds, intval($dateObject->format('u')));
}

public function provideValidDateStrings(): array
public static function provideValidDateStrings(): array
{
return [
[
Expand Down
Loading