mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
chore: Fix CrashReport\Registry tests
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
ab310ce938
commit
5d65f14e60
2 changed files with 23 additions and 25 deletions
|
|
@ -12,27 +12,18 @@ namespace Test\Support\CrashReport;
|
|||
use Exception;
|
||||
use OC\Support\CrashReport\Registry;
|
||||
use OCP\AppFramework\QueryException;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\Support\CrashReport\ICollectBreadcrumbs;
|
||||
use OCP\Support\CrashReport\IMessageReporter;
|
||||
use OCP\Support\CrashReport\IReporter;
|
||||
use Test\TestCase;
|
||||
|
||||
class RegistryTest extends TestCase {
|
||||
/** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $serverContainer;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
private Registry $registry;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->serverContainer = $this->createMock(IServerContainer::class);
|
||||
|
||||
$this->registry = new Registry(
|
||||
$this->serverContainer
|
||||
);
|
||||
$this->registry = new Registry();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -45,13 +36,10 @@ class RegistryTest extends TestCase {
|
|||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testRegisterLazyCantLoad(): void {
|
||||
public function testRegisterLazy(): void {
|
||||
$reporterClass = '\OCA\MyApp\Reporter';
|
||||
$reporter = $this->createMock(IReporter::class);
|
||||
$this->serverContainer->expects($this->once())
|
||||
->method('query')
|
||||
->with($reporterClass)
|
||||
->willReturn($reporter);
|
||||
$this->overwriteService($reporterClass, $reporter);
|
||||
$reporter->expects($this->once())
|
||||
->method('report');
|
||||
$exception = new Exception('test');
|
||||
|
|
@ -60,16 +48,17 @@ class RegistryTest extends TestCase {
|
|||
$this->registry->delegateReport($exception);
|
||||
}
|
||||
|
||||
public function testRegisterLazy(): void {
|
||||
/**
|
||||
* Doesn't assert anything, just checks whether anything "explodes"
|
||||
*/
|
||||
public function testRegisterLazyCantLoad(): void {
|
||||
$reporterClass = '\OCA\MyApp\Reporter';
|
||||
$this->serverContainer->expects($this->once())
|
||||
->method('query')
|
||||
->with($reporterClass)
|
||||
->willThrowException(new QueryException());
|
||||
/* We do not register reporterClass in DI, so it will throw a QueryException queried */
|
||||
$exception = new Exception('test');
|
||||
|
||||
$this->registry->registerLazy($reporterClass);
|
||||
$this->registry->delegateReport($exception);
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testDelegateBreadcrumbCollection(): void {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
|
|||
use OC\Files\SetupManager;
|
||||
use OC\Files\View;
|
||||
use OC\Template\Base;
|
||||
use OCP\AppFramework\QueryException;
|
||||
use OCP\Command\IBus;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\Defaults;
|
||||
|
|
@ -91,7 +92,11 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
$this->services[$name] = Server::get($name);
|
||||
try {
|
||||
$this->services[$name] = Server::get($name);
|
||||
} catch (QueryException $e) {
|
||||
$this->services[$name] = false;
|
||||
}
|
||||
$container = \OC::$server->getAppContainerForService($name);
|
||||
$container = $container ?? \OC::$server;
|
||||
|
||||
|
|
@ -113,9 +118,13 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
|||
$container = \OC::$server->getAppContainerForService($name);
|
||||
$container = $container ?? \OC::$server;
|
||||
|
||||
$container->registerService($name, function () use ($oldService) {
|
||||
return $oldService;
|
||||
});
|
||||
if ($oldService !== false) {
|
||||
$container->registerService($name, function () use ($oldService) {
|
||||
return $oldService;
|
||||
});
|
||||
} else {
|
||||
unset($container[$oldService]);
|
||||
}
|
||||
|
||||
|
||||
unset($this->services[$name]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue