Skip to content

Commit 88bbbcf

Browse files
committed
fix: preferApp is used with short classname only
1 parent 74177ef commit 88bbbcf

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎system/Config/Factories.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ class_exists($name, false)
221221

222222
// If an App version was requested then see if it verifies
223223
if (
224-
// preferApp is used only for no namespace class or Config class.
225-
(strpos($name, '\\') === false || self::isConfig($options['component']))
224+
// preferApp is used only for no namespace class.
225+
strpos($name, '\\') === false
226226
&& $options['preferApp'] && class_exists($appname)
227227
&& self::verifyInstanceOf($options, $name)
228228
) {

‎tests/system/Config/FactoriesTest.php‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class_alias(SomeWidget::class, $class);
255255
$this->assertInstanceOf(SomeWidget::class, $result);
256256
}
257257

258-
public function testPreferAppOverridesConfigClassname()
258+
public function testShortnameReturnsConfigInApp()
259259
{
260260
// Create a config class in App
261261
$file = APPPATH . 'Config/TestRegistrar.php';
@@ -267,10 +267,30 @@ class TestRegistrar
267267
EOL;
268268
file_put_contents($file, $source);
269269

270-
$result = Factories::config(TestRegistrar::class);
270+
$result = Factories::config('TestRegistrar');
271271

272272
$this->assertInstanceOf('Config\TestRegistrar', $result);
273273

274+
// Delete the config class in App
275+
unlink($file);
276+
}
277+
278+
public function testFullClassnameIgnoresPreferApp()
279+
{
280+
// Create a config class in App
281+
$file = APPPATH . 'Config/TestRegistrar.php';
282+
$source = <<<'EOL'
283+
<?php
284+
namespace Config;
285+
class TestRegistrar
286+
{}
287+
EOL;
288+
file_put_contents($file, $source);
289+
290+
$result = Factories::config(TestRegistrar::class);
291+
292+
$this->assertInstanceOf(TestRegistrar::class, $result);
293+
274294
Factories::setOptions('config', ['preferApp' => false]);
275295

276296
$result = Factories::config(TestRegistrar::class);

0 commit comments

Comments
 (0)