Skip to content

Commit d06bce6

Browse files
authored
Merge pull request #70 from ADmad/chore/phpunit-11
Add support for PHPUnit 11
2 parents 2f455f8 + 6b5b43b commit d06bce6

File tree

9 files changed

+37
-13
lines changed

9 files changed

+37
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"cakephp/cakephp": "^5.0"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^10.1"
29+
"phpunit/phpunit": "^10.1 || ^11.0"
3030
},
3131
"autoload": {
3232
"psr-4": {

phpstan.neon

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
parameters:
22
level: 7
3-
checkMissingIterableValueType: false
4-
checkGenericClassInNonGenericObjectType: false
53
treatPhpDocTypesAsCertain: false
64
bootstrapFiles:
75
- tests/bootstrap.php
86
paths:
97
- src
8+
ignoreErrors:
9+
-
10+
identifier: missingType.iterableValue
11+
-
12+
identifier: missingType.generics

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
<issueHandlers>
2020
<PropertyNotSetInConstructor errorLevel="info" />
2121
<MissingConstructor errorLevel="info" />
22+
<RiskyTruthyFalsyComparison errorLevel="info" />
2223
</issueHandlers>
2324
</psalm>

src/Command/I18nExtractCommand.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public static function defaultName(): string
6363
public function execute(Arguments $args, ConsoleIo $io): ?int
6464
{
6565
$plugin = '';
66-
if ($args->getOption('exclude')) {
66+
if ($args->hasOption('exclude')) {
6767
$this->_exclude = explode(',', (string)$args->getOption('exclude'));
6868
}
69-
if ($args->getOption('files')) {
69+
if ($args->hasOption('files')) {
7070
$this->_files = explode(',', (string)$args->getOption('files'));
7171
}
72-
if ($args->getOption('paths')) {
72+
if ($args->hasOption('paths')) {
7373
$this->_paths = explode(',', (string)$args->getOption('paths'));
74-
} elseif ($args->getOption('plugin')) {
74+
} elseif ($args->hasOption('plugin')) {
7575
$plugin = Inflector::camelize((string)$args->getOption('plugin'));
7676
$this->_paths = [Plugin::classPath($plugin), Plugin::templatePath($plugin)];
7777
} else {
@@ -90,6 +90,10 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
9090
}
9191

9292
if ($args->hasOption('exclude-plugins') && $this->_isExtractingApp()) {
93+
/**
94+
* @phpstan-ignore-next-line
95+
* @psalm-suppress PropertyTypeCoercion
96+
*/
9397
$this->_exclude = array_merge($this->_exclude, App::path('plugins'));
9498
}
9599

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

208212
$domains = null;
209-
if ($args->getOption('domains')) {
213+
if ($args->hasOption('domains')) {
210214
$domains = explode(',', (string)$args->getOption('domains'));
211215
}
212216

@@ -222,7 +226,7 @@ protected function _saveMessages(Arguments $args, ConsoleIo $io): void
222226
foreach ($translations as $msgid => $contexts) {
223227
foreach ($contexts as $context => $details) {
224228
$references = null;
225-
if (!$args->getOption('no-location')) {
229+
if (!(bool)$args->getOption('no-location')) {
226230
$files = $details['references'];
227231
$occurrences = [];
228232
foreach ($files as $file => $lines) {

src/Middleware/I18nMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function ignoreRequestCallback(Closure $callback)
138138
*/
139139
public function detectLanguage(ServerRequest $request, ?string $default = null): string
140140
{
141-
if (empty($default)) {
141+
if (!$default) {
142142
$lang = $this->_config['defaultLanguage'];
143143
} else {
144144
$lang = $default;

tests/TestCase/Command/I18nExtractCommandTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
77
use Cake\Core\Configure;
8+
use Cake\ORM\Table;
89
use Cake\TestSuite\TestCase;
910
use TestPlugin\Plugin;
1011

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

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

21+
protected Table $model;
22+
2023
public function setUp(): void
2124
{
2225
parent::setUp();

tests/TestCase/I18n/DbMessagesLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use ADmad\I18n\I18n\DbMessagesLoader;
77
use Cake\TestSuite\TestCase;
8+
use PHPUnit\Framework\Attributes\DataProvider;
89

910
/**
1011
* Tests for DbMessagesLoader.
@@ -21,8 +22,8 @@ class DbMessagesLoaderTest extends TestCase
2122
* @param string $model
2223
* @param array $expected
2324
* @return void
24-
* @dataProvider paramsProvider
2525
*/
26+
#[DataProvider('paramsProvider')]
2627
public function testInvoke($domain, $locale, $model, $expected)
2728
{
2829
$loader = new DbMessagesLoader($domain, $locale, $model);

tests/TestCase/Validation/ValidatorTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ADmad\I18n\I18n\DbMessagesLoader;
77
use ADmad\I18n\Validation\Validator;
88
use Cake\Cache\Cache;
9+
use Cake\Core\Configure;
910
use Cake\I18n\I18n;
1011
use Cake\TestSuite\TestCase;
1112

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

20+
protected Validator $validator;
21+
1922
public function setUp(): void
2023
{
21-
Cache::clear('_cake_core_');
24+
if (version_compare(Configure::version(), '5.1.0', '<')) {
25+
Cache::clear('_cake_core_');
26+
} else {
27+
Cache::clear('_cake_translations_');
28+
}
2229

2330
I18n::config('validation', function ($domain, $locale) {
2431
$loader = new DbMessagesLoader(

tests/TestCase/View/Widget/TimezoneWidgetTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
use Cake\TestSuite\TestCase;
88
use Cake\View\StringTemplate;
99
use DateTimeZone;
10+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
1011

1112
/**
1213
* Tests for TimezoneWidget.
1314
*/
1415
class TimezoneWidgetTest extends TestCase
1516
{
17+
protected $context;
18+
19+
protected StringTemplate $templates;
20+
1621
/**
1722
* setup method.
1823
*
@@ -77,9 +82,9 @@ public function testRender()
7782

7883
/**
7984
* @see https://github.com/ADmad/cakephp-i18n/pull/52
80-
* @doesNotPerformAssertions
8185
* @return void
8286
*/
87+
#[DoesNotPerformAssertions]
8388
public function testRenderOptionsNull()
8489
{
8590
$data = [

0 commit comments

Comments
 (0)