Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests to check config logic #6

Merged
merged 2 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}