|
11 | 11 | */ |
12 | 12 | class FilesystemTest extends \PHPUnit_Framework_TestCase |
13 | 13 | { |
14 | | - use PHPMock; |
15 | | - |
16 | | - public function testCanSymlinkAFile() |
| 14 | + /** |
| 15 | + * @var Filesystem |
| 16 | + */ |
| 17 | + private $filesystem; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var string |
| 21 | + */ |
| 22 | + private $testDirectory; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var string |
| 26 | + */ |
| 27 | + private $testFile; |
| 28 | + |
| 29 | + public function setUp() |
17 | 30 | { |
18 | | - vfsStream::setup(); |
19 | | - |
20 | | - file_put_contents('vfs://root/foo', 'test'); |
21 | | - |
22 | | - $symlink = $this |
23 | | - ->getFunctionMock('Tooly\Script\Helper', 'symlink') |
24 | | - ->expects($this->once()) |
25 | | - ->willReturn(true); |
26 | | - |
27 | | - $filesystem = new Filesystem; |
28 | | - $filesystem->symlinkFile('vfs://root/foo', 'vfs://root/bar'); |
| 31 | + $this->filesystem = new Filesystem; |
| 32 | + $this->testDirectory = sys_get_temp_dir(); |
| 33 | + $this->testFile = $this->testDirectory . DIRECTORY_SEPARATOR . 'file'; |
29 | 34 | } |
30 | 35 |
|
31 | | - public function testSymlinkFileToNonExistingDirectoryWorks() |
| 36 | + public function tearDown() |
32 | 37 | { |
33 | | - $root = vfsStream::setup(); |
34 | | - |
35 | | - $mkdir = $this |
36 | | - ->getFunctionMock('Tooly\Script\Helper', 'mkdir') |
37 | | - ->expects($this->once()) |
38 | | - ->willReturnCallback(function() use ($root) { |
39 | | - $root->addChild(vfsStream::newDirectory('bar')); |
40 | | - |
41 | | - return true; |
42 | | - }); |
43 | | - |
44 | | - $symlink = $this |
45 | | - ->getFunctionMock('Tooly\Script\Helper', 'symlink') |
46 | | - ->expects($this->once()); |
47 | | - |
48 | | - file_put_contents('vfs://root/foo.txt', 'foo'); |
49 | | - |
50 | | - $filesystem = new Filesystem; |
51 | | - $filesystem->symlinkFile('vfs://root/foo.txt', 'vfs://root/bar/bar.txt'); |
| 38 | + if (is_dir($this->testDirectory)) { |
| 39 | + $this->filesystem->removeDirectory($this->testDirectory); |
| 40 | + } |
52 | 41 | } |
53 | 42 |
|
54 | | - public function testCannotCreateDirectoryReturnsFalse() |
| 43 | + public function testCanRelativeSymlinkAFile() |
55 | 44 | { |
56 | | - $root = vfsStream::setup(); |
57 | | - $filesystem = new Filesystem; |
58 | | - |
59 | | - $mkdir = $this |
60 | | - ->getFunctionMock('Tooly\Script\Helper', 'mkdir') |
61 | | - ->expects($this->exactly(2)) |
62 | | - ->willReturnCallback(function() { |
63 | | - return false; |
64 | | - }); |
65 | | - |
66 | | - $symlink = $this |
67 | | - ->getFunctionMock('Tooly\Script\Helper', 'symlink') |
68 | | - ->expects($this->never()); |
| 45 | + $symlink = $this->testDirectory . DIRECTORY_SEPARATOR . '/foo/symlink'; |
69 | 46 |
|
70 | | - $this->assertFalse($filesystem->createFile('vfs://root/foo/bar.txt', 'test')); |
71 | | - $this->assertFalse($filesystem->symlinkFile('vfs://root/foo/bar.txt', 'vfs://root/foo/baz.txt')); |
| 47 | + $this->assertTrue($this->filesystem->symlinkFile($this->testFile, $symlink)); |
| 48 | + $this->assertNotEquals('/', substr(readlink($symlink), '0', 1)); |
72 | 49 | } |
73 | 50 | } |
0 commit comments