|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PODEntender\Infrastructure\Domain\Model\FileProcessing; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Prophecy\Argument; |
|
8
|
|
|
use TightenCo\Jigsaw\Jigsaw; |
|
9
|
|
|
|
|
10
|
|
|
class JigsawBuiltOutputFilesRepositoryTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
private $jigsaw; |
|
13
|
|
|
|
|
14
|
|
|
private $filesystem; |
|
15
|
|
|
|
|
16
|
|
|
private $outputFilesRepository; |
|
17
|
|
|
|
|
18
|
|
|
protected function setUp(): void |
|
19
|
|
|
{ |
|
20
|
|
|
$this->jigsaw = $this->prophesize(Jigsaw::class); |
|
21
|
|
|
$this->filesystem = $this->prophesize(Filesystem::class); |
|
22
|
|
|
|
|
23
|
|
|
$this->outputFilesRepository = new JigsawBuiltOutputFilesRepository( |
|
24
|
|
|
$this->jigsaw->reveal(), |
|
25
|
|
|
$this->filesystem->reveal() |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
$this->jigsaw->getDestinationPath()->willReturn('/test'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testAllMapsPathsWithDestinationPathAndIndexFile(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->jigsaw->getOutputPaths()->willReturn(['/first-path', '/second-path']); |
|
34
|
|
|
$this->filesystem->exists(Argument::any())->willReturn(true); |
|
35
|
|
|
$this->filesystem->get(Argument::any())->willReturn('dummy content'); |
|
36
|
|
|
|
|
37
|
|
|
$outputFiles = $this->outputFilesRepository->all(); |
|
38
|
|
|
$firstFile = $outputFiles->first(); |
|
39
|
|
|
$lastFile = $outputFiles->last(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals('/test/first-path/index.html', $firstFile->path()); |
|
42
|
|
|
$this->assertEquals('/test/second-path/index.html', $lastFile->path()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testAllFiltersNonExistentFiles(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->jigsaw->getOutputPaths()->willReturn(['/first-path', '/second-path']); |
|
48
|
|
|
$this->filesystem->exists('/test/first-path/index.html')->willReturn(false); |
|
49
|
|
|
$this->filesystem->exists('/test/second-path/index.html')->willReturn(true); |
|
50
|
|
|
$this->filesystem->get(Argument::any())->willReturn('dummy content'); |
|
51
|
|
|
|
|
52
|
|
|
$outputFiles = $this->outputFilesRepository->all(); |
|
53
|
|
|
$firstFile = $outputFiles->first(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertCount(1, $outputFiles); |
|
56
|
|
|
$this->assertEquals('/test/second-path/index.html', $firstFile->path()); |
|
57
|
|
|
$this->assertEquals('dummy content', $firstFile->content()); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|