mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 06:05:46 +08:00
chore: fix package manager tests (#3407)
This commit is contained in:
parent
d465fd27bc
commit
b14c0780d2
15
.github/workflows/flarum-package-manager-backend.yml
vendored
Normal file
15
.github/workflows/flarum-package-manager-backend.yml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
name: Package Manager PHP
|
||||
|
||||
on: [workflow_dispatch, push, pull_request]
|
||||
|
||||
# The reusable workflow definitions will be moved to the `flarum/framework` repo soon.
|
||||
# This will break your current script.
|
||||
# When this happens, run `flarum-cli audit infra --fix` to update your infrastructure.
|
||||
|
||||
jobs:
|
||||
run:
|
||||
uses: flarum/.github/.github/workflows/REUSABLE_backend.yml@main
|
||||
with:
|
||||
enable_backend_testing: true
|
||||
|
||||
backend_directory: ./extensions/package-manager
|
|
@ -23,7 +23,7 @@
|
|||
},
|
||||
"require": {
|
||||
"flarum/core": "^1.0.0",
|
||||
"composer/composer": "^2.0"
|
||||
"composer/composer": "^2.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"flarum/testing": "^1.0.0",
|
||||
|
@ -86,7 +86,7 @@
|
|||
"test:integration": "phpunit -c tests/phpunit.integration.xml",
|
||||
"test:setup": [
|
||||
"@php tests/integration/setup.php",
|
||||
"cd $FLARUM_TEST_TMP_DIR_LOCAL && composer install"
|
||||
"cd ${FLARUM_TEST_TMP_DIR_LOCAL:-${FLARUM_TEST_TMP_DIR:-./tests/integration/tmp}} && composer install"
|
||||
]
|
||||
},
|
||||
"scripts-descriptions": {
|
||||
|
|
|
@ -58,7 +58,7 @@ class CheckForUpdatesHandler
|
|||
$actor->assertAdmin();
|
||||
|
||||
$firstOutput = $this->runComposerCommand(false);
|
||||
$firstOutput = json_decode($firstOutput, true);
|
||||
$firstOutput = json_decode($this->cleanJson($firstOutput), true);
|
||||
|
||||
$majorUpdates = false;
|
||||
|
||||
|
@ -71,7 +71,7 @@ class CheckForUpdatesHandler
|
|||
|
||||
if ($majorUpdates) {
|
||||
$secondOutput = $this->runComposerCommand(true);
|
||||
$secondOutput = json_decode($secondOutput, true);
|
||||
$secondOutput = json_decode($this->cleanJson($secondOutput), true);
|
||||
}
|
||||
|
||||
if (! isset($secondOutput)) {
|
||||
|
@ -101,6 +101,15 @@ class CheckForUpdatesHandler
|
|||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Composer can sometimes return text above the JSON.
|
||||
* This method tries to remove such occurences.
|
||||
*/
|
||||
protected function cleanJson(string $composerOutput): string
|
||||
{
|
||||
return preg_replace('/^[^{]+\n({.*)/ms', '$1', $composerOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComposerCommandFailedException
|
||||
*/
|
||||
|
|
|
@ -15,27 +15,11 @@ class SetupComposer
|
|||
{
|
||||
use UsesTmpDir;
|
||||
|
||||
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',
|
||||
'url' => __DIR__.'/tmp/packages/*',
|
||||
]
|
||||
]
|
||||
];
|
||||
private $config;
|
||||
|
||||
public function __construct(array $config = null)
|
||||
{
|
||||
$this->config = array_merge($this->config, $config ?? []);
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function run()
|
||||
|
@ -44,7 +28,7 @@ class SetupComposer
|
|||
$composerLock = $this->tmpDir().'/composer.lock';
|
||||
$packages = $this->tmpDir().'/packages';
|
||||
|
||||
file_put_contents($composerJson, json_encode($this->config, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||
file_put_contents($composerJson, json_encode($this->getConfig(), JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||
|
||||
if (! file_exists($packages)) {
|
||||
mkdir($packages);
|
||||
|
@ -53,5 +37,28 @@ class SetupComposer
|
|||
if (file_exists($composerLock)) {
|
||||
unlink($composerLock);
|
||||
}
|
||||
|
||||
echo 'composer.json created with testing packages directory.';
|
||||
}
|
||||
|
||||
private function getConfig(): array
|
||||
{
|
||||
return array_merge([
|
||||
'require' => [
|
||||
'flarum/core' => '1.0.0',
|
||||
'flarum/tags' => '1.0.3',
|
||||
'flarum/lang-english' => '*',
|
||||
],
|
||||
'config' => [
|
||||
'preferred-install' => 'dist',
|
||||
'sort-packages' => true,
|
||||
],
|
||||
'repositories' => [
|
||||
[
|
||||
'type' => 'path',
|
||||
'url' => realpath($this->tmpDir()).'/packages/*',
|
||||
]
|
||||
]
|
||||
], $this->config ?? []);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,7 @@
|
|||
<testsuites>
|
||||
<testsuite name="Flarum Integration Tests">
|
||||
<directory suffix="Test.php">./integration</directory>
|
||||
<exclude>./integration/tmp</exclude>
|
||||
<exclude>./integration/tmp</exclude>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<env name="FLARUM_TEST_TMP_DIR_LOCAL" value="tests/integration/tmp" force="true" />
|
||||
</php>
|
||||
</phpunit>
|
||||
|
|
Loading…
Reference in New Issue
Block a user