mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
fix: handle namespaced helper found on Common helper
This commit is contained in:
parent
c0c3e02e8a
commit
f551dbd0ad
@ -598,7 +598,7 @@ if (! function_exists('helper')) {
|
||||
if (str_contains($filename, '\\')) {
|
||||
$path = $loader->locateFile($filename, 'Helpers');
|
||||
|
||||
if ($path !== '') {
|
||||
if ($path === false) {
|
||||
throw FileNotFoundException::forFileNotFound($filename);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace CodeIgniter;
|
||||
|
||||
use CodeIgniter\Autoloader\Autoloader;
|
||||
use CodeIgniter\Autoloader\FileLocator;
|
||||
use CodeIgniter\Files\Exceptions\FileNotFoundException;
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
use Config\Services;
|
||||
use PHPUnit\Framework\Attributes\CoversFunction;
|
||||
@ -148,4 +150,33 @@ final class CommonHelperTest extends CIUnitTestCase
|
||||
|
||||
$this->assertSame($this->dummyHelpers[0], foo_bar_baz());
|
||||
}
|
||||
|
||||
public function testNamespacedHelperNotFound(): void
|
||||
{
|
||||
$this->expectException(FileNotFoundException::class);
|
||||
|
||||
$locator = $this->getMockLocator();
|
||||
Services::injectMock('locator', $locator);
|
||||
|
||||
helper('foo\barbaz');
|
||||
}
|
||||
|
||||
public function testNamespacedHelperFound(): void
|
||||
{
|
||||
$autoloader = new Autoloader();
|
||||
$autoloader->addNamespace('Tests\Support\Helpers', TESTPATH . '_support/Helpers');
|
||||
$locator = new FileLocator($autoloader);
|
||||
|
||||
Services::injectMock('locator', $locator);
|
||||
|
||||
$found = true;
|
||||
|
||||
try {
|
||||
helper('Tests\Support\Helpers\baguette');
|
||||
} catch (FileNotFoundException) {
|
||||
$found = false;
|
||||
}
|
||||
|
||||
$this->assertTrue($found);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user