Skip to content

Commit

Permalink
tests FileReaderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Wtyd committed Jan 27, 2025
1 parent 2e5dcdd commit ba33043
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ConfigurationFile/FileReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function findConfigurationFile(): string

foreach ($possiblePaths as $path) {
if (file_exists($path)) {
// dd($path);
$configFile = $path;
break;
}
Expand Down
42 changes: 41 additions & 1 deletion tests/Unit/ConfigurationFile/FileReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace Tests\Unit\ConfigurationFile;

use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Tests\Utils\ConfigurationFileBuilder;
use Tests\Utils\{
ConfigurationFileBuilder,
TestCase\UnitTestCase,
Traits\VirtualFileSystemTrait
};
use Wtyd\GitHooks\ConfigurationFile\Exception\ConfigurationFileNotFoundException;
use Wtyd\GitHooks\ConfigurationFile\Exception\ParseConfigurationFileException;
use Wtyd\GitHooks\ConfigurationFile\FileReaderFake;

/**
Expand Down Expand Up @@ -90,4 +92,42 @@ function it_searchs_configuration_file_first_in_the_root_directory()

$this->assertNotEquals($qaFileArray, $fileReaded);
}

/**
* @test
* @expectedException \Wtyd\GitHooks\ConfigurationFile\Exception\ConfigurationFileNotFoundException
*/
function it_throws_exception_when_configuration_file_not_found()
{
$this->createFileSystem([]);
$this->expectException(ConfigurationFileNotFoundException::class);
$this->fileReader->readFile();
}

/**
* @test
* @expectedException \Wtyd\GitHooks\ConfigurationFile\Exception\ParseConfigurationFileException
*/
function it_throws_exception_when_yaml_file_is_invalid()
{
$invalidYaml = "invalid: yaml: content";
$fileSystemStructure = ['githooks.yml' => $invalidYaml];
$this->createFileSystem($fileSystemStructure);

$this->expectException(ParseConfigurationFileException::class);
$this->fileReader->readFile();
}

/**
* @test
* @expectedException \InvalidArgumentException
*/
function it_throws_exception_when_file_type_is_not_supported()
{
$fileSystemStructure = ['githooks.txt' => 'unsupported content'];
$this->createFileSystem($fileSystemStructure);

$this->expectException(ConfigurationFileNotFoundException::class);
$this->fileReader->readFile();
}
}

0 comments on commit ba33043

Please sign in to comment.