Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update package versions #22

Merged
merged 5 commits into from
Apr 16, 2024
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
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@
*.ttf -text diff
*.woff -text diff
*.woff2 -text diff

# Exclude directories/files from composer vendor package
/tests export-ignore
/.* export-ignore
/php*.json export-ignore
/php*.xml export-ignore
/php*.dist export-ignore
/php*.neon export-ignore
/renovate.json export-ignore
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.2']
php-versions: ['8.1', '8.2', '8.3']
composer-flags: ['', '--prefer-lowest']
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
run: php -dpcov.enabled=1 -dpcov.exclude="~vendor~" vendor/bin/phpunit --testsuite unit --coverage-clover ./.coverage/coverage.xml

- name: Check coverage
run: php vendor/bin/phpfci inspect ./.coverage/coverage.xml ./.coverage/phpfci.xml --exit-code-on-failure
run: test ! -f ./.coverage/coverage.xml || php vendor/bin/phpfci inspect ./.coverage/coverage.xml --exit-code-on-failure --reportText

quality:
name: Quality checks
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/vendor
/composer.lock
/phpunit.xml
/.phpunit.result.cache
/.phpunit.cache
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
}
},
"require-dev": {
"digitalrevolution/phpunit-file-coverage-inspection": "^v1.0",
"digitalrevolution/accessorpair-constraint": "2.1.7",
"digitalrevolution/phpunit-file-coverage-inspection": "^v2.0.0",
"digitalrevolution/accessorpair-constraint": "^v2.1.18",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.6",
"phpmd/phpmd": "@stable",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
"phpstan/extension-installer": "^1.1"
"phpmd/phpmd": "^2.14",
"phpunit/phpunit": "^10.5.1",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpstan/extension-installer": "^1.3"
},
"scripts": {
"check": ["@check:phpstan", "@check:phpmd", "@check:phpcs"],
Expand Down
16 changes: 7 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
failOnRisky="true"
failOnWarning="true"
failOnDeprecation="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutResourceUsageDuringSmallTests="true"
beStrictAboutTodoAnnotatedTests="true"
executionOrder="defects"
>
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="true">
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</coverage>
</source>
</phpunit>
5 changes: 4 additions & 1 deletion src/PhoneNumber/PhoneNumberFormatOptions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
declare(strict_types=1);


namespace DR\Internationalization\PhoneNumber;

use libphonenumber\PhoneNumberFormat;
Expand Down Expand Up @@ -37,6 +36,7 @@ class PhoneNumberFormatOptions
public const FORMAT_INTERNATIONAL_DIAL = 4;

private ?string $defaultCountryCode = null;
/** @phpstan-var ?Format */
private ?int $format = null;

public function getDefaultCountryCode(): ?string
Expand All @@ -51,6 +51,9 @@ public function setDefaultCountryCode(?string $defaultCountryCode): self
return $this;
}

