Skip to content

Commit

Permalink
refactor: update to PHP 8.1 and PHPUnit 10.5 || 11.0 (#445)
Browse files Browse the repository at this point in the history
* Require PHP 8.1 and update dependencies

* Normalize composer.json

* Migrate phpunit.xml.dist

* Fix PHPUnit deprecations

* Do not instantiate a TestCase class
  • Loading branch information
paulbalandan authored May 5, 2024
1 parent eabb10e commit 216a826
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 65 deletions.
52 changes: 26 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
{
"name": "codeigniter4/translations",
"type": "project",
"description": "Translations for CodeIgniter v4 web framework",
"homepage": "https://codeigniter.com",
"license": "MIT",
"type": "project",
"homepage": "https://codeigniter.com",
"support": {
"forum": "http://forum.codeigniter.com/",
"source": "https://github.com/codeigniter4/translations",
"slack": "https://codeigniterchat.slack.com"
},
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"ext-intl": "*"
},
"require-dev": {
"ext-tokenizer": "*",
"codeigniter/coding-standard": "^1.1",
"codeigniter/coding-standard": "^1.7",
"codeigniter4/codeigniter4": "4.x-dev",
"friendsofphp/php-cs-fixer": "^3.1",
"nexusphp/cs-config": "^3.3",
"phpunit/phpunit": "^9.5"
"friendsofphp/php-cs-fixer": "^3.53",
"nexusphp/cs-config": "^3.22",
"phpunit/phpunit": "^10.5 || ^11.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-develop": "4.x-dev"
"repositories": [
{
"type": "vcs",
"url": "https://github.com/codeigniter4/CodeIgniter4",
"canonical": true
}
},
],
"autoload": {
"psr-4": {
"Translations\\": ""
Expand All @@ -37,16 +39,14 @@
"Translations\\Tests\\AutoReview\\": "tests/AutoReview"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/codeigniter4/CodeIgniter4",
"canonical": true
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-develop": "4.x-dev"
}
],
"support": {
"forum": "http://forum.codeigniter.com/",
"source": "https://github.com/codeigniter4/translations",
"slack": "https://codeigniterchat.slack.com"
}
}
12 changes: 4 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd"
bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
backupGlobals="false"
colors="true"
columns="max"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="true">
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Automatic Review Test Suite">
<directory suffix="Test.php">tests/AutoReview</directory>
Expand All @@ -23,11 +19,11 @@
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage" processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">Language</directory>
</include>
</coverage>
</source>

<php>
<env name="app.baseURL" value="http://example.com/"/>
Expand Down
8 changes: 4 additions & 4 deletions tests/AutoReview/LicenseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace Translations\Tests\AutoReview;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

