Skip to content

Commit 86a84ce

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
Conflicts: user_guide_src/source/concepts/autoloader.rst
2 parents 52c2222 + 7cd5c99 commit 86a84ce

File tree

15 files changed

+99
-71
lines changed

15 files changed

+99
-71
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"require-dev": {
2121
"codeigniter/coding-standard": "^1.5",
22-
"codeigniter/phpstan-codeigniter": "^v1.1",
22+
"codeigniter/phpstan-codeigniter": "^1.4",
2323
"ergebnis/composer-normalize": "^2.28",
2424
"fakerphp/faker": "^1.9",
2525
"kint-php/kint": "^5.0.4",

phpstan-baseline.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -836,16 +836,6 @@
836836
'count' => 4,
837837
'path' => __DIR__ . '/system/Config/BaseConfig.php',
838838
];
839-
$ignoreErrors[] = [
840-
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
841-
'count' => 1,
842-
'path' => __DIR__ . '/system/Config/BaseConfig.php',
843-
];
844-
$ignoreErrors[] = [
845-
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
846-
'count' => 2,
847-
'path' => __DIR__ . '/system/Config/BaseService.php',
848-
];
849839
$ignoreErrors[] = [
850840
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
851841
'count' => 3,

phpstan.neon.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,3 @@ parameters:
3838
booleansInConditions: true
3939
disallowedConstructs: true
4040
matchingInheritedMethodNames: true
41-
codeigniter:
42-
additionalConfigNamespaces:
43-
- CodeIgniter\Config\

system/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ function function_usable(string $functionName): bool
579579
if (! function_exists('helper')) {
580580
/**
581581
* Loads a helper file into memory. Supports namespaced helpers,
582-
* both in and out of the 'helpers' directory of a namespaced directory.
582+
* both in and out of the 'Helpers' directory of a namespaced directory.
583583
*
584584
* Will load ALL helpers of the matching name, in the following order:
585585
* 1. app/Helpers

system/Config/BaseConfig.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class BaseConfig
5555
/**
5656
* The modules configuration.
5757
*
58-
* @var Modules
58+
* @var Modules|null
5959
*/
6060
protected static $moduleConfig;
6161

@@ -74,6 +74,15 @@ public static function __set_state(array $array)
7474
return $obj;
7575
}
7676

77+
/**
78+
* @internal For testing purposes only.
79+
* @testTag
80+
*/
81+
public static function setModules(Modules $modules): void
82+
{
83+
static::$moduleConfig = $modules;
84+
}
85+
7786
/**
7887
* Will attempt to get environment variables with names
7988
* that match the properties of the child class.
@@ -82,7 +91,7 @@ public static function __set_state(array $array)
8291
*/
8392
public function __construct()
8493
{
85-
static::$moduleConfig = config(Modules::class);
94+
static::$moduleConfig ??= new Modules();
8695

8796
if (! static::$override) {
8897
return;

system/Config/BaseService.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ public static function injectMock(string $name, $mock)
331331
protected static function discoverServices(string $name, array $arguments)
332332
{
333333
if (! static::$discovered) {
334-
$config = config(Modules::class);
335-
336-
if ($config->shouldDiscover('services')) {
334+
if ((new Modules())->shouldDiscover('services')) {
337335
$locator = static::locator();
338336
$files = $locator->search('Config/Services');
339337

@@ -377,9 +375,7 @@ protected static function discoverServices(string $name, array $arguments)
377375
protected static function buildServicesCache(): void
378376
{
379377
if (! static::$discovered) {
380-
$config = config(Modules::class);
381-
382-
if ($config->shouldDiscover('services')) {
378+
if ((new Modules())->shouldDiscover('services')) {
383379
$locator = static::locator();
384380
$files = $locator->search('Config/Services');
385381

system/Validation/StrictRules/Rules.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function equals($str, string $val): bool
6363
*/
6464
public function exact_length($str, string $val): bool
6565
{
66+
if (is_int($str) || is_float($str)) {
67+
$str = (string) $str;
68+
}
69+
6670
if (! is_string($str)) {
6771
return false;
6872
}

tests/system/Cache/FactoriesCacheFileVarExportHandlerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use CodeIgniter\Config\Factories;
1616
use CodeIgniter\Test\CIUnitTestCase;
1717
use Config\App;
18-
use Config\Modules;
1918

2019
/**
2120
* @internal
@@ -58,7 +57,6 @@ public function testSave()
5857

5958
$this->assertArrayHasKey('aliases', $cachedData);
6059
$this->assertArrayHasKey('instances', $cachedData);
61-
$this->assertArrayHasKey(Modules::class, $cachedData['aliases']);
6260
$this->assertArrayHasKey('App', $cachedData['aliases']);
6361
}
6462

tests/system/Config/BaseConfigTest.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
namespace CodeIgniter\Config;
1313

14+
use CodeIgniter\Autoloader\FileLocator;
1415
use CodeIgniter\Test\CIUnitTestCase;
16+
use Config\Modules;
1517
use Encryption;
18+
use PHPUnit\Framework\MockObject\MockObject;
1619
use RegistrarConfig;
1720
use RuntimeException;
1821
use SimpleConfig;
@@ -45,6 +48,9 @@ protected function setUp(): void
4548
if (! class_exists('Encryption', false)) {
4649
require $this->fixturesFolder . '/Encryption.php';
4750
}
51+
52+
BaseConfig::$registrars = [];
53+
BaseConfig::setModules(new Modules()); // reset to clean copy of Modules
4854
}
4955

5056
public function testBasicValues(): void
@@ -265,32 +271,28 @@ public function testBadRegistrar(): void
265271
$this->assertSame('bar', $config->foo);
266272
}
267273

268-
public function testNotEnabled(): void
274+
public function testDiscoveryNotEnabledWillNotPopulateRegistrarsArray(): void
269275
{
270-
$modulesConfig = config('Modules');
271-
$modulesConfig->enabled = false;
272-
273-
$config = new RegistrarConfig();
274-
$config::$registrars = [];
275-
$expected = $config::$registrars;
276+
/** @var MockObject&Modules $modules */
277+
$modules = $this->createMock(Modules::class);
278+
$modules->method('shouldDiscover')->with('registrars')->willReturn(false);
276279

277-
$method = $this->getPrivateMethodInvoker($config, 'registerProperties');
278-
$method();
280+
RegistrarConfig::setModules($modules);
281+
$config = new RegistrarConfig();
279282

280-
$this->assertSame($expected, $config::$registrars);
283+
$this->assertSame([], $config::$registrars);
281284
}
282285

283-
public function testDidDiscovery(): void
286+
public function testRedoingDiscoveryWillStillSetDidDiscoveryPropertyToTrue(): void
284287
{
285-
$modulesConfig = config('Modules');
286-
$modulesConfig->enabled = true;
288+
/** @var FileLocator&MockObject $locator */
289+
$locator = $this->createMock(FileLocator::class);
290+
$locator->method('search')->with('Config/Registrar.php')->willReturn([]);
291+
Services::injectMock('locator', $locator);
287292

288-
$config = new RegistrarConfig();
289-
$config::$registrars = [];
290-
$this->setPrivateProperty($config, 'didDiscovery', false);
293+
$this->setPrivateProperty(RegistrarConfig::class, 'didDiscovery', false);
291294

292-
$method = $this->getPrivateMethodInvoker($config, 'registerProperties');
293-
$method();
295+
$config = new RegistrarConfig();
294296

295297
$this->assertTrue($this->getPrivateProperty($config, 'didDiscovery'));
296298
}

tests/system/Validation/RulesTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,10 @@ public function testMaxLengthReturnsFalseWithNonNumericVal(): void
398398

399399
/**
400400
* @dataProvider provideExactLength
401+
*
402+
* @param int|string|null $data
401403
*/
402-
public function testExactLength(?string $data, bool $expected): void
404+
public function testExactLength($data, bool $expected): void
403405
{
404406
$this->validation->setRules(['foo' => 'exact_length[3]']);
405407
$this->assertSame($expected, $this->validation->run(['foo' => $data]));
@@ -408,10 +410,13 @@ public function testExactLength(?string $data, bool $expected): void
408410
public static function provideExactLength(): iterable
409411
{
410412
yield from [
411-
'null' => [null, false],
412-
'exact' => ['bar', true],
413-
'less' => ['ba', false],
414-
'greater' => ['bars', false],
413+
'null' => [null, false],
414+
'exact' => ['bar', true],
415+
'exact_int' => [123, true],
416+
'less' => ['ba', false],
417+
'less_int' => [12, false],
418+
'greater' => ['bars', false],
419+
'greater_int' => [1234, false],
415420
];
416421
}
417422

0 commit comments

Comments
 (0)