Skip to content

Commit c7bc0fe

Browse files
committed
fix: make test more stable
1 parent 5a32252 commit c7bc0fe

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tests/OptionsTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,37 @@
1313

1414
use Composer\IO\IOInterface;
1515
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\Process\Process;
1617
use Symfony\Flex\Options;
1718

1819
class OptionsTest extends TestCase
1920
{
2021
public function testShouldWrite()
2122
{
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+
2235
$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));
2437

2538
// 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));
2740

2841
// We have an IO, and it allowed to write the file
2942
$io = $this->createMock(IOInterface::class);
3043
$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));
3245

3346
// 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));
3548
}
3649
}

0 commit comments

Comments
 (0)