Skip to content

Commit 5b88a7e

Browse files
committed
Fixed invalid symlinks for real this time.
1 parent c3a1013 commit 5b88a7e

File tree

9 files changed

+75
-97
lines changed

9 files changed

+75
-97
lines changed

config/autoload/development/export.local.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
return [
1717
ConfigKey::MAIN => [
1818
ConfigKey::DIRECTORIES => [
19-
// ConfigKey::DIRECTORY_CACHE => __DIR__ . '/../../../data/cache',
20-
ConfigKey::DIRECTORY_FACTORIO => __DIR__ . '/../../../data/factorio',
21-
ConfigKey::DIRECTORY_INSTANCES => __DIR__ . '/../../../data/instances',
22-
ConfigKey::DIRECTORY_LOGS => __DIR__ . '/../../../data/log',
23-
ConfigKey::DIRECTORY_MODS => __DIR__ . '/../../../data/mods',
24-
ConfigKey::DIRECTORY_TEMP => __DIR__ . '/../../../data/temp',
19+
// ConfigKey::DIRECTORY_CACHE => 'data/cache',
20+
ConfigKey::DIRECTORY_FACTORIO => 'data/factorio',
21+
ConfigKey::DIRECTORY_INSTANCES => 'data/instances',
22+
ConfigKey::DIRECTORY_LOGS => 'data/log',
23+
ConfigKey::DIRECTORY_MODS => 'data/mods',
24+
ConfigKey::DIRECTORY_TEMP => 'data/temp',
2525
],
2626
ConfigKey::PARALLEL_DOWNLOADS => 4,
2727
ConfigKey::PARALLEL_RENDERS => 8,

src/Factorio/FactorioDownloader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ public function __construct(
9696
) {
9797
$this->console = $console;
9898
$this->fileSystem = $fileSystem;
99-
$this->factorioDirectory = $factorioDirectory;
99+
$this->factorioDirectory = (string) realpath($factorioDirectory);
100100
$this->factorioDownloadUsername = $factorioDownloadUsername;
101101
$this->factorioDownloadToken = $factorioDownloadToken;
102-
$this->tempDirectory = $tempDirectory;
102+
$this->tempDirectory = (string) realpath($tempDirectory);
103103
}
104104

105105
/**

src/Process/ModDownloadProcessFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ModDownloadProcessFactory
2222
public function __construct(Facade $modPortalClientFacade, string $tempDirectory)
2323
{
2424
$this->modPortalClientFacade = $modPortalClientFacade;
25-
$this->tempDirectory = $tempDirectory;
25+
$this->tempDirectory = (string) realpath($tempDirectory);
2626
}
2727

2828
/**

src/Process/RenderIconProcessFactory.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function __construct(
2727
string $renderIconBinary
2828
) {
2929
$this->serializer = $exportDataSerializer;
30-
$this->factorioDirectory = $factorioDirectory;
31-
$this->modsDirectory = $modsDirectory;
32-
$this->renderIconBinary = $renderIconBinary;
30+
$this->factorioDirectory = (string) realpath($factorioDirectory);
31+
$this->modsDirectory = (string) realpath($modsDirectory);
32+
$this->renderIconBinary = (string) realpath($renderIconBinary);
3333
}
3434

3535
/**
@@ -40,12 +40,12 @@ public function __construct(
4040
public function create(Icon $icon): RenderIconProcess
4141
{
4242
$command = [
43-
(string) realpath($this->renderIconBinary),
43+
$this->renderIconBinary,
4444
$this->serializer->serialize($icon, 'json'),
4545
];
4646
$env = [
47-
'FACTORIO_DATA_DIRECTORY' => (string) realpath($this->factorioDirectory . '/data'),
48-
'FACTORIO_MODS_DIRECTORY' => (string) realpath($this->modsDirectory),
47+
'FACTORIO_DATA_DIRECTORY' => $this->factorioDirectory . '/data',
48+
'FACTORIO_MODS_DIRECTORY' => $this->modsDirectory,
4949
];
5050

5151
return new RenderIconProcess($icon, $command, $env);

src/Service/ModFileService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public function __construct(
3939
) {
4040
$this->exportSerializer = $exportSerializer;
4141
$this->zipArchiveExtractor = $zipArchiveExtractor;
42-
$this->factorioDirectory = $factorioDirectory;
43-
$this->modsDirectory = $modsDirectory;
42+
$this->factorioDirectory = (string) realpath($factorioDirectory);
43+
$this->modsDirectory = (string) realpath($modsDirectory);
4444
}
4545

4646
/**

test/src/Factorio/FactorioDownloaderTest.php

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ protected function setUp(): void
5555
*/
5656
public function testConstruct(): void
5757
{
58-
$factorioDirectory = 'abc';
59-
$factorioDownloadUsername = 'def';
60-
$factorioDownloadToken = 'ghi';
61-
$tempDirectory = 'jkl';
58+
$factorioDirectory = 'data/factorio';
59+
$expectedFactorioDirectory = realpath(__DIR__ . '/../../../data/factorio');
60+
$factorioDownloadUsername = 'abc';
61+
$factorioDownloadToken = 'def';
62+
$tempDirectory = 'data/temp';
63+
$expectedTempDirectory = realpath(__DIR__ . '/../../../data/temp');
6264

6365
$downloader = new FactorioDownloader(
6466
$this->console,
@@ -71,10 +73,10 @@ public function testConstruct(): void
7173

7274
$this->assertSame($this->console, $this->extractProperty($downloader, 'console'));
7375
$this->assertSame($this->fileSystem, $this->extractProperty($downloader, 'fileSystem'));
74-
$this->assertSame($factorioDirectory, $this->extractProperty($downloader, 'factorioDirectory'));
76+
$this->assertSame($expectedFactorioDirectory, $this->extractProperty($downloader, 'factorioDirectory'));
7577
$this->assertSame($factorioDownloadUsername, $this->extractProperty($downloader, 'factorioDownloadUsername'));
7678
$this->assertSame($factorioDownloadToken, $this->extractProperty($downloader, 'factorioDownloadToken'));
77-
$this->assertSame($tempDirectory, $this->extractProperty($downloader, 'tempDirectory'));
79+
$this->assertSame($expectedTempDirectory, $this->extractProperty($downloader, 'tempDirectory'));
7880
}
7981

8082
/**
@@ -83,13 +85,13 @@ public function testConstruct(): void
8385
*/
8486
public function testDownload(): void
8587
{
86-
$tempDirectory = 'abc';
88+
$tempDirectory = 'data/temp';
8789
$version = '1.2.3';
8890

89-
$expectedHeadlessArchive = 'abc/headless.tar.xz';
90-
$expectedHeadlessDirectory = 'abc/headless';
91-
$expectedFullArchive = 'abc/full.tar.xz';
92-
$expectedFullDirectory = 'abc/full';
91+
$expectedHeadlessArchive = realpath(__DIR__ . '/../../../data/temp') . '/headless.tar.xz';
92+
$expectedHeadlessDirectory = realpath(__DIR__ . '/../../../data/temp') . '/headless';
93+
$expectedFullArchive = realpath(__DIR__ . '/../../../data/temp') . '/full.tar.xz';
94+
$expectedFullDirectory = realpath(__DIR__ . '/../../../data/temp') . '/full';
9395

9496
/* @var DownloadProcess&MockObject $headlessProcess */
9597
$headlessProcess = $this->createMock(DownloadProcess::class);
@@ -278,23 +280,29 @@ public function testPatchHeadless(): void
278280
public function testReplaceOldVersion(): void
279281
{
280282
$headlessDirectory = 'abc';
281-
$factorioDirectory = 'def';
283+
$factorioDirectory = 'data/factorio';
282284

283285
$this->fileSystem->expects($this->exactly(3))
284286
->method('remove')
285287
->withConsecutive(
286-
[$this->identicalTo('def/bin')],
287-
[$this->identicalTo('def/data')],
288-
[$this->identicalTo('def/config-path.cfg')]
288+
[$this->identicalTo(realpath(__DIR__ . '/../../../data/factorio') . '/bin')],
289+
[$this->identicalTo(realpath(__DIR__ . '/../../../data/factorio') . '/data')],
290+
[$this->identicalTo(realpath(__DIR__ . '/../../../data/factorio') . '/config-path.cfg')]
289291
);
290292
$this->fileSystem->expects($this->exactly(3))
291293
->method('rename')
292294
->withConsecutive(
293-
[$this->identicalTo('abc/factorio/bin'), $this->identicalTo('def/bin')],
294-
[$this->identicalTo('abc/factorio/data'), $this->identicalTo('def/data')],
295+
[
296+
$this->identicalTo('abc/factorio/bin'),
297+
$this->identicalTo(realpath(__DIR__ . '/../../../data/factorio') . '/bin'),
298+
],
299+
[
300+
$this->identicalTo('abc/factorio/data'),
301+
$this->identicalTo(realpath(__DIR__ . '/../../../data/factorio') . '/data'),
302+
],
295303
[
296304
$this->identicalTo('abc/factorio/config-path.cfg'),
297-
$this->identicalTo('def/config-path.cfg'),
305+
$this->identicalTo(realpath(__DIR__ . '/../../../data/factorio') . '/config-path.cfg'),
298306
],
299307
);
300308

test/src/Process/ModDownloadProcessFactoryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class ModDownloadProcessFactoryTest extends TestCase
2222
{
2323
public function test(): void
2424
{
25-
$tempDirectory = 'foo';
25+
$tempDirectory = 'data/temp';
26+
$expectedDestinationFile = realpath(__DIR__ . '/../../../data/temp') . '/ghi';
2627

2728
$mod = new Mod();
2829
$mod->setName('abc');
@@ -36,7 +37,7 @@ public function test(): void
3637
->with($this->identicalTo('def'))
3738
->willReturn('jkl');
3839

39-
$expectedResult = new ModDownloadProcess($mod, $release, 'jkl', 'foo/ghi');
40+
$expectedResult = new ModDownloadProcess($mod, $release, 'jkl', $expectedDestinationFile);
4041

4142
$instance = new ModDownloadProcessFactory($modPortalClientFacade, $tempDirectory);
4243
$result = $instance->create($mod, $release);

test/src/Process/RenderIconProcessFactoryTest.php

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,99 +4,68 @@
44

55
namespace FactorioItemBrowserTest\Export\Process;
66

7-
use BluePsyduck\TestHelper\ReflectionTrait;
87
use FactorioItemBrowser\Export\Process\RenderIconProcessFactory;
98
use FactorioItemBrowser\ExportData\Entity\Icon;
109
use JMS\Serializer\SerializerInterface;
1110
use PHPUnit\Framework\MockObject\MockObject;
1211
use PHPUnit\Framework\TestCase;
13-
use ReflectionException;
1412

1513
/**
1614
* The PHPUnit test of the RenderIconProcessFactory class.
1715
*
1816
* @author BluePsyduck <[email protected]>
1917
* @license http://opensource.org/licenses/GPL-3.0 GPL v3
20-
* @coversDefaultClass \FactorioItemBrowser\Export\Process\RenderIconProcessFactory
18+
* @covers \FactorioItemBrowser\Export\Process\RenderIconProcessFactory
2119
*/
2220
class RenderIconProcessFactoryTest extends TestCase
2321
{
24-
use ReflectionTrait;
22+
/** @var SerializerInterface&MockObject */
23+
private SerializerInterface $serializer;
24+
private string $factorioDirectory = 'data/factorio';
25+
private string $modsDirectory = 'data/mods';
26+
private string $renderIconBinary = 'bin/render-icon';
2527

26-
/**
27-
* The mocked serializer.
28-
* @var SerializerInterface&MockObject
29-
*/
30-
protected $serializer;
31-
32-
/**
33-
* Sets up the test case.
34-
*/
3528
protected function setUp(): void
3629
{
37-
parent::setUp();
38-
3930
$this->serializer = $this->createMock(SerializerInterface::class);
4031
}
4132

4233
/**
43-
* Tests the constructing.
44-
* @throws ReflectionException
45-
* @covers ::__construct
34+
* @param array<string> $mockedMethods
35+
* @return RenderIconProcessFactory&MockObject
4636
*/
47-
public function testConstruct(): void
37+
private function createInstance(array $mockedMethods = []): RenderIconProcessFactory
4838
{
49-
$factorioDirectory = 'abc';
50-
$modsDirectory = 'def';
51-
$renderIconBinary = 'ghi';
52-
53-
$factory = new RenderIconProcessFactory(
54-
$this->serializer,
55-
$factorioDirectory,
56-
$modsDirectory,
57-
$renderIconBinary
58-
);
59-
60-
$this->assertSame($this->serializer, $this->extractProperty($factory, 'serializer'));
61-
$this->assertSame($factorioDirectory, $this->extractProperty($factory, 'factorioDirectory'));
62-
$this->assertSame($modsDirectory, $this->extractProperty($factory, 'modsDirectory'));
63-
$this->assertSame($renderIconBinary, $this->extractProperty($factory, 'renderIconBinary'));
39+
return $this->getMockBuilder(RenderIconProcessFactory::class)
40+
->disableProxyingToOriginalMethods()
41+
->onlyMethods($mockedMethods)
42+
->setConstructorArgs([
43+
$this->serializer,
44+
$this->factorioDirectory,
45+
$this->modsDirectory,
46+
$this->renderIconBinary
47+
])
48+
->getMock();
6449
}
6550

66-
/**
67-
* Tests the create method.
68-
* @covers ::create
69-
*/
7051
public function testCreate(): void
7152
{
7253
$serializedIcon = 'abc';
73-
74-
/* @var Icon&MockObject $icon */
7554
$icon = $this->createMock(Icon::class);
76-
77-
$factorioDirectory = '.';
78-
$modsDirectory = 'test';
79-
$renderIconBinary = 'bin/render-icon';
80-
81-
$expectedCommandLine = sprintf("'%s' 'abc'", realpath($renderIconBinary));
55+
$expectedCommandLine = sprintf("'%s' 'abc'", realpath('bin/render-icon'));
8256
$expectedEnv = [
83-
'FACTORIO_DATA_DIRECTORY' => realpath('data'),
84-
'FACTORIO_MODS_DIRECTORY' => realpath('test'),
57+
'FACTORIO_DATA_DIRECTORY' => realpath('data/factorio') . '/data',
58+
'FACTORIO_MODS_DIRECTORY' => realpath('data/mods'),
8559
];
8660

8761
$this->serializer->expects($this->once())
8862
->method('serialize')
8963
->with($this->identicalTo($icon), $this->identicalTo('json'))
9064
->willReturn($serializedIcon);
9165

92-
$factory = new RenderIconProcessFactory(
93-
$this->serializer,
94-
$factorioDirectory,
95-
$modsDirectory,
96-
$renderIconBinary
97-
);
66+
$instance = $this->createInstance();
67+
$result = $instance->create($icon);
9868

99-
$result = $factory->create($icon);
10069
$this->assertSame($expectedCommandLine, $result->getCommandLine());
10170
$this->assertSame($expectedEnv, $result->getEnv());
10271
$this->assertSame($icon, $result->getIcon());

test/src/Service/ModFileServiceTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class ModFileServiceTest extends TestCase
2929
private SerializerInterface $exportSerializer;
3030
/** @var ZipArchiveExtractor&MockObject */
3131
private ZipArchiveExtractor $zipArchiveExtractor;
32-
private string $factorioDirectory = 'foo';
33-
private string $modsDirectory = 'bar';
32+
private string $factorioDirectory = 'data/factorio';
33+
private string $modsDirectory = 'data/mods';
3434

3535
protected function setUp(): void
3636
{
@@ -187,9 +187,9 @@ public function testReadFileWithException(): void
187187
public function provideGetLocalDirectory(): array
188188
{
189189
return [
190-
['base', 'foo/data/base'],
191-
['core', 'foo/data/core'],
192-
['abc', 'bar/abc'],
190+
['base', realpath(__DIR__ . '/../../../data/factorio') . '/data/base'],
191+
['core', realpath(__DIR__ . '/../../../data/factorio') . '/data/core'],
192+
['abc', realpath(__DIR__ . '/../../../data/mods') . '/abc'],
193193
];
194194
}
195195

0 commit comments

Comments
 (0)