fix tests

This commit is contained in:
Daniel Waxweiler 2023-05-21 14:47:36 +02:00
parent 4e99fab421
commit 3bcea397d7
11 changed files with 87 additions and 59 deletions

1
.gitignore vendored
View File

@ -4,4 +4,5 @@ coverage/
node_modules/ node_modules/
vendor/ vendor/
.phpunit.cache
.phpunit.result.cache .phpunit.result.cache

View File

@ -39,7 +39,7 @@ The current changelog can be found under [source/changelog.txt](source/changelog
- Run ESLint: `npm run eslint` - Run ESLint: `npm run eslint`
- Run JavaScript code coverage with tests: `npm run coverage` - Run JavaScript code coverage with tests: `npm run coverage`
- Run tests: `npm test` & `./vendor/bin/phpunit tests` (`composer dump-autoload -o` after newly created class) - Run tests: `npm test` & `./vendor/bin/phpunit` (`composer dump-autoload` after newly created class)
- Delete build folder: `npm run clean` - Delete build folder: `npm run clean`
- Update PHP dependencies: `composer update` - Update PHP dependencies: `composer update`
- Check for direct PHP dependency updates: `composer outdated --direct` - Check for direct PHP dependency updates: `composer outdated --direct`

View File

@ -1,8 +1,8 @@
{ {
"autoload": { "autoload": {
"classmap": [ "psr-4": {
"source/includes" "MobilizonConnector\\": "source/includes/"
] }
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.6" "phpunit/phpunit": "^9.6"

50
composer.lock generated
View File

@ -9,30 +9,30 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "doctrine/instantiator", "name": "doctrine/instantiator",
"version": "1.5.0", "version": "2.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/instantiator.git", "url": "https://github.com/doctrine/instantiator.git",
"reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0",
"reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.1 || ^8.0" "php": "^8.1"
}, },
"require-dev": { "require-dev": {
"doctrine/coding-standard": "^9 || ^11", "doctrine/coding-standard": "^11",
"ext-pdo": "*", "ext-pdo": "*",
"ext-phar": "*", "ext-phar": "*",
"phpbench/phpbench": "^0.16 || ^1", "phpbench/phpbench": "^1.2",
"phpstan/phpstan": "^1.4", "phpstan/phpstan": "^1.9.4",
"phpstan/phpstan-phpunit": "^1", "phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", "phpunit/phpunit": "^9.5.27",
"vimeo/psalm": "^4.30 || ^5.4" "vimeo/psalm": "^5.4"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -59,7 +59,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/doctrine/instantiator/issues", "issues": "https://github.com/doctrine/instantiator/issues",
"source": "https://github.com/doctrine/instantiator/tree/1.5.0" "source": "https://github.com/doctrine/instantiator/tree/2.0.0"
}, },
"funding": [ "funding": [
{ {
@ -75,7 +75,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-12-30T00:15:36+00:00" "time": "2022-12-30T00:23:10+00:00"
}, },
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
@ -138,16 +138,16 @@
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
"version": "v4.15.4", "version": "v4.15.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/nikic/PHP-Parser.git", "url": "https://github.com/nikic/PHP-Parser.git",
"reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290" "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6bb5176bc4af8bcb7d926f88718db9b96a2d4290", "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/11e2663a5bc9db5d714eedb4277ee300403b4a9e",
"reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290", "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -188,9 +188,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/nikic/PHP-Parser/issues", "issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.4" "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.5"
}, },
"time": "2023-03-05T19:49:14+00:00" "time": "2023-05-19T20:20:00+00:00"
}, },
{ {
"name": "phar-io/manifest", "name": "phar-io/manifest",
@ -623,16 +623,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "9.6.7", "version": "9.6.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "c993f0d3b0489ffc42ee2fe0bd645af1538a63b2" "reference": "17d621b3aff84d0c8b62539e269e87d8d5baa76e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c993f0d3b0489ffc42ee2fe0bd645af1538a63b2", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/17d621b3aff84d0c8b62539e269e87d8d5baa76e",
"reference": "c993f0d3b0489ffc42ee2fe0bd645af1538a63b2", "reference": "17d621b3aff84d0c8b62539e269e87d8d5baa76e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -706,7 +706,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.7" "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.8"
}, },
"funding": [ "funding": [
{ {
@ -722,7 +722,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-04-14T08:58:40+00:00" "time": "2023-05-11T05:14:45+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",

27
phpunit.xml Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">source/includes</directory>
</include>
</coverage>
</phpunit>

View File

@ -1,11 +1,6 @@
<?php <?php
namespace MobilizonConnector; namespace MobilizonConnector;
// Exit if this file is called directly.
if (!defined('ABSPATH')) {
exit;
}
final class DateTimeWrapper { final class DateTimeWrapper {
private $dateTime; private $dateTime;
private $locale; private $locale;

View File

@ -1,11 +1,6 @@
<?php <?php
namespace MobilizonConnector; namespace MobilizonConnector;
// Exit if this file is called directly.
if (!defined('ABSPATH')) {
exit;
}
final class Formatter final class Formatter
{ {
public static function format_date(string $locale, string $timeZone, string $start, ?string $end, bool $isShortOffsetNameShown): string { public static function format_date(string $locale, string $timeZone, string $start, ?string $end, bool $isShortOffsetNameShown): string {

View File

@ -1,44 +1,47 @@
<?php <?php
declare(strict_types=1);
use MobilizonConnector\DateTimeWrapper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
final class DateTimeWrapperTest extends TestCase { final class DateTimeWrapperTest extends TestCase {
public function testCanGetShortDateForUsualDate(): void { public function testCanGetShortDateForUsualDate(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z');
$this->assertEquals('24/12/2020', $d->getShortDate()); $this->assertSame('24/12/2020', $d->getShortDate());
} }
public function testCanGetShortDateForUsualDateWithLocaleWithUnderscore(): void { public function testCanGetShortDateForUsualDateWithLocaleWithUnderscore(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z');
$this->assertEquals('24/12/2020', $d->getShortDate(), 'en_GB'); $this->assertSame('24/12/2020', $d->getShortDate(), 'en_GB');
} }
public function testCanGetShortDateForUsualDateWithTimezoneString(): void { public function testCanGetShortDateForUsualDateWithTimezoneString(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', 'Europe/Rome'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', 'Europe/Rome');
$this->assertEquals('24/12/2020', $d->getShortDate()); $this->assertSame('24/12/2020', $d->getShortDate());
} }
public function testCanGetShortDateForUsualDateWithNamedOffset(): void { public function testCanGetShortDateForUsualDateWithNamedOffset(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', 'UTC'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', 'UTC');
$this->assertEquals('24/12/2020', $d->getShortDate()); $this->assertSame('24/12/2020', $d->getShortDate());
} }
public function testCanGetShortDateForUsualDateWithOffset(): void { public function testCanGetShortDateForUsualDateWithOffset(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', '+02:00'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', '+02:00');
$this->assertEquals('24/12/2020', $d->getShortDate()); $this->assertSame('24/12/2020', $d->getShortDate());
} }
public function testCanGetShortDateForUsualDateWithEmptyTimezone(): void { public function testCanGetShortDateForUsualDateWithEmptyTimezone(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', ''); $d = new DateTimeWrapper('2020-12-24T16:45:00Z', 'en-GB', '');
$this->assertEquals('24/12/2020', $d->getShortDate()); $this->assertSame('24/12/2020', $d->getShortDate());
} }
public function testCanGet24TimeForUsualTime(): void { public function testCanGet24TimeForUsualTime(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z');
$this->assertEquals('16:45', $d->get24Time()); $this->assertSame('16:45', $d->get24Time());
} }
public function testCanGetShortOffsetNameForUsualTime(): void { public function testCanGetShortOffsetNameForUsualTime(): void {
$d = new DateTimeWrapper('2020-12-24T16:45:00Z'); $d = new DateTimeWrapper('2020-12-24T16:45:00Z');
$this->assertEquals(0, $d->getOffset()); // TODO was UTC $this->assertSame('0', $d->getOffset()); // TODO was UTC
} }
} }

View File

@ -1,45 +1,52 @@
<?php <?php
declare(strict_types=1);
use MobilizonConnector\Formatter;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
final class FormatterTest extends TestCase final class FormatterTest extends PHPUnit\Framework\TestCase
{ {
public function testCanDateFormatOneDate(): void { public function testCanDateFormatOneDate(): void {
$this->assertEquals('15/04/2021 10:30 - 15:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', false)); $this->assertSame('15/04/2021 10:30 - 15:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', false));
} }
public function testCanDateFormatOneDateWithOffset(): void { public function testCanDateFormatOneDateWithOffset(): void {
$this->assertEquals('15/04/2021 10:30 - 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', true)); $this->assertSame('15/04/2021 10:30 - 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', true));
}
public function testCanDateFormatOneDateWithTimeZoneOffset(): void {
$this->assertSame('15/04/2021 11:30 - 16:30', Formatter::format_date('en-GB', '+01:00', '2021-04-15T10:30:00Z', '2021-04-15T15:30:00Z', false));
} }
public function testCanDateFormatTwoDates(): void { public function testCanDateFormatTwoDates(): void {
$this->assertEquals('15/04/2021 10:30 - 16/04/2021 15:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', false)); $this->assertSame('15/04/2021 10:30 - 16/04/2021 15:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', false));
} }
public function testCanDateFormatTwoDatesWithOffset(): void { public function testCanDateFormatTwoDatesWithOffset(): void {
$this->assertEquals('15/04/2021 10:30 - 16/04/2021 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', true)); $this->assertSame('15/04/2021 10:30 - 16/04/2021 15:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', '2021-04-16T15:30:00Z', true));
} }
public function testCanDateFormatWhenSecondDateIsNull(): void { public function testCanDateFormatWhenSecondDateIsNull(): void {
$this->assertEquals('15/04/2021 10:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, false)); $this->assertSame('15/04/2021 10:30', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, false));
} }
public function testCanDateFormatWhenSecondDateIsNullWithOffset(): void { public function testCanDateFormatWhenSecondDateIsNullWithOffset(): void {
$this->assertEquals('15/04/2021 10:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, true)); $this->assertSame('15/04/2021 10:30 (0)', Formatter::format_date('en-GB', 'UTC', '2021-04-15T10:30:00Z', null, true));
} }
public function testCanLocationFormatBothParameters(): void { public function testCanLocationFormatBothParameters(): void {
$this->assertEquals('a, b', Formatter::format_location('a', 'b')); $this->assertSame('a, b', Formatter::format_location('a', 'b'));
} }
public function testLocationFormatDescriptionOnly(): void { public function testLocationFormatDescriptionOnly(): void {
$this->assertEquals('a', Formatter::format_location('a', '')); $this->assertSame('a', Formatter::format_location('a', ''));
} }
public function testLocationFormatDescriptionWithSpaceOnly() { public function testLocationFormatDescriptionWithSpaceOnly(): void {
$this->assertEquals('', Formatter::format_location(' ', '')); $this->assertSame('', Formatter::format_location(' ', ''));
} }
public function testLocationFormatLocalityOnly(): void { public function testLocationFormatLocalityOnly(): void {
$this->assertEquals('a', Formatter::format_location('', 'a')); $this->assertSame('a', Formatter::format_location('', 'a'));
} }
} }