1
0
mirror of https://github.com/flarum/core.git synced 2025-08-15 04:44:08 +02:00

chore: fix package manager tests (#3407)

This commit is contained in:
Sami Mazouz
2022-04-25 13:31:16 +01:00
committed by GitHub
parent d465fd27bc
commit b14c0780d2
5 changed files with 55 additions and 27 deletions

View File

@@ -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
*/