app['config'], $this->app['view'], null, false); // Clear aliases and macros to have a small output file AliasLoader::getInstance()->setAliases([]); Request::flushMacros(); // Generate the helper file and return the content $content = $generator->generate(); $this->assertStringContainsString('namespace Facades\Illuminate\Foundation\Exceptions {', $content, 'Could not find Facades\Illuminate\Foundation\Exceptions namespace in the generated helper file.'); $this->assertStringContainsString('namespace Facades\App\Exceptions {', $content, 'Could not find Facades\App\Exceptions namespace in the generated helper file.'); $parsed = collect((new Php7(new Emulative()))->parse($content) ?: []); // test the Facades\Illuminate\Foundation\Exceptions namespace in the generated helper file $frameworkExceptionsNamespace = $parsed->first(function ($stmt) { return ($stmt instanceof Namespace_) && $stmt->name->toString() === 'Facades\Illuminate\Foundation\Exceptions'; }); $this->assertNotNull($frameworkExceptionsNamespace, 'Could not find Facades\Illuminate\Foundation\Exceptions namespace'); $this->assertSame('Facades\Illuminate\Foundation\Exceptions', $frameworkExceptionsNamespace->name->toString()); $this->verifyNamespace($frameworkExceptionsNamespace, 'Illuminate\Foundation\Exceptions\Handler'); // test the Facades\App\Exceptions namespace in the generated helper file $appExceptionsNamespace = $parsed->first(function ($stmt) { return ($stmt instanceof Namespace_) && $stmt->name->toString() === 'Facades\App\Exceptions'; }); $this->assertNotNull($appExceptionsNamespace, 'Could not find Facades\App\Exceptions namespace'); $this->assertSame('Facades\App\Exceptions', $appExceptionsNamespace->name->toString()); $this->verifyNamespace($appExceptionsNamespace, 'App\Exceptions\Handler'); } private function verifyNamespace(Namespace_ $namespace, $target) { $stmts = collect($namespace->stmts); $this->assertInstanceOf(Class_::class, $stmts[0], 'Expected instance of Class_'); $statement = $stmts[0]; $this->assertArrayHasKey('comments', $statement->getAttributes()); $this->assertStringContainsString('@mixin \\' . $target, $statement->getAttributes()['comments'][0]->getText(), 'Mixin comment not found'); $this->assertSame(class_basename($target), $statement->name->toString(), 'Class name not found'); $this->assertSame($target, $statement->extends->toString(), 'Class extends not found'); } protected function getPackageProviders($app) { return [IdeHelperServiceProvider::class]; } }