4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Gherkin\Suite\Setup;
13 use Behat\Testwork\Filesystem\FilesystemLogger;
14 use Behat\Testwork\Suite\Setup\SuiteSetup;
15 use Behat\Testwork\Suite\Suite;
18 * Sets up gherkin suite in the filesystem (creates feature folders).
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
22 final class SuiteWithPathsSetup implements SuiteSetup
29 * @var null|FilesystemLogger
36 * @param string $basePath
37 * @param null|FilesystemLogger $logger
39 public function __construct($basePath, FilesystemLogger $logger = null)
41 $this->basePath = $basePath;
42 $this->logger = $logger;
48 public function supportsSuite(Suite $suite)
50 return $suite->hasSetting('paths') && is_array($suite->getSetting('paths'));
56 public function setupSuite(Suite $suite)
58 foreach ($suite->getSetting('paths') as $locator) {
59 if (0 !== strpos($locator, '@') && !is_dir($path = $this->locatePath($locator))) {
60 $this->createFeatureDirectory($path);
66 * Creates feature directory.
70 private function createFeatureDirectory($path)
72 mkdir($path, 0777, true);
75 $this->logger->directoryCreated($path, 'place your *.feature files here');
80 * Locates path from a relative one.
86 private function locatePath($path)
88 if ($this->isAbsolutePath($path)) {
92 return $this->basePath . DIRECTORY_SEPARATOR . $path;
96 * Returns whether the file path is an absolute path.
98 * @param string $file A file path
102 private function isAbsolutePath($file)
104 if ($file[0] == '/' || $file[0] == '\\'
105 || (strlen($file) > 3 && ctype_alpha($file[0])
107 && ($file[2] == '\\' || $file[2] == '/')
109 || null !== parse_url($file, PHP_URL_SCHEME)