From 51c01c61e4f430633176505eaf1c6cdabad85b07 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Sat, 16 Nov 2024 10:53:50 +0100 Subject: [PATCH] Implement GitHub actions --- .github/workflows/verify-stability.yaml | 143 ++++++++++++++++++++++++ tests/Service/DateServiceTest.php | 58 +++++----- 2 files changed, 173 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/verify-stability.yaml diff --git a/.github/workflows/verify-stability.yaml b/.github/workflows/verify-stability.yaml new file mode 100644 index 0000000..962035d --- /dev/null +++ b/.github/workflows/verify-stability.yaml @@ -0,0 +1,143 @@ +name: Verify stability + +on: + push: + branches: + - master + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + Validate: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.0', '8.1', '8.2' ] + env: + extensions: dom, fileinfo, intl, json, pcre, simplexml + key: cache-v1 # can be any string, change to clear the extension cache. + steps: + - name: Hello + run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - name: Checkout branch + uses: actions/checkout@v4 + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + - name: Validate Composer (composer.json and composer.lock) + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + php_extensions: intl + command: validate --strict --no-check-publish + - name: Cache Composer dependencies + id: composer-cache + uses: actions/cache@v4 + with: + path: /tmp/composer-cache + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + - name: Install Composer dependencies + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + php_extensions: intl + dev: no + PHPStan: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.0', '8.1', '8.2' ] + env: + extensions: dom, fileinfo, intl, json, pcre, simplexml + key: cache-v1 # can be any string, change to clear the extension cache. + needs: [ Validate ] + if: needs.Validate.result == 'success' + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + - name: Install Composer dependencies + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + php_extensions: intl + - name: Analyse code with PHPStan + run: vendor/bin/phpstan analyse --memory-limit 256M + PHPUnit: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.0', '8.1', '8.2' ] + env: + extensions: dom, fileinfo, intl, json, pcre, simplexml + key: cache-v1 # can be any string, change to clear the extension cache. + needs: [ PHPStan ] + if: needs.PHPStan.result == 'success' + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + - name: Install locales + run: | + sudo apt-get update \ + && sudo apt-get install -y --no-install-recommends --fix-missing \ + locales + - name: Generate locales + run: | + sudo sed -i "s/^# de_DE/de_DE/g; \ + s/^# es_ES/es_ES/g; \ + s/^# en_GB/en_GB/g; \ + s/^# en_US/en_US/g; \ + s/^# fr_FR/fr_FR/g; \ + s/^# it_IT/it_IT/g; \ + s/^# pl_PL/pl_PL/g; \ + s/^# ru_RU/ru_RU/g;" /etc/locale.gen \ + && sudo locale-gen + - name: Install Composer dependencies + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + php_extensions: intl + - name: Run PHPUnit tests + run: vendor/bin/phpunit --no-coverage + - name: Bye 👋 + run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/tests/Service/DateServiceTest.php b/tests/Service/DateServiceTest.php index 786e2d6..7680cbf 100644 --- a/tests/Service/DateServiceTest.php +++ b/tests/Service/DateServiceTest.php @@ -181,7 +181,7 @@ public function provideDateFormattedUsingDefaults(): Generator */ public function provideDateFormattedUsingLocale(): Generator { - $locale = 'en_EN'; + $locale = 'en_US'; $dateString = '1900-02-01 08:25:40'; /* @@ -387,21 +387,21 @@ public function testConstructor(): void DateService::class, OopVisibilityType::IS_PUBLIC, 3, - 3 + 3, ); } /** - * @param DateTimeInterface $dateTime The date to format - * @param string $dateLength Type of date length - * @param string $expected Expected date + * @param DateTimeInterface $dateTime The date to format + * @param string $dateLength Type of date length + * @param string $expected Expected date * * @dataProvider provideDateFormattedUsingDefaults */ public function testFormatDateUsingDefaults( DateTimeInterface $dateTime, string $dateLength, - string $expected + string $expected, ): void { static::bootKernel([ 'environment' => 'default', @@ -416,13 +416,13 @@ public function testFormatDateUsingDefaults( } /** - * @param int $dateType Type/length of date part in the returned string. One of constants of the + * @param int $dateType Type/length of date part in the returned string. One of constants of the * \IntlDateFormatter class, e.g. \IntlDateFormatter::SHORT. - * @param int $timeType Type/length of time part in the returned string. One of constants of the + * @param int $timeType Type/length of time part in the returned string. One of constants of the * \IntlDateFormatter class, e.g. \IntlDateFormatter::MEDIUM. - * @param string $locale Locale used to format given date - * @param DateTimeInterface $dateTime The date to format - * @param string $expected Expected date + * @param string $locale Locale used to format given date + * @param DateTimeInterface $dateTime The date to format + * @param string $expected Expected date * * @dataProvider provideDateFormattedUsingLocale */ @@ -431,7 +431,7 @@ public function testFormatDateUsingLocaleAndDefaults( int $timeType, string $locale, DateTimeInterface $dateTime, - string $expected + string $expected, ): void { static::bootKernel([ 'environment' => 'default', @@ -443,7 +443,7 @@ public function testFormatDateUsingLocaleAndDefaults( $dateType, $timeType, $locale, - $dateTime + $dateTime, ) ; @@ -451,13 +451,13 @@ public function testFormatDateUsingLocaleAndDefaults( } /** - * @param int $dateType Type/length of date part in the returned string. One of constants of the + * @param int $dateType Type/length of date part in the returned string. One of constants of the * \IntlDateFormatter class, e.g. \IntlDateFormatter::SHORT. - * @param int $timeType Type/length of time part in the returned string. One of constants of the + * @param int $timeType Type/length of time part in the returned string. One of constants of the * \IntlDateFormatter class, e.g. \IntlDateFormatter::MEDIUM. - * @param string $locale Locale used to format given date - * @param DateTimeInterface $dateTime The date to format - * @param string $expected Expected date + * @param string $locale Locale used to format given date + * @param DateTimeInterface $dateTime The date to format + * @param string $expected Expected date * * @dataProvider provideDateFormattedUsingLocale */ @@ -466,7 +466,7 @@ public function testFormatDateUsingLocaleAndTestEnvironment( int $timeType, string $locale, DateTimeInterface $dateTime, - string $expected + string $expected, ): void { $formatted = $this ->dateService @@ -474,7 +474,7 @@ public function testFormatDateUsingLocaleAndTestEnvironment( $dateType, $timeType, $locale, - $dateTime + $dateTime, ) ; @@ -482,22 +482,23 @@ public function testFormatDateUsingLocaleAndTestEnvironment( } /** - * @param DateTimeInterface $dateTime The date to format - * @param string $dateLength Type of date length - * @param string $expected Expected date + * @param DateTimeInterface $dateTime The date to format + * @param string $dateLength Type of date length + * @param string $expected Expected date * * @dataProvider provideDateFormattedUsingTestEnvironment */ public function testFormatDateUsingTestEnvironment( DateTimeInterface $dateTime, string $dateLength, - string $expected + string $expected, ): void { static::assertSame($expected, $this->dateService->formatDate($dateTime, $dateLength)); } /** * @param string $dateLength Unknown type of date length + * * @dataProvider provideUnknownDateLength */ public function testFormatDateUsingUnknownDateLength(string $dateLength): void @@ -508,13 +509,13 @@ public function testFormatDateUsingUnknownDateLength(string $dateLength): void /** * @param string $dateLength Type of date length - * @param string $expected Expected date format + * @param string $expected Expected date format * * @dataProvider provideDateFormatUsingDefaults */ public function testGetFormatUsingDefaults( string $dateLength, - string $expected + string $expected, ): void { static::bootKernel([ 'environment' => 'default', @@ -530,19 +531,20 @@ public function testGetFormatUsingDefaults( /** * @param string $dateLength Type of date length - * @param string $expected Expected date format + * @param string $expected Expected date format * * @dataProvider provideDateFormatUsingTestEnvironment */ public function testGetFormatUsingTestEnvironment( string $dateLength, - string $expected + string $expected, ): void { static::assertSame($expected, $this->dateService->getFormat($dateLength)); } /** * @param string $dateLength Unknown type of date length + * * @dataProvider provideUnknownDateLength */ public function testGetFormatUsingUnknownDateLength(string $dateLength): void