Ejemplo n.º 1
0
 /**
  * Removes any files that don't pass regex validation
  *
  * @param   ConfigData $config ConfigData object
  * @return  array
  */
 public function filterFilesWithRegex(ConfigData $config)
 {
     $include = $this->getIncludeFiles($config->getAllDetectedFiles(), $config->getIncludeFileRegex());
     $exclude = $this->getExcludeFiles($config->getAllDetectedFiles(), $config->getExcludeFileRegex());
     $validFiles = array_values(array_diff($include, $exclude));
     return $validFiles;
 }
 /**
  * Process the file queue into usable objects
  *
  * Returns an array of DataContainer objects for use in the CodeWorker.
  *
  * @return  array
  */
 public function processFiles()
 {
     foreach ($this->config->getFilesToMock() as $file) {
         try {
             $fileData = $this->processFile($file, $this->config);
             $this->processDataWithWorkers($fileData);
         } catch (MockMakerException $e) {
             echo "\nMockMakerException: {$e->getMessage()}\n";
             continue;
         }
     }
     return implode(PHP_EOL . str_repeat("-", 50) . PHP_EOL, $this->mockCode);
 }
Ejemplo n.º 3
0
 /**
  * Sets a 'base' namespace for mocks
  *
  * This is used when generating mock code. MockMaker can make
  * a best-guess attempt at generating this for you, but it's
  * difficult to be psychic and get it right. Basically, whatever
  * the valid namespace should be for Whatever\Save\Path\You\Picked
  * should be set here. It will be used for both top-level 'read dir'
  * classes, and appended to for sub-level classes detected during
  * a recursive read.
  *
  * @param   string $namespace
  * @return  MockMaker
  */
 public function useBaseNamespaceForMocks($namespace)
 {
     $this->config->setMockFileBaseNamespace($namespace);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Creates and populates a EntityData object with the basic information it needs
  *
  * @param   string     $file
  * @param   ConfigData $config
  * @return  EntityData
  * @throws  MockMakerException
  */
 private function getBasicEntityInformation($file, ConfigData $config)
 {
     $obj = new EntityData();
     $obj->getFileData()->setFileName(PathWorker::getLastElementInPath($file))->setFileDirectory(PathWorker::getPathUpToName($file) . '/')->setFullFilePath($file);
     $obj->setClassName(PathWorker::getClassNameFromFilePath($file))->setClassNamespace($this->determineClassNamespace($file, $config->getProjectRootPath()))->setReflectionClass($this->createReflectionClass($obj))->setClassType($this->getClassType($obj->getReflectionClass()));
     return $obj;
 }
Ejemplo n.º 5
0
 /**
  * Gathers all files found in read directories
  *
  * @param   ConfigData $config
  * @return  array
  */
 private function findAllTargetFiles(ConfigData $config)
 {
     return DirectoryWorker::getFilesFromReadDirs($config->getReadDirectories(), $config->getRecursiveRead());
 }
Ejemplo n.º 6
0
 /**
  * Generates the mock file's namespace
  *
  * If a mockFileBaseNamespace is not defined, this will use composer
  * to try to find a valid one. Failing that, a wild-assed-guess is returned.
  *
  * @param   string     $mockSavePath    Fully qualified file save path of file to be mocked
  * @param   ConfigData $config          ConfigData object
  *                                      Required data points are:
  *                                      - getMockFileBaseNamespace()
  *                                      - getProjectRootPath()
  *                                      - getMockWriteDir()
  * @return  string
  */
 private function generateMockFileNamespace($mockSavePath, ConfigData $config)
 {
     $wagNamespace = PathWorker::convertFilePathToClassPath($mockSavePath, $config->getProjectRootPath());
     if ($config->getMockFileBaseNamespace()) {
         return $this->determineWithBaseNamespace($mockSavePath, $config->getMockFileBaseNamespace());
     }
     $composerWorker = new ComposerWorker();
     $composerData = $composerWorker->getNamespaceFromComposer($mockSavePath, $config->getProjectRootPath());
     if (!$composerData) {
         return $wagNamespace;
     }
     $relNamespacePath = str_replace($composerData['path'], '', $mockSavePath);
     $namespace = $composerData['namespace'] . str_replace('/', '\\', $relNamespacePath);
     return rtrim($namespace, '\\');
 }