writeFileIfMissingOrChanged($file); } } /** * Remove unused files. * * @param array $files The files that needs to be there (others will be removed) * * @return void */ private function removeUnusedFiles($files) { $dirs = []; foreach ($files as $file) { list($filename, $content) = $file; $dir = dirname($filename); if (!isset($dirs[$dir])) { $dirs[$dir] = []; } $dirs[$dir][] = basename($filename); } foreach ($dirs as $dir => $filesSupposedToBeInDir) { $fileIterator = new \FilesystemIterator($dir); while ($fileIterator->valid()) { $filename = $fileIterator->getFilename(); if (!in_array($filename, $filesSupposedToBeInDir)) { unlink($dir . '/' . $filename); } $fileIterator->next(); } } } /** * Line-up test files. * * This method should make sure that the files passed in are there and are up-to-date. * - If a file is missing, it should be created. * - If a file has changed content, it should be updated * - If the directory contains a file/dir that should not be there, it should be removed * * @param array $files The files that needs to be there * * @return void */ public function lineUp($files) { // 1. Put missing files / changed files $this->writeMissingAndChangedFiles($files); // 2. Remove unused files $this->removeUnusedFiles($files); } }