framework/extensions/package-manager/tests/integration/SetupComposer.php

58 lines
1.4 KiB
PHP
Raw Normal View History

2021-11-09 03:22:07 +08:00
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\PackageManager\Tests\integration;
use Flarum\Testing\integration\UsesTmpDir;
class SetupComposer
{
use UsesTmpDir;
2021-11-25 01:25:43 +08:00
private $config = [
'require' => [
'flarum/core' => '1.0.0',
'flarum/tags' => '1.0.3',
'flarum/lang-english' => '*',
],
'config' => [
'preferred-install' => 'dist',
'sort-packages' => true,
],
'repositories' => [
[
'type' => 'path',
2022-01-24 13:37:14 +08:00
'url' => __DIR__.'/tmp/packages/*',
2021-11-25 01:25:43 +08:00
]
]
];
public function __construct(array $config = null)
{
$this->config = array_merge($this->config, $config ?? []);
}
2021-11-09 03:22:07 +08:00
public function run()
{
2021-11-25 01:25:43 +08:00
$composerJson = $this->tmpDir().'/composer.json';
$composerLock = $this->tmpDir().'/composer.lock';
$packages = $this->tmpDir().'/packages';
file_put_contents($composerJson, json_encode($this->config, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
if (! file_exists($packages)) {
mkdir($packages);
}
if (file_exists($composerLock)) {
unlink($composerLock);
}
2021-11-09 03:22:07 +08:00
}
}