Skip to content

Commit

Permalink
Merge pull request #9354 from samsonasik/fix-namespaced-helper
Browse files Browse the repository at this point in the history
fix: handle namespaced helper found on Common helper
  • Loading branch information
samsonasik authored Dec 30, 2024
2 parents c0c3e02 + f551dbd commit 4cd4918
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ function helper($filenames): void
if (str_contains($filename, '\\')) {
$path = $loader->locateFile($filename, 'Helpers');

if ($path !== '') {
if ($path === false) {
throw FileNotFoundException::forFileNotFound($filename);
}

Expand Down
31 changes: 31 additions & 0 deletions tests/system/CommonHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

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;
Expand Down Expand Up @@ -148,4 +150,33 @@ function foo_bar_baz(): string

$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);
}
}

0 comments on commit 4cd4918

Please sign in to comment.