|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Tests\Theme; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Configuration\Configuration; |
|
6
|
|
|
use ApiGen\Tests\ContainerFactory; |
|
7
|
|
|
use ApiGen\Theme\ThemeResources; |
|
8
|
|
|
use ApiGen\Utils\FileSystem; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
final class ThemeResourcesTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var Configuration |
|
15
|
|
|
*/ |
|
16
|
|
|
private $configuration; |
|
17
|
|
|
|
|
18
|
|
|
protected function setUp(): void |
|
19
|
|
|
{ |
|
20
|
|
|
$container = (new ContainerFactory)->create(); |
|
21
|
|
|
$this->configuration = $container->getByType(Configuration::class); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testCopyToDestination(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$sourceDir = TEMP_DIR . '/source'; |
|
27
|
|
|
$sourceFile = TEMP_DIR . '/other-source/other-file.txt'; |
|
28
|
|
|
$destinationDir = TEMP_DIR . '/destination'; |
|
29
|
|
|
|
|
30
|
|
|
$this->configuration->resolveOptions([ |
|
31
|
|
|
'source' => [__DIR__], |
|
32
|
|
|
'destination' => __DIR__ . '/Destination', |
|
33
|
|
|
'template' => [ |
|
34
|
|
|
'resources' => [ |
|
35
|
|
|
$sourceFile => 'other-file-renamed.txt', |
|
36
|
|
|
$sourceDir => 'assets' |
|
37
|
|
|
] |
|
38
|
|
|
] |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
|
|
$this->prepareSources($sourceFile, $sourceDir); |
|
42
|
|
|
|
|
43
|
|
|
$themeResources = new ThemeResources($this->configuration, new FileSystem); |
|
44
|
|
|
$themeResources->copyToDestination($destinationDir); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertFileExists($destinationDir . '/assets/file.txt'); |
|
47
|
|
|
$this->assertFileExists($destinationDir . '/other-file-renamed.txt'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function prepareSources(string $sourceFile, string $sourceDir): void |
|
51
|
|
|
{ |
|
52
|
|
|
mkdir(dirname($sourceFile), 0777); |
|
53
|
|
|
file_put_contents($sourceFile, '...'); |
|
54
|
|
|
mkdir($sourceDir, 0777); |
|
55
|
|
|
file_put_contents($sourceDir . '/file.txt', '...'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|