Skip to content

Commit

Permalink
Merge pull request #70 from ADmad/chore/phpunit-11
Browse files Browse the repository at this point in the history
Add support for PHPUnit 11
  • Loading branch information
ADmad authored Oct 29, 2024
2 parents 2f455f8 + 6b5b43b commit d06bce6
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"cakephp/cakephp": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^10.1"
"phpunit/phpunit": "^10.1 || ^11.0"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 5 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
parameters:
level: 7
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
bootstrapFiles:
- tests/bootstrap.php
paths:
- src
ignoreErrors:
-
identifier: missingType.iterableValue
-
identifier: missingType.generics
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<issueHandlers>
<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<RiskyTruthyFalsyComparison errorLevel="info" />
</issueHandlers>
</psalm>
16 changes: 10 additions & 6 deletions src/Command/I18nExtractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public static function defaultName(): string
public function execute(Arguments $args, ConsoleIo $io): ?int
{
$plugin = '';
if ($args->getOption('exclude')) {
if ($args->hasOption('exclude')) {
$this->_exclude = explode(',', (string)$args->getOption('exclude'));
}
if ($args->getOption('files')) {
if ($args->hasOption('files')) {
$this->_files = explode(',', (string)$args->getOption('files'));
}
if ($args->getOption('paths')) {
if ($args->hasOption('paths')) {
$this->_paths = explode(',', (string)$args->getOption('paths'));
} elseif ($args->getOption('plugin')) {
} elseif ($args->hasOption('plugin')) {
$plugin = Inflector::camelize((string)$args->getOption('plugin'));
$this->_paths = [Plugin::classPath($plugin), Plugin::templatePath($plugin)];
} else {
Expand All @@ -90,6 +90,10 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
}

if ($args->hasOption('exclude-plugins') && $this->_isExtractingApp()) {
/**
* @phpstan-ignore-next-line
* @psalm-suppress PropertyTypeCoercion
*/
$this->_exclude = array_merge($this->_exclude, App::path('plugins'));
}

Expand Down Expand Up @@ -206,7 +210,7 @@ protected function _saveMessages(Arguments $args, ConsoleIo $io): void
});

$domains = null;
if ($args->getOption('domains')) {
if ($args->hasOption('domains')) {
$domains = explode(',', (string)$args->getOption('domains'));
}

Expand All @@ -222,7 +226,7 @@ protected function _saveMessages(Arguments $args, ConsoleIo $io): void
foreach ($translations as $msgid => $contexts) {
foreach ($contexts as $context => $details) {
$references = null;
if (!$args->getOption('no-location')) {
if (!(bool)$args->getOption('no-location')) {
$files = $details['references'];
$occurrences = [];
foreach ($files as $file => $lines) {
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/I18nMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function ignoreRequestCallback(Closure $callback)
*/
public function detectLanguage(ServerRequest $request, ?string $default = null): string
{
if (empty($default)) {
if (!$default) {
$lang = $this->_config['defaultLanguage'];
} else {
$lang = $default;
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Command/I18nExtractCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
use Cake\Core\Configure;
use Cake\ORM\Table;
use Cake\TestSuite\TestCase;
use TestPlugin\Plugin;

Expand All @@ -17,6 +18,8 @@ class I18nExtractCommandTest extends TestCase

protected array $fixtures = ['plugin.ADmad/I18n.I18nMessages'];

protected Table $model;

public function setUp(): void
{
parent::setUp();
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/I18n/DbMessagesLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use ADmad\I18n\I18n\DbMessagesLoader;
use Cake\TestSuite\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Tests for DbMessagesLoader.
Expand All @@ -21,8 +22,8 @@ class DbMessagesLoaderTest extends TestCase
* @param string $model
* @param array $expected
* @return void
* @dataProvider paramsProvider
*/
#[DataProvider('paramsProvider')]
public function testInvoke($domain, $locale, $model, $expected)
{
$loader = new DbMessagesLoader($domain, $locale, $model);
Expand Down
9 changes: 8 additions & 1 deletion tests/TestCase/Validation/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ADmad\I18n\I18n\DbMessagesLoader;
use ADmad\I18n\Validation\Validator;
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\I18n\I18n;
use Cake\TestSuite\TestCase;

Expand All @@ -16,9 +17,15 @@ class ValidatorTest extends TestCase
{
protected array $fixtures = ['plugin.ADmad/I18n.I18nMessages'];

protected Validator $validator;

public function setUp(): void
{
Cache::clear('_cake_core_');
if (version_compare(Configure::version(), '5.1.0', '<')) {
Cache::clear('_cake_core_');
} else {
Cache::clear('_cake_translations_');
}

I18n::config('validation', function ($domain, $locale) {
$loader = new DbMessagesLoader(
Expand Down
7 changes: 6 additions & 1 deletion tests/TestCase/View/Widget/TimezoneWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
use Cake\TestSuite\TestCase;
use Cake\View\StringTemplate;
use DateTimeZone;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;

/**
* Tests for TimezoneWidget.
*/
class TimezoneWidgetTest extends TestCase
{
protected $context;

protected StringTemplate $templates;

/**
* setup method.
*
Expand Down Expand Up @@ -77,9 +82,9 @@ public function testRender()

/**
* @see https://github.com/ADmad/cakephp-i18n/pull/52
* @doesNotPerformAssertions
* @return void
*/
#[DoesNotPerformAssertions]
public function testRenderOptionsNull()
{
$data = [
Expand Down

0 comments on commit d06bce6

Please sign in to comment.