mirror of
https://github.com/nextcloud/server.git
synced 2025-02-07 09:59:46 +00:00
1f7e2ba599
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace lib\AppFramework\Bootstrap;
|
|
|
|
use OC\AppFramework\Bootstrap\FunctionInjector;
|
|
use OC\AppFramework\Utility\SimpleContainer;
|
|
use Test\TestCase;
|
|
|
|
interface Foo {
|
|
}
|
|
|
|
class FunctionInjectorTest extends TestCase {
|
|
/** @var SimpleContainer */
|
|
private $container;
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->container = new SimpleContainer();
|
|
}
|
|
|
|
public function testInjectFnNotRegistered(): void {
|
|
$this->expectException(\OCP\AppFramework\QueryException::class);
|
|
|
|
(new FunctionInjector($this->container))->injectFn(static function (Foo $p1): void {
|
|
});
|
|
}
|
|
|
|
public function testInjectFnNotRegisteredButNullable(): void {
|
|
(new FunctionInjector($this->container))->injectFn(static function (?Foo $p1): void {
|
|
});
|
|
|
|
// Nothing to assert. No errors means everything is fine.
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
|
|
public function testInjectFnByType(): void {
|
|
$this->container->registerService(Foo::class, function () {
|
|
$this->addToAssertionCount(1);
|
|
return new class implements Foo {
|
|
};
|
|
});
|
|
|
|
(new FunctionInjector($this->container))->injectFn(static function (Foo $p1): void {
|
|
});
|
|
|
|
// Nothing to assert. No errors means everything is fine.
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
|
|
public function testInjectFnByName(): void {
|
|
$this->container->registerParameter('test', 'abc');
|
|
|
|
(new FunctionInjector($this->container))->injectFn(static function ($test): void {
|
|
});
|
|
|
|
// Nothing to assert. No errors means everything is fine.
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
}
|