/** * Get the directory to use * * The --dir option takes priority over everything else; * then we convert the --namespace into a PSR-0 directory; * finally we use the default directory * * @param array $details * @param Sanitizer $sanitizer Instance of Sanitizer * * @return string */ public function getDirectory($details, $sanitizer) { if (!empty($details['dir'])) { $dir = $details['dir']; } elseif (!empty($details['namespace'])) { $dir = $sanitizer->convertNamespaceToPath($details['namespace']); } else { $dir = 'app/Forms'; } return $dir; }
public function it_gets_the_full_form_path(Sanitizer $sanitizer, Filesystem $filesystem) { /* * This test duplicates some code as it also tests the makeSureFinalDirectoryExists */ define('DS', DIRECTORY_SEPARATOR); $details = ['namespace' => 'This\\Is\\The\\Test\\Namespace', 'dir' => 'This/Is/Yet/Another/Test/Directory', 'className' => 'FooBar']; $sanitizer->stripDoubleDirectorySeparators('This/Is/Yet/Another/Test/Directory/FooBarForm.php')->willReturn('This/Is/Yet/Another/Test/Directory/FooBarForm.php'); /* * Mock the filesystem and tell the method that the directory already exists otherwise it will go & create it */ $filesystem->isDirectory('This/Is/Yet/Another/Test/Directory')->willReturn(true); $this->getFullPath($sanitizer, $details, $filesystem)->shouldReturn('This/Is/Yet/Another/Test/Directory/FooBarForm.php'); }