diff --git a/.gitignore b/.gitignore index 31e0180..569ac1a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ coverage/ node_modules/ vendor/ +.phpunit.cache .phpunit.result.cache diff --git a/README.md b/README.md index de6e9b8..d9ec707 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The current changelog can be found under [source/changelog.txt](source/changelog - Run ESLint: `npm run eslint` - 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` - Update PHP dependencies: `composer update` - Check for direct PHP dependency updates: `composer outdated --direct` diff --git a/composer.json b/composer.json index d6a3430..69806a6 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "autoload": { - "classmap": [ - "source/includes" - ] + "psr-4": { + "MobilizonConnector\\": "source/includes/" + } }, "require-dev": { "phpunit/phpunit": "^9.6" diff --git a/composer.lock b/composer.lock index 31e8407..7814239 100644 --- a/composer.lock +++ b/composer.lock @@ -9,30 +9,30 @@ "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.5.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^9 || ^11", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.30 || ^5.4" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5.27", + "vimeo/psalm": "^5.4" }, "type": "library", "autoload": { @@ -59,7 +59,7 @@ ], "support": { "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": [ { @@ -75,7 +75,7 @@ "type": "tidelift" } ], - "time": "2022-12-30T00:15:36+00:00" + "time": "2022-12-30T00:23:10+00:00" }, { "name": "myclabs/deep-copy", @@ -138,16 +138,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.4", + "version": "v4.15.5", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290" + "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6bb5176bc4af8bcb7d926f88718db9b96a2d4290", - "reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/11e2663a5bc9db5d714eedb4277ee300403b4a9e", + "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e", "shasum": "" }, "require": { @@ -188,9 +188,9 @@ ], "support": { "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", @@ -623,16 +623,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.7", + "version": "9.6.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c993f0d3b0489ffc42ee2fe0bd645af1538a63b2" + "reference": "17d621b3aff84d0c8b62539e269e87d8d5baa76e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c993f0d3b0489ffc42ee2fe0bd645af1538a63b2", - "reference": "c993f0d3b0489ffc42ee2fe0bd645af1538a63b2", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/17d621b3aff84d0c8b62539e269e87d8d5baa76e", + "reference": "17d621b3aff84d0c8b62539e269e87d8d5baa76e", "shasum": "" }, "require": { @@ -706,7 +706,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "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": [ { @@ -722,7 +722,7 @@ "type": "tidelift" } ], - "time": "2023-04-14T08:58:40+00:00" + "time": "2023-05-11T05:14:45+00:00" }, { "name": "sebastian/cli-parser", diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..5a15cdb --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,27 @@ + + + + + tests + + + + + + source/includes + + + diff --git a/source/includes/date-time-wrapper.php b/source/includes/DateTimeWrapper.php similarity index 92% rename from source/includes/date-time-wrapper.php rename to source/includes/DateTimeWrapper.php index 2ffb03d..30fde7a 100644 --- a/source/includes/date-time-wrapper.php +++ b/source/includes/DateTimeWrapper.php @@ -1,11 +1,6 @@ assertEquals('24/12/2020', $d->getShortDate()); + $this->assertSame('24/12/2020', $d->getShortDate()); } public function testCanGetShortDateForUsualDateWithLocaleWithUnderscore(): void { $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 { $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 { $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 { $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 { $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 { $d = new DateTimeWrapper('2020-12-24T16:45:00Z'); - $this->assertEquals('16:45', $d->get24Time()); + $this->assertSame('16:45', $d->get24Time()); } public function testCanGetShortOffsetNameForUsualTime(): void { $d = new DateTimeWrapper('2020-12-24T16:45:00Z'); - $this->assertEquals(0, $d->getOffset()); // TODO was UTC + $this->assertSame('0', $d->getOffset()); // TODO was UTC } } diff --git a/tests/FormatterTest.php b/tests/FormatterTest.php index b4e7006..80d4bd3 100644 --- a/tests/FormatterTest.php +++ b/tests/FormatterTest.php @@ -1,45 +1,52 @@ 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 { - $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 { - $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 { - $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 { - $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 { - $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 { - $this->assertEquals('a, b', Formatter::format_location('a', 'b')); + $this->assertSame('a, b', Formatter::format_location('a', 'b')); } public function testLocationFormatDescriptionOnly(): void { - $this->assertEquals('a', Formatter::format_location('a', '')); + $this->assertSame('a', Formatter::format_location('a', '')); } - public function testLocationFormatDescriptionWithSpaceOnly() { - $this->assertEquals('', Formatter::format_location(' ', '')); + public function testLocationFormatDescriptionWithSpaceOnly(): void { + $this->assertSame('', Formatter::format_location(' ', '')); } public function testLocationFormatLocalityOnly(): void { - $this->assertEquals('a', Formatter::format_location('', 'a')); + $this->assertSame('a', Formatter::format_location('', 'a')); } }