/** @test */ public function it_gets_class_info_for_given_full_class_name() { // Parsed in this format from Laravels GeneratorCommand $className = 'app/ProjectNamespace/Forms/PostForm'; $expected = (object) ['namespace' => 'ProjectNamespace\\Forms', 'className' => 'PostForm']; $classInfo = $this->formGenerator->getClassInfo($className); $this->assertEquals($expected, $classInfo); }
/** @test */ public function it_gets_class_info_for_given_full_class_name() { // Parsed in this format from Laravels GeneratorCommand $className = 'VendorName\\Posts\\Form\\MainForm'; $expected = (object) ['namespace' => 'VendorName\\Posts\\Form', 'className' => 'MainForm']; $shorterName = 'VendorName\\PostForm'; $expectedForShorter = (object) ['namespace' => 'VendorName', 'className' => 'PostForm']; $classInfo = $this->formGenerator->getClassInfo($className); $shorterClassInfo = $this->formGenerator->getClassInfo($shorterName); $this->assertEquals($expected, $classInfo); $this->assertEquals($expectedForShorter, $shorterClassInfo); }
/** * Replace the namespace for the given stub. * * @param string $stub * @param string $name * @return $this */ protected function replaceNamespace(&$stub, $name) { $path = $this->option('path'); $namespace = $this->option('namespace'); if (!$namespace) { $namespace = $this->formGenerator->getClassInfo($name)->namespace; if ($path) { $namespace = str_replace('/', '\\', trim($path, '/')); } } $stub = str_replace('{{namespace}}', $namespace, $stub); return $this; }
/** * Replace the namespace for the given stub. * * @param string $stub * @param string $name * @return $this */ protected function replaceNamespace(&$stub, $name) { $stub = str_replace( '{{namespace}}', $this->formGenerator->getClassInfo($name)->namespace, $stub ); return $this; }