-
Notifications
You must be signed in to change notification settings - Fork 16
/
RepackCommandTest.php
74 lines (59 loc) 路 2.07 KB
/
RepackCommandTest.php
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
66
67
68
69
70
71
72
73
74
<?php
namespace Castor\Tests\Slow;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
class RepackCommandTest extends TestCase
{
public function test()
{
$castorAppDirPath = self::setupRepackedCastorApp('castor-test-repack');
(new Process([
'vendor/jolicode/castor/bin/castor',
'repack',
'--os', 'linux',
], cwd: $castorAppDirPath))->mustRun();
$phar = $castorAppDirPath . '/my-app.linux.phar';
$this->assertFileExists($phar);
(new Process([$phar], cwd: $castorAppDirPath))->mustRun();
$p = (new Process([$phar, 'hello'], cwd: $castorAppDirPath))->mustRun();
$this->assertSame('hello', $p->getOutput());
// Twice, because we want to be sure the phar is not corrupted after a
// run
$p = (new Process([$phar, 'hello'], cwd: $castorAppDirPath))->mustRun();
$this->assertSame('hello', $p->getOutput());
}
public static function setupRepackedCastorApp(string $castorAppDirName): string
{
$castorAppDirPath = sys_get_temp_dir() . '/' . $castorAppDirName;
$fs = new Filesystem();
$fs->remove($castorAppDirPath);
$fs->mkdir($castorAppDirPath);
$fs->dumpFile($castorAppDirPath . '/castor.php', <<<'PHP'
<?php
use Castor\Attribute\AsTask;
#[AsTask()]
function hello(): void
{
echo "hello";
}
PHP
);
$fs->dumpFile($castorAppDirPath . '/composer.json', json_encode([
'repositories' => [
[
'type' => 'path',
'url' => __DIR__ . '/..',
],
],
'require' => [
'jolicode/castor' => '*@dev',
],
]));
(new Process(['composer', 'install'],
cwd: $castorAppDirPath,
env: ['COMPOSER_MIRROR_PATH_REPOS' => '1'],
))->mustRun();
return $castorAppDirPath;
}
}