Skip to content

Commit ba33043

Browse files
committed
tests FileReaderTest
1 parent 2e5dcdd commit ba33043

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/ConfigurationFile/FileReader.php

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function findConfigurationFile(): string
6969

7070
foreach ($possiblePaths as $path) {
7171
if (file_exists($path)) {
72+
// dd($path);
7273
$configFile = $path;
7374
break;
7475
}

tests/Unit/ConfigurationFile/FileReaderTest.php

+41-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
namespace Tests\Unit\ConfigurationFile;
44

55
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
6-
use Tests\Utils\ConfigurationFileBuilder;
76
use Tests\Utils\{
7+
ConfigurationFileBuilder,
88
TestCase\UnitTestCase,
99
Traits\VirtualFileSystemTrait
1010
};
11+
use Wtyd\GitHooks\ConfigurationFile\Exception\ConfigurationFileNotFoundException;
12+
use Wtyd\GitHooks\ConfigurationFile\Exception\ParseConfigurationFileException;
1113
use Wtyd\GitHooks\ConfigurationFile\FileReaderFake;
1214

1315
/**
@@ -90,4 +92,42 @@ function it_searchs_configuration_file_first_in_the_root_directory()
9092

9193
$this->assertNotEquals($qaFileArray, $fileReaded);
9294
}
95+
96+
/**
97+
* @test
98+
* @expectedException \Wtyd\GitHooks\ConfigurationFile\Exception\ConfigurationFileNotFoundException
99+
*/
100+
function it_throws_exception_when_configuration_file_not_found()
101+
{
102+
$this->createFileSystem([]);
103+
$this->expectException(ConfigurationFileNotFoundException::class);
104+
$this->fileReader->readFile();
105+
}
106+
107+
/**
108+
* @test
109+
* @expectedException \Wtyd\GitHooks\ConfigurationFile\Exception\ParseConfigurationFileException
110+
*/
111+
function it_throws_exception_when_yaml_file_is_invalid()
112+
{
113+
$invalidYaml = "invalid: yaml: content";
114+
$fileSystemStructure = ['githooks.yml' => $invalidYaml];
115+
$this->createFileSystem($fileSystemStructure);
116+
117+
$this->expectException(ParseConfigurationFileException::class);
118+
$this->fileReader->readFile();
119+
}
120+
121+
/**
122+
* @test
123+
* @expectedException \InvalidArgumentException
124+
*/
125+
function it_throws_exception_when_file_type_is_not_supported()
126+
{
127+
$fileSystemStructure = ['githooks.txt' => 'unsupported content'];
128+
$this->createFileSystem($fileSystemStructure);
129+
130+
$this->expectException(ConfigurationFileNotFoundException::class);
131+
$this->fileReader->readFile();
132+
}
93133
}

0 commit comments

Comments
 (0)