Skip to content

Commit

Permalink
feature/006-support-dotfiles (#13)
Browse files Browse the repository at this point in the history
* feature/006-support-dotfiles

* remove

* refactor search for config file

* restore output

* clean up

* edit readme

* edit changelog
  • Loading branch information
mikeerickson authored and freekmurze committed Aug 5, 2017
1 parent 3e7fd9d commit 11f6e5a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `phpunit-watcher` will be documented in this file

## 1.2.0 - 2017-08-05

- check parent directories for config file

## 1.1.0 - 2017-08-02

- add interactive commands
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ watch:
fileMask: '*.php'
```
If a such a config file does not exist in the project directory, the tool will check if the file exists in any of the parent directories of the project directory.
Want to pass some arguments to PHPUnit no problem, just tack them on:
```bash
Expand Down
24 changes: 23 additions & 1 deletion src/WatcherCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class WatcherCommand extends Command
{
const PHPUNIT_WATCH_CONFIG_FILENAME = "/.phpunit-watcher.yml";

protected function configure()
{
$this->setName('watch')
Expand Down Expand Up @@ -40,7 +42,7 @@ protected function determineOptions(InputInterface $input): array

protected function getOptionsFromConfigFile(): array
{
$configFile = getcwd().'/.phpunit-watcher.yml';
$configFile = $this->getConfigFileLocation();

if (! file_exists($configFile)) {
return [];
Expand All @@ -49,6 +51,26 @@ protected function getOptionsFromConfigFile(): array
return Yaml::parse(file_get_contents($configFile));
}

protected function getConfigFileLocation()
{
$configName = '.phpunit-watcher.yml';

$configDirectory = getcwd();

while(is_dir($configDirectory)) {
$configFullPath = "{$configDirectory}/{$configName}";

if (file_exists($configFullPath)) {
return $configFullPath;
}

if ($configDirectory === DIRECTORY_SEPARATOR) {
return;
}
$configDirectory = dirname($configDirectory);
};
}

protected function displayOptions(array $options, InputInterface $input, OutputInterface $output)
{
$output = new SymfonyStyle($input, $output);
Expand Down

0 comments on commit 11f6e5a

Please sign in to comment.