/**
* @internal
*
* @coversNothing
*
* @group license-review
*/
#[CoversNothing]
#[Group('license-review')]
final class LicenseTest extends TestCase
{
public function testLicenseCopyrightYearIsUpdated(): void
Expand Down
32 changes: 20 additions & 12 deletions tests/AutoReview/TranslationsCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

namespace Translations\Tests\AutoReview;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Translations\Tests\AbstractTranslationTestCase;

/**
* This test case eases away the boring review of tiny details in one's pull request.
*
* @internal
*
* @coversNothing
*
* @group auto-review
*/
#[CoversNothing]
#[Group('auto-review')]
final class TranslationsCodeTest extends TestCase
{
public function testLocalesArrayAreArrangedByLocaleCode(): void
Expand All @@ -36,12 +36,9 @@ public function testLocalesArrayAreArrangedByLocaleCode(): void

public function testAllTranslatedLocalesAreIncludedInTheReadMe(): void
{
$locales = (new class () extends AbstractTranslationTestCase {})->translationKeys();
$locales = array_keys($locales);

$readme = $this->getContentsOrFail(__DIR__ . '/../../README.md');

foreach ($locales as $locale) {
foreach ($this->locales() as $locale) {
$this->assertSame(1, preg_match(sprintf('/\| %s \s+\|/', $locale), $readme), sprintf(
'The locale "%s" is not found in the README.md file. Please add it.',
$locale
Expand All @@ -51,19 +48,30 @@ public function testAllTranslatedLocalesAreIncludedInTheReadMe(): void

public function testAllTranslatedLocalesAreNotIncludedInMissing(): void
{
$locales = (new class () extends AbstractTranslationTestCase {})->translationKeys();
$locales = array_keys($locales);

$missing = $this->getContentsOrFail(__DIR__ . '/../../MISSING.md');

foreach ($locales as $locale) {
foreach ($this->locales() as $locale) {
$this->assertSame(0, preg_match(sprintf('/\| %s \s+\|/', $locale), $missing), sprintf(
'The locale "%s" is already translated and should no longer be found in MISSING.md file.',
$locale
));
}
}

/**
* Get all the ISO 639-1 and 639-2 locale codes.
*
* @return iterable<string>
*/
private function locales(): iterable
{
helper('filesystem');

foreach (directory_map(getcwd() . '/Language', 1) as $dir) {
yield trim($dir, '\\/');
}
}

private function getContentsOrFail(string $filepath): string
{
$contents = @file_get_contents($filepath);
Expand Down
23 changes: 8 additions & 15 deletions tests/Language/AbstractTranslationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Translations\Tests;

use CodeIgniter\CLI\CLI;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -94,9 +95,8 @@ abstract class AbstractTranslationTestCase extends TestCase
/**
* This tests that all language files configured in the main CI4 repository
* have a corresponding language file in the current locale.
*
* @dataProvider localesProvider
*/
#[DataProvider('localesProvider')]
final public function testAllConfiguredLanguageFilesAreTranslated(string $locale): void
{
$filesNotTranslated = array_diff(
Expand All @@ -119,9 +119,8 @@ final public function testAllConfiguredLanguageFilesAreTranslated(string $locale
/**
* This tests that all translated language files in the current locale have a
* corresponding language file in the main CI4 repository.
*
* @dataProvider localesProvider
*/
#[DataProvider('localesProvider')]
final public function testAllTranslatedLanguageFilesAreConfigured(string $locale): void
{
$filesNotConfigured = array_diff(
Expand All @@ -144,9 +143,8 @@ final public function testAllTranslatedLanguageFilesAreConfigured(string $locale
/**
* This tests that all language keys defined by a language file in the main CI4
* repository have corresponding keys in the current locale.
*
* @dataProvider localesProvider
*/
#[DataProvider('localesProvider')]
final public function testAllConfiguredLanguageKeysAreIncluded(string $locale): void
{
$keysNotIncluded = [];
Expand Down Expand Up @@ -177,9 +175,8 @@ final public function testAllConfiguredLanguageKeysAreIncluded(string $locale):
/**
* This tests that all included language keys in a language file for the current
* locale have corresponding keys in the main CI4 repository.
*
* @dataProvider localesProvider
*/
#[DataProvider('localesProvider')]
final public function testAllIncludedLanguageKeysAreConfigured(string $locale): void
{
$keysNotConfigured = [];
Expand Down Expand Up @@ -211,9 +208,8 @@ final public function testAllIncludedLanguageKeysAreConfigured(string $locale):
* This tests that all included language keys in a language file for the current
* locale that have corresponding keys in the main CI4 repository are really translated
* and do not only copy the main repository's value.
*
* @dataProvider localesProvider
*/
#[DataProvider('localesProvider')]
final public function testAllIncludedLanguageKeysAreTranslated(string $locale): void
{
// These keys are usually not translated because they contain either
Expand Down Expand Up @@ -263,9 +259,8 @@ final public function testAllIncludedLanguageKeysAreTranslated(string $locale):
/**
* This tests that the order of all language keys defined by a translation language file
* resembles the order in the main CI4 repository.
*
* @dataProvider localesProvider
*/
#[DataProvider('localesProvider')]
final public function testAllConfiguredLanguageKeysAreInOrder(string $locale): void
{
$diffs = [];
Expand Down Expand Up @@ -317,9 +312,7 @@ final public static function localesProvider(): iterable
return [$locale => [$locale]];
}

/**
* @dataProvider localesProvider
*/
#[DataProvider('localesProvider')]
final public function testLocaleHasCorrespondingTestCaseFile(string $locale): void
{
$class = array_flip(self::$locales)[$locale];
Expand Down

0 comments on commit 216a826

Please sign in to comment.