forked from symfony/flex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilesManagerTest.php
More file actions
65 lines (52 loc) · 2.27 KB
/
FilesManagerTest.php
File metadata and controls
65 lines (52 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Flex\Tests;
use Composer\IO\IOInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
use Symfony\Flex\FilesManager;
use Symfony\Flex\Lock;
class FilesManagerTest extends TestCase
{
public function testShouldWrite()
{
@mkdir(FLEX_TEST_DIR);
(new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun();
(new Process(['git', 'config', 'user.name', 'Unit test'], FLEX_TEST_DIR))->mustRun();
(new Process(['git', 'config', 'user.email', ''], FLEX_TEST_DIR))->mustRun();
$filePath = FLEX_TEST_DIR.'/a.txt';
file_put_contents($filePath, 'a');
(new Process(['git', 'add', '-A'], FLEX_TEST_DIR))->mustRun();
(new Process(['git', 'commit', '-m', 'setup of original files'], FLEX_TEST_DIR))->mustRun();
file_put_contents($filePath, 'b');
$io = $this->getMockBuilder(IOInterface::class)->getMock();
$io->method('askConfirmation')->willReturn(true);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
$lock->method('all')->willReturn([
'symfony/my-package' => [
'files' => [
$filePath,
],
],
]);
$filesManager = new FilesManager($io, $lock, FLEX_TEST_DIR);
// We need to set the writtenFiles property to reset the state
$reflection = new \ReflectionProperty(FilesManager::class, 'writtenFiles');
$reflection->setAccessible(true);
$this->assertTrue($filesManager->shouldWriteFile('non-existing-file.txt', false, false));
$this->assertFalse($filesManager->shouldWriteFile($filePath, false, false));
// It allowed to write the file
$reflection->setValue($filesManager, []);
$this->assertTrue($filesManager->shouldWriteFile($filePath, true, false));
// We skip all questions, so we're able to write
$reflection->setValue($filesManager, []);
$this->assertTrue($filesManager->shouldWriteFile($filePath, true, true));
}
}