diff options
Diffstat (limited to 'tests/lib/AppFramework/Utility/SimpleContainerTest.php')
-rw-r--r-- | tests/lib/AppFramework/Utility/SimpleContainerTest.php | 91 |
1 files changed, 48 insertions, 43 deletions
diff --git a/tests/lib/AppFramework/Utility/SimpleContainerTest.php b/tests/lib/AppFramework/Utility/SimpleContainerTest.php index d27d29db951..33800c7376f 100644 --- a/tests/lib/AppFramework/Utility/SimpleContainerTest.php +++ b/tests/lib/AppFramework/Utility/SimpleContainerTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Test\AppFramework\Utility; use OC\AppFramework\Utility\SimpleContainer; +use OCP\AppFramework\QueryException; use Psr\Container\NotFoundExceptionInterface; interface TestInterface { @@ -20,40 +21,40 @@ class ClassEmptyConstructor implements IInterfaceConstructor { } class ClassSimpleConstructor implements IInterfaceConstructor { - public $test; - public function __construct($test) { - $this->test = $test; + public function __construct( + public $test, + ) { } } class ClassComplexConstructor { - public $class; - public $test; - public function __construct(ClassSimpleConstructor $class, $test) { - $this->class = $class; - $this->test = $test; + public function __construct( + public ClassSimpleConstructor $class, + public $test, + ) { } } class ClassNullableUntypedConstructorArg { - public function __construct($class) { + public function __construct( + public $class, + ) { } } class ClassNullableTypedConstructorArg { - public $class; - public function __construct(?\Some\Class $class) { - $this->class = $class; + public function __construct( + public ?\Some\Class $class, + ) { } } interface IInterfaceConstructor { } class ClassInterfaceConstructor { - public $class; - public $test; - public function __construct(IInterfaceConstructor $class, $test) { - $this->class = $class; - $this->test = $test; + public function __construct( + public IInterfaceConstructor $class, + public $test, + ) { } } @@ -67,7 +68,7 @@ class SimpleContainerTest extends \Test\TestCase { - public function testRegister() { + public function testRegister(): void { $this->container->registerParameter('test', 'abc'); $this->assertEquals('abc', $this->container->query('test')); } @@ -76,12 +77,12 @@ class SimpleContainerTest extends \Test\TestCase { /** * Test querying a class that is not registered without autoload enabled */ - public function testNothingRegistered() { + public function testNothingRegistered(): void { try { $this->container->query('something really hard', false); $this->fail('Expected `QueryException` exception was not thrown'); } catch (\Throwable $exception) { - $this->assertInstanceOf(\OCP\AppFramework\QueryException::class, $exception); + $this->assertInstanceOf(QueryException::class, $exception); $this->assertInstanceOf(NotFoundExceptionInterface::class, $exception); } } @@ -90,38 +91,38 @@ class SimpleContainerTest extends \Test\TestCase { /** * Test querying a class that is not registered with autoload enabled */ - public function testNothingRegistered_autoload() { + public function testNothingRegistered_autoload(): void { try { $this->container->query('something really hard'); $this->fail('Expected `QueryException` exception was not thrown'); } catch (\Throwable $exception) { - $this->assertInstanceOf(\OCP\AppFramework\QueryException::class, $exception); + $this->assertInstanceOf(QueryException::class, $exception); $this->assertInstanceOf(NotFoundExceptionInterface::class, $exception); } } - public function testNotAClass() { - $this->expectException(\OCP\AppFramework\QueryException::class); + public function testNotAClass(): void { + $this->expectException(QueryException::class); $this->container->query('Test\AppFramework\Utility\TestInterface'); } - public function testNoConstructorClass() { + public function testNoConstructorClass(): void { $object = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor'); $this->assertTrue($object instanceof ClassEmptyConstructor); } - public function testInstancesOnlyOnce() { + public function testInstancesOnlyOnce(): void { $object = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor'); $object2 = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor'); $this->assertSame($object, $object2); } - public function testConstructorSimple() { + public function testConstructorSimple(): void { $this->container->registerParameter('test', 'abc'); $object = $this->container->query( 'Test\AppFramework\Utility\ClassSimpleConstructor' @@ -131,7 +132,7 @@ class SimpleContainerTest extends \Test\TestCase { } - public function testConstructorComplex() { + public function testConstructorComplex(): void { $this->container->registerParameter('test', 'abc'); $object = $this->container->query( 'Test\AppFramework\Utility\ClassComplexConstructor' @@ -142,7 +143,7 @@ class SimpleContainerTest extends \Test\TestCase { } - public function testConstructorComplexInterface() { + public function testConstructorComplexInterface(): void { $this->container->registerParameter('test', 'abc'); $this->container->registerService( 'Test\AppFramework\Utility\IInterfaceConstructor', function ($c) { @@ -157,7 +158,7 @@ class SimpleContainerTest extends \Test\TestCase { } - public function testOverrideService() { + public function testOverrideService(): void { $this->container->registerService( 'Test\AppFramework\Utility\IInterfaceConstructor', function ($c) { return $c->query('Test\AppFramework\Utility\ClassSimpleConstructor'); @@ -172,13 +173,13 @@ class SimpleContainerTest extends \Test\TestCase { $this->assertTrue($object instanceof ClassEmptyConstructor); } - public function testRegisterAliasParamter() { + public function testRegisterAliasParamter(): void { $this->container->registerParameter('test', 'abc'); $this->container->registerAlias('test1', 'test'); $this->assertEquals('abc', $this->container->query('test1')); } - public function testRegisterAliasService() { + public function testRegisterAliasService(): void { $this->container->registerService('test', function () { return new \StdClass; }, true); @@ -191,7 +192,7 @@ class SimpleContainerTest extends \Test\TestCase { $this->container->query('test'), $this->container->query('test1')); } - public function sanitizeNameProvider() { + public static function sanitizeNameProvider(): array { return [ ['ABC\\Foo', 'ABC\\Foo'], ['\\ABC\\Foo', '\\ABC\\Foo'], @@ -200,10 +201,8 @@ class SimpleContainerTest extends \Test\TestCase { ]; } - /** - * @dataProvider sanitizeNameProvider - */ - public function testSanitizeName($register, $query) { + #[\PHPUnit\Framework\Attributes\DataProvider('sanitizeNameProvider')] + public function testSanitizeName($register, $query): void { $this->container->registerService($register, function () { return 'abc'; }); @@ -211,15 +210,17 @@ class SimpleContainerTest extends \Test\TestCase { } - public function testConstructorComplexNoTestParameterFound() { - $this->expectException(\OCP\AppFramework\QueryException::class); + public function testConstructorComplexNoTestParameterFound(): void { + $this->expectException(QueryException::class); $object = $this->container->query( 'Test\AppFramework\Utility\ClassComplexConstructor' ); + /* Use the object to trigger DI on PHP >= 8.4 */ + get_object_vars($object); } - public function testRegisterFactory() { + public function testRegisterFactory(): void { $this->container->registerService('test', function () { return new \StdClass(); }, false); @@ -227,7 +228,7 @@ class SimpleContainerTest extends \Test\TestCase { $this->container->query('test'), $this->container->query('test')); } - public function testRegisterAliasFactory() { + public function testRegisterAliasFactory(): void { $this->container->registerService('test', function () { return new \StdClass(); }, false); @@ -241,9 +242,13 @@ class SimpleContainerTest extends \Test\TestCase { } public function testQueryUntypedNullable(): void { - $this->expectException(\OCP\AppFramework\QueryException::class); + $this->expectException(QueryException::class); - $this->container->query(ClassNullableUntypedConstructorArg::class); + $object = $this->container->query( + ClassNullableUntypedConstructorArg::class + ); + /* Use the object to trigger DI on PHP >= 8.4 */ + get_object_vars($object); } public function testQueryTypedNullable(): void { |