Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-07-05 23:03:12 +0300
committerGitHub <noreply@github.com>2020-07-05 23:03:12 +0300
commitd3d11cb826654d9c597443edb1d22d63521a2698 (patch)
tree457a0a7c9add6c677b2627f8505b203e76e5dc8f /tests
parent52af709ceaf77b1f8b6b8f7b81dbbc115784f792 (diff)
parent9993a3b839a4354a2ccf67d4aac53922c2de9b54 (diff)
Merge pull request #21626 from nextcloud/enhancement/injectible-callables
Callable parameter injection
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php84
-rw-r--r--tests/lib/AppFramework/Utility/SimpleContainerTest.php9
2 files changed, 90 insertions, 3 deletions
diff --git a/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php b/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php
new file mode 100644
index 00000000000..cd2332b0588
--- /dev/null
+++ b/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php
@@ -0,0 +1,84 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+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);
+ }
+}
diff --git a/tests/lib/AppFramework/Utility/SimpleContainerTest.php b/tests/lib/AppFramework/Utility/SimpleContainerTest.php
index f8a43058305..36fa1febfcf 100644
--- a/tests/lib/AppFramework/Utility/SimpleContainerTest.php
+++ b/tests/lib/AppFramework/Utility/SimpleContainerTest.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* ownCloud - App Framework
*
@@ -67,13 +69,14 @@ class SimpleContainerTest extends \Test\TestCase {
}
+
public function testRegister() {
$this->container->registerParameter('test', 'abc');
$this->assertEquals('abc', $this->container->query('test'));
}
-
+
public function testNothingRegistered() {
$this->expectException(\OCP\AppFramework\QueryException::class);
@@ -81,7 +84,7 @@ class SimpleContainerTest extends \Test\TestCase {
}
-
+
public function testNotAClass() {
$this->expectException(\OCP\AppFramework\QueryException::class);
@@ -190,7 +193,7 @@ class SimpleContainerTest extends \Test\TestCase {
$this->assertEquals('abc', $this->container->query($query));
}
-
+
public function testConstructorComplexNoTestParameterFound() {
$this->expectException(\OCP\AppFramework\QueryException::class);