Skip to content

Commit 9b9ec82

Browse files
authored
Merge pull request #21 from dotkernel/issue-20
Issue #20: Increased coverage
2 parents 71de84a + 99f5351 commit 9b9ec82

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

test/ApplicationTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Dot\Cli\Application;
88
use Dot\Cli\FileLocker;
99
use Dot\Cli\FileLockerInterface;
10+
use Exception;
1011
use PHPUnit\Framework\TestCase;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Input\StringInput;
@@ -20,7 +21,25 @@ class ApplicationTest extends TestCase
2021
/**
2122
* @throws Throwable
2223
*/
23-
public function testDoRun(): void
24+
public function testDoRunWillFailWithoutLockFile(): void
25+
{
26+
$fileLocker = $this->createMock(FileLockerInterface::class);
27+
28+
$exception = new Exception();
29+
$fileLocker->expects($this->once())->method('lock')->willThrowException($exception);
30+
31+
$input = new StringInput('list');
32+
$output = new BufferedOutput();
33+
34+
$application = new Application($fileLocker, $this->getConfig()['dot_cli']);
35+
$result = $application->doRun($input, $output);
36+
$this->assertSame($result, Command::FAILURE);
37+
}
38+
39+
/**
40+
* @throws Throwable
41+
*/
42+
public function testDoRunWillSucceed(): void
2443
{
2544
$config = $this->getConfig();
2645

test/Factory/ApplicationFactoryTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Psr\Container\ContainerExceptionInterface;
1515
use Psr\Container\ContainerInterface;
1616
use Psr\Container\NotFoundExceptionInterface;
17+
use Symfony\Component\EventDispatcher\EventDispatcher;
1718

1819
class ApplicationFactoryTest extends TestCase
1920
{
@@ -129,12 +130,13 @@ public function testWillCreateApplication(): void
129130

130131
$container->method('has')->willReturnMap([
131132
['config', true],
132-
['Dot\Cli\Factory\SymfonyEventDispatcher', false],
133+
['Dot\Cli\Factory\SymfonyEventDispatcher', true],
133134
[FileLockerInterface::class, true],
134135
]);
135136

136137
$container->method('get')->willReturnMap([
137138
['config', $this->getConfig()],
139+
['Dot\Cli\Factory\SymfonyEventDispatcher', new EventDispatcher()],
138140
[FileLockerInterface::class, $fileLocker],
139141
]);
140142

test/FileLockerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ public function testWillNotUnlockWithoutValidCommandName(): void
134134
$this->assertNull($fileLocker->getLockFile());
135135
}
136136

137+
public function testWillNotUnlockWhenEnabledAndWithoutValidCommandName(): void
138+
{
139+
$config = $this->getConfig();
140+
141+
$fileLocker = new FileLocker(true, $config['dirPath']);
142+
$this->assertNull($fileLocker->getLockFile());
143+
$fileLocker->unlock();
144+
$this->assertInstanceOf(FileLocker::class, $fileLocker);
145+
$this->assertNull($fileLocker->getLockFile());
146+
}
147+
137148
/**
138149
* @throws Exception
139150
*/

0 commit comments

Comments
 (0)