/**
* @phpstan-return ?Format
*/
public function getFormat(): ?int
{
return $this->format;
Expand Down
14 changes: 2 additions & 12 deletions tests/Unit/Currency/CurrencyFormatOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
use DigitalRevolution\AccessorPairConstraint\AccessorPairAsserter;
use DigitalRevolution\AccessorPairConstraint\Constraint\ConstraintConfig;
use DR\Internationalization\Currency\CurrencyFormatOptions;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \DR\Internationalization\Currency\CurrencyFormatOptions
*/
#[CoversClass(CurrencyFormatOptions::class)]
class CurrencyFormatOptionsTest extends TestCase
{
use AccessorPairAsserter;

/**
* @covers ::setSymbol
* @covers ::hasSymbol
* @covers ::setCurrencyCode
* @covers ::getCurrencyCode
*/
public function testAccessors(): void
{
$config = new ConstraintConfig();
Expand All @@ -31,9 +24,6 @@ public function testAccessors(): void
static::assertAccessorPairs(CurrencyFormatOptions::class, $config);
}

/**
* @covers ::__toString
*/
public function testToString(): void
{
$options = new CurrencyFormatOptions();
Expand Down
37 changes: 2 additions & 35 deletions tests/Unit/Currency/CurrencyFormatterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,22 @@
use DR\Internationalization\Currency\CurrencyFormatOptions;
use DR\Internationalization\Currency\CurrencyFormatterFactory;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \DR\Internationalization\Currency\CurrencyFormatterFactory
* @covers ::__construct
*/
#[CoversClass(CurrencyFormatterFactory::class)]
class CurrencyFormatterFactoryTest extends TestCase
{
private const MINUS = "\xE2\x88\x92";
private const NBSP = "\xC2\xA0";

/**
* @covers ::create
*/
public function testCreateLocaleIsRequired(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('unable to format currency without a locale');
(new CurrencyFormatterFactory(new CurrencyFormatOptions()))->create(new CurrencyFormatOptions());
}

/**
* @covers ::create
* @covers ::applyCurrencyFormatOptions
*/
public function testCreateWithDefaults(): void
{
$defaultOptions = (new CurrencyFormatOptions())->setLocale('nl_NL');
Expand All @@ -50,10 +41,6 @@ public function testCreateWithDefaults(): void
static::assertSame('-2.005,56', $formatter->format(-2005.555));
}

/**
* @covers ::create
* @covers ::applyCurrencyFormatOptions
*/
public function testCreateDefaultCurrencyWithCustomSettings(): void
{
$defaultOptions = (new CurrencyFormatOptions())->setLocale('nl_NL');
Expand All @@ -63,10 +50,6 @@ public function testCreateDefaultCurrencyWithCustomSettings(): void
static::assertSame('-2.005,1235', $formatter->format(-2005.123456));
}

/**
* @covers ::create
* @covers ::applyCurrencyFormatOptions
*/
public function testCreateSwedishCurrencyWithSymbol(): void
{
$defaultOptions = (new CurrencyFormatOptions())->setLocale('sv_SE');
Expand All @@ -78,10 +61,6 @@ public function testCreateSwedishCurrencyWithSymbol(): void
static::assertSame(self::MINUS . '2' . self::NBSP . '005,56' . self::NBSP . 'kr', $formatter->format(-2005.555));
}

/**
* @covers ::create
* @covers ::applyCurrencyFormatOptions
*/
public function testCreateSwedishCurrencyWithoutSymbol(): void
{
$defaultOptions = (new CurrencyFormatOptions())->setLocale('sv_SE')->setCurrencyCode('SEK');
Expand All @@ -94,10 +73,6 @@ public function testCreateSwedishCurrencyWithoutSymbol(): void
static::assertSame(self::MINUS . '2' . self::NBSP . '005,56', $formatter->format(-2005.555));
}

/**
* @covers ::create
* @covers ::applyCurrencyFormatOptions
*/
public function testCreateIrishCurrency(): void
{
$defaultOptions = (new CurrencyFormatOptions())->setLocale('en_IE')->setCurrencyCode('EUR');
Expand All @@ -108,10 +83,6 @@ public function testCreateIrishCurrency(): void
static::assertSame("€" . '2,005.56', $formatter->format(2005.555));
}

/**
* @covers ::create
* @covers ::applyCurrencyFormatOptions
*/
public function testCreateForeignCurrencyWithoutSymbolOrGrouping(): void
{
$defaultOptions = (new CurrencyFormatOptions())->setLocale('nl_NL')->setCurrencyCode('SEK');
Expand All @@ -125,10 +96,6 @@ public function testCreateForeignCurrencyWithoutSymbolOrGrouping(): void
static::assertSame('-2005,56', $formatter->format(-2005.555));
}

/**
* @covers ::create
* @covers ::applyCurrencyFormatOptions
*/
public function testCreateForeignCurrencyWithSymbol(): void
{
$defaultOptions = (new CurrencyFormatOptions())->setLocale('nl_NL')->setCurrencyCode('SEK');
Expand Down
18 changes: 8 additions & 10 deletions tests/Unit/Date/DayOfTheWeekFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
use DR\Internationalization\Date\DayOfTheWeekFormatter;
use Exception;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @phpstan-import-type DayOfTheWeek from DayOfTheWeekFormatter
* @coversDefaultClass \DR\Internationalization\Date\DayOfTheWeekFormatter
* @covers ::__construct
*/
#[CoversClass(DayOfTheWeekFormatter::class)]
class DayOfTheWeekFormatterTest extends TestCase
{
/**
* @phpstan-param DayOfTheWeek $dayOfWeek
* @dataProvider formatDayOfTheWeekDataProvider
* @covers ::format
* @throws Exception
*/
#[DataProvider('formatDayOfTheWeekDataProvider')]
public function testFormat(string $locale, int $dayOfWeek, string $expected): void
{
$formatter = new DayOfTheWeekFormatter($locale);
Expand All @@ -29,10 +29,9 @@ public function testFormat(string $locale, int $dayOfWeek, string $expected): vo

/**
* @phpstan-param DayOfTheWeek $dayOfWeek
* @dataProvider formatDayOfTheWeekInvalidDataProvider
* @covers ::format
* @throws Exception
*/
#[DataProvider('formatDayOfTheWeekInvalidDataProvider')]
public function testFormatInvalid(int $dayOfWeek, string $expectedMessage): void
{
$formatter = new DayOfTheWeekFormatter('en_GB');
Expand All @@ -42,10 +41,9 @@ public function testFormatInvalid(int $dayOfWeek, string $expectedMessage): void
}

/**
* @dataProvider formatDayOfTheWeekInvalidDataProvider
* @covers ::format
* @throws Exception
*/
#[DataProvider('formatDayOfTheWeekInvalidDataProvider')]
public function testFormatInvalidCustomLocale(): void
{
$formatter = new DayOfTheWeekFormatter('en_GB');
Expand All @@ -55,7 +53,7 @@ public function testFormatInvalidCustomLocale(): void
/**
* @return array<string, array>
*/
public function formatDayOfTheWeekDataProvider(): array
public static function formatDayOfTheWeekDataProvider(): array
{
return [
'EN-Mon' => ['en_GB', DayOfTheWeekFormatter::MONDAY, 'Monday'],
Expand Down Expand Up @@ -103,7 +101,7 @@ public function formatDayOfTheWeekDataProvider(): array
/**
* @return array[]
*/
public function formatDayOfTheWeekInvalidDataProvider(): array
public static function formatDayOfTheWeekInvalidDataProvider(): array
{
return [
[0, '0 is not a valid ISO-8601 numeric representation of the day of the week.'],
Expand Down
22 changes: 7 additions & 15 deletions tests/Unit/DateFormatServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@

namespace DR\Internationalization\Tests\Unit;

use DateTime;
use DR\Internationalization\DateFormatService;
use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \DR\Internationalization\DateFormatService
* @covers ::__construct
*/
#[CoversClass(DateFormatService::class)]
class DateFormatServiceTest extends TestCase
{
/**
* @covers ::format
* @covers ::getDateFormatter
* @dataProvider dataProviderDateFormats
*/
#[DataProvider('dataProviderDateFormats')]
public function testFormat($locale, $timeZone, $value, $format, $expectedValue): void
{
$formatService = new DateFormatService($locale, $timeZone);
Expand All @@ -27,11 +23,11 @@ public function testFormat($locale, $timeZone, $value, $format, $expectedValue):
/**
* @return Generator<string, array<string>>
*/
public function dataProviderDateFormats(): Generator
public static function dataProviderDateFormats(): Generator
{
yield 'nl_NL, Y-M-d' => ['nl_NL', 'Europe/Amsterdam', 2222222222, 'Y-M-d', '2040-6-2'];
yield 'nl_NL, string input' => ['nl_NL', 'Europe/Amsterdam', '2022-08-16 + 1 day', 'Y-M-d', '2022-8-17'];
yield 'nl_NL, DateTime input' => ['nl_NL', 'Europe/Amsterdam', new \DateTime('2022-08-16 + 1 day'), 'Y-M-d', '2022-8-17'];
yield 'nl_NL, DateTime input' => ['nl_NL', 'Europe/Amsterdam', new DateTime('2022-08-16 + 1 day'), 'Y-M-d', '2022-8-17'];
yield 'nl_NL, long format' => [
'nl_NL',
'Europe/Amsterdam',
Expand All @@ -56,10 +52,6 @@ public function dataProviderDateFormats(): Generator
];
}

/**
* @covers ::format
* @covers ::getDateFormatter
*/
public function testFormatDuplicateFormat(): void
{
$formatService = new DateFormatService('nl_NL', 'Europe/Amsterdam');
Expand Down
Loading