|
13 | 13 |
|
14 | 14 | use Composer\IO\IOInterface;
|
15 | 15 | use PHPUnit\Framework\TestCase;
|
| 16 | +use Symfony\Component\Process\Process; |
16 | 17 | use Symfony\Flex\Options;
|
17 | 18 |
|
18 | 19 | class OptionsTest extends TestCase
|
19 | 20 | {
|
20 | 21 | public function testShouldWrite()
|
21 | 22 | {
|
| 23 | + @mkdir(FLEX_TEST_DIR); |
| 24 | + (new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun(); |
| 25 | + (new Process(['git', 'config', 'user.name', 'Unit test'], FLEX_TEST_DIR))->mustRun(); |
| 26 | + (new Process(['git', 'config', 'user.email', ''], FLEX_TEST_DIR))->mustRun(); |
| 27 | + |
| 28 | + $filePath = FLEX_TEST_DIR . '/a.txt'; |
| 29 | + file_put_contents($filePath, 'a'); |
| 30 | + (new Process(['git', 'add', '-A'], FLEX_TEST_DIR))->mustRun(); |
| 31 | + (new Process(['git', 'commit', '-m', 'setup of original files'], FLEX_TEST_DIR))->mustRun(); |
| 32 | + |
| 33 | + file_put_contents($filePath, 'b'); |
| 34 | + |
22 | 35 | $this->assertTrue((new Options([], null))->shouldWriteFile('non-existing-file.txt', false, false));
|
23 |
| - $this->assertFalse((new Options([], null))->shouldWriteFile(__FILE__, false, false)); |
| 36 | + $this->assertFalse((new Options([], null))->shouldWriteFile($filePath, false, false)); |
24 | 37 |
|
25 | 38 | // We don't have an IO, so we don't write the file
|
26 |
| - $this->assertFalse((new Options([], null))->shouldWriteFile(__FILE__, true, false)); |
| 39 | + $this->assertFalse((new Options([], null))->shouldWriteFile($filePath, true, false)); |
27 | 40 |
|
28 | 41 | // We have an IO, and it allowed to write the file
|
29 | 42 | $io = $this->createMock(IOInterface::class);
|
30 | 43 | $io->expects($this->once())->method('askConfirmation')->willReturn(true);
|
31 |
| - $this->assertTrue((new Options([], $io))->shouldWriteFile(__FILE__, true, false)); |
| 44 | + $this->assertTrue((new Options([], $io))->shouldWriteFile($filePath, true, false)); |
32 | 45 |
|
33 | 46 | // We skip all questions, so we're able to write
|
34 |
| - $this->assertTrue((new Options([], null))->shouldWriteFile(__FILE__, true, true)); |
| 47 | + $this->assertTrue((new Options([], null))->shouldWriteFile($filePath, true, true)); |
35 | 48 | }
|
36 | 49 | }
|
0 commit comments