Skip to content

Commit 4cd4918

Browse files
authored
Merge pull request #9354 from samsonasik/fix-namespaced-helper
fix: handle namespaced helper found on Common helper
2 parents c0c3e02 + f551dbd commit 4cd4918

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

system/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ function helper($filenames): void
598598
if (str_contains($filename, '\\')) {
599599
$path = $loader->locateFile($filename, 'Helpers');
600600

601-
if ($path !== '') {
601+
if ($path === false) {
602602
throw FileNotFoundException::forFileNotFound($filename);
603603
}
604604

tests/system/CommonHelperTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
namespace CodeIgniter;
1515

16+
use CodeIgniter\Autoloader\Autoloader;
1617
use CodeIgniter\Autoloader\FileLocator;
18+
use CodeIgniter\Files\Exceptions\FileNotFoundException;
1719
use CodeIgniter\Test\CIUnitTestCase;
1820
use Config\Services;
1921
use PHPUnit\Framework\Attributes\CoversFunction;
@@ -148,4 +150,33 @@ function foo_bar_baz(): string
148150

149151
$this->assertSame($this->dummyHelpers[0], foo_bar_baz());
150152
}
153+
154+
public function testNamespacedHelperNotFound(): void
155+
{
156+
$this->expectException(FileNotFoundException::class);
157+
158+
$locator = $this->getMockLocator();
159+
Services::injectMock('locator', $locator);
160+
161+
helper('foo\barbaz');
162+
}
163+
164+
public function testNamespacedHelperFound(): void
165+
{
166+
$autoloader = new Autoloader();
167+
$autoloader->addNamespace('Tests\Support\Helpers', TESTPATH . '_support/Helpers');
168+
$locator = new FileLocator($autoloader);
169+
170+
Services::injectMock('locator', $locator);
171+
172+
$found = true;
173+
174+
try {
175+
helper('Tests\Support\Helpers\baguette');
176+
} catch (FileNotFoundException) {
177+
$found = false;
178+
}
179+
180+
$this->assertTrue($found);
181+
}
151182
}

0 commit comments

Comments
 (0)