2021-11-09 03:22:07 +08:00
|
|
|
<?php
|
|
|
|
|
2021-11-25 01:25:43 +08:00
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2021-11-09 03:22:07 +08:00
|
|
|
namespace Flarum\PackageManager\Tests\integration;
|
|
|
|
|
2021-11-25 01:25:43 +08:00
|
|
|
use FilesystemIterator;
|
|
|
|
use Flarum\PackageManager\Composer\ComposerAdapter;
|
|
|
|
use RecursiveDirectoryIterator;
|
|
|
|
use RecursiveIteratorIterator;
|
|
|
|
|
2021-11-09 03:22:07 +08:00
|
|
|
trait RefreshComposerSetup
|
|
|
|
{
|
|
|
|
public function tearDown(): void
|
|
|
|
{
|
|
|
|
$composerSetup = new SetupComposer();
|
|
|
|
@unlink($this->tmpDir().'/composer.lock');
|
|
|
|
|
2021-11-25 01:25:43 +08:00
|
|
|
$this->deleteDummyExtensions();
|
|
|
|
|
2021-11-09 03:22:07 +08:00
|
|
|
$composerSetup->run();
|
|
|
|
|
|
|
|
$this->composer('install');
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2021-11-25 01:25:43 +08:00
|
|
|
|
|
|
|
private function deleteDummyExtensions(): void
|
|
|
|
{
|
|
|
|
$dir = $this->tmpDir().'/packages';
|
|
|
|
|
|
|
|
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
|
|
|
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
|
|
|
|
2022-03-12 07:11:20 +08:00
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file->isDir()) {
|
2021-11-25 01:25:43 +08:00
|
|
|
rmdir($file->getRealPath());
|
|
|
|
} else {
|
|
|
|
unlink($file->getRealPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rmdir($dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function forgetComposerApp(): void
|
|
|
|
{
|
|
|
|
$this->app()->getContainer()->instance(ComposerAdapter::class, null);
|
|
|
|
}
|
2021-11-09 03:22:07 +08:00
|
|
|
}
|