diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index b61a20958fe1..5edaefd3ff06 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1174,11 +1174,11 @@ public function getNamespace() return $this->namespace; } - $composer = json_decode(file_get_contents(base_path('composer.json')), true); + $composer = json_decode(file_get_contents($this->basePath('composer.json')), true); foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) { foreach ((array) $path as $pathChoice) { - if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) { + if (realpath($this->path()) === realpath($this->basePath($pathChoice))) { return $this->namespace = $namespace; } } diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index 3ad5ad8d8eb2..292214d7e409 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -309,6 +309,15 @@ public function testBootedCallbacks() $this->assertEquals(4, $counter); } + + public function testGetNamespace() + { + $app1 = new Application(realpath(__DIR__.'/fixtures/laravel1')); + $app2 = new Application(realpath(__DIR__.'/fixtures/laravel2')); + + $this->assertSame('Laravel\\One\\', $app1->getNamespace()); + $this->assertSame('Laravel\\Two\\', $app2->getNamespace()); + } } class ApplicationBasicServiceProviderStub extends ServiceProvider diff --git a/tests/Foundation/fixtures/laravel1/composer.json b/tests/Foundation/fixtures/laravel1/composer.json new file mode 100644 index 000000000000..a0ee8154c7b9 --- /dev/null +++ b/tests/Foundation/fixtures/laravel1/composer.json @@ -0,0 +1,7 @@ +{ + "autoload": { + "psr-4": { + "Laravel\\One\\": "app/" + } + } +} diff --git a/tests/Foundation/fixtures/laravel2/composer.json b/tests/Foundation/fixtures/laravel2/composer.json new file mode 100644 index 000000000000..81ef5ca3c3f4 --- /dev/null +++ b/tests/Foundation/fixtures/laravel2/composer.json @@ -0,0 +1,7 @@ +{ + "autoload": { + "psr-4": { + "Laravel\\Two\\": "app/" + } + } +}