Skip to content

Commit

Permalink
Merge branch 'cli-config-option'
Browse files Browse the repository at this point in the history
  • Loading branch information
seregazhuk committed Oct 4, 2019
2 parents a748c9d + 42d1113 commit 903dd6a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Any output from this script is prefixed with `[php-watcher]`, otherwise all
PHP-Watcher supports customization of its behavior with config files. The
file for options may be named `.php-watcher.yml`, `php-watcher.yml` or `php
-watcher.yml.dist`. The tool will look for a file in the current working directory in that order.
An alternative local configuration file can be specified with the `--config
<file>` option.

The specificity is as follows, so that a command line argument will always override the config file settings:

Expand Down
36 changes: 36 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types=1);

namespace tests;

use tests\Helper\Filesystem;
use tests\Helper\WatcherRunner;
use tests\Helper\WatcherTestCase;

final class ConfigTest extends WatcherTestCase
{
/** @test */
public function command_line_options_override_config_values(): void
{
$configFile = Filesystem::createConfigFile(['watch' => ['directory-to-watch']]);
$fileToWatch = Filesystem::createHelloWorldPHPFile();

$watcher = (new WatcherRunner())->run($fileToWatch, ['--watch', 'tests', '--config', $configFile]);
sleep(1);

$output = $watcher->getOutput();
$this->assertStringNotContainsString('directory-to-watch', $output);
}

/** @test */
public function it_can_use_config_path_from_command_line_arg(): void
{
$configFile = Filesystem::createConfigFile(['watch' => ['directory-to-watch']]);
$fileToWatch = Filesystem::createHelloWorldPHPFile();

$watcher = (new WatcherRunner())->run($fileToWatch, ['--config', $configFile]);
sleep(1);

$output = $watcher->getOutput();
$this->assertStringContainsString('directory-to-watch', $output);
}
}

0 comments on commit 903dd6a

Please sign in to comment.