/** * @param string $filepath * * @return string */ public function render($filepath) { $path = Path::combine($this->baseFolder, $filepath); ob_start(); include $path; return ob_get_clean(); }
public function testDelete_WhenFolderMissing_MustNotThrow() { $base = Path::combine(self::$base, 'delete_missing'); $this->assertFalse(is_dir($base), 'Unable to set up test'); Folder::delete($base); $this->assertFalse(is_dir($base)); }
/** * Format an array diff by using plain PHP templates. * * @param \nochso\Diff\Diff $diff * * @return mixed */ public function format(Diff $diff) { $this->diff = $diff; $diff->escapeText($this->escaper); ob_start(); include Path::combine($this->basePath, $this->path); return ob_get_clean(); }
/** * @param array $dirs * * @return array */ protected function getVcsIgnoreFiles(array $dirs) { $files = ['.gitignore', '.hgignore', '_darcs/prefs/boring']; $filepaths = []; foreach ($dirs as $dir) { foreach ($files as $file) { $filepaths[] = Path::combine($dir, $file); } } return $filepaths; }
/** * fromFile returns tests from a file and requires that the first section is a name/description of the dataset. * * @param string $path * @param string $testSeparator * @param string $parameterSeparator * * @return array */ public static function fromFile($path, $testSeparator = '###', $parameterSeparator = '===') { $paramSplitter = '/\\n?' . $parameterSeparator . '\\n?/'; $testSplitter = '/\\n?' . $testSeparator . '\\n?/'; $path = Path::combine(__DIR__ . '/fixtures', $path); $rawTests = preg_split($testSplitter, file_get_contents($path)); $tests = []; $testName = pathinfo($path, PATHINFO_FILENAME); foreach ($rawTests as $rawTest) { $params = preg_split($paramSplitter, $rawTest); $tests[$testName . ' ' . $params[0]] = array_slice($params, 1); } return $tests; }
while ($n--) { $phpCsFixer->run($parameter); } chdir(__DIR__); }, 'php-cs-fixer Symfony', "```bash\n\$ " . $phpCsFixer->getCommand() . "\n```"); $phpFmt = Exec::create('fmt.phar', '--dry-run', '--psr'); $unit->addClosure(function ($n, $parameter) use($phpFmt) { chdir($parameter); while ($n--) { $phpFmt->run($parameter); } chdir(__DIR__); }, 'phpfmt PSR-2', "```bash\n\$ " . $phpFmt->getCommand() . "\n```"); foreach ($repos as $repoName => $repo) { $repoDir = Path::combine($tmpDir, 'repo', $repoName); if (!is_dir($repoDir)) { $clone = Exec::create('git')->run('clone', '--depth=1', '--single-branch', $repo, $repoDir); } $reset = Exec::create('git')->run('--git-dir=' . $repoDir . '/.git', '--work-tree=' . $repoDir, 'reset', '--hard', 'HEAD'); $phpCsCache = Path::combine($repoDir, '.php_cs.cache'); if (is_file($phpCsCache)) { unlink($phpCsCache); } $phpCsConfig = Path::combine($repoDir, '.php_cs'); if (is_file($phpCsConfig)) { unlink($phpCsConfig); } $unit->addParam(new Parameter($repoDir, $repoName, "[{$repo}]({$repo})")); } $report->unitList->add($unit); $report->run();
/** * @covers nochso\Omni\VcsVersionInfo::extractTag * @covers nochso\Omni\VcsVersionInfo::readMercurial */ public function testMercurial() { if (!OS::hasBinary('hg') || getenv('TRAVIS')) { $this->markTestSkipped('hg (Mercurial) has to be available for this test.'); } $repoDir = Path::combine(self::$base, 'hg'); Folder::ensure($repoDir); // Set up a new repo with a single committed file Exec::create('hg')->run('init', $repoDir); // From now on prefix all 'hg' commands with repo and cwd path $hg = Exec::create('hg', '--repository', $repoDir, '--cwd', $repoDir); $fooPath = Path::combine($repoDir, 'foo.txt'); touch($fooPath); $hg->run('add', $fooPath); $hg->run('commit', '-m init', '-u', 'Unit tester'); $vcs = new VcsVersionInfo('name', null, $repoDir); $this->assertRegExp('/^[0-9a-f]+$/', $vcs->getVersion(), 'Version without a tag must be rev hash'); file_put_contents($fooPath, 'throw dirt at tree'); $vcs = new VcsVersionInfo('name', null, $repoDir); $this->assertRegExp('/^[0-9a-f]+-dirty$/', $vcs->getVersion(), 'Dirty version without a tag must end in -dirty'); $hg->run('tag', '-u', 'Unit tester', '1.0.0'); $hg->run('update', '1.0.0'); $vcs = new VcsVersionInfo('name', null, $repoDir); $this->assertSame('1.0.0-dirty', $vcs->getVersion(), 'Dirty version with a tag must end in -dirty'); $hg->run('update', '--clean', '1.0.0'); $vcs = new VcsVersionInfo('name', null, $repoDir); $this->assertSame('1.0.0', $vcs->getVersion(), 'Clean version at specific tag'); file_put_contents($fooPath, 'move on to next commit'); $hg->run('commit', '-m move-on', '-u', 'Unit tester'); $vcs = new VcsVersionInfo('name', null, $repoDir); $this->assertRegExp('/^1\\.0\\.0-1-m[0-9a-f]+$/', $vcs->getVersion(), 'Commit after latest tag'); file_put_contents($fooPath, 'throw more dirt at tree'); $vcs = new VcsVersionInfo('name', null, $repoDir); $this->assertRegExp('/^1\\.0\\.0-1-m[0-9a-f]+-dirty$/', $vcs->getVersion(), 'Commit after latest tag'); Folder::delete($repoDir); }
/** * @dataProvider isAbsoluteProvider */ public function testIsAbsolute($expected, $path, $message = '') { $this->assertSame($expected, Path::isAbsolute($path), $message); }
/** * @param string|null $overrideTarget * * @return string */ public function getTargetFilepath($overrideTarget = null) { $target = $overrideTarget; // --target is optional. If empty, try the frontmatter key. if ($target === null) { $target = $this->frontmatter->get('target', null); } // Still empty: try replacing WRITEME* with README* if ($target === null) { // Only work with the actual file name $filename = basename($this->filepath); if (preg_match('/^(writeme)((\\..+)?)/i', $filename, $matches)) { $name = $matches[1]; $extension = $matches[2]; if (strtoupper($name) === $name) { $target = 'README' . $extension; } else { $target = 'readme' . $extension; } $target = Path::combine(dirname($this->filepath), $target); } } if ($target === null) { throw new \RuntimeException(sprintf('Could not guess target file name from CLI option, frontmatter key "target" or source file name "%s".', $this->filepath)); } return $target; }
/** * @param string $filepath * @param array $folders * * @return array */ private function makeFoldersRelativeToFile($filepath, $folders) { $fileFolder = dirname($filepath); if ($fileFolder === '.') { $fileFolder = ''; } $combiner = function ($path) use($fileFolder) { if (!Path::isAbsolute($path)) { return Path::combine($fileFolder, $path); } return $path; }; return array_map($combiner, $folders); }
public function saveTargetProvider() { $tempFolder = Path::combine(sys_get_temp_dir(), 'nochso_writeme_test'); Folder::ensure($tempFolder); return ['Specified target path' => [new Document(''), Path::combine($tempFolder, 'target.md'), Path::combine($tempFolder, 'target.md')], 'WRITEME turns to README' => [new Document('', Path::combine($tempFolder, 'WRITEME.md')), null, Path::combine($tempFolder, 'README.md')], 'WRITEME turns to README (case insensitive)' => [new Document('', Path::combine($tempFolder, 'writeme')), null, Path::combine($tempFolder, 'readme')], 'Get target path from frontmatter' => [new Document("---\ntarget: " . Path::combine($tempFolder, 'target.md') . "\n---"), null, Path::combine($tempFolder, 'target.md')]]; }