summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2022-12-15 10:37:27 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2023-01-18 14:00:38 +0100
commit20fcfb573951a594f71afaf97678d38d8b05c9f2 (patch)
tree9adb7ba2d021269dc0efd4d47d4076563a28c363 /tests/lib
parent9e08e4999821a0cf7c6b08fd9ab05f8d057c8362 (diff)
downloadnextcloud-server-20fcfb573951a594f71afaf97678d38d8b05c9f2.tar.gz
nextcloud-server-20fcfb573951a594f71afaf97678d38d8b05c9f2.zip
feat(app framework)!: Inject services into controller methods
Usually Nextcloud DI goes through constructor injection. This has the implication that each instance of a class builds the full DI tree. That is the injected services, their services, etc. Occasionally there is a service that is only needed for one controller method. Then the DI tree is build regardless if used or not. If services are injected into the method, we only build the DI tree if that method gets executed. This is also how Laravel allows injection. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/AppFramework/Http/DispatcherTest.php29
1 files changed, 19 insertions, 10 deletions
diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php
index 016bd7efb58..7f81701a8b3 100644
--- a/tests/lib/AppFramework/Http/DispatcherTest.php
+++ b/tests/lib/AppFramework/Http/DispatcherTest.php
@@ -36,6 +36,7 @@ use OCP\Diagnostics\IEventLogger;
use OCP\IConfig;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use OCP\IRequestId;
@@ -104,10 +105,10 @@ class DispatcherTest extends \Test\TestCase {
private $config;
/** @var LoggerInterface|MockObject */
private $logger;
- /**
- * @var IEventLogger|MockObject
- */
+ /** @var IEventLogger|MockObject */
private $eventLogger;
+ /** @var ContainerInterface|MockObject */
+ private $container;
protected function setUp(): void {
parent::setUp();
@@ -116,6 +117,7 @@ class DispatcherTest extends \Test\TestCase {
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->eventLogger = $this->createMock(IEventLogger::class);
+ $this->container = $this->createMock(ContainerInterface::class);
$app = $this->getMockBuilder(
'OC\AppFramework\DependencyInjection\DIContainer')
->disableOriginalConstructor()
@@ -154,7 +156,8 @@ class DispatcherTest extends \Test\TestCase {
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container,
);
$this->response = $this->createMock(Response::class);
@@ -330,7 +333,8 @@ class DispatcherTest extends \Test\TestCase {
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
@@ -362,7 +366,8 @@ class DispatcherTest extends \Test\TestCase {
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
@@ -397,7 +402,8 @@ class DispatcherTest extends \Test\TestCase {
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
@@ -431,7 +437,8 @@ class DispatcherTest extends \Test\TestCase {
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
@@ -466,7 +473,8 @@ class DispatcherTest extends \Test\TestCase {
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
@@ -503,7 +511,8 @@ class DispatcherTest extends \Test\TestCase {
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);