Skip to content

Commit

Permalink
Fix in $context->get() when no appDir is specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopetkov committed May 31, 2018
1 parent 354974e commit 9aa2dcf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/App/ContextsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function get(string $filename)
$matchedDir = null;
for ($i = 0; $i < 2; $i++) { // first try - check cache, second try - update cache and check again
foreach (self::$dirsCache as $dir) {
if (substr($filename, 0, $dir[1]) === $dir[0] || $dir[0] === $filename . DIRECTORY_SEPARATOR) {
if ($dir[1] > 0 && (substr($filename, 0, $dir[1]) === $dir[0] || $dir[0] === $filename . DIRECTORY_SEPARATOR)) {
$matchedDir = $dir[0];
break;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ public function testAddonContext()
// $this->assertTrue($content === 'data:image/svg+xml;base64,c2FtcGxlLXN2Zy1jb250ZW50');
}

/**
*
*/
public function testAddonContextWithNoAppContext()
{
$app = $this->getApp(['appDir' => null]);
$addonDir = $app->config->addonsDir . DIRECTORY_SEPARATOR . 'tempaddon' . uniqid() . DIRECTORY_SEPARATOR;

$this->createFile($addonDir . 'index.php', '<?php ');

BearFramework\Addons::register('tempaddon', $addonDir);
$app->addons->add('tempaddon');

$context = $app->context->get($addonDir . 'index.php');
$this->assertTrue($context->dir === rtrim($addonDir, DIRECTORY_SEPARATOR));

$context = $app->context->get($addonDir);
$this->assertTrue($context->dir === rtrim($addonDir, DIRECTORY_SEPARATOR));
}

/**
*
*/
Expand Down

0 comments on commit 9aa2dcf

Please sign in to comment.