Add git_update.sh and adjust update/test hooks
This commit is contained in:
@@ -398,25 +398,20 @@ it('handles migration failure', function (): void {
|
||||
File::shouldReceive('directories')->andReturn(['/tmp/extract/speedbb']);
|
||||
File::shouldReceive('copyDirectory')->andReturnTrue();
|
||||
|
||||
$artisanPath = base_path('artisan');
|
||||
$originalArtisan = file_get_contents($artisanPath);
|
||||
file_put_contents($artisanPath, "#!/usr/bin/env php\n<?php exit(1);\n");
|
||||
chmod($artisanPath, 0755);
|
||||
putenv('SYSTEM_UPDATE_PHP_BINARY=/nope');
|
||||
$_ENV['SYSTEM_UPDATE_PHP_BINARY'] = '/nope';
|
||||
$_SERVER['SYSTEM_UPDATE_PHP_BINARY'] = '/nope';
|
||||
|
||||
withFakeBin([
|
||||
'tar' => "#!/bin/sh\nexit 0\n",
|
||||
'composer' => "#!/bin/sh\nexit 0\n",
|
||||
'npm' => "#!/bin/sh\nexit 0\n",
|
||||
], function () use ($artisanPath, $originalArtisan): void {
|
||||
try {
|
||||
Sanctum::actingAs(makeAdminForSystemUpdate());
|
||||
$response = $this->postJson('/api/system/update');
|
||||
], function (): void {
|
||||
Sanctum::actingAs(makeAdminForSystemUpdate());
|
||||
$response = $this->postJson('/api/system/update');
|
||||
|
||||
$response->assertStatus(500);
|
||||
$response->assertJsonFragment(['message' => 'Migrations failed.']);
|
||||
} finally {
|
||||
file_put_contents($artisanPath, $originalArtisan);
|
||||
}
|
||||
$response->assertStatus(500);
|
||||
$response->assertJsonFragment(['message' => 'Migrations failed.']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -424,6 +419,9 @@ it('handles fallback copyDirectory update success', function (): void {
|
||||
putenv('GITEA_OWNER=acme');
|
||||
putenv('GITEA_REPO=speedbb');
|
||||
putenv('GITEA_API_BASE=https://git.example.test/api/v1');
|
||||
putenv('SYSTEM_UPDATE_PHP_BINARY=php');
|
||||
$_ENV['SYSTEM_UPDATE_PHP_BINARY'] = 'php';
|
||||
$_SERVER['SYSTEM_UPDATE_PHP_BINARY'] = 'php';
|
||||
|
||||
Http::fake([
|
||||
'https://git.example.test/api/v1/repos/acme/speedbb/releases/latest' => Http::response([
|
||||
@@ -438,25 +436,21 @@ it('handles fallback copyDirectory update success', function (): void {
|
||||
File::shouldReceive('directories')->andReturn(['/tmp/extract/speedbb']);
|
||||
File::shouldReceive('copyDirectory')->andReturnTrue();
|
||||
|
||||
$artisanPath = base_path('artisan');
|
||||
$originalArtisan = file_get_contents($artisanPath);
|
||||
file_put_contents($artisanPath, "#!/usr/bin/env php\n<?php exit(0);\n");
|
||||
chmod($artisanPath, 0755);
|
||||
putenv('SYSTEM_UPDATE_PHP_BINARY=php');
|
||||
$_ENV['SYSTEM_UPDATE_PHP_BINARY'] = 'php';
|
||||
$_SERVER['SYSTEM_UPDATE_PHP_BINARY'] = 'php';
|
||||
|
||||
withFakeBin([
|
||||
'tar' => "#!/bin/sh\nexit 0\n",
|
||||
'composer' => "#!/bin/sh\nexit 0\n",
|
||||
'npm' => "#!/bin/sh\nexit 0\n",
|
||||
], function () use ($artisanPath, $originalArtisan): void {
|
||||
try {
|
||||
Sanctum::actingAs(makeAdminForSystemUpdate());
|
||||
$response = $this->postJson('/api/system/update');
|
||||
'php' => "#!/bin/sh\nexit 0\n",
|
||||
], function (): void {
|
||||
Sanctum::actingAs(makeAdminForSystemUpdate());
|
||||
$response = $this->postJson('/api/system/update');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonFragment(['message' => 'Update finished.']);
|
||||
$response->assertJsonStructure(['used_rsync']);
|
||||
} finally {
|
||||
file_put_contents($artisanPath, $originalArtisan);
|
||||
}
|
||||
$response->assertOk();
|
||||
$response->assertJsonFragment(['message' => 'Update finished.']);
|
||||
$response->assertJsonStructure(['used_rsync']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,155 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace s9e\TextFormatter {
|
||||
class Parser
|
||||
{
|
||||
public function parse(string $text): string
|
||||
{
|
||||
return '<r/>';
|
||||
}
|
||||
use App\Actions\BbcodeFormatter;
|
||||
|
||||
it('returns empty string for null and empty input', function (): void {
|
||||
expect(BbcodeFormatter::format(null))->toBe('');
|
||||
expect(BbcodeFormatter::format(''))->toBe('');
|
||||
});
|
||||
|
||||
it('formats bbcode content', function (): void {
|
||||
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
|
||||
$parserProp->setAccessible(true);
|
||||
$parserProp->setValue(
|
||||
\Mockery::mock(\s9e\TextFormatter\Parser::class)
|
||||
->shouldReceive('parse')
|
||||
->andReturn('<r/>')
|
||||
->getMock()
|
||||
);
|
||||
|
||||
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
|
||||
$rendererProp->setAccessible(true);
|
||||
$rendererProp->setValue(
|
||||
\Mockery::mock(\s9e\TextFormatter\Renderer::class)
|
||||
->shouldReceive('render')
|
||||
->andReturn('<b>Bold</b>')
|
||||
->getMock()
|
||||
);
|
||||
|
||||
$html = BbcodeFormatter::format('[b]Bold[/b]');
|
||||
|
||||
expect($html)->toContain('<b>');
|
||||
});
|
||||
|
||||
it('initializes parser and renderer when not set', function (): void {
|
||||
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
|
||||
$parserProp->setAccessible(true);
|
||||
$parserProp->setValue(null);
|
||||
|
||||
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
|
||||
$rendererProp->setAccessible(true);
|
||||
$rendererProp->setValue(null);
|
||||
|
||||
$html = BbcodeFormatter::format('[b]Bold[/b]');
|
||||
|
||||
expect($html)->toBeString();
|
||||
expect($parserProp->getValue())->not->toBeNull();
|
||||
expect($rendererProp->getValue())->not->toBeNull();
|
||||
});
|
||||
|
||||
it('build returns parser and renderer', function (): void {
|
||||
putenv('BBCODE_FORCE_FAIL');
|
||||
unset($_ENV['BBCODE_FORCE_FAIL'], $_SERVER['BBCODE_FORCE_FAIL']);
|
||||
|
||||
$ref = new ReflectionMethod(BbcodeFormatter::class, 'build');
|
||||
$ref->setAccessible(true);
|
||||
|
||||
$result = $ref->invoke(null);
|
||||
|
||||
expect($result)->toBeArray();
|
||||
expect($result)->toHaveCount(2);
|
||||
expect($result[0])->toBeInstanceOf(\s9e\TextFormatter\Parser::class);
|
||||
expect($result[1])->toBeInstanceOf(\s9e\TextFormatter\Renderer::class);
|
||||
});
|
||||
|
||||
it('formats with real build when parser is reset', function (): void {
|
||||
putenv('BBCODE_FORCE_FAIL');
|
||||
unset($_ENV['BBCODE_FORCE_FAIL'], $_SERVER['BBCODE_FORCE_FAIL']);
|
||||
|
||||
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
|
||||
$parserProp->setAccessible(true);
|
||||
$parserProp->setValue(null);
|
||||
|
||||
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
|
||||
$rendererProp->setAccessible(true);
|
||||
$rendererProp->setValue(null);
|
||||
|
||||
$html = BbcodeFormatter::format('[b]Bold[/b]');
|
||||
expect($html)->toBeString();
|
||||
expect($parserProp->getValue())->not->toBeNull();
|
||||
expect($rendererProp->getValue())->not->toBeNull();
|
||||
});
|
||||
|
||||
it('throws when bbcode formatter cannot initialize', function (): void {
|
||||
putenv('BBCODE_FORCE_FAIL=1');
|
||||
$_ENV['BBCODE_FORCE_FAIL'] = '1';
|
||||
$_SERVER['BBCODE_FORCE_FAIL'] = '1';
|
||||
|
||||
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
|
||||
$parserProp->setAccessible(true);
|
||||
$parserProp->setValue(null);
|
||||
|
||||
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
|
||||
$rendererProp->setAccessible(true);
|
||||
$rendererProp->setValue(null);
|
||||
|
||||
try {
|
||||
BbcodeFormatter::format('test');
|
||||
$this->fail('Expected exception not thrown.');
|
||||
} catch (Throwable $e) {
|
||||
expect($e)->toBeInstanceOf(RuntimeException::class);
|
||||
} finally {
|
||||
putenv('BBCODE_FORCE_FAIL');
|
||||
unset($_ENV['BBCODE_FORCE_FAIL'], $_SERVER['BBCODE_FORCE_FAIL']);
|
||||
}
|
||||
});
|
||||
|
||||
class Renderer
|
||||
{
|
||||
public function render(string $xml): string
|
||||
{
|
||||
return '<p>ok</p>';
|
||||
}
|
||||
}
|
||||
|
||||
class Configurator
|
||||
{
|
||||
public static bool $returnEmpty = false;
|
||||
public object $plugins;
|
||||
public object $tags;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->plugins = new class {
|
||||
public function load(string $name): object
|
||||
{
|
||||
return new class {
|
||||
public function addFromRepository(string $name): self
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$this->tags = new class implements \ArrayAccess {
|
||||
public array $store = [];
|
||||
public function add($name)
|
||||
{
|
||||
$obj = new \stdClass();
|
||||
$this->store[$name] = $obj;
|
||||
return $obj;
|
||||
}
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return array_key_exists($offset, $this->store);
|
||||
}
|
||||
public function offsetGet($offset): mixed
|
||||
{
|
||||
return $this->store[$offset] ?? null;
|
||||
}
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
$this->store[$offset] = $value;
|
||||
}
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
unset($this->store[$offset]);
|
||||
}
|
||||
};
|
||||
|
||||
$this->tags['QUOTE'] = new \stdClass();
|
||||
}
|
||||
|
||||
public function finalize(): array
|
||||
{
|
||||
if (self::$returnEmpty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'parser' => new Parser(),
|
||||
'renderer' => new Renderer(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
use App\Actions\BbcodeFormatter;
|
||||
|
||||
it('returns empty string for null and empty input', function (): void {
|
||||
expect(BbcodeFormatter::format(null))->toBe('');
|
||||
expect(BbcodeFormatter::format(''))->toBe('');
|
||||
});
|
||||
|
||||
it('formats bbcode content', function (): void {
|
||||
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
|
||||
$parserProp->setAccessible(true);
|
||||
$parserProp->setValue(
|
||||
\Mockery::mock(\s9e\TextFormatter\Parser::class)
|
||||
->shouldReceive('parse')
|
||||
->andReturn('<r/>')
|
||||
->getMock()
|
||||
);
|
||||
|
||||
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
|
||||
$rendererProp->setAccessible(true);
|
||||
$rendererProp->setValue(
|
||||
\Mockery::mock(\s9e\TextFormatter\Renderer::class)
|
||||
->shouldReceive('render')
|
||||
->andReturn('<b>Bold</b>')
|
||||
->getMock()
|
||||
);
|
||||
|
||||
$html = BbcodeFormatter::format('[b]Bold[/b]');
|
||||
|
||||
expect($html)->toContain('<b>');
|
||||
});
|
||||
|
||||
it('initializes parser and renderer when not set', function (): void {
|
||||
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
|
||||
$parserProp->setAccessible(true);
|
||||
$parserProp->setValue(null);
|
||||
|
||||
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
|
||||
$rendererProp->setAccessible(true);
|
||||
$rendererProp->setValue(null);
|
||||
|
||||
$html = BbcodeFormatter::format('[b]Bold[/b]');
|
||||
|
||||
expect($html)->toBeString();
|
||||
expect($parserProp->getValue())->not->toBeNull();
|
||||
expect($rendererProp->getValue())->not->toBeNull();
|
||||
});
|
||||
|
||||
it('throws when bbcode formatter cannot initialize', function (): void {
|
||||
\s9e\TextFormatter\Configurator::$returnEmpty = true;
|
||||
|
||||
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
|
||||
$parserProp->setAccessible(true);
|
||||
$parserProp->setValue(null);
|
||||
|
||||
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
|
||||
$rendererProp->setAccessible(true);
|
||||
$rendererProp->setValue(null);
|
||||
|
||||
try {
|
||||
BbcodeFormatter::format('test');
|
||||
$this->fail('Expected exception not thrown.');
|
||||
} catch (Throwable $e) {
|
||||
expect($e)->toBeInstanceOf(RuntimeException::class);
|
||||
} finally {
|
||||
\s9e\TextFormatter\Configurator::$returnEmpty = false;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
\Mockery::close();
|
||||
});
|
||||
}
|
||||
afterEach(function (): void {
|
||||
\Mockery::close();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user