Skip to content

Commit

Permalink
fix empty config didnt lead to use default config correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Dec 23, 2023
1 parent 7b23380 commit 53918ae
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
### Fixed

- Fixed bug where the **DuplicateContentRule** validation didn't work for single-hierarchy storages like INI, ...
- If an empty config value was provided, it did not correctly use the default phpunuhi.xml file.

### Removed

Expand Down
2 changes: 2 additions & 0 deletions src/Traits/CommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ protected function getConfigFile(InputInterface $input): string
$configFile = '';
}

$configFile = trim($configFile);

if ($configFile === '' || $configFile === '0') {
$configFile = 'phpunuhi.xml';
}
Expand Down
37 changes: 37 additions & 0 deletions tests/phpunit/Traits/CommandTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\TestCase;
use PHPUnuhi\PHPUnuhi;
use PHPUnuhi\Traits\CommandTrait;
use Symfony\Component\Console\Input\InputInterface;

class CommandTraitTest extends TestCase
{
Expand All @@ -20,4 +21,40 @@ public function testShowHeader(): void

$this->showHeader();
}

/**
* @return void
*/
public function testGetConfigFileWithCustomValue(): void
{
$input = $this->createMock(InputInterface::class);
$input->method('getOption')->willReturn('test.xml');

$config = $this->getConfigFile($input);

$expected = getcwd() . '/test.xml';

$this->assertEquals($expected, $config);
}

/**
* @testWith [ null ]
* [ "" ]
* [ " " ]
*
* @param $option
* @return void
*/
public function testGetConfigFileWithoutValueGivesDefaultConfig($option): void
{
$input = $this->createMock(InputInterface::class);
$input->method('getOption')->willReturn($option);

$config = $this->getConfigFile($input);

$expected = getcwd() . '/phpunuhi.xml';

$this->assertEquals($expected, $config);
}

}

0 comments on commit 53918ae

Please sign in to comment.