From 7e91779a2ca908bb0d1ef6e87eeed7cf019855dc Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 2 Nov 2023 23:44:10 +0100 Subject: [PATCH] x --- .github/workflows/tests.yml | 5 + tests/DI/Compiler.addExtension.phpt | 43 --- tests/DI/Compiler.arguments.phpt | 82 ---- tests/DI/Compiler.code.phpt | 24 -- tests/DI/Compiler.config.phpt | 60 --- tests/DI/Compiler.configOverride.phpt | 62 --- tests/DI/Compiler.dependencies.phpt | 84 ---- .../Compiler.dynamicParameters.validator.phpt | 98 ----- tests/DI/Compiler.extension.anonymous.phpt | 21 - .../Compiler.extension.defaultServices.phpt | 104 ----- tests/DI/Compiler.extension.getConfig.phpt | 41 -- tests/DI/Compiler.extension.phpt | 70 ---- tests/DI/Compiler.extension.schema.class.phpt | 77 ---- .../Compiler.extension.schema.deprecated.phpt | 34 -- .../DI/Compiler.extension.schema.dynamic.phpt | 70 ---- .../Compiler.extension.schema.overriding.phpt | 64 ---- tests/DI/Compiler.extension.schema.phpt | 74 ---- .../DI/Compiler.extensionOverride.errors.phpt | 24 -- tests/DI/Compiler.extensionOverride.phpt | 297 --------------- tests/DI/Compiler.functions.phpt | 91 ----- tests/DI/Compiler.generatedAccessor.phpt | 54 --- ...r.generatedFactory.nullableParameters.phpt | 75 ---- tests/DI/Compiler.generatedFactory.phpt | 343 ----------------- ...ompiler.generatedFactory.polymorphism.phpt | 111 ------ ...Compiler.generatedFactory.returnTypes.phpt | 69 ---- ...ler.generatedFactory.scalarParameters.phpt | 63 --- tests/DI/Compiler.generatedLocator.phpt | 118 ------ tests/DI/Compiler.generatedLocatorMulti.phpt | 64 ---- tests/DI/Compiler.loadConfig.include.phpt | 55 --- .../Compiler.loadDefinitionsFromConfig.phpt | 21 - tests/DI/Compiler.missingDefinition.phpt | 25 -- tests/DI/Compiler.parameters.circular.phpt | 38 -- tests/DI/Compiler.parameters.code.phpt | 70 ---- tests/DI/Compiler.parameters.phpt | 159 -------- tests/DI/Compiler.referenceBug.phpt | 41 -- tests/DI/Compiler.services.autowiring.phpt | 83 ---- tests/DI/Compiler.services.byClass.phpt | 65 ---- tests/DI/Compiler.services.create.phpt | 128 ------- tests/DI/Compiler.services.imported.phpt | 54 --- tests/DI/Compiler.services.removed.phpt | 21 - tests/DI/Compiler.services.setup.phpt | 90 ----- tests/DI/Compiler.unknownDefinitionKey.phpt | 25 -- ...erExtension.loadDefinitionsFromConfig.phpt | 32 -- tests/DI/CompilerExtension.loadFromFile.phpt | 35 -- .../DI/CompilerExtension.validateConfig.phpt | 67 ---- tests/DI/ConstantsExtension.basic.phpt | 26 -- tests/DI/Container.circular.phpt | 35 -- tests/DI/Container.createInstance.phpt | 45 --- tests/DI/Container.dynamic.php80.phpt | 22 -- tests/DI/Container.dynamic.phpt | 70 ---- tests/DI/Container.errors.phpt | 30 -- tests/DI/Container.getByType.alias.phpt | 44 --- tests/DI/Container.getByType.phpt | 68 ---- tests/DI/Container.getServiceType.phpt | 42 -- tests/DI/Container.getServiceType2.phpt | 44 --- tests/DI/Container.inject.methods.phpt | 63 --- tests/DI/Container.inject.properties.phpt | 57 --- tests/DI/Container.static-dynamic.phpt | 93 ----- tests/DI/ContainerBuilder.accessor.phpt | 74 ---- tests/DI/ContainerBuilder.accessor^2.phpt | 49 --- tests/DI/ContainerBuilder.aliases.phpt | 87 ----- tests/DI/ContainerBuilder.aliases2.phpt | 92 ----- .../ContainerBuilder.autowiring.builtin.phpt | 40 -- .../ContainerBuilder.autowiring.chaining.phpt | 81 ---- .../ContainerBuilder.autowiring.excluded.phpt | 74 ---- ...ContainerBuilder.autowiring.implement.phpt | 49 --- .../DI/ContainerBuilder.autowiring.local.phpt | 67 ---- .../ContainerBuilder.autowiring.novalue.phpt | 69 ---- .../ContainerBuilder.autowiring.type[].phpt | 97 ----- .../DI/ContainerBuilder.autowiring.types.phpt | 229 ----------- tests/DI/ContainerBuilder.basic.phpt | 126 ------ tests/DI/ContainerBuilder.basic2.phpt | 37 -- tests/DI/ContainerBuilder.basic3.phpt | 29 -- tests/DI/ContainerBuilder.basic4.phpt | 52 --- tests/DI/ContainerBuilder.byClass.phpt | 128 ------- tests/DI/ContainerBuilder.case.phpt | 20 - tests/DI/ContainerBuilder.create.error.phpt | 358 ------------------ .../ContainerBuilder.create.resolveClass.phpt | 39 -- tests/DI/ContainerBuilder.create.rich.phpt | 66 ---- tests/DI/ContainerBuilder.createService.phpt | 33 -- tests/DI/ContainerBuilder.enum.phpt | 39 -- tests/DI/ContainerBuilder.error.phpt | 46 --- .../ContainerBuilder.factory.arguments.phpt | 44 --- tests/DI/ContainerBuilder.factory.params.phpt | 57 --- tests/DI/ContainerBuilder.factory.phpt | 63 --- ...ContainerBuilder.factory.resolveClass.phpt | 117 ------ tests/DI/ContainerBuilder.factory^2.phpt | 44 --- tests/DI/ContainerBuilder.findByTag.phpt | 62 --- .../DI/ContainerBuilder.getByType.alias.phpt | 53 --- tests/DI/ContainerBuilder.getByType.phpt | 78 ---- .../ContainerBuilder.getDefinitionByType.phpt | 35 -- tests/DI/ContainerBuilder.imported.phpt | 51 --- tests/DI/ContainerBuilder.literal.phpt | 21 - tests/DI/ContainerBuilder.metadata.phpt | 64 ---- tests/DI/ContainerBuilder.names.phpt | 47 --- tests/DI/ContainerBuilder.recursive.phpt | 32 -- .../DI/ContainerBuilder.removeDefinition.phpt | 64 ---- .../ContainerBuilder.resolve.Container.phpt | 34 -- ...tainerBuilder.resolveTypes.next.php80.phpt | 31 -- .../ContainerBuilder.resolveTypes.next.phpt | 195 ---------- .../ContainerBuilder.resolveTypes.php80.phpt | 30 -- tests/DI/ContainerBuilder.resolveTypes.phpt | 186 --------- tests/DI/ContainerBuilder.selfdependency.phpt | 30 -- tests/DI/ContainerBuilder.tagged().phpt | 68 ---- tests/DI/ContainerBuilder.typed().phpt | 68 ---- tests/DI/ContainerLoader.basic.phpt | 28 -- tests/DI/ContainerLoader.isExpired.phpt | 56 --- tests/DI/ContainerLoader.loadFile.phpt | 32 -- tests/DI/DIExtension.debugger.phpt | 24 -- tests/DI/DIExtension.excluded.phpt | 28 -- tests/DI/DIExtension.exportParameters.phpt | 84 ---- tests/DI/DIExtension.exportTags.phpt | 102 ----- tests/DI/DIExtension.exportTypes.phpt | 132 ------- tests/DI/DIExtension.parentClass.phpt | 28 -- tests/DI/DecoratorExtension.basic.phpt | 92 ----- ...DecoratorExtension.factories.accessor.phpt | 45 --- tests/DI/DecoratorExtension.factories.phpt | 60 --- tests/DI/DefinitionSchema.normalize.phpt | 55 --- .../Definitions.AccessorDefinition.api.phpt | 114 ------ ...Definitions.AccessorDefinition.render.phpt | 61 --- ...efinitions.AccessorDefinition.resolve.phpt | 69 ---- .../DI/Definitions.FactoryDefinition.api.phpt | 113 ------ .../Definitions.FactoryDefinition.render.phpt | 58 --- ...Definitions.FactoryDefinition.resolve.phpt | 80 ---- tests/DI/Definitions.ImportedDefinition.phpt | 53 --- .../DI/Definitions.LocatorDefinition.api.phpt | 153 -------- ...tions.LocatorDefinition.render.create.phpt | 66 ---- ...initions.LocatorDefinition.render.get.phpt | 66 ---- ...itions.LocatorDefinition.render.multi.phpt | 70 ---- ...Definitions.LocatorDefinition.resolve.phpt | 76 ---- tests/DI/Definitions.Reference.phpt | 41 -- tests/DI/Definitions.ServiceDefinition.phpt | 118 ------ tests/DI/ExtensionsExtension.basic.phpt | 73 ---- tests/DI/ExtensionsExtension.error.phpt | 20 - tests/DI/Helpers.convertType.phpt | 94 ----- tests/DI/Helpers.escape().phpt | 23 -- tests/DI/Helpers.expand().phpt | 83 ---- tests/DI/Helpers.filterArguments.phpt | 33 -- tests/DI/Helpers.getReturnType.phpt | 30 -- tests/DI/Helpers.merge.neon.phpt | 44 --- tests/DI/Helpers.parseAnnotation().phpt | 64 ---- tests/DI/InjectExtension.basic.phpt | 136 ------- tests/DI/InjectExtension.errors.phpt | 110 ------ .../InjectExtension.getInjectMethods().phpt | 70 ---- ...Extension.getInjectProperties().php74.phpt | 39 -- ...Extension.getInjectProperties().php80.phpt | 36 -- ...InjectExtension.getInjectProperties().phpt | 98 ----- ...xtension.getInjectProperties().traits.phpt | 47 --- tests/DI/InjectExtension.implement.phpt | 50 --- tests/DI/InjectExtension.type1.phpt | 45 --- tests/DI/InjectExtension.type2.phpt | 52 --- tests/DI/Loader.errors.phpt | 24 -- tests/DI/Loader.include.nomerge.phpt | 48 --- tests/DI/Loader.include.params.phpt | 38 -- tests/DI/Loader.include.phpt | 38 -- tests/DI/Loader.recursiveInclude.phpt | 19 - tests/DI/NeonAdapter.basic.phpt | 70 ---- tests/DI/NeonAdapter.preprocess.phpt | 102 ----- tests/DI/PhpAdapter.phpt | 50 --- tests/DI/Resolver.autowireArguments.80.phpt | 57 --- tests/DI/Resolver.autowireArguments.81.phpt | 43 --- tests/DI/Resolver.autowireArguments.82.phpt | 33 -- .../DI/Resolver.autowireArguments.errors.phpt | 105 ----- tests/DI/Resolver.autowireArguments.phpt | 119 ------ 164 files changed, 5 insertions(+), 11217 deletions(-) delete mode 100644 tests/DI/Compiler.addExtension.phpt delete mode 100644 tests/DI/Compiler.arguments.phpt delete mode 100644 tests/DI/Compiler.code.phpt delete mode 100644 tests/DI/Compiler.config.phpt delete mode 100644 tests/DI/Compiler.configOverride.phpt delete mode 100644 tests/DI/Compiler.dependencies.phpt delete mode 100644 tests/DI/Compiler.dynamicParameters.validator.phpt delete mode 100644 tests/DI/Compiler.extension.anonymous.phpt delete mode 100644 tests/DI/Compiler.extension.defaultServices.phpt delete mode 100644 tests/DI/Compiler.extension.getConfig.phpt delete mode 100644 tests/DI/Compiler.extension.phpt delete mode 100644 tests/DI/Compiler.extension.schema.class.phpt delete mode 100644 tests/DI/Compiler.extension.schema.deprecated.phpt delete mode 100644 tests/DI/Compiler.extension.schema.dynamic.phpt delete mode 100644 tests/DI/Compiler.extension.schema.overriding.phpt delete mode 100644 tests/DI/Compiler.extension.schema.phpt delete mode 100644 tests/DI/Compiler.extensionOverride.errors.phpt delete mode 100644 tests/DI/Compiler.extensionOverride.phpt delete mode 100644 tests/DI/Compiler.functions.phpt delete mode 100644 tests/DI/Compiler.generatedAccessor.phpt delete mode 100644 tests/DI/Compiler.generatedFactory.nullableParameters.phpt delete mode 100644 tests/DI/Compiler.generatedFactory.phpt delete mode 100644 tests/DI/Compiler.generatedFactory.polymorphism.phpt delete mode 100644 tests/DI/Compiler.generatedFactory.returnTypes.phpt delete mode 100644 tests/DI/Compiler.generatedFactory.scalarParameters.phpt delete mode 100644 tests/DI/Compiler.generatedLocator.phpt delete mode 100644 tests/DI/Compiler.generatedLocatorMulti.phpt delete mode 100644 tests/DI/Compiler.loadConfig.include.phpt delete mode 100644 tests/DI/Compiler.loadDefinitionsFromConfig.phpt delete mode 100644 tests/DI/Compiler.missingDefinition.phpt delete mode 100644 tests/DI/Compiler.parameters.circular.phpt delete mode 100644 tests/DI/Compiler.parameters.code.phpt delete mode 100644 tests/DI/Compiler.parameters.phpt delete mode 100644 tests/DI/Compiler.referenceBug.phpt delete mode 100644 tests/DI/Compiler.services.autowiring.phpt delete mode 100644 tests/DI/Compiler.services.byClass.phpt delete mode 100644 tests/DI/Compiler.services.create.phpt delete mode 100644 tests/DI/Compiler.services.imported.phpt delete mode 100644 tests/DI/Compiler.services.removed.phpt delete mode 100644 tests/DI/Compiler.services.setup.phpt delete mode 100644 tests/DI/Compiler.unknownDefinitionKey.phpt delete mode 100644 tests/DI/CompilerExtension.loadDefinitionsFromConfig.phpt delete mode 100644 tests/DI/CompilerExtension.loadFromFile.phpt delete mode 100644 tests/DI/CompilerExtension.validateConfig.phpt delete mode 100644 tests/DI/ConstantsExtension.basic.phpt delete mode 100644 tests/DI/Container.circular.phpt delete mode 100644 tests/DI/Container.createInstance.phpt delete mode 100644 tests/DI/Container.dynamic.php80.phpt delete mode 100644 tests/DI/Container.dynamic.phpt delete mode 100644 tests/DI/Container.errors.phpt delete mode 100644 tests/DI/Container.getByType.alias.phpt delete mode 100644 tests/DI/Container.getByType.phpt delete mode 100644 tests/DI/Container.getServiceType.phpt delete mode 100644 tests/DI/Container.getServiceType2.phpt delete mode 100644 tests/DI/Container.inject.methods.phpt delete mode 100644 tests/DI/Container.inject.properties.phpt delete mode 100644 tests/DI/Container.static-dynamic.phpt delete mode 100644 tests/DI/ContainerBuilder.accessor.phpt delete mode 100644 tests/DI/ContainerBuilder.accessor^2.phpt delete mode 100644 tests/DI/ContainerBuilder.aliases.phpt delete mode 100644 tests/DI/ContainerBuilder.aliases2.phpt delete mode 100644 tests/DI/ContainerBuilder.autowiring.builtin.phpt delete mode 100644 tests/DI/ContainerBuilder.autowiring.chaining.phpt delete mode 100644 tests/DI/ContainerBuilder.autowiring.excluded.phpt delete mode 100644 tests/DI/ContainerBuilder.autowiring.implement.phpt delete mode 100644 tests/DI/ContainerBuilder.autowiring.local.phpt delete mode 100644 tests/DI/ContainerBuilder.autowiring.novalue.phpt delete mode 100644 tests/DI/ContainerBuilder.autowiring.type[].phpt delete mode 100644 tests/DI/ContainerBuilder.autowiring.types.phpt delete mode 100644 tests/DI/ContainerBuilder.basic.phpt delete mode 100644 tests/DI/ContainerBuilder.basic2.phpt delete mode 100644 tests/DI/ContainerBuilder.basic3.phpt delete mode 100644 tests/DI/ContainerBuilder.basic4.phpt delete mode 100644 tests/DI/ContainerBuilder.byClass.phpt delete mode 100644 tests/DI/ContainerBuilder.case.phpt delete mode 100644 tests/DI/ContainerBuilder.create.error.phpt delete mode 100644 tests/DI/ContainerBuilder.create.resolveClass.phpt delete mode 100644 tests/DI/ContainerBuilder.create.rich.phpt delete mode 100644 tests/DI/ContainerBuilder.createService.phpt delete mode 100644 tests/DI/ContainerBuilder.enum.phpt delete mode 100644 tests/DI/ContainerBuilder.error.phpt delete mode 100644 tests/DI/ContainerBuilder.factory.arguments.phpt delete mode 100644 tests/DI/ContainerBuilder.factory.params.phpt delete mode 100644 tests/DI/ContainerBuilder.factory.phpt delete mode 100644 tests/DI/ContainerBuilder.factory.resolveClass.phpt delete mode 100644 tests/DI/ContainerBuilder.factory^2.phpt delete mode 100644 tests/DI/ContainerBuilder.findByTag.phpt delete mode 100644 tests/DI/ContainerBuilder.getByType.alias.phpt delete mode 100644 tests/DI/ContainerBuilder.getByType.phpt delete mode 100644 tests/DI/ContainerBuilder.getDefinitionByType.phpt delete mode 100644 tests/DI/ContainerBuilder.imported.phpt delete mode 100644 tests/DI/ContainerBuilder.literal.phpt delete mode 100644 tests/DI/ContainerBuilder.metadata.phpt delete mode 100644 tests/DI/ContainerBuilder.names.phpt delete mode 100644 tests/DI/ContainerBuilder.recursive.phpt delete mode 100644 tests/DI/ContainerBuilder.removeDefinition.phpt delete mode 100644 tests/DI/ContainerBuilder.resolve.Container.phpt delete mode 100644 tests/DI/ContainerBuilder.resolveTypes.next.php80.phpt delete mode 100644 tests/DI/ContainerBuilder.resolveTypes.next.phpt delete mode 100644 tests/DI/ContainerBuilder.resolveTypes.php80.phpt delete mode 100644 tests/DI/ContainerBuilder.resolveTypes.phpt delete mode 100644 tests/DI/ContainerBuilder.selfdependency.phpt delete mode 100644 tests/DI/ContainerBuilder.tagged().phpt delete mode 100644 tests/DI/ContainerBuilder.typed().phpt delete mode 100644 tests/DI/ContainerLoader.basic.phpt delete mode 100644 tests/DI/ContainerLoader.isExpired.phpt delete mode 100644 tests/DI/ContainerLoader.loadFile.phpt delete mode 100644 tests/DI/DIExtension.debugger.phpt delete mode 100644 tests/DI/DIExtension.excluded.phpt delete mode 100644 tests/DI/DIExtension.exportParameters.phpt delete mode 100644 tests/DI/DIExtension.exportTags.phpt delete mode 100644 tests/DI/DIExtension.exportTypes.phpt delete mode 100644 tests/DI/DIExtension.parentClass.phpt delete mode 100644 tests/DI/DecoratorExtension.basic.phpt delete mode 100644 tests/DI/DecoratorExtension.factories.accessor.phpt delete mode 100644 tests/DI/DecoratorExtension.factories.phpt delete mode 100644 tests/DI/DefinitionSchema.normalize.phpt delete mode 100644 tests/DI/Definitions.AccessorDefinition.api.phpt delete mode 100644 tests/DI/Definitions.AccessorDefinition.render.phpt delete mode 100644 tests/DI/Definitions.AccessorDefinition.resolve.phpt delete mode 100644 tests/DI/Definitions.FactoryDefinition.api.phpt delete mode 100644 tests/DI/Definitions.FactoryDefinition.render.phpt delete mode 100644 tests/DI/Definitions.FactoryDefinition.resolve.phpt delete mode 100644 tests/DI/Definitions.ImportedDefinition.phpt delete mode 100644 tests/DI/Definitions.LocatorDefinition.api.phpt delete mode 100644 tests/DI/Definitions.LocatorDefinition.render.create.phpt delete mode 100644 tests/DI/Definitions.LocatorDefinition.render.get.phpt delete mode 100644 tests/DI/Definitions.LocatorDefinition.render.multi.phpt delete mode 100644 tests/DI/Definitions.LocatorDefinition.resolve.phpt delete mode 100644 tests/DI/Definitions.Reference.phpt delete mode 100644 tests/DI/Definitions.ServiceDefinition.phpt delete mode 100644 tests/DI/ExtensionsExtension.basic.phpt delete mode 100644 tests/DI/ExtensionsExtension.error.phpt delete mode 100644 tests/DI/Helpers.convertType.phpt delete mode 100644 tests/DI/Helpers.escape().phpt delete mode 100644 tests/DI/Helpers.expand().phpt delete mode 100644 tests/DI/Helpers.filterArguments.phpt delete mode 100644 tests/DI/Helpers.getReturnType.phpt delete mode 100644 tests/DI/Helpers.merge.neon.phpt delete mode 100644 tests/DI/Helpers.parseAnnotation().phpt delete mode 100644 tests/DI/InjectExtension.basic.phpt delete mode 100644 tests/DI/InjectExtension.errors.phpt delete mode 100644 tests/DI/InjectExtension.getInjectMethods().phpt delete mode 100644 tests/DI/InjectExtension.getInjectProperties().php74.phpt delete mode 100644 tests/DI/InjectExtension.getInjectProperties().php80.phpt delete mode 100644 tests/DI/InjectExtension.getInjectProperties().phpt delete mode 100644 tests/DI/InjectExtension.getInjectProperties().traits.phpt delete mode 100644 tests/DI/InjectExtension.implement.phpt delete mode 100644 tests/DI/InjectExtension.type1.phpt delete mode 100644 tests/DI/InjectExtension.type2.phpt delete mode 100644 tests/DI/Loader.errors.phpt delete mode 100644 tests/DI/Loader.include.nomerge.phpt delete mode 100644 tests/DI/Loader.include.params.phpt delete mode 100644 tests/DI/Loader.include.phpt delete mode 100644 tests/DI/Loader.recursiveInclude.phpt delete mode 100644 tests/DI/NeonAdapter.basic.phpt delete mode 100644 tests/DI/NeonAdapter.preprocess.phpt delete mode 100644 tests/DI/PhpAdapter.phpt delete mode 100644 tests/DI/Resolver.autowireArguments.80.phpt delete mode 100644 tests/DI/Resolver.autowireArguments.81.phpt delete mode 100644 tests/DI/Resolver.autowireArguments.82.phpt delete mode 100644 tests/DI/Resolver.autowireArguments.errors.phpt delete mode 100644 tests/DI/Resolver.autowireArguments.phpt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cf1784de2..98ebc531f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,6 +40,11 @@ jobs: - run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable - run: vendor/bin/tester tests -s -C + - if: failure() + uses: actions/upload-artifact@v3 + with: + name: output + path: tests/tmp code_coverage: diff --git a/tests/DI/Compiler.addExtension.phpt b/tests/DI/Compiler.addExtension.phpt deleted file mode 100644 index 21de503e4..000000000 --- a/tests/DI/Compiler.addExtension.phpt +++ /dev/null @@ -1,43 +0,0 @@ -compiler->addExtension('bar', new self); - } -} - - -Assert::exception(function () { - $compiler = new DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - $container = createContainer($compiler); -}, Nette\DeprecatedException::class, "Extensions 'bar' were added while container was being compiled."); - - -Assert::exception(function () { - $compiler = new DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - $compiler->addExtension('foo', new FooExtension); -}, Nette\InvalidArgumentException::class, "Name 'foo' is already used or reserved."); - - -Assert::exception(function () { - $compiler = new DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - $compiler->addExtension('Foo', new FooExtension); -}, Nette\InvalidArgumentException::class, "Name of extension 'Foo' has the same name as 'foo' in a case-insensitive manner."); diff --git a/tests/DI/Compiler.arguments.phpt b/tests/DI/Compiler.arguments.phpt deleted file mode 100644 index 36697adec..000000000 --- a/tests/DI/Compiler.arguments.phpt +++ /dev/null @@ -1,82 +0,0 @@ -args[] = func_get_args(); - } - - - public function method() - { - $this->args[] = func_get_args(); - } - - - public function add($a, $b) - { - return $a + $b; - } -} - - -define('MyConstantTest', 'one'); - -$container = createContainer(new DI\Compiler, " -services: - lorem: - factory: Lorem(::MyConstantTest, Lorem::DolorSit, NOT_CONSTANT_TEST) - setup: - - method( @lorem, @self, @container ) - - method( @lorem::add(1, 2), [x: ::strtoupper('hello')] ) - - method( [Lorem, method], 'Lorem::add', Lorem::add ) - - method( not(true) ) - - method( @lorem::var, @self::var, @container::parameters ) - - method( @lorem::DolorSit, @self::DolorSit ) -"); - -$container->parameters = ['something']; - -$lorem = $container->getService('lorem'); - -// constants -Assert::same(['one', Lorem::DolorSit, 'NOT_CONSTANT_TEST'], $lorem->args[0]); - -// services -Assert::same([$lorem, $lorem, $container], $lorem->args[1]); - -// statements -Assert::same([3, ['x' => 'HELLO']], $lorem->args[2]); - -// non-statements -Assert::same([['Lorem', 'method'], 'Lorem::add', 'Lorem::add'], $lorem->args[3]); - -// special -Assert::same([false], $lorem->args[4]); - -// service variables -Assert::same([$lorem->var, $lorem->var, $container->parameters], $lorem->args[5]); - -// service constant -Assert::same([Lorem::DolorSit, Lorem::DolorSit], $lorem->args[6]); diff --git a/tests/DI/Compiler.code.phpt b/tests/DI/Compiler.code.phpt deleted file mode 100644 index 99cdc1ae4..000000000 --- a/tests/DI/Compiler.code.phpt +++ /dev/null @@ -1,24 +0,0 @@ -load(Tester\FileMock::create(' -services: - - stdClass - name: stdClass -', 'neon')); - -$compiler = new Nette\DI\Compiler; -$code = $compiler->addConfig($config) - ->compile(); - -Assert::matchFile( - __DIR__ . '/expected/compiler.code.php', - $code -); diff --git a/tests/DI/Compiler.config.phpt b/tests/DI/Compiler.config.phpt deleted file mode 100644 index bcd1a7b03..000000000 --- a/tests/DI/Compiler.config.phpt +++ /dev/null @@ -1,60 +0,0 @@ -getConfig() - ); - - $compiler->addConfig([ - 'parameters' => [ - 'item1' => 1, - ], - ]); - $compiler->compile(); - - Assert::same( - [ - 'parameters' => [ - 'item1' => 1, - ], - 'services' => [], - ], - $compiler->getConfig() - ); -}); - -test('Compiler config with parameters overriding', function () { - $compiler = new DI\Compiler; - - $compiler->loadConfig(Tester\FileMock::create(' -parameters: - languages: [java] -', 'neon')); - - $compiler->loadConfig(Tester\FileMock::create(' -parameters: - languages!: [php,node] -', 'neon')); - - $compiler->compile(); - - Assert::same( - ['php', 'node'], - $compiler->getConfig()['parameters']['languages'] - ); -}); diff --git a/tests/DI/Compiler.configOverride.phpt b/tests/DI/Compiler.configOverride.phpt deleted file mode 100644 index 3ff8b2cf5..000000000 --- a/tests/DI/Compiler.configOverride.phpt +++ /dev/null @@ -1,62 +0,0 @@ -addConfig([ - 'services' => [ - 's1' => Ipsum::class, - 's2' => ['type' => Ipsum::class], - ], -]); -$compiler->addConfig([ - 'services' => [ - 's1' => ['arguments' => [2]], - 's2' => ['type' => Ipsum::class, 'alteration' => true], - ], -]); - -$code = $compiler->setClassName($class) - ->compile(); - -file_put_contents(getTempDir() . '/code.php', "getService('s1')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -$compiler->addConfig([ - 'services' => [ - 's3' => ['type' => Ipsum::class, 'alteration' => true], - ], -]); - -Assert::exception(function () use ($compiler, $class) { - $compiler->setClassName($class) - ->compile(); -}, DI\InvalidConfigurationException::class, "Service 's3': missing original definition for alteration."); diff --git a/tests/DI/Compiler.dependencies.phpt b/tests/DI/Compiler.dependencies.phpt deleted file mode 100644 index 02cf5d733..000000000 --- a/tests/DI/Compiler.dependencies.phpt +++ /dev/null @@ -1,84 +0,0 @@ -exportDependencies() -); -Assert::false(DependencyChecker::isExpired(...$compiler->exportDependencies())); - - -$compiler->addDependencies(['file1', __FILE__]); -Assert::same( - [ - DependencyChecker::Version, - ['file1' => false, __FILE__ => filemtime(__FILE__)], - [], - [], - [], - '40cd750bba9870f18aada2478b24840a', - ], - $compiler->exportDependencies() -); -Assert::false(DependencyChecker::isExpired(...$compiler->exportDependencies())); - - -$compiler->addDependencies(['file1', null, 'file3']); -Assert::same( - [ - DependencyChecker::Version, - ['file1' => false, __FILE__ => filemtime(__FILE__), 'file3' => false], - [], - [], - [], - '40cd750bba9870f18aada2478b24840a', - ], - $compiler->exportDependencies() -); - -$res = $compiler->exportDependencies(); -$res[1]['file4'] = 123; -Assert::true(DependencyChecker::isExpired(...$res)); - - -if (PHP_VERSION_ID >= 80100) { - // test serialization of parameters - - require $file = realpath(__DIR__ . '/fixtures/dependency.php81.php'); - - $compiler->addDependencies([new ReflectionClass(Dep1::class)]); - Assert::same( - [ - DependencyChecker::Version, - ['file1' => false, __FILE__ => filemtime(__FILE__), 'file3' => false], - [$file => filemtime($file)], - ['Dep1'], - [], - 'ff31f9bba26681aa5b228503003778cc', - ], - $compiler->exportDependencies() - ); - - Assert::false(DependencyChecker::isExpired(...$compiler->exportDependencies())); -} diff --git a/tests/DI/Compiler.dynamicParameters.validator.phpt b/tests/DI/Compiler.dynamicParameters.validator.phpt deleted file mode 100644 index 0139adf8a..000000000 --- a/tests/DI/Compiler.dynamicParameters.validator.phpt +++ /dev/null @@ -1,98 +0,0 @@ - Expect::string()->dynamic(), - 'intnull' => Expect::int()->nullable()->dynamic(), - ]) - ); - } -} - -test("Dynamic parameter of type int given to 'string' configuration", function () { - $compiler = new DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - $compiler->setDynamicParameterNames(['dynamic']); - Assert::exception(function () use ($compiler) { - $container = createContainer($compiler, ' - foo: - key: - string: %dynamic% - ', ['dynamic' => 123]); - $container->initialize(); - }, Nette\Utils\AssertionException::class, "The dynamic parameter used in 'foo › key › string' expects to be string, int 123 given."); -}); - - -test("Dynamic parameter of type null given to 'string' configuration", function () { - $compiler = new DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - $compiler->setDynamicParameterNames(['dynamic']); - Assert::exception(function () use ($compiler) { - $container = createContainer($compiler, ' - foo: - key: - string: %dynamic% - ', ['dynamic' => null]); - $container->initialize(); - }, Nette\Utils\AssertionException::class, "The dynamic parameter used in 'foo › key › string' expects to be string, null given."); -}); - - -test("Dynamic sub-parameter of type int given to 'string' configuration", function () { - $compiler = new DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - $compiler->setDynamicParameterNames(['dynamic']); - Assert::exception(function () use ($compiler) { - $container = createContainer($compiler, ' - foo: - key: - string: %dynamic.sub% - ', ['dynamic' => ['sub' => 123]]); - $container->initialize(); - }, Nette\Utils\AssertionException::class, "The dynamic parameter used in 'foo › key › string' expects to be string, int 123 given."); -}); - - -test("Dynamic parameter of type int successfully given to 'int|null' configuration", function () { - $compiler = new DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - $compiler->setDynamicParameterNames(['dynamic']); - Assert::noError(function () use ($compiler) { - $container = createContainer($compiler, ' - foo: - key: - intnull: %dynamic% - ', ['dynamic' => 123]); - $container->initialize(); - }); -}); - - -test("Dynamic parameter of type null successfully given to 'int|null' configuration", function () { - $compiler = new DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - $compiler->setDynamicParameterNames(['dynamic']); - Assert::noError(function () use ($compiler) { - $container = createContainer($compiler, ' - foo: - key: - intnull: %dynamic% - ', ['dynamic' => null]); - $container->initialize(); - }); -}); diff --git a/tests/DI/Compiler.extension.anonymous.phpt b/tests/DI/Compiler.extension.anonymous.phpt deleted file mode 100644 index 12e848a16..000000000 --- a/tests/DI/Compiler.extension.anonymous.phpt +++ /dev/null @@ -1,21 +0,0 @@ -addExtension(null, new FooExtension); -$compiler->addExtension(null, new FooExtension); - -Assert::count(4, $compiler->getExtensions()); diff --git a/tests/DI/Compiler.extension.defaultServices.phpt b/tests/DI/Compiler.extension.defaultServices.phpt deleted file mode 100644 index 0266b5d53..000000000 --- a/tests/DI/Compiler.extension.defaultServices.phpt +++ /dev/null @@ -1,104 +0,0 @@ -getContainerBuilder(); - - if (!$builder->getByType(Foo::class)) { - Assert::fail('Foo service should be defined.'); - } - - if (!$builder->getByType(IBar::class)) { - Assert::fail('IBar service should be defined.'); - } - - if (!$builder->getByType(Lorem::class)) { - Assert::fail('Lorem service should be defined.'); - } - - if (!$builder->getByType(IIpsumFactory::class)) { - Assert::fail('IIpsumFactory service should be defined.'); - } - - if (!$builder->getByType(FooBar::class)) { - $builder->addDefinition('five')->setType(FooBar::class); - } - } -} - - -$loader = new DI\Config\Loader; -$compiler = new DI\Compiler; -$extension = new FooExtension; -$compiler->addExtension('database', $extension); - -$container = createContainer($compiler, ' -services: - one: Foo - two: Bar - three: Factory::createLorem() - four: - type: Ipsum - implement: IIpsumFactory -'); - - -Assert::type(Foo::class, $container->getService('one')); -Assert::type(Bar::class, $container->getService('two')); -Assert::type(Lorem::class, $container->getService('three')); -Assert::type(IIpsumFactory::class, $container->getService('four')); - -Assert::type(FooBar::class, $container->getByType(IFooBar::class)); diff --git a/tests/DI/Compiler.extension.getConfig.phpt b/tests/DI/Compiler.extension.getConfig.phpt deleted file mode 100644 index ede945995..000000000 --- a/tests/DI/Compiler.extension.getConfig.phpt +++ /dev/null @@ -1,41 +0,0 @@ -compiler->getExtensions(); - $this->barConfig = $exts['bar']->getConfig(); - } -} - - -class BarExtension extends Nette\DI\CompilerExtension -{ -} - - -$compiler = new Nette\DI\Compiler; -$compiler->addExtension('foo', $foo = new FooExtension); -$compiler->addExtension('bar', new BarExtension); -createContainer($compiler, ' -bar: - lorem: ipsum -'); - -Assert::same(['lorem' => 'ipsum'], $foo->barConfig); diff --git a/tests/DI/Compiler.extension.phpt b/tests/DI/Compiler.extension.phpt deleted file mode 100644 index b22616b74..000000000 --- a/tests/DI/Compiler.extension.phpt +++ /dev/null @@ -1,70 +0,0 @@ - 'hello'], $this->config); - Notes::add(__METHOD__); - } - - - public function beforeCompile() - { - Notes::add(__METHOD__); - } - - - public function afterCompile(Nette\PhpGenerator\ClassType $class) - { - Notes::add(__METHOD__); - } -} - -class FooExtension extends Nette\DI\CompilerExtension -{ -} - - -$compiler = new DI\Compiler; -$extension = new DatabaseExtension; -$compiler->addExtension('database', $extension); -$compiler->addExtension('foo', new FooExtension); -$container = createContainer($compiler, ' -parameters: - bar: hello - - -database: - foo: %bar% - -foo: -'); - - -Assert::same([ - 'DatabaseExtension::loadConfiguration', - 'DatabaseExtension::beforeCompile', - 'DatabaseExtension::afterCompile', -], Notes::fetch()); - - -Assert::same('database.', $extension->prefix('')); -Assert::same('database.member', $extension->prefix('member')); -Assert::same('@database.member', $extension->prefix('@member')); - - -Assert::same(['foo' => 'hello'], $extension->getConfig()); diff --git a/tests/DI/Compiler.extension.schema.class.phpt b/tests/DI/Compiler.extension.schema.class.phpt deleted file mode 100644 index faa54c922..000000000 --- a/tests/DI/Compiler.extension.schema.class.phpt +++ /dev/null @@ -1,77 +0,0 @@ -config = new class { - /** @var ?string */ - public $key; - }; - } -} - - -Assert::exception(function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - createContainer($compiler, ' - foo: - unknown: 123 - '); -}, Nette\DI\InvalidConfigurationException::class, "Unexpected item 'foo\u{a0}›\u{a0}unknown'."); - - -Assert::exception(function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - createContainer($compiler, ' - foo: - key: 123 - '); -}, Nette\DI\InvalidConfigurationException::class, "The item 'foo\u{a0}›\u{a0}key' expects to be ?string, 123 given."); - - -test('Successful configuration with a provided key', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - foo: - key: hello - '); - Assert::type('object', $foo->getConfig()); - Assert::equal(['key' => 'hello'], (array) $foo->getConfig()); -}); - - -test('Successful configuration without any specific key', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - foo: - '); - Assert::type('object', $foo->getConfig()); - Assert::equal(['key' => null], (array) $foo->getConfig()); -}); - - -test('Successful configuration with default values', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - '); - Assert::type('object', $foo->getConfig()); - Assert::equal(['key' => null], (array) $foo->getConfig()); -}); diff --git a/tests/DI/Compiler.extension.schema.deprecated.phpt b/tests/DI/Compiler.extension.schema.deprecated.phpt deleted file mode 100644 index ccd4434fa..000000000 --- a/tests/DI/Compiler.extension.schema.deprecated.phpt +++ /dev/null @@ -1,34 +0,0 @@ - Expect::string()->deprecated(), - ]); - } -} - - -Assert::error(function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - createContainer($compiler, ' - foo: - key: hello - '); -}, E_USER_DEPRECATED, "The item 'foo\u{a0}›\u{a0}key' is deprecated."); diff --git a/tests/DI/Compiler.extension.schema.dynamic.phpt b/tests/DI/Compiler.extension.schema.dynamic.phpt deleted file mode 100644 index 4b26b660c..000000000 --- a/tests/DI/Compiler.extension.schema.dynamic.phpt +++ /dev/null @@ -1,70 +0,0 @@ - Expect::string()->dynamic(), - ]); - } -} - - -Assert::exception(function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - createContainer($compiler, ' - foo: - key: 123 - '); -}, Nette\DI\InvalidConfigurationException::class, "The item 'foo\u{a0}›\u{a0}key' expects to be %a?%string, 123 given."); - - -test('valid type', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - foo: - key: hello - '); - Assert::equal((object) ['key' => 'hello'], $foo->getConfig()); -}); - - -test('Statement', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - foo: - key: ::trim("x") - '); - Assert::type(Nette\DI\Definitions\Statement::class, $foo->getConfig()->key); -}); - - -test('Statement via parameter', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - parameters: - dynamic: ::trim("x") - - foo: - key: %dynamic% - '); - Assert::type(Nette\DI\Definitions\Statement::class, $foo->getConfig()->key); -}); diff --git a/tests/DI/Compiler.extension.schema.overriding.phpt b/tests/DI/Compiler.extension.schema.overriding.phpt deleted file mode 100644 index 47aa2a640..000000000 --- a/tests/DI/Compiler.extension.schema.overriding.phpt +++ /dev/null @@ -1,64 +0,0 @@ - Expect::arrayOf('string'), - ]); - } -} - -test('Merging config', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - $compiler->addConfig([ - 'foo' => [ - 'mapping' => ['foo'], - ], - ]); - createContainer($compiler, ' - foo: - mapping: [bar] - '); - Assert::equal((object) ['mapping' => ['foo', 'bar']], $foo->getConfig()); -}); - -test('Prevent merging config', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - $compiler->addConfig([ - 'foo' => [ - 'mapping' => ['foo'], - ], - ]); - createContainer($compiler, ' - foo: - mapping!: [bar] - '); - Assert::equal((object) ['mapping' => ['bar']], $foo->getConfig()); -}); - -test('Prevent merging config with no predefined parameters', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - foo: - mapping!: [bar] - '); - Assert::equal((object) ['mapping' => ['bar']], $foo->getConfig()); -}); diff --git a/tests/DI/Compiler.extension.schema.phpt b/tests/DI/Compiler.extension.schema.phpt deleted file mode 100644 index 1dd71038b..000000000 --- a/tests/DI/Compiler.extension.schema.phpt +++ /dev/null @@ -1,74 +0,0 @@ - Expect::string(), - ]); - } -} - - -Assert::exception(function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - createContainer($compiler, ' - foo: - unknown: 123 - '); -}, Nette\DI\InvalidConfigurationException::class, "Unexpected item 'foo\u{a0}›\u{a0}unknown'."); - - -Assert::exception(function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', new FooExtension); - createContainer($compiler, ' - foo: - key: 123 - '); -}, Nette\DI\InvalidConfigurationException::class, "The item 'foo\u{a0}›\u{a0}key' expects to be string, 123 given."); - - -test('Extension with valid string configuration', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - foo: - key: hello - '); - Assert::equal((object) ['key' => 'hello'], $foo->getConfig()); -}); - - -test('Extension with no key configuration', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - foo: - '); - Assert::equal((object) ['key' => null], $foo->getConfig()); -}); - - -test('Extension without configuration', function () { - $compiler = new Nette\DI\Compiler; - $compiler->addExtension('foo', $foo = new FooExtension); - createContainer($compiler, ' - '); - Assert::equal((object) ['key' => null], $foo->getConfig()); -}); diff --git a/tests/DI/Compiler.extensionOverride.errors.phpt b/tests/DI/Compiler.extensionOverride.errors.phpt deleted file mode 100644 index a4b942814..000000000 --- a/tests/DI/Compiler.extensionOverride.errors.phpt +++ /dev/null @@ -1,24 +0,0 @@ -getContainerBuilder(); - - $builder->addDefinition('one1') - ->setCreator(Lorem::class, [1]); - $builder->addDefinition('one2') - ->setCreator(Lorem::class, [1]); - $builder->addDefinition('one3') - ->setCreator(Lorem::class, [1]); - $builder->addDefinition('one4') - ->setCreator(Lorem::class, [1]); - $builder->addDefinition('one5') - ->setCreator(Lorem::class, [1]); - $builder->addDefinition('one6') - ->setCreator(Lorem::class, [1]); - $builder->addDefinition('one7') - ->setCreator(Lorem::class, [1]); - $builder->addDefinition('one8') - ->setCreator(Lorem::class, [1]) - ->addSetup('__construct', [2]); - $builder->addDefinition('one9') - ->setCreator(Lorem::class, [1]); - $builder->addDefinition('one10') - ->setCreator(Lorem::class, [1]); - - $builder->addDefinition('two1') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('two2') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('two3') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('two4') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1, 2]); - $builder->addDefinition('two5') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('two6') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1, 2]); - $builder->addDefinition('two7') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('two8') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1, 2]); - $builder->addDefinition('two9') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1, 2]); - $builder->addDefinition('two10') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('two11') - ->setType(Lorem::class) - ->setCreator('Factory::createLorem', [1]); - - $builder->addDefinition('three1') - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('three2') - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('three3') - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('three4') - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('three5') - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('three6') - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('three7') - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('three8') - ->setCreator('Factory::createLorem', [1]); - $builder->addDefinition('three9') - ->setCreator('Factory::createLorem', [1]); - } -} - - -$compiler = new DI\Compiler; -$extension = new FooExtension; -$compiler->addExtension('database', $extension); -$container = createContainer($compiler, 'files/compiler.extensionOverride.neon'); - - -Assert::type(Ipsum::class, $container->getService('one1')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('one2')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('one3')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Lorem::class, $container->getService('one4')); -Assert::same([ - 'Lorem::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('one5')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('one6')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('one7')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('one8')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - -Assert::exception(function () use ($container) { - $container->getService('one9'); -}, TypeError::class, '%a% must be %a% Ipsum,%a?% Lorem returned'); -Notes::fetch(); - -Assert::type(Ipsum::class, $container->getService('one10')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - - -Assert::type(Ipsum::class, $container->getService('two1')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('two2')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('two3')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Lorem::class, $container->getService('two4')); -Assert::same([ - 'Lorem::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('two5')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('two6')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('two7')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Lorem::class, $container->getService('two8')); -Assert::same([ - 'Lorem::__construct 1 new', -], Notes::fetch()); - -Assert::type(Lorem::class, $container->getService('two9')); -Assert::same([ - 'Lorem::__construct new', -], Notes::fetch()); - -Assert::type(Lorem::class, $container->getService('two10')); -Assert::same([ - 'Lorem::__construct 2 new', -], Notes::fetch()); - -Assert::exception(function () use ($container) { - $container->getService('two11'); -}, TypeError::class, '%a% must be %a% Ipsum,%a?% Lorem returned'); -Notes::fetch(); - -Assert::type(Ipsum::class, $container->getService('two12')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - - - -Assert::type(Ipsum::class, $container->getService('three1')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('three2')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('three3')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Lorem::class, $container->getService('three4')); -Assert::same([ - 'Lorem::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('three5')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('three6')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::type(Ipsum::class, $container->getService('three7')); -Assert::same([ - 'Ipsum::__construct 2', -], Notes::fetch()); - -Assert::exception(function () use ($container) { - $container->getService('three8'); -}, TypeError::class, '%a% must be %a% Ipsum,%a?% Lorem returned'); -Notes::fetch(); - -Assert::type(Ipsum::class, $container->getService('three9')); -Assert::same([ - 'Ipsum::__construct ', -], Notes::fetch()); diff --git a/tests/DI/Compiler.functions.phpt b/tests/DI/Compiler.functions.phpt deleted file mode 100644 index 85df0b7e4..000000000 --- a/tests/DI/Compiler.functions.phpt +++ /dev/null @@ -1,91 +0,0 @@ -args[$nm] = $args; - } -} - - -const NUM = 231; - -$compiler = new DI\Compiler; -$compiler->setDynamicParameterNames(['dynamic']); -$container = createContainer($compiler, ' -parameters: - t: true - f: false - fn: ::constant(NUM) - not: not(%f%) - string: string(%f%) - -services: - ok: - factory: Service - setup: - - not( not(%f%), not(%t%), not(%fn%), not(%dynamic%), %not% ) - - string( string(%f%), string(%t%), string(%fn%), string(%dynamic%), %string% ) - - bool( bool(%f%), bool(%t%) ) - - int( int(%f%), int(%t%), int(%fn%), int(%dynamic%) ) - - float( float(%f%), float(%t%), float(%fn%), float(%dynamic%) ) - - bad1: Service(bool(123)) - bad2: - factory: Service - setup: - - method(bool(123)) -', ['dynamic' => 123]); - - -$obj = $container->getByName('ok'); - -Assert::same( - [ - 'not' => [true, false, false, false, true], - 'string' => ['0', '1', '231', '123', '0'], - 'bool' => [false, true], - 'int' => [0, 1, 231, 123], - 'float' => [0.0, 1.0, 231.0, 123.0], - ], - $obj->args -); - -Assert::exception(function () use ($container) { - $container->getByName('bad1'); -}, Nette\InvalidStateException::class, "Cannot convert '123' to bool."); - -Assert::exception(function () use ($container) { - $container->getByName('bad2'); -}, Nette\InvalidStateException::class, "Cannot convert '123' to bool."); - - -// wrong arguments count -Assert::exception(function () { - createContainer(new DI\Compiler, ' - services: - - Service(bool(123, 10)) - '); -}, Nette\InvalidStateException::class, 'Service of type Service: Function bool() expects 1 parameter, 2 given. (used in Service::__construct())'); diff --git a/tests/DI/Compiler.generatedAccessor.phpt b/tests/DI/Compiler.generatedAccessor.phpt deleted file mode 100644 index 443770764..000000000 --- a/tests/DI/Compiler.generatedAccessor.phpt +++ /dev/null @@ -1,54 +0,0 @@ -getService('lorem')); -Assert::notSame($container->getService('lorem'), $container->getService('lorem2')); - -Assert::type(ILoremAccessor::class, $container->getService('one')); -Assert::same($container->getService('one')->get(), $container->getService('lorem')); - -Assert::type(ILoremAccessor::class, $container->getService('two')); -Assert::same($container->getService('two')->get(), $container->getService('lorem')); - -Assert::type(ILoremAccessor::class, $container->getService('three')); -Assert::same($container->getService('three')->get(), $container->getService('lorem2')); - -Assert::type(ILoremAccessor::class, $container->getService('four')); -Assert::same($container->getService('four')->get(), $container->getService('lorem')); diff --git a/tests/DI/Compiler.generatedFactory.nullableParameters.phpt b/tests/DI/Compiler.generatedFactory.nullableParameters.phpt deleted file mode 100644 index 929af4eea..000000000 --- a/tests/DI/Compiler.generatedFactory.nullableParameters.phpt +++ /dev/null @@ -1,75 +0,0 @@ -title = $title; - $this->foo = $foo; - $this->lorem = $lorem; - } -} - -$compiler = new DI\Compiler; -// parameters are deprecated -$container = @createContainer($compiler, ' -services: - - article: - factory: Article(%title%, %foo%, %lorem%) - implement: IArticleFactory - parameters: [?string title, ?Foo foo, ?int lorem: null] - - article2: - implement: IArticleFactory - arguments: [%title%, %foo%, %lorem%] - parameters: [?string title, ?Foo foo, ?int lorem: null] - - article3: - implement: IArticleFactory -'); - -foreach (['article', 'article2', 'article3'] as $serviceName) { - $service = $container->getService($serviceName); - Assert::type(IArticleFactory::class, $service); - $article = $service->create('lorem-ipsum', $foo = new Foo, 1); - Assert::type(Article::class, $article); - Assert::same('lorem-ipsum', $article->title); - Assert::same($foo, $article->foo); - Assert::same(1, $article->lorem); - - $article = $service->create(null, null); - Assert::type(Article::class, $article); - Assert::null($article->title); - Assert::null($article->foo); - Assert::same($serviceName === 'article3' ? 1 : null, $article->lorem); -} diff --git a/tests/DI/Compiler.generatedFactory.phpt b/tests/DI/Compiler.generatedFactory.phpt deleted file mode 100644 index 40a2026ed..000000000 --- a/tests/DI/Compiler.generatedFactory.phpt +++ /dev/null @@ -1,343 +0,0 @@ -ipsum = $ipsum; - } -} - -interface IFinderFactory -{ - /** - * @return Adapt\NeonAdapter comment - */ - public function create(); -} - -interface IArticleFactory -{ - public function create($title): Article; -} - -class Article -{ - public const Abc = 123; - - public $title; - public $method; - public $prop; - - - public function __construct($title) - { - $this->title = $title; - } - - - public function method($arg) - { - $this->method = $arg; - } -} - -class Ipsum -{ -} - -class Foo -{ - public $bar; - - public $baz; - - - public function __construct(Bar $bar, ?Baz $baz = null) - { - $this->bar = $bar; - $this->baz = $baz; - } -} - -class Bar -{ -} - -class Baz -{ -} - -interface IFooFactory -{ - public function create(?Baz $baz = null): Foo; -} - -class Dolor -{ - public $bar; - - public $foo; - - - public function __construct(?Bar $bar, $foo) - { - $this->bar = $bar; - $this->foo = $foo; - } -} - -interface DolorFactory -{ - public function create(?Bar $bar, $foo): Dolor; -} - - -class TestClass -{ - public $foo; - - public $bar; - - - public function __construct($foo, $bar) - { - $this->foo = $foo; - $this->bar = $bar; - } -} - -interface ITestClassFactory -{ - public function create($bar): TestClass; -} - -class TestExtension extends DI\CompilerExtension -{ - public function loadConfiguration() - { - $builder = $this->getContainerBuilder(); - $builder->addFactoryDefinition('fooFactory2') - ->setParameters(['Baz baz' => null]) - ->setImplement(IFooFactory::class) - ->getResultDefinition() - ->setCreator(Foo::class) - ->setArguments([1 => $builder::literal('$baz')]); - - $builder->addFactoryDefinition('overridenFactory') - ->setImplement(ILoremFactory::class) - ->setAutowired(false); - - // see definition by config in Compiler::parseService() - } -} - -$compiler = new DI\Compiler; -$compiler->addExtension('test', new TestExtension); -@$container = createContainer($compiler, 'files/compiler.generatedFactory.neon'); // missing type triggers warning - - -Assert::type(ILoremFactory::class, $container->getService('lorem')); -$lorem = $container->getService('lorem')->create(); -Assert::type(Lorem::class, $lorem); -Assert::type(Ipsum::class, $lorem->ipsum); -Assert::same($container->getService('ipsum'), $lorem->ipsum); - -Assert::type(ILoremFactory::class, $container->getByType(ILoremFactory::class)); - -Assert::type(IFinderFactory::class, $container->getService('finder')); -$finder = $container->getService('finder')->create(); -Assert::type(Nette\DI\Config\Adapters\NeonAdapter::class, $finder); - - -Assert::type(IArticleFactory::class, $container->getService('article')); -$article = $container->getService('article')->create('nemam'); -Assert::type(Article::class, $article); -Assert::same('nemam', $article->title); -Assert::same(123, $article->method); -Assert::same(123, $article->prop); - - -Assert::type(IFooFactory::class, $container->getService('fooFactory1')); -$foo = $container->getService('fooFactory1')->create($container->getService('baz')); -Assert::type(Foo::class, $foo); -Assert::type(Bar::class, $foo->bar); -Assert::same($container->getService('bar'), $foo->bar); -Assert::type(Baz::class, $foo->baz); -Assert::same($container->getService('baz'), $foo->baz); -$foo = $container->getService('fooFactory1')->create(); -Assert::type(Foo::class, $foo); -Assert::type(Bar::class, $foo->bar); -Assert::same($container->getService('bar'), $foo->bar); -Assert::null($foo->baz); - - -Assert::type(IFooFactory::class, $container->getService('fooFactory2')); -$foo = $container->getService('fooFactory2')->create($container->getService('baz')); -Assert::type(Foo::class, $foo); -Assert::type(Bar::class, $foo->bar); -Assert::same($container->getService('bar'), $foo->bar); -Assert::type(Baz::class, $foo->baz); -Assert::same($container->getService('baz'), $foo->baz); -$foo = $container->getService('fooFactory2')->create(); -Assert::type(Foo::class, $foo); -Assert::type(Bar::class, $foo->bar); -Assert::same($container->getService('bar'), $foo->bar); -Assert::null($foo->baz); - - -Assert::type(ILoremFactory::class, $container->getService('overridenFactory')); -$foo = $container->getService('overridenFactory')->create(); -Assert::type(Lorem::class, $foo); -Assert::same(123, $foo->var); - - -Assert::type(IArticleFactory::class, $container->getService('article2')); -$article = $container->getService('article2')->create('nemam'); -Assert::type(Article::class, $article); -Assert::same('nemam', $article->title); - - -Assert::type(IFooFactory::class, $container->getService('fooFactory3')); -$foo = $container->getService('fooFactory3')->create($container->getService('baz')); -Assert::type(Foo::class, $foo); -Assert::type(Bar::class, $foo->bar); -Assert::same($container->getService('bar'), $foo->bar); -Assert::type(Baz::class, $foo->baz); -Assert::same($container->getService('baz'), $foo->baz); -$foo = $container->getService('fooFactory3')->create(); -Assert::type(Foo::class, $foo); -Assert::type(Bar::class, $foo->bar); -Assert::same($container->getService('bar'), $foo->bar); -Assert::null($foo->baz); - - -Assert::type(IFooFactory::class, $container->getService('fooFactory4')); -$foo = $container->getService('fooFactory4')->create($container->getService('baz')); -Assert::type(Foo::class, $foo); -Assert::type(Bar::class, $foo->bar); -Assert::same($container->getService('bar'), $foo->bar); -Assert::type(Baz::class, $foo->baz); -Assert::same($container->getService('baz'), $foo->baz); -$foo = $container->getService('fooFactory4')->create(); -Assert::type(Foo::class, $foo); -Assert::type(Bar::class, $foo->bar); -Assert::same($container->getService('bar'), $foo->bar); -Assert::null($foo->baz); - - -Assert::type(ITestClassFactory::class, $container->getService('factory5')); -$obj = $container->getService('factory5')->create('bar'); -Assert::same('foo', $obj->foo); -Assert::same('bar', $obj->bar); - -Assert::type(DolorFactory::class, $factory = $container->getService('dolorFactory')); -Assert::type(Dolor::class, $obj = $factory->create($bar = new Bar, 'abc')); -Assert::same($bar, $obj->bar); -Assert::same('abc', $obj->foo); - -Assert::type(Dolor::class, $obj = $factory->create(null, 'abc')); -Assert::null($obj->bar); -Assert::same('abc', $obj->foo); - - -class Bad1 -{ - public function __construct(Bar $bar) - { - } -} - -interface Bad2 -{ - public function create(Baz $bar): Bad1; -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addFactoryDefinition('one') - ->setImplement(Bad2::class); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad2): Type of \$bar in Bad2::create() doesn't match type in Bad1 constructor."); - - - -class Bad3 -{ - public function __construct($bar) - { - } -} - -interface Bad4 -{ - public function create($baz): Bad3; -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addFactoryDefinition('one') - ->setImplement(Bad4::class); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad4): Cannot implement Bad4::create(): factory method parameters (\$baz) are not matching Bad3::__construct() parameters (\$bar). Did you mean to use '\$bar' in factory method?"); - - - -class Bad5 -{ - public function __construct($xxx) - { - } -} - -interface Bad6 -{ - public function create($baz): Bad5; -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addFactoryDefinition('one') - ->setImplement(Bad6::class); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad6): Cannot implement Bad6::create(): factory method parameters (\$baz) are not matching Bad5::__construct() parameters (\$xxx)."); - - - -interface Bad7 -{ - public function get(): stdClass; -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition(stdClass::class)->setCreator(stdClass::class); - $builder->addAccessorDefinition('one') - ->setImplement(Bad7::class) - ->setClass(stdClass::class) - ->addSetup('method'); - $builder->complete(); -}, Nette\MemberAccessException::class, 'Call to undefined method Nette\DI\Definitions\AccessorDefinition::addSetup().'); diff --git a/tests/DI/Compiler.generatedFactory.polymorphism.phpt b/tests/DI/Compiler.generatedFactory.polymorphism.phpt deleted file mode 100644 index fbfc44dd5..000000000 --- a/tests/DI/Compiler.generatedFactory.polymorphism.phpt +++ /dev/null @@ -1,111 +0,0 @@ -shape = $shape; - } - - - public function getName(): string - { - return $this->shape->getName(); - } -} - -$compiler = new DI\Compiler; -$container = createContainer($compiler, ' -services: - circle: - implement: ICircleFactory - - triangle: - implement: ITriangleFactory - - ellipse: - implement: IEllipseFactory -'); - -Assert::type(ICircleFactory::class, $container->getService('circle')); -$picture = $container->getService('circle')->create(new Circle); -Assert::type(Picture::class, $picture); -Assert::same('circle', $picture->getName()); - -Assert::type(ITriangleFactory::class, $container->getService('triangle')); -$picture = $container->getService('triangle')->create(new Triangle); -Assert::type(Picture::class, $picture); -Assert::same('triangle', $picture->getName()); - -Assert::type(IEllipseFactory::class, $container->getService('ellipse')); -$picture = $container->getService('ellipse')->create(new Ellipse); -Assert::type(Picture::class, $picture); -Assert::same('ellipse', $picture->getName()); - -Assert::type(ICircleFactory::class, $container->getService('circle')); -$picture = $container->getService('circle')->create(new Ellipse); -Assert::type(Picture::class, $picture); -Assert::same('ellipse', $picture->getName()); - -Assert::throws(function () use ($container) { - $container->getService('ellipse')->create(new Circle); -}, TypeError::class); diff --git a/tests/DI/Compiler.generatedFactory.returnTypes.phpt b/tests/DI/Compiler.generatedFactory.returnTypes.phpt deleted file mode 100644 index 15a4d097c..000000000 --- a/tests/DI/Compiler.generatedFactory.returnTypes.phpt +++ /dev/null @@ -1,69 +0,0 @@ -title = $title; - } -} - -class FooArticle extends Article -{ -} - -$compiler = new DI\Compiler; -// parameters are deprecated -$container = @createContainer($compiler, ' -services: - article: - factory: Article(%title%) - implement: IArticleFactory - parameters: [title] - - article2: - implement: IArticleFactory - arguments: [%title%] - parameters: [title] - - article3: - implement: IArticleFactory - factory: FooArticle -'); - -Assert::type(IArticleFactory::class, $container->getService('article')); -$article = $container->getService('article')->create('lorem-ipsum'); -Assert::type(Article::class, $article); -Assert::same('lorem-ipsum', $article->title); - -Assert::type(IArticleFactory::class, $container->getService('article2')); -$article = $container->getService('article2')->create('lorem-ipsum'); -Assert::type(Article::class, $article); -Assert::same('lorem-ipsum', $article->title); - - -Assert::type(IArticleFactory::class, $container->getService('article3')); -$article = $container->getService('article3')->create('lorem-ipsum'); -Assert::type(FooArticle::class, $article); -Assert::same('lorem-ipsum', $article->title); diff --git a/tests/DI/Compiler.generatedFactory.scalarParameters.phpt b/tests/DI/Compiler.generatedFactory.scalarParameters.phpt deleted file mode 100644 index 68666489d..000000000 --- a/tests/DI/Compiler.generatedFactory.scalarParameters.phpt +++ /dev/null @@ -1,63 +0,0 @@ -title = $title; - } -} - -$compiler = new DI\Compiler; -// parameters are deprecated -$container = @createContainer($compiler, ' -services: - article: - factory: Article(%title%) - implement: IArticleFactory - parameters: [string title] - - article2: - implement: IArticleFactory - arguments: [%title%] - parameters: [string title] - - article3: - implement: IArticleFactory -'); - -Assert::type(IArticleFactory::class, $container->getService('article')); -$article = $container->getService('article')->create('lorem-ipsum'); -Assert::type(Article::class, $article); -Assert::same('lorem-ipsum', $article->title); - -Assert::type(IArticleFactory::class, $container->getService('article2')); -$article = $container->getService('article2')->create('lorem-ipsum'); -Assert::type(Article::class, $article); -Assert::same('lorem-ipsum', $article->title); - -Assert::type(IArticleFactory::class, $container->getService('article3')); -$article = $container->getService('article3')->create('lorem-ipsum'); -Assert::type(Article::class, $article); -Assert::same('lorem-ipsum', $article->title); diff --git a/tests/DI/Compiler.generatedLocator.phpt b/tests/DI/Compiler.generatedLocator.phpt deleted file mode 100644 index 9dfb58a2d..000000000 --- a/tests/DI/Compiler.generatedLocator.phpt +++ /dev/null @@ -1,118 +0,0 @@ -getService('one'); -Assert::type(Lorem::class, $one->get('a')); -Assert::type(LoremChild::class, $one->get('b')); -Assert::same($one->get('a'), $one->get('a')); - -Assert::exception(function () use ($one) { - $one->get('undefined'); -}, Nette\DI\MissingServiceException::class, "Service 'undefined' is not defined."); - -// tagged accessor -$two = $container->getService('two'); -Assert::same($container->getService('lorem1'), $two->get('1')); -Assert::same($container->getService('lorem2'), $two->get('2')); - -Assert::exception(function () use ($two) { - $two->get('3'); -}, Nette\DI\MissingServiceException::class, "Service '3' is not defined."); - -// factory -$three = $container->getService('three'); -Assert::type(Lorem::class, $three->create('a')); -Assert::type(LoremChild::class, $three->create('b')); -Assert::notSame($three->create('a'), $three->create('a')); - -// tagged factory -$four = $container->getService('four'); -Assert::type(Lorem::class, $four->create('3')); -Assert::notSame($container->getService('lorem3'), $four->create('3')); - -// nullable accessor -$five = $container->getService('five'); -Assert::type(Lorem::class, $five->get('1')); -Assert::type(Lorem::class, $five->get('2')); -Assert::null($five->get('3')); - -// nullable factory -$six = $container->getService('six'); -Assert::type(Lorem::class, $six->create('1')); -Assert::type(Lorem::class, $six->create('2')); -Assert::null($six->create('3')); - -// accessor with one service -$one = $container->getService('seven'); -Assert::type(Lorem::class, $one->get('a')); diff --git a/tests/DI/Compiler.generatedLocatorMulti.phpt b/tests/DI/Compiler.generatedLocatorMulti.phpt deleted file mode 100644 index c2e8f95eb..000000000 --- a/tests/DI/Compiler.generatedLocatorMulti.phpt +++ /dev/null @@ -1,64 +0,0 @@ -getService('one'); -Assert::type(Lorem::class, $one->getA()); -Assert::type(Lorem::class, $one->getB()); -Assert::same($one->getA(), $one->getB()); - -// factory -Assert::type(Lorem::class, $one->createC()); -Assert::type(Lorem::class, $one->createD()); -Assert::notSame($one->createC(), $one->createD()); - -// nullable -$two = $container->getService('two'); -Assert::null($two->getB()); -Assert::null($two->createD()); - -// undefined -Assert::exception(function () use ($two) { - $two->getA(); -}, Nette\DI\MissingServiceException::class, 'Service is not defined.'); - -Assert::exception(function () use ($two) { - $two->createC(); -}, Nette\DI\MissingServiceException::class, 'Service is not defined.'); diff --git a/tests/DI/Compiler.loadConfig.include.phpt b/tests/DI/Compiler.loadConfig.include.phpt deleted file mode 100644 index 26d00f815..000000000 --- a/tests/DI/Compiler.loadConfig.include.phpt +++ /dev/null @@ -1,55 +0,0 @@ -loadConfig('files/loader.includes.neon'); -$compiler->compile(); - -Assert::same([ - 'files/loader.includes.neon', - 'files/loader.includes.child.neon', - 'files/loader.includes.child.php', - __DIR__ . DIRECTORY_SEPARATOR . 'files/loader.includes.grandchild.neon', - (new ReflectionClass(Nette\DI\Extensions\ServicesExtension::class))->getFileName(), - (new ReflectionClass(Nette\DI\Extensions\ParametersExtension::class))->getFileName(), -], array_keys($compiler->exportDependencies()[1])); - - -Assert::equal([ - 'parameters' => [ - 'me' => [ - 'loader.includes.child.neon', - 'loader.includes.grandchild.neon', - 'loader.includes.child.php', - ], - 'scalar' => 1, - 'list' => [5, 6, 1, 2], - 'force' => [1, 2], - ], - 'services' => [ - 'a' => (object) [ - 'type' => null, - 'create' => stdClass::class, - 'arguments' => [], - 'setup' => [], - 'inject' => null, - 'autowired' => false, - 'tags' => [], - 'reset' => [], - 'alteration' => null, - 'defType' => Nette\DI\Definitions\ServiceDefinition::class, - ], - ], -], $compiler->getConfig()); diff --git a/tests/DI/Compiler.loadDefinitionsFromConfig.phpt b/tests/DI/Compiler.loadDefinitionsFromConfig.phpt deleted file mode 100644 index 29102ceee..000000000 --- a/tests/DI/Compiler.loadDefinitionsFromConfig.phpt +++ /dev/null @@ -1,21 +0,0 @@ -load(__DIR__ . '/files/compiler.parseServices.namespace.neon'); -(new DI\Compiler($builder))->loadDefinitionsFromConfig($config['services']); - - -Assert::true($builder->hasDefinition('comments')); -Assert::true($builder->hasDefinition('articlesList')); -Assert::true($builder->hasDefinition('commentsControl')); diff --git a/tests/DI/Compiler.missingDefinition.phpt b/tests/DI/Compiler.missingDefinition.phpt deleted file mode 100644 index 61e8915e1..000000000 --- a/tests/DI/Compiler.missingDefinition.phpt +++ /dev/null @@ -1,25 +0,0 @@ -addConfig($loader->load(Tester\FileMock::create($config, 'neon')))->compile(); -}, Nette\InvalidArgumentException::class, 'Circular reference detected for parameters: %foo%, %foobar%, %bar%'); - - -Assert::exception(function () { - $config = ' -parameters: - outer: - inner: %outer.inner% -'; - $loader = new DI\Config\Loader; - $compiler = new DI\Compiler; - $compiler->addConfig($loader->load(Tester\FileMock::create($config, 'neon')))->compile(); -}, Nette\InvalidArgumentException::class, 'Circular reference detected for parameters: %outer.inner%'); diff --git a/tests/DI/Compiler.parameters.code.phpt b/tests/DI/Compiler.parameters.code.phpt deleted file mode 100644 index bc01ecb50..000000000 --- a/tests/DI/Compiler.parameters.code.phpt +++ /dev/null @@ -1,70 +0,0 @@ -load(Tester\FileMock::create(' -parameters: - static: 123 - expr: ::trim(" a ") - dynamic: 123 - dynamicArray: - dynamic: %dynamic% - inner: %arrayDynamic.dynamic.foo% - expr: ::trim(" a ") - arrayExpr: - expr: ::trim(" a ") - arrayExpr2: - expr: %expr% - arrayDynamic: - dynamic: %dynamic% - inner: %arrayDynamic.dynamic.foo% - arrayMix: - expr: %expr% - dynamic: %dynamic% - refStatic: %static% - refDynamic: %dynamic% - refDynamic2: %dynamic.foo% - refExpr: %expr% - refArrayE1: %arrayExpr% - refArrayE2: %arrayExpr.expr% - refArrayD1: %arrayDynamic% - refArrayD2: %arrayDynamic.dynamic% - refArrayD3: %refArrayD2.foo% - -services: - - Service( - %static% - %expr% - %dynamic% - %dynamic.foo% - %arrayExpr% - %arrayExpr.expr% - %arrayDynamic% - %arrayDynamic.dynamic% - %arrayDynamic.inner% - ) -', 'neon')); - -$compiler = new Nette\DI\Compiler; -$compiler->setDynamicParameterNames(['dynamic', 'dynamicArray']); -$code = $compiler->addConfig($config) - ->compile(); - -Assert::matchFile( - __DIR__ . '/expected/compiler.parameters.php', - $code -); diff --git a/tests/DI/Compiler.parameters.phpt b/tests/DI/Compiler.parameters.phpt deleted file mode 100644 index 1601de60f..000000000 --- a/tests/DI/Compiler.parameters.phpt +++ /dev/null @@ -1,159 +0,0 @@ -arg = $arg; - } -} - - -test('Statement as parameter', function () { - $compiler = new DI\Compiler; - $container = createContainer($compiler, ' - parameters: - bar: ::trim(" a ") - - services: - one: Service(%bar%) - '); - - Assert::same([], $container->parameters); - Assert::same([], $container->getParameters()); - Assert::exception(function () use ($container) { - $container->getParameter('bar'); - }, Nette\InvalidStateException::class, "Parameter 'bar' not found. Check if 'di › export › parameters' is enabled."); - Assert::same('a', $container->getService('one')->arg); -}); - - -test('Statement within string expansion', function () { - $compiler = new DI\Compiler; - $container = createContainer($compiler, ' - parameters: - bar: ::trim(" a ") - expand: hello%bar% - - services: - one: Service(%expand%) - '); - - Assert::same([], $container->getParameters()); - Assert::same('helloa', $container->getService('one')->arg); -}); - - -test('NOT class constant as parameter', function () { - $compiler = new DI\Compiler; - $container = createContainer($compiler, ' - parameters: - bar: Service::Name - - services: - one: Service(%bar%) - '); - - Assert::same(['bar' => 'Service::Name'], $container->getParameters()); // not resolved - Assert::same('hello', $container->getService('one')->arg); -}); - - -test('Class method and constant resolution', function () { - $compiler = new DI\Compiler; - $container = createContainer($compiler, ' - parameters: - bar: Service::method(Service::Name) - - services: - one: Service(%bar%) - '); - - Assert::same([], $container->getParameters()); - Assert::same('Service::method hello', $container->getService('one')->arg); -}); - - -test('Parameter NOT referencing a service', function () { - $compiler = new DI\Compiler; - $container = createContainer($compiler, ' - parameters: - bar: @two - - services: - one: Service(%bar%) - two: Service(two) - '); - - // intentionally not resolved, it is not possible to distinguish a string from a reference - Assert::same(['bar' => '@two'], $container->getParameters()); - Assert::same($container->getService('two'), $container->getService('one')->arg); -}); - - -test('Parameter as an instantiated class', function () { - $compiler = new DI\Compiler; - $container = createContainer($compiler, ' - parameters: - bar: Service(@two) - - services: - one: Service(%bar%) - two: Service(two) - '); - - Assert::equal([], $container->getParameters()); - Assert::same($container->getService('two'), $container->getService('one')->arg->arg); -}); - - -test('Parameter as array of services', function () { - $compiler = new DI\Compiler; - $container = createContainer($compiler, ' - parameters: - bar: typed(Service) - - services: - one: Service(%bar%) - two: Service(two) - '); - - Assert::same([], $container->getParameters()); - Assert::same([$container->getService('two')], $container->getService('one')->arg); -}); - - -test('Not circular reference', function () { - $compiler = new DI\Compiler; - $container = createContainer($compiler, ' - parameters: - array: - foo: foo - bar: %array.foo% - '); - - Assert::same( - ['array' => ['foo' => 'foo', 'bar' => 'foo']], - $container->getParameters() - ); -}); diff --git a/tests/DI/Compiler.referenceBug.phpt b/tests/DI/Compiler.referenceBug.phpt deleted file mode 100644 index 4351067ae..000000000 --- a/tests/DI/Compiler.referenceBug.phpt +++ /dev/null @@ -1,41 +0,0 @@ -args = func_get_args(); - } -} - - -$container = createContainer(new DI\Compiler, ' -services: - - stdClass - a: Lorem(x: true) - b: Lorem(x: Lorem(x: true)) - c: Lorem("@test") -'); - - -Assert::same(['@foo', '@@foo', '@\stdClass', true], $container->getService('a')->args); -Assert::equal(['@foo', '@@foo', '@\stdClass', new Lorem('@foo', '@@foo', '@\stdClass', true)], $container->getService('b')->args); -Assert::same(['@test'], $container->getService('c')->args); diff --git a/tests/DI/Compiler.services.autowiring.phpt b/tests/DI/Compiler.services.autowiring.phpt deleted file mode 100644 index ec043dcd2..000000000 --- a/tests/DI/Compiler.services.autowiring.phpt +++ /dev/null @@ -1,83 +0,0 @@ -getService('model')); - -Assert::same([ - 'Model::test', - 'Model::test', - 'Model::test', - 'Lorem::test', - 'Lorem::test', -], Notes::fetch()); diff --git a/tests/DI/Compiler.services.byClass.phpt b/tests/DI/Compiler.services.byClass.phpt deleted file mode 100644 index beda60a2f..000000000 --- a/tests/DI/Compiler.services.byClass.phpt +++ /dev/null @@ -1,65 +0,0 @@ -value = $value; - } - - - public static function foo() - { - } -} - - -$container = createContainer(new DI\Compiler, ' -services: - three: @\Lorem - - one: - factory: Lorem(@\Ipsum) - - two: - factory: Ipsum(1) - setup: - - @\Ipsum::foo() - - four: @\Lorem - - @\Ipsum: - arguments: [2] -'); - - -Assert::type(Lorem::class, $container->getService('one')); -Assert::type(Ipsum::class, $container->getService('two')); -Assert::same(2, $container->getService('two')->value); -Assert::type(Lorem::class, $container->getService('three')); -Assert::same($container->getService('one'), $container->getService('three')); -Assert::type(Lorem::class, $container->getService('four')); -Assert::same($container->getService('one'), $container->getService('four')); diff --git a/tests/DI/Compiler.services.create.phpt b/tests/DI/Compiler.services.create.phpt deleted file mode 100644 index 9f8b11b8a..000000000 --- a/tests/DI/Compiler.services.create.phpt +++ /dev/null @@ -1,128 +0,0 @@ -arg = $arg; - } - - - public function foo(...$args): self - { - $this->foo = $args; - return $this; - } -} - -class Ipsum -{ - public $arg; - - - public function __construct($arg) - { - $this->arg = $arg; - } -} - - -$container = createContainer(new DI\Compiler, 'files/compiler.services.create.neon'); - - -Assert::type(Ipsum::class, $container->getService('one')); -Assert::same(1, $container->getService('one')->arg); - -Assert::type(Ipsum::class, $container->getService('two')); -Assert::same(1, $container->getService('two')->arg); - -Assert::type(Lorem::class, $container->getService('three')); -Assert::same('Factory::createLorem 1 2', $container->getService('three')->arg); - -Assert::type(Lorem::class, $container->getService('four')); -Assert::same('Factory::createLorem 1', $container->getService('four')->arg); - -Assert::type(Lorem::class, $container->getService('five')); -Assert::same('Factory::createLorem 1', $container->getService('five')->arg); - -Assert::type(Lorem::class, $container->getService('six')); -Assert::same('Factory::createLorem 1', $container->getService('six')->arg); - -Assert::type(Lorem::class, $container->getService('seven')); - -Assert::type(Lorem::class, $container->getService('eight')); - -Assert::type(Lorem::class, $container->getService('nine')); -Assert::same('Factory::createLorem 1 2', $container->getService('nine')->arg); -Assert::same([], $container->getService('nine')->foo); - -Assert::type(Ipsum::class, $container->getService('referencedService')); -Assert::same($container->getService('one'), $container->getService('referencedService')); - -Assert::type(Ipsum::class, $container->getService('referencedServiceWithSetup')); -Assert::notSame($container->getService('one'), $container->getService('referencedServiceWithSetup')); - -Assert::type(Ipsum::class, $container->getService('calledService')); -Assert::same($container->getService('one'), $container->getService('calledService')); // called without arguments is reference - -Assert::type(Ipsum::class, $container->getService('calledServiceWithArgs')); -Assert::notSame($container->getService('one'), $container->getService('calledServiceWithArgs')); - -Assert::type(stdClass::class, $container->getByType('\stdClass')); - - -Assert::type(Ipsum::class, $container->getService('serviceAsParam')); -Assert::type(Ipsum::class, $container->getService('serviceAsParam')->arg); -Assert::same($container->getService('one'), $container->getService('serviceAsParam')->arg); - -Assert::type(Ipsum::class, $container->getService('calledServiceAsParam')); -Assert::type(Ipsum::class, $container->getService('calledServiceAsParam')->arg); -Assert::notSame($container->getService('one'), $container->getService('calledServiceAsParam')->arg); - -Assert::type(Ipsum::class, $container->getService('calledServiceWithArgsAsParam')); -Assert::type(Ipsum::class, $container->getService('calledServiceWithArgsAsParam')->arg); -Assert::notSame($container->getService('one'), $container->getService('calledServiceWithArgsAsParam')->arg); - - -Assert::type(Lorem::class, $container->getService('rich1')); -Assert::same(1, $container->getService('rich1')->arg); -Assert::same([], $container->getService('rich1')->foo); - -Assert::type(Lorem::class, $container->getService('rich2')); -Assert::type(Ipsum::class, $container->getService('rich2')->arg); -Assert::same($container->getService('one'), $container->getService('rich2')->arg->arg); -Assert::same([1], $container->getService('rich2')->foo); - -Assert::type(Lorem::class, $container->getService('rich3')); -Assert::same('Factory::createLorem 1', $container->getService('rich3')->arg); -Assert::same([], $container->getService('rich3')->foo); - -Assert::type(Lorem::class, $container->getService('rich4')); -Assert::same('Factory::createLorem 1', $container->getService('rich4')->arg); -Assert::same([], $container->getService('rich4')->foo); diff --git a/tests/DI/Compiler.services.imported.phpt b/tests/DI/Compiler.services.imported.phpt deleted file mode 100644 index 19cbd5815..000000000 --- a/tests/DI/Compiler.services.imported.phpt +++ /dev/null @@ -1,54 +0,0 @@ -getService('one'); -}, Nette\DI\ServiceCreationException::class, "Unable to create imported service 'one', it must be added using addService()"); - - -$container = createContainer(new DI\Compiler, ' -services: - one: - type: Service - imported: true -'); - -Assert::exception(function () use ($container) { - $container->getService('one'); -}, Nette\DI\ServiceCreationException::class, "Unable to create imported service 'one', it must be added using addService()"); - - -$container = @createContainer(new DI\Compiler, ' -services: - one: - class: Service - dynamic: true -'); - -Assert::exception(function () use ($container) { - $container->getService('one'); -}, Nette\DI\ServiceCreationException::class, "Unable to create imported service 'one', it must be added using addService()"); diff --git a/tests/DI/Compiler.services.removed.phpt b/tests/DI/Compiler.services.removed.phpt deleted file mode 100644 index 62aa00a23..000000000 --- a/tests/DI/Compiler.services.removed.phpt +++ /dev/null @@ -1,21 +0,0 @@ -hasService('ipsum')); diff --git a/tests/DI/Compiler.services.setup.phpt b/tests/DI/Compiler.services.setup.phpt deleted file mode 100644 index b95de0cad..000000000 --- a/tests/DI/Compiler.services.setup.phpt +++ /dev/null @@ -1,90 +0,0 @@ -args = $args; - self::$instances[] = $this; - } - - - public function test(...$args) - { - Notes::add(__METHOD__ . ' ' . implode(' ', $args) . ' ' . implode(' ', $this->args)); - } - - - public static function staticTest(...$args) - { - Notes::add(__METHOD__ . ' ' . implode(' ', $args)); - } -} - - -function globtest(...$args) -{ - Notes::add(__METHOD__ . ' ' . implode(' ', $args)); -} - - -$container = createContainer(new DI\Compiler, 'files/compiler.services.setup.neon'); - - -Assert::same([ -], Notes::fetch()); - -Assert::type(Lorem::class, $container->getService('lorem')); - -Assert::same([ - 'Lorem::test 2', - 'Lorem::test 3', - 'Lorem::test 4', - 'Ipsum::staticTest 5', - 'Ipsum::test 6 ', - 'globtest 7', - 'Ipsum::test a', - 'Ipsum::test 10 b', -], Notes::fetch()); - -Assert::same(8, $container->getService('lorem')->test); -Assert::same(9, Ipsum::$staticTest); -Assert::equal(new Lorem, $container->getService('ipsum')->test); -Assert::same([1, 2], $container->getService('lorem')->arr); - -Assert::count(4, Ipsum::$instances); -Assert::same([$container->getService('lorem')], Ipsum::$instances[3]->args); diff --git a/tests/DI/Compiler.unknownDefinitionKey.phpt b/tests/DI/Compiler.unknownDefinitionKey.phpt deleted file mode 100644 index 569013ea9..000000000 --- a/tests/DI/Compiler.unknownDefinitionKey.phpt +++ /dev/null @@ -1,25 +0,0 @@ -load(__DIR__ . '/files/compiler.parseServices.namespace.neon'); -$config['services']['articlesList']['factory']->arguments[0] = new Reference('extension.articles'); - -$builder = new DI\ContainerBuilder; -$compiler = new DI\Compiler($builder); -$compilerExtension = (new CompilerExtension)->setCompiler($compiler, 'blog'); -$compilerExtension->loadDefinitionsFromConfig($config['services']); - - -Assert::same('@blog.articles', $builder->getDefinition('blog.comments')->getCreator()->arguments[1]); -Assert::equal(new Reference('blog.articles'), $builder->getDefinition('blog.articlesList')->getCreator()->arguments[0]); -Assert::equal(new Reference('blog.comments'), $builder->getDefinition('blog.commentsControl')->getCreator()->arguments[0]->getEntity()); diff --git a/tests/DI/CompilerExtension.loadFromFile.phpt b/tests/DI/CompilerExtension.loadFromFile.phpt deleted file mode 100644 index 06db9cd3b..000000000 --- a/tests/DI/CompilerExtension.loadFromFile.phpt +++ /dev/null @@ -1,35 +0,0 @@ -setCompiler(new DI\Compiler, 'my'); -$res = $ext->loadFromFile(Tester\FileMock::create($config, 'neon')); -Assert::equal([ - 'services' => [ - 'one' => [ - 'factory' => 'Ipsum', - ], - ], -], $res); diff --git a/tests/DI/CompilerExtension.validateConfig.phpt b/tests/DI/CompilerExtension.validateConfig.phpt deleted file mode 100644 index 1c6f2f35b..000000000 --- a/tests/DI/CompilerExtension.validateConfig.phpt +++ /dev/null @@ -1,67 +0,0 @@ -validateConfig([])); - Assert::same(['a' => 2, 'b' => 1], $ext->validateConfig(['a' => 1, 'b' => 1], ['a' => 2])); -}); - -test('', function () { - $ext = new MyExtension; - $ext->setConfig(['a' => 2]); - Assert::same(['a' => 2, 'b' => 1], $ext->validateConfig(['a' => 1, 'b' => 1])); - Assert::same(['a' => 2, 'b' => 1], $ext->getConfig()); -}); - -test('', function () { - $ext = new MyExtension; - $ext->setConfig(['a' => 2]); - Assert::same(['a' => 3, 'b' => 1], $ext->validateConfig(['a' => 1, 'b' => 1], ['a' => 3])); - Assert::same(['a' => 2], $ext->getConfig()); -}); - -test('', function () { - $ext = new MyExtension; - $ext->setConfig(['a' => 2]); - Assert::same(['a' => 1, 'b' => 1], $ext->validateConfig(['a' => 1, 'b' => 1], null)); - Assert::same(['a' => 2], $ext->getConfig()); -}); - -Assert::exception(function () { - $ext = new MyExtension; - $ext->validateConfig(['a' => 1, 'b' => 1], ['c' => 1]); -}, Nette\DI\InvalidConfigurationException::class, "Unknown configuration option 'my\u{a0}›\u{a0}c', did you mean 'my\u{a0}›\u{a0}a'?"); - -Assert::exception(function () { - $ext = new MyExtension; - $ext->validateConfig(['a' => 1, 'b' => 1], ['ccc' => 1, 'ddd' => 2]); -}, Nette\DI\InvalidConfigurationException::class, "Unknown configuration option 'my\u{a0}›\u{a0}ccc', 'my\u{a0}›\u{a0}ddd'."); - -Assert::exception(function () { - $ext = new MyExtension; - $ext->validateConfig(['a' => 1, 'b' => 1], ['c' => 1, 'd' => 1], 'name.x'); -}, Nette\DI\InvalidConfigurationException::class, "Unknown configuration option 'name\u{a0}›\u{a0}x\u{a0}›\u{a0}c', did you mean 'name\u{a0}›\u{a0}x\u{a0}›\u{a0}a'?"); - -Assert::exception(function () { - $ext = new MyExtension; - $ext->setConfig(['c' => 1, 'd' => 1]); - $ext->validateConfig(['a' => 1, 'b' => 1]); -}, Nette\DI\InvalidConfigurationException::class, "Unknown configuration option 'my\u{a0}›\u{a0}c', did you mean 'my\u{a0}›\u{a0}a'?"); diff --git a/tests/DI/ConstantsExtension.basic.phpt b/tests/DI/ConstantsExtension.basic.phpt deleted file mode 100644 index 925c641d8..000000000 --- a/tests/DI/ConstantsExtension.basic.phpt +++ /dev/null @@ -1,26 +0,0 @@ -addExtension('constants', new Nette\DI\Extensions\ConstantsExtension); -$container = @createContainer($compiler, ' -constants: - a: hello - A: WORLD -'); -$container->initialize(); - -Assert::same('hello', a); -Assert::same('WORLD', A); diff --git a/tests/DI/Container.circular.phpt b/tests/DI/Container.circular.phpt deleted file mode 100644 index 33a32117b..000000000 --- a/tests/DI/Container.circular.phpt +++ /dev/null @@ -1,35 +0,0 @@ -getService('two'); - } - - - protected function createServiceTwo() - { - return $this->getService('one'); - } -} - - -$container = new MyContainer; - -Assert::exception(function () use ($container) { - $container->getService('one'); -}, Nette\InvalidStateException::class, 'Circular reference detected for: one, two.'); diff --git a/tests/DI/Container.createInstance.phpt b/tests/DI/Container.createInstance.phpt deleted file mode 100644 index afb36d874..000000000 --- a/tests/DI/Container.createInstance.phpt +++ /dev/null @@ -1,45 +0,0 @@ -container = $container; - } - - - public function method(stdClass $obj, DI\Container $container) - { - return isset($obj->prop); - } -} - - -$builder = new DI\ContainerBuilder; -$builder->addDefinition('one') - ->setType(stdClass::class); - - -$container = createContainer($builder); - -$test = $container->createInstance(Test::class); -Assert::type(Test::class, $test); -Assert::same($container, $test->container); -Assert::false($container->callMethod([$test, 'method'])); -Assert::true($container->callMethod([$test, 'method'], [(object) ['prop' => true]])); diff --git a/tests/DI/Container.dynamic.php80.phpt b/tests/DI/Container.dynamic.php80.phpt deleted file mode 100644 index 384474b5e..000000000 --- a/tests/DI/Container.dynamic.php80.phpt +++ /dev/null @@ -1,22 +0,0 @@ -addService('six', function (): stdClass|Closure {}); // @ triggers service should be defined as "imported" - $container->getService('six'); -}, Nette\InvalidStateException::class, "Return type of closure is expected to not be nullable/built-in/complex, 'stdClass|Closure' given."); diff --git a/tests/DI/Container.dynamic.phpt b/tests/DI/Container.dynamic.phpt deleted file mode 100644 index 9d7e0a9e4..000000000 --- a/tests/DI/Container.dynamic.phpt +++ /dev/null @@ -1,70 +0,0 @@ -addService('one', $one); - $container->addService('two', $two); - - Assert::true($container->hasService('one')); - Assert::true($container->isCreated('one')); - Assert::true($container->hasService('two')); - Assert::false($container->hasService('undefined')); - - Assert::same($one, $container->getService('one')); - Assert::same($two, $container->getService('two')); - - Assert::same(Service::class, $container->getServiceType('one')); - Assert::same(Service::class, $container->getServiceType('two')); -}); - - -test('closure', function () use ($container) { - @$container->addService('four', function () { // @ triggers service should be defined as "imported" - return new Service; - }); - - Assert::true($container->hasService('four')); - Assert::false($container->isCreated('four')); - Assert::true($container->getService('four') instanceof Service); - Assert::true($container->isCreated('four')); - Assert::same($container->getService('four'), $container->getService('four')); // shared - - Assert::same('', $container->getServiceType('four')); -}); - - -test('closure with typehint', function () use ($container) { - @$container->addService('five', function (): Service { // @ triggers service should be defined as "imported" - return new Service; - }); - - Assert::same(Service::class, $container->getServiceType('five')); -}); - - -// bad closure -Assert::exception(function () use ($container) { - @$container->addService('six', function () {}); // @ triggers service should be defined as "imported" - $container->getService('six'); -}, Nette\UnexpectedValueException::class, "Unable to create service 'six', value returned by closure is not object."); diff --git a/tests/DI/Container.errors.phpt b/tests/DI/Container.errors.phpt deleted file mode 100644 index 244c46786..000000000 --- a/tests/DI/Container.errors.phpt +++ /dev/null @@ -1,30 +0,0 @@ -addService('', $service); -}, Nette\InvalidArgumentException::class, 'Service name must be a non-empty string.'); - -Assert::exception(function () use ($container) { - $container->getService('one'); -}, Nette\DI\MissingServiceException::class, "Service 'one' not found."); - -Assert::exception(function () use ($container, $service) { - $container->addService('one', $service); - $container->addService('one', $service); -}, Nette\InvalidStateException::class, "Service 'one' already exists."); diff --git a/tests/DI/Container.getByType.alias.phpt b/tests/DI/Container.getByType.alias.phpt deleted file mode 100644 index 108e5480c..000000000 --- a/tests/DI/Container.getByType.alias.phpt +++ /dev/null @@ -1,44 +0,0 @@ -addDefinition('one') - ->setType(Service::class); -$two = $builder->addDefinition('two') - ->setType(Alias::class); - -$container = createContainer($builder); - - -Assert::exception(function () use ($container) { - $container->getByType(Service::class); -}, Nette\DI\MissingServiceException::class, 'Multiple services of type Service found: one, two.'); - -Assert::exception(function () use ($container) { - $container->getByType(Alias::class); -}, Nette\DI\MissingServiceException::class, 'Multiple services of type Service found: one, two.'); - -Assert::exception(function () use ($builder) { - $builder->getByType('\service'); -}, Nette\DI\ServiceCreationException::class, 'Multiple services of type Service found: one, two'); - - - -Assert::same(['one', 'two'], $container->findByType(Service::class)); -Assert::same(['one', 'two'], $container->findByType(Alias::class)); -Assert::same(['one', 'two'], $container->findByType('\service')); diff --git a/tests/DI/Container.getByType.phpt b/tests/DI/Container.getByType.phpt deleted file mode 100644 index 96e81f22e..000000000 --- a/tests/DI/Container.getByType.phpt +++ /dev/null @@ -1,68 +0,0 @@ -addDefinition('one') - ->setType(Service::class); -$child = $builder->addDefinition('child') - ->setType(Child::class) - ->setAutowired(false); -$two = $builder->addDefinition('two') - ->setType(Service2::class); -$three = $builder->addDefinition('three') - ->setType(Service2::class) - ->setAutowired(false); - -$container = createContainer($builder); - - -Assert::type(Service::class, $container->getByType(Service::class)); - -Assert::null($container->getByType(Child::class, false)); - -Assert::type(Service2::class, $container->getByType(Service2::class)); - -Assert::exception(function () use ($container) { - $container->getByType(stdClass::class); -}, Nette\DI\MissingServiceException::class, 'Multiple services of type stdClass found: one, two.'); - -Assert::null($container->getByType('unknown', false)); - -Assert::exception(function () use ($container) { - $container->getByType('unknown'); -}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found. Check the class name because it cannot be found."); - -Assert::exception(function () use ($container) { - $container->getByType('Exception'); -}, Nette\DI\MissingServiceException::class, 'Service of type Exception not found. Did you add it to configuration file?'); - - -Assert::same(['one', 'child'], $container->findByType(Service::class)); -Assert::same(['child'], $container->findByType(Child::class)); -Assert::same(['two', 'three'], $container->findByType(Service2::class)); -Assert::same([], $container->findByType('unknown')); diff --git a/tests/DI/Container.getServiceType.phpt b/tests/DI/Container.getServiceType.phpt deleted file mode 100644 index 9790cd102..000000000 --- a/tests/DI/Container.getServiceType.phpt +++ /dev/null @@ -1,42 +0,0 @@ - 'one', - ]; - - - public function createServiceOne(): One - { - } - - - public function createServiceTwo(): Two - { - } -} - - -$container = new MyContainer; - -Assert::same('One', $container->getServiceType('one')); -Assert::same('Two', $container->getServiceType('two')); -Assert::same('One', $container->getServiceType('three')); - -Assert::exception(function () use ($container) { - $container->getServiceType('four'); -}, Nette\DI\MissingServiceException::class, "Service 'four' not found."); diff --git a/tests/DI/Container.getServiceType2.phpt b/tests/DI/Container.getServiceType2.phpt deleted file mode 100644 index dc724d1de..000000000 --- a/tests/DI/Container.getServiceType2.phpt +++ /dev/null @@ -1,44 +0,0 @@ -addDefinition('one') - ->setType(Service::class); -$child = $builder->addAccessorDefinition('acc') - ->setImplement(Accessor::class); -$two = $builder->addFactoryDefinition('fac') - ->setImplement(Factory::class); - -$container = createContainer($builder); - - -Assert::same(Service::class, $container->getServiceType('one')); -Assert::same(Accessor::class, $container->getServiceType('acc')); -Assert::same(Factory::class, $container->getServiceType('fac')); diff --git a/tests/DI/Container.inject.methods.phpt b/tests/DI/Container.inject.methods.phpt deleted file mode 100644 index ffc0c3f62..000000000 --- a/tests/DI/Container.inject.methods.phpt +++ /dev/null @@ -1,63 +0,0 @@ -injects[] = __METHOD__; - } - - - public function injectA(stdClass $obj) - { - $this->injects[] = __METHOD__; - } - - - protected function injectB(stdClass $obj) - { - $this->injects[] = __METHOD__; - } - - - public function injectOptional(?DateTime $obj = null) - { - $this->injects[] = __METHOD__; - } -} - -class Test2 extends Test1 -{ - public function injectC(stdClass $obj) - { - $this->injects[] = __METHOD__; - } -} - - -$builder = new DI\ContainerBuilder; -$builder->addDefinition('one') - ->setType(stdClass::class); - - -$container = createContainer($builder); - -$test = new Test2; -$container->callInjects($test); -Assert::same(['Test1::inject', 'Test1::injectA', 'Test1::injectOptional', 'Test2::injectC'], $test->injects); diff --git a/tests/DI/Container.inject.properties.phpt b/tests/DI/Container.inject.properties.phpt deleted file mode 100644 index b633c0f8b..000000000 --- a/tests/DI/Container.inject.properties.phpt +++ /dev/null @@ -1,57 +0,0 @@ -addDefinition('one') - ->setType(stdClass::class); -$builder->addDefinition('two') - ->setType(Foo::class); - - -$container = createContainer($builder); - -$test = new Test2; -$container->callInjects($test); -Assert::type(stdClass::class, $test->varA); -Assert::type(stdClass::class, $test->varB); -Assert::type(stdClass::class, $test->varC); -Assert::type(Foo::class, $test->varD); diff --git a/tests/DI/Container.static-dynamic.phpt b/tests/DI/Container.static-dynamic.phpt deleted file mode 100644 index 23a426ddc..000000000 --- a/tests/DI/Container.static-dynamic.phpt +++ /dev/null @@ -1,93 +0,0 @@ -hasService('one')); - - $container->addService('one', new stdClass); - - Assert::true($container->hasService('one')); - Assert::same('', $container->getServiceType('one')); - - Assert::type(stdClass::class, $container->getService('one')); - Assert::same($container->getService('one'), $container->getService('one')); // shared -}); - - -test('closure', function () { - $container = new MyContainer; - - $container->addService('one', function () { return new stdClass; }); - - Assert::true($container->hasService('one')); - Assert::same('', $container->getServiceType('one')); - Assert::type(stdClass::class, $container->getService('one')); - Assert::same($container->getService('one'), $container->getService('one')); // shared -}); - - -test('closure & typehint', function () { - $container = new MyContainer; - - $container->addService('one', function (): stdClass { return new stdClass; }); - - Assert::same(stdClass::class, $container->getServiceType('one')); - Assert::true($container->hasService('one')); - Assert::type(stdClass::class, $container->getService('one')); -}); - - -test('closure & matching typehint', function () { - $container = new MyContainer; - - class MyClass extends stdClass - { - } - - $container->addService('typehint', function (): MyClass { return new MyClass; }); - - Assert::same(MyClass::class, $container->getServiceType('typehint')); - Assert::true($container->hasService('typehint')); - Assert::type(MyClass::class, $container->getService('typehint')); -}); - - -Assert::exception(function () { // closure & wrong typehint - $container = new MyContainer; - $container->addService('typehint', function () { return new DateTime; }); -}, Nette\InvalidArgumentException::class, "Service 'typehint' must be instance of stdClass, add typehint to closure."); - - -Assert::exception(function () { // closure & wrong typehint - $container = new MyContainer; - $container->addService('typehint', function (): DateTime { return new DateTime; }); -}, Nette\InvalidArgumentException::class, "Service 'typehint' must be instance of stdClass, DateTime given."); diff --git a/tests/DI/ContainerBuilder.accessor.phpt b/tests/DI/ContainerBuilder.accessor.phpt deleted file mode 100644 index e6b528e09..000000000 --- a/tests/DI/ContainerBuilder.accessor.phpt +++ /dev/null @@ -1,74 +0,0 @@ -accessor = $accessor; - } -} - - -$builder = new DI\ContainerBuilder; -$builder->addDefinition('service') - ->setCreator(stdClass::class); - -$builder->addDefinition('service2') - ->setAutowired(false) - ->setCreator(stdClass::class); - -$builder->addAccessorDefinition('one') - ->setImplement(StdClassAccessor::class) - ->setReference(stdClass::class); - -@$builder->addAccessorDefinition('two') - ->setImplement(AnnotatedAccessor::class); // missing type triggers warning - -$builder->addAccessorDefinition('three') - ->setImplement(StdClassAccessor::class) - ->setAutowired(false) - ->setReference('@service2'); - -$builder->addDefinition('four') - ->setType(AccessorReceiver::class); - - -$container = createContainer($builder); - -Assert::type(StdClassAccessor::class, $container->getService('one')); -Assert::same($container->getService('one')->get(), $container->getService('service')); - -Assert::type(AnnotatedAccessor::class, $container->getService('two')); -Assert::same($container->getService('two')->get(), $container->getService('service')); - -Assert::type(StdClassAccessor::class, $container->getService('three')); -Assert::same($container->getService('three')->get(), $container->getService('service2')); - -Assert::type(AccessorReceiver::class, $container->getService('four')); diff --git a/tests/DI/ContainerBuilder.accessor^2.phpt b/tests/DI/ContainerBuilder.accessor^2.phpt deleted file mode 100644 index 103faadb6..000000000 --- a/tests/DI/ContainerBuilder.accessor^2.phpt +++ /dev/null @@ -1,49 +0,0 @@ -addAccessorDefinition('one') - ->setImplement(StdClassAccessorAccessor::class); - -$builder->addAccessorDefinition('two') - ->setImplement(StdClassAccessor::class); - -$builder->addDefinition('three') - ->setClass(stdClass::class); - - -$container = createContainer($builder); - - -$one = $container->getService('one'); -Assert::type(StdClassAccessorAccessor::class, $one); - -$accessor = $one->get(); -Assert::type(StdClassAccessor::class, $accessor); -Assert::same($one->get(), $one->get()); - -Assert::type(stdClass::class, $accessor->get()); -Assert::same($accessor->get(), $accessor->get()); diff --git a/tests/DI/ContainerBuilder.aliases.phpt b/tests/DI/ContainerBuilder.aliases.phpt deleted file mode 100644 index 2ff62dc18..000000000 --- a/tests/DI/ContainerBuilder.aliases.phpt +++ /dev/null @@ -1,87 +0,0 @@ -addDefinition('aliasForFactory') - ->setCreator('@serviceFactory'); - -$builder->addDefinition('aliasForFactoryViaClass') - ->setCreator('@\ServiceFactory'); - -$builder->addFactoryDefinition('aliasedFactory') - ->setImplement(ServiceFactory::class) - ->setAutowired(false) - ->getResultDefinition() - ->setCreator('@service'); - -$builder->addFactoryDefinition('aliasedFactoryViaClass') - ->setImplement(ServiceFactory::class) - ->setAutowired(false) - ->getResultDefinition() - ->setCreator('@\Service'); - -$builder->addDefinition('aliasedService') - ->setCreator('@service'); - -$builder->addDefinition('aliasedServiceViaClass') - ->setCreator('@\Service'); - -$builder->addFactoryDefinition('serviceFactory') - ->setImplement(ServiceFactory::class) - ->getResultDefinition() - ->setCreator('@service'); - -$builder->addFactoryDefinition('serviceFactoryViaClass') - ->setImplement(ServiceFactory2::class) - ->getResultDefinition() - ->setCreator('@\Service'); - -$builder->addDefinition('service') - ->setType(Service::class); - - -$container = createContainer($builder); - -Assert::type(Service::class, $container->getService('service')); -Assert::type(Service::class, $container->getService('aliasedService')); -Assert::type(Service::class, $container->getService('aliasedServiceViaClass')); - -Assert::type(ServiceFactory::class, $container->getService('serviceFactory')); -Assert::type(ServiceFactory2::class, $container->getService('serviceFactoryViaClass')); - -Assert::type(ServiceFactory::class, $container->getService('aliasedFactory')); -Assert::type(ServiceFactory::class, $container->getService('aliasedFactoryViaClass')); -Assert::type(ServiceFactory::class, $container->getService('aliasForFactory')); -Assert::type(ServiceFactory::class, $container->getService('aliasForFactoryViaClass')); - -// autowiring test -Assert::type(Service::class, $container->getByType(Service::class)); -Assert::type(ServiceFactory::class, $container->getByType(ServiceFactory::class)); -Assert::type(ServiceFactory2::class, $container->getByType(ServiceFactory2::class)); diff --git a/tests/DI/ContainerBuilder.aliases2.phpt b/tests/DI/ContainerBuilder.aliases2.phpt deleted file mode 100644 index 944cbbbe5..000000000 --- a/tests/DI/ContainerBuilder.aliases2.phpt +++ /dev/null @@ -1,92 +0,0 @@ -addFactoryDefinition('serviceFactory') - ->setImplement(ServiceFactory::class) - ->getResultDefinition() - ->setCreator('@service'); - -$builder->addFactoryDefinition('serviceFactoryViaClass') - ->setImplement(ServiceFactory2::class) - ->getResultDefinition() - ->setCreator('@\Service'); - -$builder->addDefinition('service') - ->setType(stdClass::class); - - -$builder->addAlias('aliased.service', 'service'); -$builder->addAlias('aliased.serviceFactory', 'serviceFactory'); -$builder->addAlias('aliased.serviceFactoryViaClass', 'serviceFactoryViaClass'); -$builder->addAlias('aliased.serviceToRemove', 'service'); - -Assert::same([ - 'aliased.service' => 'service', - 'aliased.serviceFactory' => 'serviceFactory', - 'aliased.serviceFactoryViaClass' => 'serviceFactoryViaClass', - 'aliased.serviceToRemove' => 'service', -], $builder->getAliases()); - -$builder->removeAlias('aliased.serviceToRemove'); - -Assert::same([ - 'aliased.service' => 'service', - 'aliased.serviceFactory' => 'serviceFactory', - 'aliased.serviceFactoryViaClass' => 'serviceFactoryViaClass', -], $builder->getAliases()); - -// Access to service definition using alias -Assert::true($builder->hasDefinition('aliased.service')); -Assert::same($builder->getDefinition('service'), $builder->getDefinition('aliased.service')); - -// Replace service definition using alias -$builder->removeDefinition('aliased.service'); -Assert::false($builder->hasDefinition('aliased.service')); -$builder->addDefinition('aliased.service') - ->setType(Service::class); - - -$container = createContainer($builder); - -Assert::type(Service::class, $container->getService('service')); -Assert::type(Service::class, $container->getService('aliased.service')); -Assert::same($container->getService('service'), $container->getService('aliased.service')); - -Assert::type(ServiceFactory::class, $container->getService('serviceFactory')); -Assert::type(ServiceFactory::class, $container->getService('aliased.serviceFactory')); - -Assert::type(ServiceFactory2::class, $container->getService('aliased.serviceFactoryViaClass')); -Assert::type(ServiceFactory2::class, $container->getService('serviceFactoryViaClass')); - -// autowiring test -Assert::type(Service::class, $container->getByType(Service::class)); -Assert::type(ServiceFactory::class, $container->getByType(ServiceFactory::class)); -Assert::type(ServiceFactory2::class, $container->getByType(ServiceFactory2::class)); diff --git a/tests/DI/ContainerBuilder.autowiring.builtin.phpt b/tests/DI/ContainerBuilder.autowiring.builtin.phpt deleted file mode 100644 index 0feccb920..000000000 --- a/tests/DI/ContainerBuilder.autowiring.builtin.phpt +++ /dev/null @@ -1,40 +0,0 @@ -addDefinition('foo') - ->setType(Foo::class); -$builder->addDefinition('bar') - ->setType(Bar::class); - -$container = createContainer($builder); - -Assert::type(Foo::class, $container->getService('foo')); -Assert::type(Bar::class, $container->getService('bar')); diff --git a/tests/DI/ContainerBuilder.autowiring.chaining.phpt b/tests/DI/ContainerBuilder.autowiring.chaining.phpt deleted file mode 100644 index a8783d4ba..000000000 --- a/tests/DI/ContainerBuilder.autowiring.chaining.phpt +++ /dev/null @@ -1,81 +0,0 @@ -getByType(Baz::class)); - - -$compiler = new DI\Compiler; -$container = createContainer($compiler, ' -services: - - Foo()::create()::create() - - Test -'); -Assert::type(Baz::class, $container->getByType(Baz::class)); - - -$compiler = new DI\Compiler; -$container = createContainer($compiler, ' -services: - - Foo - - @\Foo::create()::create() - - Test -'); -Assert::type(Baz::class, $container->getByType(Baz::class)); - - -$compiler = new DI\Compiler; -$container = createContainer($compiler, ' -services: - baz: - type: Baz - factory: Foo::createUnknown()::foo() -'); -Assert::true($container->hasService('baz')); diff --git a/tests/DI/ContainerBuilder.autowiring.excluded.phpt b/tests/DI/ContainerBuilder.autowiring.excluded.phpt deleted file mode 100644 index 82037e8c2..000000000 --- a/tests/DI/ContainerBuilder.autowiring.excluded.phpt +++ /dev/null @@ -1,74 +0,0 @@ -addDefinition('bar') - ->setType(Bar::class); -$builder->addExcludedClasses([Foo::class, IBar::class]); - - -Assert::same('bar', $builder->getByType(Bar::class)); -Assert::null($builder->getByType(IBar::class)); -Assert::null($builder->getByType(Foo::class)); -Assert::null($builder->getByType(IFoo::class)); - -Assert::same(['bar'], array_keys($builder->findAutowired(Bar::class))); -Assert::same([], array_keys($builder->findAutowired(IBar::class))); -Assert::same([], array_keys($builder->findAutowired(Foo::class))); -Assert::same([], array_keys($builder->findAutowired(IFoo::class))); - -Assert::same(['bar'], array_keys($builder->findByType(Bar::class))); -Assert::same(['bar'], array_keys($builder->findByType(IBar::class))); -Assert::same(['bar'], array_keys($builder->findByType(Foo::class))); -Assert::same(['bar'], array_keys($builder->findByType(IFoo::class))); - - -$container = createContainer($builder); - -Assert::type(Bar::class, $container->getByType(Bar::class)); - -Assert::exception(function () use ($container) { - $container->getByType(IBar::class); -}, DI\MissingServiceException::class); - -Assert::exception(function () use ($container) { - $container->getByType(Foo::class); -}, DI\MissingServiceException::class); - -Assert::exception(function () use ($container) { - $container->getByType(IFoo::class); -}, DI\MissingServiceException::class); - -Assert::same(['bar'], $container->findByType(Bar::class)); -Assert::same(['bar'], $container->findByType(IBar::class)); -Assert::same(['bar'], $container->findByType(Foo::class)); -Assert::same(['bar'], $container->findByType(IFoo::class)); diff --git a/tests/DI/ContainerBuilder.autowiring.implement.phpt b/tests/DI/ContainerBuilder.autowiring.implement.phpt deleted file mode 100644 index 6c9ac20d9..000000000 --- a/tests/DI/ContainerBuilder.autowiring.implement.phpt +++ /dev/null @@ -1,49 +0,0 @@ -foo = $foo; - } -} - - -$compiler = new DI\Compiler; -$container = createContainer($compiler, ' -services: - - Foo - - - implement: ITestFactory - setup: - - inject -'); - - -$test = $container->getByType(ITestFactory::class)->create(); -Assert::type(Foo::class, $test->foo); diff --git a/tests/DI/ContainerBuilder.autowiring.local.phpt b/tests/DI/ContainerBuilder.autowiring.local.phpt deleted file mode 100644 index f7536377f..000000000 --- a/tests/DI/ContainerBuilder.autowiring.local.phpt +++ /dev/null @@ -1,67 +0,0 @@ -arg = $arg; - } -} - - -class M -{ -} - - -class M1 extends M -{ -} - - -class M2 extends M -{ -} - - -$builder = new DI\ContainerBuilder; -$builder->addDefinition('foo') - ->setType(Foo::class); - -$builder->addDefinition('m1') - ->setType(M1::class) - ->addSetup('@foo::test'); - -$builder->addDefinition('m2') - ->setType(M2::class) - ->addSetup('@foo::test') - ->setAutowired(false); - - -$container = createContainer($builder); - -$foo = $container->getService('foo'); -Assert::type(Foo::class, $foo); -Assert::null($foo->arg); - -Assert::type(M1::class, $container->getService('m1')); -Assert::same($foo->arg, $container->getService('m1')); - -Assert::type(M2::class, $container->getService('m2')); -Assert::same($foo->arg, $container->getService('m2')); diff --git a/tests/DI/ContainerBuilder.autowiring.novalue.phpt b/tests/DI/ContainerBuilder.autowiring.novalue.phpt deleted file mode 100644 index 1a9b7cca4..000000000 --- a/tests/DI/ContainerBuilder.autowiring.novalue.phpt +++ /dev/null @@ -1,69 +0,0 @@ -addDefinition('foo')->setType(Foo::class); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'foo' (type of Foo): Parameter \$x in Foo::__construct() has no class type or default value, so its value must be specified."); - - -class Bar -{ - public function __construct(array $x) - { - } -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('foo')->setType(Bar::class); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'foo' (type of Bar): Parameter \$x in Bar::__construct() has no class type or default value, so its value must be specified."); - - -class Bar2 -{ - public function __construct(array $x = []) - { - } -} - -Assert::noError(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('foo')->setType(Bar2::class); - $container = createContainer($builder); -}); - - -class Bar3 -{ - public function __construct(?stdClass $x = null) - { - } -} - -Assert::noError(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('foo')->setType(Bar3::class); - $container = createContainer($builder); -}); diff --git a/tests/DI/ContainerBuilder.autowiring.type[].phpt b/tests/DI/ContainerBuilder.autowiring.type[].phpt deleted file mode 100644 index 351b370a7..000000000 --- a/tests/DI/ContainerBuilder.autowiring.type[].phpt +++ /dev/null @@ -1,97 +0,0 @@ - $waldos - * @param array $foos - * @param string[] $strings - */ - public function __construct(array $bars = [], array $waldos = [], ?array $foos = null, array $strings = ['default']) - { - $this->bars = $bars; - $this->waldos = $waldos; - $this->foos = $foos; - $this->strings = $strings; - } -} - -class Service -{ -} - -class ServiceChild extends Service -{ -} - - -$builder = new DI\ContainerBuilder; - -$builder->addDefinition('foo') - ->setType(Foo::class); -$builder->addDefinition('s1') - ->setType(Service::class); -$builder->addDefinition('s2') - ->setType(Service::class); -$builder->addDefinition('s3') - ->setType(ServiceChild::class); -$builder->addDefinition('s4') - ->setType(stdClass::class); -$builder->addDefinition('s5') - ->setType(Service::class) - ->setAutowired(false); - -$container = createContainer($builder); - -$foo = $container->getService('foo'); -Assert::type(Foo::class, $foo); -Assert::same([ - $container->getService('s1'), - $container->getService('s2'), - $container->getService('s3'), -], $foo->bars); -Assert::same([ - $container->getService('s1'), - $container->getService('s2'), - $container->getService('s3'), -], $foo->waldos); -Assert::same([], $foo->foos); -Assert::same(['default'], $foo->strings); - - -// runtime - -$foo2 = $container->createInstance(Foo::class); -Assert::type(Foo::class, $foo2); -Assert::same([ - $container->getService('s1'), - $container->getService('s2'), - $container->getService('s3'), -], $foo2->bars); -Assert::same([ - $container->getService('s1'), - $container->getService('s2'), - $container->getService('s3'), -], $foo2->waldos); -Assert::same([$foo], $foo2->foos); // difference -Assert::same(['default'], $foo2->strings); diff --git a/tests/DI/ContainerBuilder.autowiring.types.phpt b/tests/DI/ContainerBuilder.autowiring.types.phpt deleted file mode 100644 index 59967dccc..000000000 --- a/tests/DI/ContainerBuilder.autowiring.types.phpt +++ /dev/null @@ -1,229 +0,0 @@ -addDefinition('bar') - ->setType(Bar::class) - ->setAutowired(Bar::class); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same(null, $builder->getByType(IBar::class)); - Assert::same(null, $builder->getByType(Foo::class)); - Assert::same(null, $builder->getByType(IFoo::class)); -}); - - -test('Autowiring limited to Bar class via self', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired('self'); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same(null, $builder->getByType(IBar::class)); - Assert::same(null, $builder->getByType(Foo::class)); - Assert::same(null, $builder->getByType(IFoo::class)); -}); - - -test('Autowiring limited to IBar interface and its implementations', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired(IBar::class); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same('bar', $builder->getByType(IBar::class)); - Assert::same(null, $builder->getByType(Foo::class)); - Assert::same(null, $builder->getByType(IFoo::class)); -}); - - -test('Autowiring limited to Foo class and its subclasses', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired(Foo::class); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same(null, $builder->getByType(IBar::class)); - Assert::same('bar', $builder->getByType(Foo::class)); - Assert::same(null, $builder->getByType(IFoo::class)); -}); - - -test('Autowiring limited to IFoo interface and its implementations', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired(IFoo::class); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same(null, $builder->getByType(IBar::class)); - Assert::same('bar', $builder->getByType(Foo::class)); - Assert::same('bar', $builder->getByType(IFoo::class)); -}); - - -test('Autowiring limited to two interfaces', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired([IFoo::class, IBar::class]); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same('bar', $builder->getByType(IBar::class)); - Assert::same('bar', $builder->getByType(Foo::class)); - Assert::same('bar', $builder->getByType(IFoo::class)); -}); - - -test('Autowiring limited to two classes', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired([Foo::class, Bar::class]); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same(null, $builder->getByType(IBar::class)); - Assert::same('bar', $builder->getByType(Foo::class)); - Assert::same(null, $builder->getByType(IFoo::class)); -}); - - -test('Autowiring limited to class and interface', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired([Foo::class, IBar::class]); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same('bar', $builder->getByType(IBar::class)); - Assert::same('bar', $builder->getByType(Foo::class)); - Assert::same(null, $builder->getByType(IFoo::class)); -}); - - -test('Autowiring limited to class and interface', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired([IFoo::class, Bar::class]); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::same(null, $builder->getByType(IBar::class)); - Assert::same('bar', $builder->getByType(Foo::class)); - Assert::same('bar', $builder->getByType(IFoo::class)); -}); - - -test('Distribution between two services with parent-child relation', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired(Bar::class); - - $builder->addDefinition('foo') - ->setType(Foo::class) - ->setAutowired(); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::null($builder->getByType(IBar::class)); - Assert::same('foo', $builder->getByType(Foo::class)); - Assert::same('foo', $builder->getByType(IFoo::class)); -}); - - -test('Distribution between two services of same type', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one') - ->setType(stdClass::class); - - $builder->addDefinition('two') - ->setType(stdClass::class) - ->setAutowired(stdClass::class); - - Assert::same('two', $builder->getByType(stdClass::class)); -}); - - -test('', function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired([Bar::class, IFoo::class]); - - $builder->addDefinition('foo') - ->setType(Foo::class) - ->setAutowired(); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::null($builder->getByType(IBar::class)); - Assert::same('bar', $builder->getByType(Foo::class)); - Assert::same('bar', $builder->getByType(IFoo::class)); -}); - - -test('', function () { - $builder = new DI\ContainerBuilder; - $bar = $builder->addDefinition('bar') - ->setType(Bar::class) - ->setAutowired([Bar::class, IFoo::class]); - - $foo = $builder->addDefinition('foo') - ->setType(Foo::class) - ->setAutowired(IFoo::class); - - Assert::same('bar', $builder->getByType(Bar::class)); - Assert::null($builder->getByType(IBar::class)); - - Assert::exception(function () use ($builder) { - $builder->getByType(Foo::class); - }, DI\ServiceCreationException::class, 'Multiple services of type Foo found: bar, foo'); - - Assert::exception(function () use ($builder) { - $builder->getByType(IFoo::class); - }, DI\ServiceCreationException::class, 'Multiple services of type IFoo found: bar, foo'); -}); - - -test('', function () { - $builder = new DI\ContainerBuilder; - $bar = $builder->addDefinition('bar') - ->setType(Foo::class) - ->setAutowired([Bar::class]); - - Assert::exception(function () use ($builder) { - $builder->getByType(Foo::class); - }, DI\ServiceCreationException::class, "Incompatible class Bar in autowiring definition of service 'bar'."); -}); diff --git a/tests/DI/ContainerBuilder.basic.phpt b/tests/DI/ContainerBuilder.basic.phpt deleted file mode 100644 index 02e380000..000000000 --- a/tests/DI/ContainerBuilder.basic.phpt +++ /dev/null @@ -1,126 +0,0 @@ -methods[] = [__FUNCTION__, func_get_args()]; - } - - - public function __call($nm, $args) - { - $this->methods[] = [$nm, $args]; - } -} - - -$builder = new DI\ContainerBuilder; -$builder->addDefinition('one') - ->setCreator(Service::class, ['@@string']); -$builder->addDefinition('three') - ->setCreator(Service::class, ['a', 'b']); - -$builder->addDefinition('four') - ->setCreator(Service::class, ['a', 'b']) - ->addSetup('methodA', ['a', 'b']) - ->addSetup('@four::methodB', [1, 2]) - ->addSetup('methodC', ['@self', '@container']) - ->addSetup('methodD', ['@one']); - -$builder->addDefinition('five', null) - ->setCreator('Service::create'); - -$six = $builder->addDefinition('six') - ->setCreator('Service::create', ['@container', 'a', 'b']) - ->addSetup(['@six', 'methodA'], ['a', 'b']); - -$builder->addDefinition('seven') - ->setCreator([$six, 'create'], ['@container', $six]) - ->addSetup([$six, 'methodA']) - ->addSetup('$service->methodA(?)', ['a']); - -$six = $builder->addDefinition('eight') - ->setCreator('Service::create', [new Reference('container'), 'a', 'b']) - ->addSetup([new Reference('self'), 'methodA'], [new Reference('eight'), new Reference('self')]) - ->addSetup([new Reference('eight'), 'methodB']) - ->addSetup([new Reference('six'), 'methodC']) - ->addSetup(new Reference('six')); - - -$container = createContainer($builder); - -Assert::type(Service::class, $container->getService('one')); -Assert::true($container->hasService('One')); // limitation, first character is case insensitive -Assert::false($container->hasService('oNe')); - -Assert::same([ - ['__construct', ['@string']], -], $container->getService('one')->methods); - -Assert::type(Service::class, $container->getService('three')); -Assert::same([ - ['__construct', ['a', 'b']], -], $container->getService('three')->methods); - -Assert::type(Service::class, $container->getService('four')); -Assert::same([ - ['__construct', ['a', 'b']], - ['methodA', ['a', 'b']], - ['methodB', [1, 2]], - ['methodC', [$container->getService('four'), $container]], - ['methodD', [$container->getService('one')]], -], $container->getService('four')->methods); - -Assert::type(Service::class, $container->getService('five')); -Assert::same([ - ['__construct', [[]]], -], $container->getService('five')->methods); - -Assert::type(Service::class, $container->getService('six')); -Assert::same([ - ['__construct', [['a', 'b']]], - ['methodA', ['a', 'b']], -], $container->getService('six')->methods); - -Assert::type(Service::class, $container->getService('seven')); -Assert::same([ - ['__construct', [['a', 'b']]], - ['methodA', ['a', 'b']], - ['methodA', []], -], $container->getService('six')->methods); - -Assert::same([ - ['__construct', [[$container->getService('six')]]], - ['methodA', ['a']], -], $container->getService('seven')->methods); - -Assert::type(Service::class, $container->getService('eight')); -Assert::same([ - ['__construct', [['a', 'b']]], - ['methodA', [$container->getService('eight'), $container->getService('eight')]], - ['methodB', []], -], $container->getService('eight')->methods); diff --git a/tests/DI/ContainerBuilder.basic2.phpt b/tests/DI/ContainerBuilder.basic2.phpt deleted file mode 100644 index a042e2e2f..000000000 --- a/tests/DI/ContainerBuilder.basic2.phpt +++ /dev/null @@ -1,37 +0,0 @@ -addDefinition('one') - ->setCreator('Factory::create'); - - -$container = createContainer($builder); - -Assert::type(Factory::class, $container->getService('one')); diff --git a/tests/DI/ContainerBuilder.basic3.phpt b/tests/DI/ContainerBuilder.basic3.phpt deleted file mode 100644 index ad684c8ef..000000000 --- a/tests/DI/ContainerBuilder.basic3.phpt +++ /dev/null @@ -1,29 +0,0 @@ -addDefinition('one') - ->setCreator('::create'); - - -$container = createContainer($builder); - -Assert::type(stdClass::class, $container->getService('one')); diff --git a/tests/DI/ContainerBuilder.basic4.phpt b/tests/DI/ContainerBuilder.basic4.phpt deleted file mode 100644 index 48663dcb2..000000000 --- a/tests/DI/ContainerBuilder.basic4.phpt +++ /dev/null @@ -1,52 +0,0 @@ -getService('classA')); -Assert::type(ClassB::class, $container->getService('classB1')); -Assert::type(ClassB::class, $container->getService('classB2')); -Assert::type(ClassC::class, $container->getService('classC')); diff --git a/tests/DI/ContainerBuilder.byClass.phpt b/tests/DI/ContainerBuilder.byClass.phpt deleted file mode 100644 index 744a47218..000000000 --- a/tests/DI/ContainerBuilder.byClass.phpt +++ /dev/null @@ -1,128 +0,0 @@ -methods[] = [__FUNCTION__, func_get_args()]; - return new stdClass; - } -} - - -class UninstantiableFactory -{ - public static function getInstance() - { - return new self; - } - - - private function __construct() - { - } - - - public function create(): stdClass - { - } -} - - -$builder = new DI\ContainerBuilder; -$builder->addDefinition('factory') - ->setType(Factory::class); - -$builder->addDefinition('annotatedFactory') - ->setType(AnnotatedFactory::class); - -$builder->addDefinition('two') - ->setType(stdClass::class) - ->setAutowired(false) - ->setCreator('@factory::create', ['@\Factory']) - ->addSetup(['@\Factory', 'create'], ['@\Factory']); - -$builder->addDefinition('three') - ->setType(stdClass::class) - ->setAutowired(false) - ->setCreator('@\Factory::create', ['@\Factory']); - -$builder->addDefinition('four') - ->setAutowired(false) - ->setCreator('@\AnnotatedFactory::create'); - -$builder->addDefinition('five') - ->setType(stdClass::class) - ->setAutowired(false) - ->setCreator('@\IFactory::create'); - -$builder->addDefinition('uninstantiableFactory') - ->setType(UninstantiableFactory::class) - ->setCreator('UninstantiableFactory::getInstance'); - -$builder->addDefinition('six') - ->setAutowired(false) - ->setCreator('@\UninstantiableFactory::create'); - - - -$container = createContainer($builder); - -$factory = $container->getService('factory'); -Assert::type(Factory::class, $factory); - -Assert::type(stdClass::class, $container->getService('two')); -Assert::same([ - ['create', [$factory]], - ['create', [$factory]], -], Factory::$methods); - -Factory::$methods = null; - -Assert::type(stdClass::class, $container->getService('three')); -Assert::same([ - ['create', [$factory]], -], Factory::$methods); - -$annotatedFactory = $container->getService('annotatedFactory'); -Assert::type(AnnotatedFactory::class, $annotatedFactory); - -Assert::type(stdClass::class, $container->getService('four')); -Assert::same([ - ['create', []], -], $annotatedFactory->methods); - -Assert::type(stdClass::class, $container->getService('five')); diff --git a/tests/DI/ContainerBuilder.case.phpt b/tests/DI/ContainerBuilder.case.phpt deleted file mode 100644 index 3f25eaefb..000000000 --- a/tests/DI/ContainerBuilder.case.phpt +++ /dev/null @@ -1,20 +0,0 @@ -addDefinition('one'); - $builder->addDefinition('One'); -}, Nette\InvalidStateException::class, "Service 'One' has the same name as 'one' in a case-insensitive manner."); diff --git a/tests/DI/ContainerBuilder.create.error.phpt b/tests/DI/ContainerBuilder.create.error.phpt deleted file mode 100644 index 5cbbdbe75..000000000 --- a/tests/DI/ContainerBuilder.create.error.phpt +++ /dev/null @@ -1,358 +0,0 @@ -addDefinition('one')->setType('X')->setCreator('Unknown'); -}, Nette\InvalidArgumentException::class, "Service 'one': Class or interface 'X' not found."); - - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition(null)->setCreator('Unknown'); - $builder->complete(); -}, Nette\DI\ServiceCreationException::class, "Service (Unknown::__construct()): Class 'Unknown' not found."); - - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator('@two'); - $builder->addDefinition('two')->setCreator('Unknown'); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'two': Class 'Unknown' not found."); - - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator(new Reference('two')); - $builder->addDefinition('two')->setCreator('Unknown'); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'two': Class 'Unknown' not found."); - - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator('stdClass::foo'); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one': Method stdClass::foo() is not callable."); - - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator('Nette\DI\Container::foo'); // has __magic - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one': Method Nette\\DI\\Container::foo() is not callable."); - - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addFactoryDefinition('one') - ->setImplement('Unknown'); -}, Nette\InvalidArgumentException::class, "Service 'one': Interface 'Unknown' not found."); - - - -interface Bad4 -{ - public function create(); -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - @$builder->addFactoryDefinition('one') - ->setImplement(Bad4::class); // missing type triggers warning - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad4): Return type of Bad4::create() is not declared."); - - -interface Bad5 -{ - public function get($arg); -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addAccessorDefinition('one') - ->setImplement(Bad5::class); - $builder->complete(); -}, Nette\InvalidArgumentException::class, "Service 'one': Method Bad5::get() must have no parameters."); - - -class Bad6 -{ - protected function create() - { - } -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator('Bad6::create'); - $builder->complete(); -}, Nette\DI\ServiceCreationException::class, "Service 'one': Method Bad6::create() is not callable."); - - -class Bad7 -{ - public static function create() - { - } -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator('Bad7::create'); - $builder->complete(); -}, Nette\DI\ServiceCreationException::class, "Service 'one': Unknown service type, specify it or declare return type of factory method."); - - -class Bad8 -{ - private function __construct() - { - } -} - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setType(Bad8::class); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad8): Class Bad8 has private constructor."); - - -class Good -{ - public function __construct() - { - } -} - -// fail in argument -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator(Good::class, [new Statement('Unknown')]); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Good): Class 'Unknown' not found. (used in Good::__construct())"); - -// fail in argument -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator(Good::class, [new Statement(Bad8::class)]); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Good): Class Bad8 has private constructor. (used in Good::__construct())"); - - -abstract class Bad9 -{ - protected function __construct() - { - } -} - -// abstract class cannot be instantiated -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setType(Bad9::class); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of Bad9): Class Bad9 is abstract."); - - -trait Bad10 -{ - public function method() - { - } -} - -// trait cannot be instantiated -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('one')->setCreator('Bad10::method'); - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one': Method Bad10::method() is not callable."); - - -class ConstructorParam -{ - public function __construct(stdClass $x) - { - } -} - -class MethodParam -{ - public function foo(stdClass $x): self - { - } -} - -// autowiring fail -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: ConstructorParam -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of ConstructorParam): Multiple services of type stdClass found: a, b (required by \$x in ConstructorParam::__construct())"); - - -// forced autowiring fail -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: ConstructorParam(@\stdClass) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of ConstructorParam): Multiple services of type stdClass found: a, b (used in ConstructorParam::__construct())"); - - -// autowiring fail in chain -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: MethodParam()::foo() -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of MethodParam): Multiple services of type stdClass found: a, b (required by \$x in MethodParam::foo())"); - - -// forced autowiring fail in chain -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: MethodParam()::foo(@\stdClass) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of MethodParam): Multiple services of type stdClass found: a, b (used in foo())"); - - -// autowiring fail in argument -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: Good(ConstructorParam()) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (required by \$x in ConstructorParam::__construct()) (used in Good::__construct())"); - - -// forced autowiring fail in argument -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: Good(ConstructorParam(@\stdClass)) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in ConstructorParam::__construct())"); - - -// autowiring fail in chain in argument -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: Good(MethodParam()::foo()) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (required by \$x in MethodParam::foo()) (used in Good::__construct())"); - - -// forced autowiring fail in chain in argument -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: Good(MethodParam()::foo(@\stdClass)) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in foo())"); - - -// forced autowiring fail in property passing -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: - factory: Good - setup: - - $a = @\stdClass -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in @bad::\$a)"); - - -// autowiring fail in rich property passing -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: - factory: Good - setup: - - $a = MethodParam()::foo(@\stdClass) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in foo())"); - - -// autowiring fail in method calling -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: - factory: MethodParam - setup: - - foo -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of MethodParam): Multiple services of type stdClass found: a, b (required by \$x in MethodParam::foo())"); - - -// forced autowiring fail in method calling -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: - factory: Good - setup: - - bar(@\stdClass) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in @bad::bar())"); - - -// autowiring fail in rich method calling -Assert::exception(function () { - createContainer(new DI\Compiler, ' -services: - a: stdClass - b: stdClass - bad: - factory: Good - setup: - - bar(MethodParam()::foo(@\stdClass)) -'); -}, Nette\DI\ServiceCreationException::class, "Service 'bad' (type of Good): Multiple services of type stdClass found: a, b (used in foo())"); diff --git a/tests/DI/ContainerBuilder.create.resolveClass.phpt b/tests/DI/ContainerBuilder.create.resolveClass.phpt deleted file mode 100644 index 006cb75c7..000000000 --- a/tests/DI/ContainerBuilder.create.resolveClass.phpt +++ /dev/null @@ -1,39 +0,0 @@ -addDefinition('one') - ->setType(Factory::class); - -$builder->addDefinition('two') - ->setCreator('@one::createBar'); - - -$container = createContainer($builder); - -Assert::type(Bar::class, $container->getByType(Bar::class)); diff --git a/tests/DI/ContainerBuilder.create.rich.phpt b/tests/DI/ContainerBuilder.create.rich.phpt deleted file mode 100644 index d91bb826b..000000000 --- a/tests/DI/ContainerBuilder.create.rich.phpt +++ /dev/null @@ -1,66 +0,0 @@ -mark = true; - } -} - -class Obj -{ - public $args; - public $mark; - - - public function foo(...$args): self - { - $this->args[] = $args; - return $this; - } -} - - -$builder = new DI\ContainerBuilder; -$one = $builder->addDefinition('one') - ->setCreator([new Statement(Factory::class), 'create']) - ->addSetup([new Statement(Factory::class), 'mark'], ['@self']); - -$two = $builder->addDefinition('two') - ->setCreator([new Statement([$one, 'foo'], [1]), 'foo'], [2]); - - -$container = createContainer($builder); - -Assert::same(Obj::class, $one->getType()); -Assert::type(Obj::class, $container->getService('one')); -Assert::true($container->getService('one')->mark); - -Assert::same(Obj::class, $two->getType()); -Assert::type(Obj::class, $container->getService('two')); -Assert::true($container->getService('two')->mark); -Assert::same([[1], [2]], $container->getService('two')->args); diff --git a/tests/DI/ContainerBuilder.createService.phpt b/tests/DI/ContainerBuilder.createService.phpt deleted file mode 100644 index ae14bd0b7..000000000 --- a/tests/DI/ContainerBuilder.createService.phpt +++ /dev/null @@ -1,33 +0,0 @@ -addDefinition('one') - ->setType(stdClass::class); - - -$container = createContainer($builder); - -$one = $container->getService('one'); -$a = $container->createService('one'); -$b = $container->createService('one'); - -Assert::type(stdClass::class, $one); -Assert::type(stdClass::class, $a); -Assert::type(stdClass::class, $b); - -Assert::notSame($one, $a); -Assert::notSame($one, $b); -Assert::notSame($a, $b); diff --git a/tests/DI/ContainerBuilder.enum.phpt b/tests/DI/ContainerBuilder.enum.phpt deleted file mode 100644 index 4854584c9..000000000 --- a/tests/DI/ContainerBuilder.enum.phpt +++ /dev/null @@ -1,39 +0,0 @@ -getService('foo')); diff --git a/tests/DI/ContainerBuilder.error.phpt b/tests/DI/ContainerBuilder.error.phpt deleted file mode 100644 index 3bef4bab2..000000000 --- a/tests/DI/ContainerBuilder.error.phpt +++ /dev/null @@ -1,46 +0,0 @@ -addDefinition('one') - ->setType(stdClass::class) - ->addSetup('::1234'); - -Assert::exception(function () use ($builder) { - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of stdClass): Expected function, method or property name, '1234' given."); - - - -$builder = new DI\ContainerBuilder; -$builder->addDefinition('extension.one') - ->setType(stdClass::class); -$builder->addDefinition('25_service') - ->setType(stdClass::class); - -Assert::exception(function () use ($builder) { - $builder->getByType(stdClass::class); -}, Nette\DI\ServiceCreationException::class, 'Multiple services of type stdClass found: 25_service, extension.one. If you want to overwrite service extension.one, give it proper name.'); - - - -$builder = new DI\ContainerBuilder; -$builder->addDefinition('one') - ->setType(stdClass::class) - ->addSetup('$prop[]'); - -Assert::exception(function () use ($builder) { - $builder->complete(); -}, Nette\InvalidStateException::class, "Service 'one' (type of stdClass): Missing argument for \$prop[]."); diff --git a/tests/DI/ContainerBuilder.factory.arguments.phpt b/tests/DI/ContainerBuilder.factory.arguments.phpt deleted file mode 100644 index 8967dd02b..000000000 --- a/tests/DI/ContainerBuilder.factory.arguments.phpt +++ /dev/null @@ -1,44 +0,0 @@ -value = $value; - } -} - -interface FooFactory -{ - public function create(): Foo; -} - - -$builder = new DI\ContainerBuilder; -$builder->addFactoryDefinition('fooFactory') - ->setImplement(FooFactory::class) - ->getResultDefinition() - ->setArguments(['bar']); - - -$container = createContainer($builder); - -Assert::type(FooFactory::class, $container->getService('fooFactory')); -Assert::type(Foo::class, $foo = $container->getService('fooFactory')->create()); -Assert::same('bar', $foo->value); diff --git a/tests/DI/ContainerBuilder.factory.params.phpt b/tests/DI/ContainerBuilder.factory.params.phpt deleted file mode 100644 index 4b44ac44c..000000000 --- a/tests/DI/ContainerBuilder.factory.params.phpt +++ /dev/null @@ -1,57 +0,0 @@ -addFactoryDefinition('one') - ->setImplement(StdClassFactory::class) - ->getResultDefinition() - ->setCreator(stdClass::class) - ->addSetup('$a', [$builder::literal('$a')]); - -@$builder->addFactoryDefinition('two') - ->setParameters(['stdClass foo', 'array bar', 'foobar' => null]) // parameters is deprecated - ->setImplement(StdClassFactory::class) - ->getResultDefinition() - ->setCreator(stdClass::class) - ->addSetup('$a', [$builder::literal('$foo')]); - -$builder->addDefinition('three') - ->setType(stdClass::class); - -$builder->addDefinition('four') - ->setCreator('@one::create', [1 => [1]]) - ->setAutowired(false); - -$builder->addDefinition('five') - ->setCreator('@two::create', [1 => [1]]) - ->setAutowired(false); - - -$container = createContainer($builder); - -Assert::type(StdClassFactory::class, $container->getService('one')); -Assert::type(StdClassFactory::class, $container->getService('two')); - -Assert::type(stdClass::class, $container->getService('four')); -Assert::same($container->getService('four')->a, $container->getService('three')); - -Assert::type(stdClass::class, $container->getService('five')); -Assert::same($container->getService('five')->a, $container->getService('three')); diff --git a/tests/DI/ContainerBuilder.factory.phpt b/tests/DI/ContainerBuilder.factory.phpt deleted file mode 100644 index 7c1b277c6..000000000 --- a/tests/DI/ContainerBuilder.factory.phpt +++ /dev/null @@ -1,63 +0,0 @@ -addFactoryDefinition('one') - ->setImplement(StdClassFactory::class) - ->getResultDefinition() - ->setCreator(stdClass::class); - -@$builder->addFactoryDefinition('two') - ->setImplement(AnnotatedFactory::class); // missing type triggers warning - -$builder->addDefinition('three') - ->setType(FactoryReceiver::class); - -$builder->addDefinition('four') - ->setCreator(FactoryReceiver::class, ['@one']); - - -$container = createContainer($builder); - -Assert::type(StdClassFactory::class, $container->getService('one')); -Assert::type(stdClass::class, $container->getService('one')->create()); -Assert::notSame($container->getService('one')->create(), $container->getService('one')->create()); - -Assert::type(AnnotatedFactory::class, $container->getService('two')); -Assert::type(stdClass::class, $container->getService('two')->create()); -Assert::notSame($container->getService('two')->create(), $container->getService('two')->create()); - -Assert::type(FactoryReceiver::class, $container->getService('three')); - -Assert::type(FactoryReceiver::class, $container->getService('four')); diff --git a/tests/DI/ContainerBuilder.factory.resolveClass.phpt b/tests/DI/ContainerBuilder.factory.resolveClass.phpt deleted file mode 100644 index f1e9f5303..000000000 --- a/tests/DI/ContainerBuilder.factory.resolveClass.phpt +++ /dev/null @@ -1,117 +0,0 @@ -addFactoryDefinition('one') - ->setImplement(StdClassFactory::class) - ->getResultDefinition() - ->setCreator(stdClass::class); - - $builder->addFactoryDefinition('two') - ->setImplement(StdClassFactory::class) - ->getResultDefinition() - ->setCreator('@eight'); - - $builder->addFactoryDefinition('three') - ->setImplement(StdClassFactory::class) - ->getResultDefinition() - ->setCreator('@one::create') // alias - ->setType(stdClass::class); // type is needed - - $builder->addDefinition('four') - ->setType(A\Factory::class); - - $builder->addDefinition('five') - ->setCreator('@four::createFoo'); - - $builder->addDefinition('six') - ->setCreator('@four::createBar'); - - $builder->addDefinition('seven') - ->setCreator('C\SelfFactory::create'); - - $builder->addDefinition('eight') - ->setCreator('stdClass'); - - - $container = createContainer($builder); - - Assert::type(StdClassFactory::class, $container->getService('one')); - - Assert::type(StdClassFactory::class, $container->getService('two')); - Assert::type(stdClass::class, $container->getService('two')->create()); - Assert::notSame($container->getService('two')->create(), $container->getService('two')->create()); - - Assert::type(StdClassFactory::class, $container->getService('three')); - Assert::type(stdClass::class, $container->getService('three')->create()); - Assert::notSame($container->getService('three')->create(), $container->getService('three')->create()); - - Assert::type(A\Foo::class, $container->getByType(A\Foo::class)); - Assert::type(B\Bar::class, $container->getByType(B\Bar::class)); - - Assert::type(C\SelfFactory::class, $container->getByType(C\SelfFactory::class)); -} diff --git a/tests/DI/ContainerBuilder.factory^2.phpt b/tests/DI/ContainerBuilder.factory^2.phpt deleted file mode 100644 index e89047173..000000000 --- a/tests/DI/ContainerBuilder.factory^2.phpt +++ /dev/null @@ -1,44 +0,0 @@ -addFactoryDefinition('one') - ->setImplement(StdClassFactoryFactory::class) - ->setResultDefinition(new DI\Definitions\FactoryDefinition); - - -$container = createContainer($builder); - - -$one = $container->getService('one'); -Assert::type(StdClassFactoryFactory::class, $one); - -$factory = $one->create(); -Assert::type(StdClassFactory::class, $factory); -Assert::notSame($one->create(), $one->create()); - -Assert::type(stdClass::class, $factory->create()); -Assert::notSame($factory->create(), $factory->create()); diff --git a/tests/DI/ContainerBuilder.findByTag.phpt b/tests/DI/ContainerBuilder.findByTag.phpt deleted file mode 100644 index a5a61919e..000000000 --- a/tests/DI/ContainerBuilder.findByTag.phpt +++ /dev/null @@ -1,62 +0,0 @@ -addDefinition('one') - ->setType(stdClass::class); -$builder->addDefinition('two') - ->setType(stdClass::class) - ->addTag('debugPanel', true); -$builder->addDefinition('three') - ->setType(stdClass::class) - ->addTag('component'); -$builder->addDefinition('five') - ->setType(stdClass::class) - ->addTag('debugPanel', [1, 2, 3]) - ->addTag('typeHint', 'Service'); - - -test('compile-time', function () use ($builder) { - Assert::same([ - 'five' => 'Service', - ], $builder->findByTag('typeHint')); - - Assert::same([ - 'two' => true, - 'five' => [1, 2, 3], - ], $builder->findByTag('debugPanel')); - - Assert::same([ - 'three' => true, - ], $builder->findByTag('component')); - - Assert::same([], $builder->findByTag('unknown')); -}); - - -test('run-time', function () use ($builder) { - $container = createContainer($builder); - - Assert::same([ - 'five' => 'Service', - ], $container->findByTag('typeHint')); - - Assert::same([ - 'five' => [1, 2, 3], - 'two' => true, - ], $container->findByTag('debugPanel')); - - Assert::same([], $container->findByTag('unknown')); -}); diff --git a/tests/DI/ContainerBuilder.getByType.alias.phpt b/tests/DI/ContainerBuilder.getByType.alias.phpt deleted file mode 100644 index d3ed77234..000000000 --- a/tests/DI/ContainerBuilder.getByType.alias.phpt +++ /dev/null @@ -1,53 +0,0 @@ -addDefinition('one') - ->setType(Service::class); -$two = $builder->addDefinition('two') - ->setType(Alias::class); - - - -Assert::exception(function () use ($builder) { - $builder->getByType(Service::class); -}, Nette\DI\ServiceCreationException::class, 'Multiple services of type Service found: one, two'); - -Assert::exception(function () use ($builder) { - $builder->getByType(Alias::class); -}, Nette\DI\ServiceCreationException::class, 'Multiple services of type Service found: one, two'); - -Assert::exception(function () use ($builder) { - $builder->getByType('\service'); -}, Nette\DI\ServiceCreationException::class, 'Multiple services of type Service found: one, two'); - - -Assert::same( - ['one' => $builder->getDefinition('one'), 'two' => $builder->getDefinition('two')], - $builder->findByType(Service::class) -); - -Assert::same( - ['one' => $builder->getDefinition('one'), 'two' => $builder->getDefinition('two')], - $builder->findByType(Alias::class) -); - -Assert::same( - ['one' => $builder->getDefinition('one'), 'two' => $builder->getDefinition('two')], - $builder->findByType('\service') -); diff --git a/tests/DI/ContainerBuilder.getByType.phpt b/tests/DI/ContainerBuilder.getByType.phpt deleted file mode 100644 index 511b9d46c..000000000 --- a/tests/DI/ContainerBuilder.getByType.phpt +++ /dev/null @@ -1,78 +0,0 @@ -addDefinition('one') - ->setType(Service::class); -$child = $builder->addDefinition('child') - ->setType(Child::class) - ->setAutowired(false); -$two = $builder->addDefinition('two') - ->setType(Service2::class); -$three = $builder->addDefinition('three') - ->setType(Service2::class) - ->setAutowired(false); - - - - -Assert::same('one', $builder->getByType('\Service')); - -Assert::null($builder->getByType(Child::class)); - -Assert::exception(function () use ($builder) { - $builder->getByType(Child::class, true); -}, Nette\DI\MissingServiceException::class, 'Service of type Child not found. Did you add it to configuration file?'); - -Assert::same('two', $builder->getByType(Service2::class)); - -Assert::exception(function () use ($builder) { - $builder->getByType(stdClass::class); -}, Nette\DI\ServiceCreationException::class, 'Multiple services of type stdClass found: one, two'); - -Assert::exception(function () use ($builder) { - $builder->getByType('unknown', true); -}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found. Check the class name because it cannot be found."); - -Assert::null($builder->getByType('unknown')); - - -Assert::same([ - 'one' => $builder->getDefinition('one'), - 'child' => $builder->getDefinition('child'), -], $builder->findByType(Service::class)); - -Assert::same([ - 'child' => $builder->getDefinition('child'), -], $builder->findByType(Child::class)); - -Assert::same( - ['two' => $builder->getDefinition('two'), 'three' => $builder->getDefinition('three')], - $builder->findByType(Service2::class) -); -Assert::same([], $builder->findByType('unknown')); diff --git a/tests/DI/ContainerBuilder.getDefinitionByType.phpt b/tests/DI/ContainerBuilder.getDefinitionByType.phpt deleted file mode 100644 index 6fcfa0ca6..000000000 --- a/tests/DI/ContainerBuilder.getDefinitionByType.phpt +++ /dev/null @@ -1,35 +0,0 @@ -addDefinition('one') - ->setType(stdClass::class); - -$builder->addDefinition('two') - ->setType(SplFileInfo::class); - -$builder->addDefinition('three') - ->setType(SplFileInfo::class); - - -$definition = $builder->getDefinitionByType(stdClass::class); -Assert::same($definitionOne, $definition); - -Assert::exception(function () use ($builder) { - $builder->getDefinitionByType('unknown'); -}, Nette\DI\MissingServiceException::class, "Service of type 'unknown' not found. Check the class name because it cannot be found."); - -Assert::exception(function () use ($builder) { - $builder->getDefinitionByType(SplFileInfo::class); -}, Nette\DI\ServiceCreationException::class, 'Multiple services of type SplFileInfo found: three, two'); diff --git a/tests/DI/ContainerBuilder.imported.phpt b/tests/DI/ContainerBuilder.imported.phpt deleted file mode 100644 index f5ba46d8a..000000000 --- a/tests/DI/ContainerBuilder.imported.phpt +++ /dev/null @@ -1,51 +0,0 @@ -addImportedDefinition('one') - ->setType(ParentClass::class); - - -// compile-time - -Assert::same('one', $builder->getByType(ParentClass::class)); - -$container = createContainer($builder); - -Assert::true($container->hasService('one')); -Assert::false($container->isCreated('one')); - -Assert::exception(function () use ($container) { - $container->getService('one'); -}, Nette\DI\ServiceCreationException::class, "Unable to create imported service 'one', it must be added using addService()"); - - -Assert::exception(function () use ($container) { - $container->addService('one', new stdClass); -}, Nette\InvalidArgumentException::class, "Service 'one' must be instance of ParentClass, stdClass given."); - -$container->addService('one', $obj = new Service); -Assert::same($obj, $container->getService('one')); - -Assert::true($container->isCreated('one')); diff --git a/tests/DI/ContainerBuilder.literal.phpt b/tests/DI/ContainerBuilder.literal.phpt deleted file mode 100644 index 7d9f29f89..000000000 --- a/tests/DI/ContainerBuilder.literal.phpt +++ /dev/null @@ -1,21 +0,0 @@ -?', (string) DI\ContainerBuilder::literal('$var->?')); -Assert::same('$var', (string) DI\ContainerBuilder::literal('$var', [])); -Assert::same('$var->item', (string) DI\ContainerBuilder::literal('$var->?', ['item'])); diff --git a/tests/DI/ContainerBuilder.metadata.phpt b/tests/DI/ContainerBuilder.metadata.phpt deleted file mode 100644 index b293ff6c2..000000000 --- a/tests/DI/ContainerBuilder.metadata.phpt +++ /dev/null @@ -1,64 +0,0 @@ -getProperty($name); - $prop->setAccessible(true); - return $prop->getValue($obj); -} - - -$compiler = new DI\Compiler; -$container = createContainer($compiler, ' -services: - lorem: - factory: stdClass - tags: - - a - b: c - d: [e] -'); - - -Assert::same( - [ - Nette\DI\Container::class => [['container']], - stdClass::class => [['lorem']], - ], - getPropertyValue($container, 'wiring') -); - -Assert::same( - ['container' => Nette\DI\Container::class], - getPropertyValue($container, 'types') -); - -Assert::same( - [ - 'a' => ['lorem' => true], - 'b' => ['lorem' => 'c'], - 'd' => ['lorem' => ['e']], - ], - getPropertyValue($container, 'tags') -); - -Assert::same( - [], - getPropertyValue($container, 'aliases') -); - -Assert::same(['lorem' => true], $container->findByTag('a')); -Assert::same([], $container->findByTag('x')); diff --git a/tests/DI/ContainerBuilder.names.phpt b/tests/DI/ContainerBuilder.names.phpt deleted file mode 100644 index c6f134977..000000000 --- a/tests/DI/ContainerBuilder.names.phpt +++ /dev/null @@ -1,47 +0,0 @@ -addDefinition('01') - ->setCreator(stdClass::class); - -$builder->addDefinition(null) - ->setCreator(stdClass::class); - -$builder->addDefinition(null) - ->setCreator(stdClass::class); - - -$container = createContainer($builder); - -Assert::type(stdClass::class, $container->getService('01')); -Assert::type(stdClass::class, $container->getService('02')); -Assert::type(stdClass::class, $container->getService('03')); - - - -Assert::exception(function () use ($builder) { - $builder->addDefinition(''); -}, Nette\InvalidArgumentException::class); - -Assert::exception(function () use ($builder) { - $builder->addDefinition('0'); -}, Nette\InvalidArgumentException::class); - -Assert::exception(function () use ($builder) { - $builder->addDefinition('1'); -}, Nette\InvalidArgumentException::class); - - - -Assert::exception(function () use ($builder) { - $builder->addDefinition('aa~'); -}, Nette\InvalidArgumentException::class); diff --git a/tests/DI/ContainerBuilder.recursive.phpt b/tests/DI/ContainerBuilder.recursive.phpt deleted file mode 100644 index 86a668d1f..000000000 --- a/tests/DI/ContainerBuilder.recursive.phpt +++ /dev/null @@ -1,32 +0,0 @@ -addDefinition('one') - ->setCreator('@two::get'); -$builder->addDefinition('two') - ->setCreator('@one::get'); - -Assert::exception(function () use ($builder) { - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'two': Circular reference detected for services: one, two."); diff --git a/tests/DI/ContainerBuilder.removeDefinition.phpt b/tests/DI/ContainerBuilder.removeDefinition.phpt deleted file mode 100644 index 7064ffc03..000000000 --- a/tests/DI/ContainerBuilder.removeDefinition.phpt +++ /dev/null @@ -1,64 +0,0 @@ -addDefinition('one') - ->setType(stdClass::class); - -$builder->addDefinition('two') - ->setType(stdClass::class); - -$builder->addDefinition('three') - ->setType(stdClass::class) - ->setAutowired(false); - -$builder->addDefinition('four') - ->setType('A'); - - -Assert::exception(function () use ($builder) { - $builder->getByType(stdClass::class); -}, Nette\DI\ServiceCreationException::class, 'Multiple services of type stdClass found: four, one, two'); - -Assert::count(4, $builder->findByType(stdClass::class)); - - -$builder->removeDefinition('one'); -$builder->removeDefinition('four'); - -Assert::same('two', $builder->getByType(stdClass::class)); - -Assert::count(2, $builder->findByType(stdClass::class)); - - -$builder->removeDefinition('three'); - -Assert::count(1, $builder->findByType(stdClass::class)); - - -$builder->addDefinition('one') - ->setType(stdClass::class); - -Assert::count(2, $builder->findByType(stdClass::class)); diff --git a/tests/DI/ContainerBuilder.resolve.Container.phpt b/tests/DI/ContainerBuilder.resolve.Container.phpt deleted file mode 100644 index 46a23fa63..000000000 --- a/tests/DI/ContainerBuilder.resolve.Container.phpt +++ /dev/null @@ -1,34 +0,0 @@ -getService('next')); diff --git a/tests/DI/ContainerBuilder.resolveTypes.next.php80.phpt b/tests/DI/ContainerBuilder.resolveTypes.next.php80.phpt deleted file mode 100644 index b3602ce2a..000000000 --- a/tests/DI/ContainerBuilder.resolveTypes.next.php80.phpt +++ /dev/null @@ -1,31 +0,0 @@ -addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createUnion']), 'next']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Return type of Factory::createUnion() is expected to not be built-in/complex, 'stdClass|array' given."); diff --git a/tests/DI/ContainerBuilder.resolveTypes.next.phpt b/tests/DI/ContainerBuilder.resolveTypes.next.phpt deleted file mode 100644 index 0dc9d879f..000000000 --- a/tests/DI/ContainerBuilder.resolveTypes.next.phpt +++ /dev/null @@ -1,195 +0,0 @@ -addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createClassPhpDoc']), 'next']); - $container = @createContainer($builder); // @return is deprecated -}); - -Assert::noError(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createClass']), 'next']); - $container = createContainer($builder); -}); - -Assert::noError(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createNullableClassPhpDoc']), 'next']); - $container = @createContainer($builder); // @return is deprecated -}); - -Assert::noError(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createNullableClass']), 'next']); - $container = createContainer($builder); -}); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createScalarPhpDoc']), 'next']); - $container = @createContainer($builder); // @return is deprecated -}, Nette\DI\ServiceCreationException::class, "Service 'a': Return type of Factory::createScalarPhpDoc() is expected to not be built-in/complex, 'array' given."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createScalar']), 'next']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Return type of Factory::createScalar() is expected to not be built-in/complex, 'array' given."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createObjectPhpDoc']), 'next']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createObject']), 'next']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createObjectNullable']), 'next']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createMixedPhpDoc']), 'next']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createMixed']), 'next']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setFactory([new Statement([Factory::class, 'createGeneric']), 'next']); - $container = @createContainer($builder); // @return is deprecated -}, Nette\DI\ServiceCreationException::class, "Service 'a': Class 'T' not found. -Check the return type of Factory::createGeneric()."); diff --git a/tests/DI/ContainerBuilder.resolveTypes.php80.phpt b/tests/DI/ContainerBuilder.resolveTypes.php80.phpt deleted file mode 100644 index 3ad0cf546..000000000 --- a/tests/DI/ContainerBuilder.resolveTypes.php80.phpt +++ /dev/null @@ -1,30 +0,0 @@ -addDefinition('a') - ->setCreator([Factory::class, 'createUnion']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Return type of Factory::createUnion() is expected to not be built-in/complex, 'stdClass|array' given."); diff --git a/tests/DI/ContainerBuilder.resolveTypes.phpt b/tests/DI/ContainerBuilder.resolveTypes.phpt deleted file mode 100644 index eafb44829..000000000 --- a/tests/DI/ContainerBuilder.resolveTypes.phpt +++ /dev/null @@ -1,186 +0,0 @@ -addDefinition('a') - ->setCreator([Factory::class, 'createClassPhpDoc']); - $container = @createContainer($builder); // @return is deprecated -}); - -Assert::noError(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createClass']); - $container = createContainer($builder); -}); - -Assert::noError(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createNullableClassPhpDoc']); - $container = @createContainer($builder); // @return is deprecated -}); - -Assert::noError(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createNullableClass']); - $container = createContainer($builder); -}); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createScalarPhpDoc']); - $container = @createContainer($builder); // @return is deprecated -}, Nette\DI\ServiceCreationException::class, "Service 'a': Return type of Factory::createScalarPhpDoc() is expected to not be built-in/complex, 'array' given."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createScalar']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Return type of Factory::createScalar() is expected to not be built-in/complex, 'array' given."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createObjectPhpDoc']); - $container = @createContainer($builder); // @return is deprecated -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createObject']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createObjectNullable']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createMixedPhpDoc']); - $container = @createContainer($builder); // @return is deprecated -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createMixed']); - $container = createContainer($builder); -}, Nette\DI\ServiceCreationException::class, "Service 'a': Unknown service type, specify it or declare return type of factory method."); - -Assert::exception(function () { - $builder = new DI\ContainerBuilder; - $builder->addDefinition('a') - ->setCreator([Factory::class, 'createGeneric']); - $container = @createContainer($builder); // @return is deprecated -}, Nette\DI\ServiceCreationException::class, "Service 'a': Class 'T' not found. -Check the return type of Factory::createGeneric()."); diff --git a/tests/DI/ContainerBuilder.selfdependency.phpt b/tests/DI/ContainerBuilder.selfdependency.phpt deleted file mode 100644 index a418c2639..000000000 --- a/tests/DI/ContainerBuilder.selfdependency.phpt +++ /dev/null @@ -1,30 +0,0 @@ -addDefinition(null) - ->setCreator(Foo::class); - -Assert::exception(function () use ($builder) { - createContainer($builder); -}, Nette\DI\ServiceCreationException::class, 'Service of type Foo: Service of type Foo required by $foo in Foo::__construct() not found. Did you add it to configuration file?'); diff --git a/tests/DI/ContainerBuilder.tagged().phpt b/tests/DI/ContainerBuilder.tagged().phpt deleted file mode 100644 index 5dd5ea611..000000000 --- a/tests/DI/ContainerBuilder.tagged().phpt +++ /dev/null @@ -1,68 +0,0 @@ -arr = $arr; - } -} - -class Service -{ -} - - -$compiler = new DI\Compiler; -$container = createContainer($compiler, ' -services: - f1: Foo(tagged(first)) - f2: Foo(tagged(second, third)) - s1: - factory: Service - tags: [first] - s2: - factory: Service - tags: [first] - s3: - factory: Service - tags: [first: false] - s4: - factory: Service - tags: [first: null] - s5: - factory: Service - tags: [second] - s6: - factory: Service - tags: [third] -'); - -$foo = $container->getService('f1'); -Assert::same([ - $container->getService('s1'), - $container->getService('s2'), - $container->getService('s3'), -], $foo->arr); - -$foo = $container->getService('f2'); -Assert::same([ - $container->getService('s5'), - $container->getService('s6'), -], $foo->arr); diff --git a/tests/DI/ContainerBuilder.typed().phpt b/tests/DI/ContainerBuilder.typed().phpt deleted file mode 100644 index ac55e4980..000000000 --- a/tests/DI/ContainerBuilder.typed().phpt +++ /dev/null @@ -1,68 +0,0 @@ -arr = $arr; - } -} - -class Service -{ -} - -class ServiceChild extends Service -{ -} - - -$compiler = new DI\Compiler; -$container = createContainer($compiler, ' -services: - f1: Foo(typed(Service)) - f2: Foo(typed(ServiceChild, stdClass)) - f3: Foo(typed(Foo)) - s1: Service - s2: Service - s3: ServiceChild - s4: stdClass - s5: - factory: Service - autowired: no -'); - -$foo = $container->getService('f1'); -Assert::same([ - $container->getService('s1'), - $container->getService('s2'), - $container->getService('s3'), -], $foo->arr); - -$foo = $container->getService('f2'); -Assert::same([ - $container->getService('s3'), - $container->getService('s4'), -], $foo->arr); - -$foo = $container->getService('f3'); -Assert::same([ - $container->getService('f1'), - $container->getService('f2'), -], $foo->arr); diff --git a/tests/DI/ContainerLoader.basic.phpt b/tests/DI/ContainerLoader.basic.phpt deleted file mode 100644 index 7b1a92aa1..000000000 --- a/tests/DI/ContainerLoader.basic.phpt +++ /dev/null @@ -1,28 +0,0 @@ -getClassName($key); -Assert::match('Container%[\w]+%', $className); - -$container = $cache->load(function () use ($className) { - return "class $className {}"; -}, $key); -Assert::type($className, new $container); - -$container = $cache->load(function () {}, 'key2'); -Assert::type(DI\Container::class, new $container); diff --git a/tests/DI/ContainerLoader.isExpired.phpt b/tests/DI/ContainerLoader.isExpired.phpt deleted file mode 100644 index 5e871c537..000000000 --- a/tests/DI/ContainerLoader.isExpired.phpt +++ /dev/null @@ -1,56 +0,0 @@ -loadFile('class1', function () {}); -}); - -// ensure files are created -$file = (new ReflectionClass('class1'))->getFileName(); -Assert::true(is_file($file)); -Assert::true(is_file("$file.meta")); - - -// load again, nothing was modified -Assert::with($loader, function () use ($file) { - Assert::false($this->isExpired($file, $newMeta)); - Assert::null($newMeta); -}); - - -// alter filemtime in files -$meta = file_get_contents("$file.meta"); -$altered = unserialize($meta); -$altered[1][__FILE__] = 123; -file_put_contents("$file.meta", serialize($altered)); - -Assert::with($loader, function () use ($file) { - Assert::true($this->isExpired($file, $newMeta)); - Assert::null($newMeta); -}); - - -// alter filemtime in classes -$altered = unserialize($meta); -$altered[2][key($altered[2])] = 123; -file_put_contents("$file.meta", serialize($altered)); - -Assert::with($loader, function () use ($file, $meta) { - Assert::true($this->isExpired($file, $newMeta)); - Assert::same($meta, $newMeta); -}); diff --git a/tests/DI/ContainerLoader.loadFile.phpt b/tests/DI/ContainerLoader.loadFile.phpt deleted file mode 100644 index 42e18fa6b..000000000 --- a/tests/DI/ContainerLoader.loadFile.phpt +++ /dev/null @@ -1,32 +0,0 @@ -loadFile('class1', function () {}); -}); - -// ensure files are created -$file = (new ReflectionClass('class1'))->getFileName(); -Assert::true(is_file($file)); -Assert::true(is_file("$file.meta")); - -// load again -file_put_contents($file, ''); // remove file to avoid class redeclare error -Assert::with($loader, function () { - $this->loadFile('class1', function () { Assert::fail('Should not be recreated'); }); -}); diff --git a/tests/DI/DIExtension.debugger.phpt b/tests/DI/DIExtension.debugger.phpt deleted file mode 100644 index 13efa0943..000000000 --- a/tests/DI/DIExtension.debugger.phpt +++ /dev/null @@ -1,24 +0,0 @@ -addExtension('tracy', new Tracy\Bridges\Nette\TracyExtension(true)); -$compiler->addExtension('di', new DIExtension(true)); -$container = createContainer($compiler, ''); -$container->initialize(); - -$bar = $container->getByType(Tracy\Bar::class); -$panel = $bar->getPanel(Nette\Bridges\DITracy\ContainerPanel::class); -Assert::type(Nette\Bridges\DITracy\ContainerPanel::class, $panel); diff --git a/tests/DI/DIExtension.excluded.phpt b/tests/DI/DIExtension.excluded.phpt deleted file mode 100644 index 8ce404932..000000000 --- a/tests/DI/DIExtension.excluded.phpt +++ /dev/null @@ -1,28 +0,0 @@ -addExtension('di', new DIExtension); -$container = createContainer($compiler, ' -di: - excluded: [stdClass] - -services: - std: stdClass -'); - -$builder = $compiler->getContainerBuilder(); -Assert::null($builder->getByType(stdClass::class)); diff --git a/tests/DI/DIExtension.exportParameters.phpt b/tests/DI/DIExtension.exportParameters.phpt deleted file mode 100644 index de381099b..000000000 --- a/tests/DI/DIExtension.exportParameters.phpt +++ /dev/null @@ -1,84 +0,0 @@ -addExtension('di', new DIExtension); - $container = createContainer($compiler, ' - parameters: - key: val - - di: - export: - parameters: true - '); - - Assert::same(['key' => 'val'], $container->parameters); - Assert::same(['key' => 'val'], $container->getParameters()); -}); - - -test('Parameters are not exported when setting is false', function () { - $compiler = new DI\Compiler; - $compiler->addExtension('di', new DIExtension); - $container = createContainer($compiler, ' - parameters: - key: val - - di: - export: - parameters: false - '); - - Assert::same([], $container->parameters); - Assert::same([], $container->getParameters()); -}); - - -test('Dynamic parameters are correctly exported when export setting is true', function () { - $compiler = new DI\Compiler; - $compiler->setDynamicParameterNames(['dynamic']); - $compiler->addExtension('di', new DIExtension); - $container = createContainer($compiler, ' - parameters: - key: %dynamic% - - di: - export: - parameters: true - ', ['dynamic' => 123]); - - Assert::same(['dynamic' => 123], $container->parameters); - Assert::same(['dynamic' => 123, 'key' => 123], $container->getParameters()); -}); - - -test('Static parameters are not exported when setting is false', function () { - $compiler = new DI\Compiler; - $compiler->setDynamicParameterNames(['dynamic']); - $compiler->addExtension('di', new DIExtension); - $container = createContainer($compiler, ' - parameters: - key: %dynamic% - - di: - export: - parameters: false - ', ['dynamic' => 123]); - - Assert::same(['dynamic' => 123], $container->parameters); - Assert::same(['dynamic' => 123], $container->getParameters()); -}); diff --git a/tests/DI/DIExtension.exportTags.phpt b/tests/DI/DIExtension.exportTags.phpt deleted file mode 100644 index 4327ea82d..000000000 --- a/tests/DI/DIExtension.exportTags.phpt +++ /dev/null @@ -1,102 +0,0 @@ -addExtension('di', new DIExtension); - $container = createContainer($compiler, ' - di: - export: - tags: true - - services: - - - factory: stdClass - tags: - first: a - second: b - '); - - Assert::same(['01' => 'a'], $container->findByTag('first')); - Assert::same(['01' => 'b'], $container->findByTag('second')); -}); - - -test('Tags are not exported when setting is false', function () { - $compiler = new DI\Compiler; - $compiler->addExtension('di', new DIExtension); - $compiler->addExportedTag('first'); - $container = createContainer($compiler, ' - di: - export: - tags: no - - services: - - - factory: stdClass - tags: - first: a - second: b - '); - - Assert::same([], $container->findByTag('first')); - Assert::same([], $container->findByTag('second')); -}); - - -test('Default tag export behavior without explicit setting', function () { - $compiler = new DI\Compiler; - $compiler->addExtension('di', new DIExtension); - $compiler->addExportedTag('first'); - $container = createContainer($compiler, ' - di: - export: - tags: - - services: - - - factory: stdClass - tags: - first: a - second: b - '); - - Assert::same(['01' => 'a'], $container->findByTag('first')); - Assert::same([], $container->findByTag('second')); -}); - - -test('Specific tag export when listed', function () { - $compiler = new DI\Compiler; - $compiler->addExtension('di', new DIExtension); - $compiler->addExportedTag('second'); - $container = createContainer($compiler, ' - di: - export: - tags: - - first - - services: - - - factory: stdClass - tags: - first: a - second: b - '); - - Assert::same(['01' => 'a'], $container->findByTag('first')); - Assert::same(['01' => 'b'], $container->findByTag('second')); -}); diff --git a/tests/DI/DIExtension.exportTypes.phpt b/tests/DI/DIExtension.exportTypes.phpt deleted file mode 100644 index d2dc0fe56..000000000 --- a/tests/DI/DIExtension.exportTypes.phpt +++ /dev/null @@ -1,132 +0,0 @@ -addExtension('di', new DIExtension); - $container = createContainer($compiler, ' - di: - export: - types: true - - services: - one: - factory: stdClass - autowired: no - - second: stdClass - '); - - Assert::same(['second', 'one'], $container->findByType(stdClass::class)); - Assert::same(['second'], $container->findAutowired(stdClass::class)); -}); - - -test('Types are not exported when setting is false', function () { - $compiler = new DI\Compiler; - $compiler->addExtension('di', new DIExtension); - $container = createContainer($compiler, ' - di: - export: - types: false - - services: - one: - factory: stdClass - autowired: no - - second: stdClass - '); - - Assert::same([], $container->findByType(stdClass::class)); - Assert::same([], $container->findAutowired(stdClass::class)); -}); - - -test('Mandatory types are exported when setting is false', function () { - $compiler = new DI\Compiler; - $compiler->addExtension('di', new DIExtension); - $compiler->addExportedType(stdClass::class); - $container = createContainer($compiler, ' - di: - export: - types: false - - services: - one: - factory: stdClass - autowired: no - - second: stdClass - '); - - Assert::same(['second', 'one'], $container->findByType(stdClass::class)); - Assert::same(['second'], $container->findAutowired(stdClass::class)); -}); - - -test('Mandatory types are exported without explicit setting', function () { - $compiler = new DI\Compiler; - $compiler->addExtension('di', new DIExtension); - $compiler->addExportedType(stdClass::class); - $container = createContainer($compiler, ' - di: - export: - types: - - services: - one: - factory: Foo - autowired: no - - second: stdClass - '); - - Assert::same([], $container->findByType(Foo::class)); - Assert::same([], $container->findAutowired(Foo::class)); - Assert::same(['second'], $container->findByType(stdClass::class)); - Assert::same(['second'], $container->findAutowired(stdClass::class)); -}); - - -test('Mandatory and specified types are exported', function () { - $compiler = new DI\Compiler; - $compiler->addExtension('di', new DIExtension); - $compiler->addExportedType(stdClass::class); - $container = createContainer($compiler, ' - di: - export: - types: - - Foo - - services: - one: - factory: Foo - autowired: no - - second: stdClass - '); - - Assert::same(['one'], $container->findByType(Foo::class)); - Assert::same([], $container->findAutowired(Foo::class)); - Assert::same(['second'], $container->findByType(stdClass::class)); - Assert::same(['second'], $container->findAutowired(stdClass::class)); -}); diff --git a/tests/DI/DIExtension.parentClass.phpt b/tests/DI/DIExtension.parentClass.phpt deleted file mode 100644 index b50584b55..000000000 --- a/tests/DI/DIExtension.parentClass.phpt +++ /dev/null @@ -1,28 +0,0 @@ -addExtension('di', new DIExtension); -$container = createContainer($compiler, ' -di: - parentClass: MyContainer -'); - -Assert::type(MyContainer::class, $container); diff --git a/tests/DI/DecoratorExtension.basic.phpt b/tests/DI/DecoratorExtension.basic.phpt deleted file mode 100644 index bf1cf50a4..000000000 --- a/tests/DI/DecoratorExtension.basic.phpt +++ /dev/null @@ -1,92 +0,0 @@ -setup[] = $a; - } -} - - -class Spec1 -{ -} - - -class Spec2 -{ -} - - -$compiler = new DI\Compiler; -$compiler->addExtension('decorator', new Nette\DI\Extensions\DecoratorExtension); -$container = createContainer($compiler, ' -decorator: - stdClass: - setup: - - setup(Object) - inject: yes - - Iface: - setup: - - setup(Iface::Name) - - setup - - $a = 10 - tags: [Iface::Name, tag: 1] - - spec1: - setup: - tags: - - spec2: - -services: - one: - factory: Service - tags: [a, tag: 2] - setup: - - setup(Service) -'); - - -$builder = $compiler->getContainerBuilder(); - -Assert::same( - ['a' => true, 'tag' => 2, DI\Extensions\InjectExtension::TagInject => true, 'Iface::Name' => true], - $builder->getDefinition('one')->getTags() -); - -Assert::true($builder->getDefinition('one')->getTag(DI\Extensions\InjectExtension::TagInject)); - -Assert::equal([ - new Statement([new Reference('self'), 'setup'], ['Service']), - new Statement([new Reference('self'), 'setup'], ['Object']), - new Statement([new Reference('self'), 'setup'], [new Nette\PhpGenerator\PhpLiteral('Iface::Name')]), - new Statement([new Reference('self'), 'setup']), - new Statement([new Reference('self'), '$a'], [10]), -], $builder->getDefinition('one')->getSetup()); diff --git a/tests/DI/DecoratorExtension.factories.accessor.phpt b/tests/DI/DecoratorExtension.factories.accessor.phpt deleted file mode 100644 index 8d6b52fbd..000000000 --- a/tests/DI/DecoratorExtension.factories.accessor.phpt +++ /dev/null @@ -1,45 +0,0 @@ -addExtension('decorator', new Nette\DI\Extensions\DecoratorExtension); -$container = createContainer($compiler, ' -decorator: - Foo: - inject: yes - FooAccessor: - tags: [a] -services: - foo: Foo - acc: {implement: FooAccessor} -'); - - -$builder = $compiler->getContainerBuilder(); - -Assert::true($builder->getDefinition('foo')->getTag(DI\Extensions\InjectExtension::TagInject)); -Assert::null($builder->getDefinition('foo')->getTag('a')); - -Assert::null($builder->getDefinition('acc')->getTag(DI\Extensions\InjectExtension::TagInject)); -Assert::true($builder->getDefinition('acc')->getTag('a')); diff --git a/tests/DI/DecoratorExtension.factories.phpt b/tests/DI/DecoratorExtension.factories.phpt deleted file mode 100644 index ba99a41dc..000000000 --- a/tests/DI/DecoratorExtension.factories.phpt +++ /dev/null @@ -1,60 +0,0 @@ -addExtension('foo', new class extends DI\CompilerExtension { - public function beforeCompile() - { - $this->getContainerBuilder() - ->addFactoryDefinition('bar') - ->setImplement(FooFactory::class); - } -}); - -$compiler->addExtension('decorator', new Nette\DI\Extensions\DecoratorExtension); -$container = createContainer($compiler, ' -decorator: - Foo: - inject: yes - setup: - - testSetup(foo) - FooFactory: - tags: [a] -services: - foo: {implement: FooFactory} -'); - - -$builder = $compiler->getContainerBuilder(); - -Assert::true($builder->getDefinition('foo')->getTag(DI\Extensions\InjectExtension::TagInject)); -Assert::true($builder->getDefinition('foo')->getTag('a')); -Assert::count(1, $builder->getDefinition('foo')->getResultDefinition()->getSetup()); - -Assert::true($builder->getDefinition('bar')->getTag(DI\Extensions\InjectExtension::TagInject)); -Assert::true($builder->getDefinition('bar')->getTag('a')); -Assert::count(1, $builder->getDefinition('bar')->getResultDefinition()->getSetup()); diff --git a/tests/DI/DefinitionSchema.normalize.phpt b/tests/DI/DefinitionSchema.normalize.phpt deleted file mode 100644 index cdd132740..000000000 --- a/tests/DI/DefinitionSchema.normalize.phpt +++ /dev/null @@ -1,55 +0,0 @@ -normalize(null, $context)); - Assert::same([], $schema->normalize([], $context)); - Assert::same([false], $schema->normalize(false, $context)); - Assert::same(['create' => true], $schema->normalize(true, $context)); - Assert::same(['create' => 'class'], $schema->normalize('class', $context)); - Assert::same(['implement' => Iface::class], $schema->normalize(Iface::class, $context)); - Assert::same(['create' => ['class', 'method']], $schema->normalize(['class', 'method'], $context)); - Assert::same(['create' => [Iface::class, 'method']], $schema->normalize([Iface::class, 'method'], $context)); - - $statement = new Statement(['class', 'method']); - Assert::same(['create' => $statement], $schema->normalize($statement, $context)); - - $statement = new Statement(Iface::class, ['foo']); - Assert::same(['implement' => Iface::class, 'create' => 'foo'], $schema->normalize($statement, $context)); - - $statement = new Statement(Iface::class, ['stdClass', 'stdClass']); - Assert::same(['implement' => Iface::class, 'references' => ['stdClass', 'stdClass']], $schema->normalize($statement, $context)); - - $statement = new Statement(Iface::class, ['tagged' => 123]); - Assert::same(['implement' => Iface::class, 'tagged' => 123], $schema->normalize($statement, $context)); - - // aliases - Assert::same(['create' => 'val'], $schema->normalize(['class' => 'val'], $context)); - Assert::same(['create' => 'val'], $schema->normalize(['factory' => 'val'], $context)); - Assert::same(['imported' => 'val'], @$schema->normalize(['dynamic' => 'val'], $context)); // triggers notice - - Assert::exception(function () use ($schema, $context) { - $schema->normalize(['class' => 'val', 'type' => 'val'], $context); - }, Nette\DI\InvalidConfigurationException::class, "Options 'class' and 'type' are aliases, use only 'type'."); -}); diff --git a/tests/DI/Definitions.AccessorDefinition.api.phpt b/tests/DI/Definitions.AccessorDefinition.api.phpt deleted file mode 100644 index ff3a9fbf1..000000000 --- a/tests/DI/Definitions.AccessorDefinition.api.phpt +++ /dev/null @@ -1,114 +0,0 @@ -setType('Foo'); -}, Nette\MemberAccessException::class); - - -Assert::exception(function () { - $def = new AccessorDefinition; - $def->setImplement('Foo'); -}, Nette\InvalidArgumentException::class, "Service '': Interface 'Foo' not found."); - - -Assert::exception(function () { - $def = new AccessorDefinition; - $def->setImplement(stdClass::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface 'stdClass' not found."); - - -Assert::exception(function () { - $def = new AccessorDefinition; - $def->setImplement(Bad1::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad1 must have just one non-static method get()."); - - -Assert::exception(function () { - $def = new AccessorDefinition; - $def->setImplement(Bad2::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad2 must have just one non-static method get()."); - - -Assert::exception(function () { - $def = new AccessorDefinition; - $def->setImplement(Bad3::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad3 must have just one non-static method get()."); - - -Assert::exception(function () { - $def = new AccessorDefinition; - $def->setImplement(Bad4::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad4 must have just one non-static method get()."); - - -Assert::exception(function () { - $def = new AccessorDefinition; - $def->setImplement(Bad5::class); -}, Nette\InvalidArgumentException::class, "Service '': Method Bad5::get() must have no parameters."); - - -Assert::noError(function () { - $def = new AccessorDefinition; - @$def->setImplement(Good1::class); // missing type triggers warning - Assert::same(Good1::class, $def->getImplement()); - Assert::same(Good1::class, $def->getType()); -}); - - -test('', function () { - $def = new AccessorDefinition; - $def->setImplement(Good1::class); - - $def->setReference(stdClass::class); - Assert::equal(new Reference('\stdClass'), $def->getReference()); - - $def->setReference('@one'); - Assert::equal(new Reference('one'), $def->getReference()); -}); diff --git a/tests/DI/Definitions.AccessorDefinition.render.phpt b/tests/DI/Definitions.AccessorDefinition.render.phpt deleted file mode 100644 index c8fd0df2a..000000000 --- a/tests/DI/Definitions.AccessorDefinition.render.phpt +++ /dev/null @@ -1,61 +0,0 @@ -setName('abc'); - $def->setImplement(Good2::class); - - $builder = new Nette\DI\ContainerBuilder; - $builder->addDefinition('a')->setType(stdClass::class); - $resolver = new Nette\DI\Resolver($builder); - - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); - - $phpGenerator = new Nette\DI\PhpGenerator($builder); - $method = $phpGenerator->generateMethod($def); - - Assert::match( - <<<'XX' -public function createServiceAbc(): Good2 -{ - return new class ($this) implements Good2 { - private $container; - - - public function __construct($container) - { - $this->container = $container; - } - - - public function get(): stdClass - { - return $this->container->getService('a'); - } - }; -} -XX - , - $method->__toString() - ); -}); diff --git a/tests/DI/Definitions.AccessorDefinition.resolve.phpt b/tests/DI/Definitions.AccessorDefinition.resolve.phpt deleted file mode 100644 index 5c7270a1f..000000000 --- a/tests/DI/Definitions.AccessorDefinition.resolve.phpt +++ /dev/null @@ -1,69 +0,0 @@ -resolveDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Type of service is unknown.'); - - -Assert::exception(function () { - $def = new AccessorDefinition; - @$def->setImplement(Bad1::class); // missing type triggers warning - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Service of type Bad1: Return type of Bad1::get() is not declared.'); - - -Assert::noError(function () { - $def = new AccessorDefinition; - $def->setImplement(Good1::class); - $def->setReference(stdClass::class); - - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); -}); - - -Assert::noError(function () { - $def = new AccessorDefinition; - $def->setImplement(Good1::class); - - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); -}); - - -Assert::exception(function () { - $def = new AccessorDefinition; - $def->setImplement(Good1::class); - - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Service of type Good1: Service of type stdClass not found. Did you add it to configuration file?'); diff --git a/tests/DI/Definitions.FactoryDefinition.api.phpt b/tests/DI/Definitions.FactoryDefinition.api.phpt deleted file mode 100644 index 526aba439..000000000 --- a/tests/DI/Definitions.FactoryDefinition.api.phpt +++ /dev/null @@ -1,113 +0,0 @@ -setType('Foo'); -}, Nette\MemberAccessException::class); - - -Assert::exception(function () { - $def = new FactoryDefinition; - $def->setImplement('Foo'); -}, Nette\InvalidArgumentException::class, "Service '': Interface 'Foo' not found."); - - -Assert::exception(function () { - $def = new FactoryDefinition; - $def->setImplement(stdClass::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface 'stdClass' not found."); - - -Assert::exception(function () { - $def = new FactoryDefinition; - $def->setImplement(Bad1::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad1 must have just one non-static method create()."); - - -Assert::exception(function () { - $def = new FactoryDefinition; - $def->setImplement(Bad2::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad2 must have just one non-static method create()."); - - -Assert::exception(function () { - $def = new FactoryDefinition; - $def->setImplement(Bad3::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad3 must have just one non-static method create()."); - - -Assert::exception(function () { - $def = new FactoryDefinition; - $def->setImplement(Bad4::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad4 must have just one non-static method create()."); - - -Assert::noError(function () { - $def = new FactoryDefinition; - @$def->setImplement(Good1::class); // missing type triggers warning - Assert::same(Good1::class, $def->getImplement()); - Assert::same(Good1::class, $def->getType()); -}); - - -test('', function () { - $def = new FactoryDefinition; - $def->setImplement(Good1::class); - - @$def->setParameters(['a' => 1]); // parameters are deprecated - Assert::same(['a' => 1], $def->getParameters()); -}); - - -test('', function () { - $def = new FactoryDefinition; - $def->setImplement(Good1::class); - - Assert::null($def->getResultType()); - - $resDefinition = $def->getResultDefinition(); - Assert::type(Nette\DI\Definitions\ServiceDefinition::class, $resDefinition); - - $resDefinition->setType(stdClass::class); - Assert::same(stdClass::class, $def->getResultType()); -}); diff --git a/tests/DI/Definitions.FactoryDefinition.render.phpt b/tests/DI/Definitions.FactoryDefinition.render.phpt deleted file mode 100644 index 146da0eeb..000000000 --- a/tests/DI/Definitions.FactoryDefinition.render.phpt +++ /dev/null @@ -1,58 +0,0 @@ -setName('abc'); - $def->setImplement(Good2::class); - - $builder = new Nette\DI\ContainerBuilder; - $builder->addDefinition('a')->setType(stdClass::class); - $resolver = new Nette\DI\Resolver($builder); - - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); - - $phpGenerator = new Nette\DI\PhpGenerator($builder); - $method = $phpGenerator->generateMethod($def); - - Assert::match( - 'public function createServiceAbc(): Good2 -{ - return new class ($this) implements Good2 { - private $container; - - - public function __construct($container) - { - $this->container = $container; - } - - - public function create(): stdClass - { - return new stdClass; - } - }; -}', - $method->__toString() - ); -}); diff --git a/tests/DI/Definitions.FactoryDefinition.resolve.phpt b/tests/DI/Definitions.FactoryDefinition.resolve.phpt deleted file mode 100644 index ea31b381c..000000000 --- a/tests/DI/Definitions.FactoryDefinition.resolve.phpt +++ /dev/null @@ -1,80 +0,0 @@ -resolveDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Type is missing in definition of service.'); - - -Assert::exception(function () { - $def = new FactoryDefinition; - @$def->setImplement(Bad1::class); // missing type triggers warning - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Service of type Bad1: Return type of Bad1::create() is not declared.'); - - -Assert::noError(function () { - $def = new FactoryDefinition; - $def->setImplement(Good1::class); - $def->getResultDefinition()->setType(stdClass::class); - - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); - Assert::same(stdClass::class, $def->getResultType()); -}); - - -Assert::noError(function () { - $def = new FactoryDefinition; - $def->setImplement(Good1::class); - - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); - Assert::same(stdClass::class, $def->getResultType()); -}); - - -Assert::noError(function () { - $def = new FactoryDefinition; - $def->setImplement(Good1::class); - - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); -}); - - -Assert::exception(function () { - $def = new FactoryDefinition; - $def->setImplement(Good1::class); - $def->getResultDefinition()->setType(DateTime::class); - - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Service of type Good1: Factory for stdClass cannot create incompatible DateTime type.'); diff --git a/tests/DI/Definitions.ImportedDefinition.phpt b/tests/DI/Definitions.ImportedDefinition.phpt deleted file mode 100644 index 067b61eae..000000000 --- a/tests/DI/Definitions.ImportedDefinition.phpt +++ /dev/null @@ -1,53 +0,0 @@ -setType('Foo'); -}, Nette\InvalidArgumentException::class, "Service '': Class or interface 'Foo' not found."); - - -Assert::exception(function () { - $def = new ImportedDefinition; - $resolver = new Nette\DI\Resolver(new Nette\DI\ContainerBuilder); - $resolver->resolveDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Type of service is unknown.'); - - -test('', function () { - $def = new ImportedDefinition; - $def->setName('abc'); - $def->setType(stdClass::class); - - $builder = new Nette\DI\ContainerBuilder; - $resolver = new Nette\DI\Resolver($builder); - - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); - - $phpGenerator = new Nette\DI\PhpGenerator($builder); - $method = $phpGenerator->generateMethod($def); - - Assert::match( - <<<'XX' -public function createServiceAbc(): void -{ - throw new Nette\DI\ServiceCreationException('Unable to create imported service \'abc\', it must be added using addService()'); -} -XX - , - $method->__toString() - ); -}); diff --git a/tests/DI/Definitions.LocatorDefinition.api.phpt b/tests/DI/Definitions.LocatorDefinition.api.phpt deleted file mode 100644 index 25068cf2f..000000000 --- a/tests/DI/Definitions.LocatorDefinition.api.phpt +++ /dev/null @@ -1,153 +0,0 @@ -setType('Foo'); -}, Nette\MemberAccessException::class); - - -Assert::exception(function () { - $def = new LocatorDefinition; - $def->setImplement('Foo'); -}, Nette\InvalidArgumentException::class, "Service '': Interface 'Foo' not found."); - - -Assert::exception(function () { - $def = new LocatorDefinition; - $def->setImplement(stdClass::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface 'stdClass' not found."); - - -Assert::exception(function () { - $def = new LocatorDefinition; - $def->setImplement(Bad1::class); -}, Nette\InvalidArgumentException::class, "Service '': Interface Bad1 must have at least one method."); - - -Assert::exception(function () { - $def = new LocatorDefinition; - $def->setImplement(Bad2::class); -}, Nette\InvalidArgumentException::class, "Service '': Method Bad2::create() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static."); - - -Assert::exception(function () { - $def = new LocatorDefinition; - $def->setImplement(Bad3::class); -}, Nette\InvalidArgumentException::class, "Service '': Method Bad3::get() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static."); - - -Assert::exception(function () { - $def = new LocatorDefinition; - $def->setImplement(Bad4::class); -}, Nette\InvalidArgumentException::class, "Service '': Method Bad4::foo() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static."); - - -Assert::exception(function () { - $def = new LocatorDefinition; - $def->setImplement(Bad5::class); -}, Nette\InvalidArgumentException::class, "Service '': Method Bad5::get() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static."); - - -Assert::exception(function () { - $def = new LocatorDefinition; - $def->setImplement(Bad6::class); -}, Nette\InvalidArgumentException::class, "Service '': Method Bad6::get() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static."); - - -Assert::noError(function () { - $def = new LocatorDefinition; - $def->setImplement(Good1::class); - Assert::same(Good1::class, $def->getImplement()); - Assert::same(Good1::class, $def->getType()); -}); - - -Assert::noError(function () { - $def = new LocatorDefinition; - $def->setImplement(Good2::class); - Assert::same(Good2::class, $def->getImplement()); - Assert::same(Good2::class, $def->getType()); -}); - - -Assert::noError(function () { - $def = new LocatorDefinition; - $def->setImplement(Good3::class); - Assert::same(Good3::class, $def->getImplement()); - Assert::same(Good3::class, $def->getType()); -}); - - -test('', function () { - $def = new LocatorDefinition; - $def->setImplement(Good1::class); - - $def->setReferences(['a' => 'stdClass', 'b' => '@one']); - Assert::equal(['a' => new Reference('\stdClass'), 'b' => new Reference('one')], $def->getReferences()); - - $def->setTagged('tagName'); - Assert::same('tagName', $def->getTagged()); -}); diff --git a/tests/DI/Definitions.LocatorDefinition.render.create.phpt b/tests/DI/Definitions.LocatorDefinition.render.create.phpt deleted file mode 100644 index 85a14ccc7..000000000 --- a/tests/DI/Definitions.LocatorDefinition.render.create.phpt +++ /dev/null @@ -1,66 +0,0 @@ -setName('abc'); - $def->setImplement(Good::class); - $def->setReferences(['first' => '@a', 'second' => 'stdClass']); - - $builder = new Nette\DI\ContainerBuilder; - $builder->addDefinition('a')->setType(stdClass::class); - $resolver = new Nette\DI\Resolver($builder); - - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); - - $phpGenerator = new Nette\DI\PhpGenerator($builder); - $method = $phpGenerator->generateMethod($def); - - Assert::match( - <<<'XX' -public function createServiceAbc(): Good -{ - return new class ($this) implements Good { - private $container;%A?% - private $mapping = ['first' => 'a', 'second' => 'a']; - - - public function __construct($container) - { - $this->container = $container; - } - - - public function create($name): stdClass - { - if (!isset($this->mapping[$name])) { - throw new Nette\DI\MissingServiceException("Service '$name' is not defined."); - } - return $this->container->createService($this->mapping[$name]); - } - }; -} -XX - , - $method->__toString() - ); -}); diff --git a/tests/DI/Definitions.LocatorDefinition.render.get.phpt b/tests/DI/Definitions.LocatorDefinition.render.get.phpt deleted file mode 100644 index cda41e2e7..000000000 --- a/tests/DI/Definitions.LocatorDefinition.render.get.phpt +++ /dev/null @@ -1,66 +0,0 @@ -setName('abc'); - $def->setImplement(Good::class); - $def->setReferences(['first' => '@a', 'second' => 'stdClass']); - - $builder = new Nette\DI\ContainerBuilder; - $builder->addDefinition('a')->setType(stdClass::class); - $resolver = new Nette\DI\Resolver($builder); - - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); - - $phpGenerator = new Nette\DI\PhpGenerator($builder); - $method = $phpGenerator->generateMethod($def); - - Assert::match( - <<<'XX' -public function createServiceAbc(): Good -{ - return new class ($this) implements Good { - private $container;%A?% - private $mapping = ['first' => 'a', 'second' => 'a']; - - - public function __construct($container) - { - $this->container = $container; - } - - - public function get($name): stdClass - { - if (!isset($this->mapping[$name])) { - throw new Nette\DI\MissingServiceException("Service '$name' is not defined."); - } - return $this->container->getService($this->mapping[$name]); - } - }; -} -XX - , - $method->__toString() - ); -}); diff --git a/tests/DI/Definitions.LocatorDefinition.render.multi.phpt b/tests/DI/Definitions.LocatorDefinition.render.multi.phpt deleted file mode 100644 index a7ed6800c..000000000 --- a/tests/DI/Definitions.LocatorDefinition.render.multi.phpt +++ /dev/null @@ -1,70 +0,0 @@ -setName('abc'); - $def->setImplement(Good::class); - $def->setReferences(['first' => '@a', 'second' => 'stdClass']); - - $builder = new Nette\DI\ContainerBuilder; - $builder->addDefinition('a')->setType(stdClass::class); - $resolver = new Nette\DI\Resolver($builder); - - $resolver->resolveDefinition($def); - $resolver->completeDefinition($def); - - $phpGenerator = new Nette\DI\PhpGenerator($builder); - $method = $phpGenerator->generateMethod($def); - - Assert::match( - <<<'XX' -public function createServiceAbc(): Good -{ - return new class ($this) implements Good { - private $container; - - - public function __construct($container) - { - $this->container = $container; - } - - - public function createFirst(): stdClass - { - return $this->container->createServiceA(); - } - - - public function getSecond(): ?stdClass - { - return $this->container->getService('a'); - } - }; -} -XX - , - $method->__toString() - ); -}); diff --git a/tests/DI/Definitions.LocatorDefinition.resolve.phpt b/tests/DI/Definitions.LocatorDefinition.resolve.phpt deleted file mode 100644 index 2a12fbf54..000000000 --- a/tests/DI/Definitions.LocatorDefinition.resolve.phpt +++ /dev/null @@ -1,76 +0,0 @@ -resolveDefinition($def); -}, Nette\DI\ServiceCreationException::class, 'Type of service is unknown.'); - - -test('', function () { - $def = new LocatorDefinition; - $def->setImplement(Good1::class); - $def->setReferences(['first' => '@a', 'second' => 'stdClass']); - - $builder = new Nette\DI\ContainerBuilder; - $builder->addDefinition('a')->setType(stdClass::class); - $builder->addDefinition('b')->setType(Service::class); - - $resolver = new Nette\DI\Resolver($builder); - $resolver->completeDefinition($def); - - Assert::equal([ - 'first' => new Reference('a'), - 'second' => new Reference('a'), - ], $def->getReferences()); -}); - - -test('', function () { - $def = new LocatorDefinition; - $def->setImplement(Good1::class); - $def->setTagged('tagName'); - - $builder = new Nette\DI\ContainerBuilder; - $builder->addDefinition('a')->addTag('tagName'); - $builder->addDefinition('b')->addTag('tagName', 'b'); - $builder->addDefinition('c')->addTag('tagName', null); - $builder->addDefinition('d')->addTag('anotherTagName'); - - $resolver = new Nette\DI\Resolver($builder); - $resolver->completeDefinition($def); - - Assert::equal([ - 1 => new Reference('a'), - 'b' => new Reference('b'), - ], $def->getReferences()); -}); diff --git a/tests/DI/Definitions.Reference.phpt b/tests/DI/Definitions.Reference.phpt deleted file mode 100644 index 593be3723..000000000 --- a/tests/DI/Definitions.Reference.phpt +++ /dev/null @@ -1,41 +0,0 @@ -isName()); -Assert::false($ref->isType()); -Assert::false($ref->isSelf()); -Assert::same('a', $ref->getValue()); - - -$ref = new Reference('a\b'); -Assert::false($ref->isName()); -Assert::true($ref->isType()); -Assert::false($ref->isSelf()); -Assert::same('a\b', $ref->getValue()); - - -$ref = Reference::fromType('a'); -Assert::false($ref->isName()); -Assert::true($ref->isType()); -Assert::false($ref->isSelf()); -Assert::same('\a', $ref->getValue()); - - -$ref = new Reference(Reference::Self); -Assert::false($ref->isName()); -Assert::false($ref->isType()); -Assert::true($ref->isSelf()); -Assert::same(Reference::Self, $ref->getValue()); diff --git a/tests/DI/Definitions.ServiceDefinition.phpt b/tests/DI/Definitions.ServiceDefinition.phpt deleted file mode 100644 index 06dcb545b..000000000 --- a/tests/DI/Definitions.ServiceDefinition.phpt +++ /dev/null @@ -1,118 +0,0 @@ -setType('Foo'); -}, Nette\InvalidArgumentException::class, "Service '': Class or interface 'Foo' not found."); - -test('type versus entity I.', function () { - $def = new ServiceDefinition; - $def->setType(stdClass::class); - Assert::same(stdClass::class, $def->getType()); - Assert::null($def->getEntity()); - - $def->setArguments([1, 2]); - Assert::same(stdClass::class, $def->getType()); - Assert::null($def->getEntity()); -}); - -test('type versus entity II.', function () { - $def = new ServiceDefinition; - $def->setCreator(stdClass::class); - Assert::null($def->getType()); - Assert::equal(new Statement(stdClass::class, []), $def->getCreator()); - - $def->setArguments([1, 2]); - Assert::null($def->getType()); - Assert::equal(new Statement(stdClass::class, [1, 2]), $def->getCreator()); - - // Demonstrate that setArguments call will always replace arguments. - $def->setArguments([1 => 200]); - Assert::equal(new Statement(stdClass::class, [1 => 200]), $def->getCreator()); -}); - -test('Test with factory being previously set.', function () { - $def1 = new ServiceDefinition; - $def1->setCreator(stdClass::class, ['foo', 'bar']); - $def1->setArgument(1, 'new'); - Assert::equal(new Statement(stdClass::class, ['foo', 'new']), $def1->getCreator()); - - // Test with factory being set implicitly. - $def2 = new ServiceDefinition; - $def2->setArgument(1, 'new'); - $def2->setArgument(2, 'bar'); - Assert::equal(new Statement(null, [1 => 'new', 2 => 'bar']), $def2->getCreator()); -}); - -test('Setting a creator with array arguments', function () { - $def = new ServiceDefinition; - $def->setCreator(stdClass::class, [1, 2]); - Assert::null($def->getType()); - Assert::equal(new Statement(stdClass::class, [1, 2]), $def->getCreator()); -}); - -test('Setting a creator with statement arguments', function () { - $def = new ServiceDefinition; - $def->setCreator(new Statement(stdClass::class, [1, 2])); - Assert::null($def->getType()); - Assert::equal(new Statement(stdClass::class, [1, 2]), $def->getCreator()); -}); - -test('Setting a creator with statement and additional arguments', function () { - $def = new ServiceDefinition; - $def->setCreator(new Statement(stdClass::class, [1, 2]), [99]); // 99 is ignored - Assert::null($def->getType()); - Assert::equal(new Statement(stdClass::class, [1, 2]), $def->getCreator()); -}); - -test('Setting setups with arguments/statements', function () { - $def = new ServiceDefinition; - $def->addSetup(stdClass::class, [1, 2]); - $def->addSetup(new Statement(stdClass::class, [1, 2])); - $def->addSetup(new Statement(stdClass::class, [1, 2]), [99]); // 99 is ignored - Assert::equal([ - new Statement(stdClass::class, [1, 2]), - new Statement(stdClass::class, [1, 2]), - new Statement(stdClass::class, [1, 2]), - ], $def->getSetup()); -}); - -test('Tag management functionality', function () { - $def = new ServiceDefinition; - $def->addTag('tag1'); - $def->addTag('tag2', [1, 2]); - Assert::equal([ - 'tag1' => true, - 'tag2' => [1, 2], - ], $def->getTags()); - - Assert::equal(true, $def->getTag('tag1')); - Assert::equal([1, 2], $def->getTag('tag2')); - Assert::equal(null, $def->getTag('tag3')); -}); - -test('deep clone', function () { - $def = new ServiceDefinition; - $def->setCreator(new Statement(stdClass::class, [1, 2])); - $def->addSetup(new Statement(stdClass::class, [1, 2])); - - $dolly = clone $def; - Assert::notSame($dolly->getCreator(), $def->getCreator()); - Assert::equal($dolly->getCreator(), $def->getCreator()); - Assert::notSame($dolly->getSetup(), $def->getSetup()); - Assert::equal($dolly->getSetup(), $def->getSetup()); -}); diff --git a/tests/DI/ExtensionsExtension.basic.phpt b/tests/DI/ExtensionsExtension.basic.phpt deleted file mode 100644 index ee5409fb6..000000000 --- a/tests/DI/ExtensionsExtension.basic.phpt +++ /dev/null @@ -1,73 +0,0 @@ -getContainerBuilder()->parameters['foo'] = 'hello'; - } -} - - -class BarExtension extends DI\CompilerExtension -{ - private $param; - - - public function __construct($param) - { - $this->param = $param; - } - - - public function loadConfiguration() - { - $this->getContainerBuilder()->parameters['bar'] = $this->param; - } -} - - -class FirstExtension extends DI\CompilerExtension -{ - private $param; - - - public function loadConfiguration() - { - $this->getContainerBuilder()->parameters['first'] = array_keys($this->compiler->getExtensions()); - } -} - - -$compiler = new DI\Compiler; -$compiler->addExtension('first', new FirstExtension); -$compiler->addExtension('extensions', new Nette\DI\Extensions\ExtensionsExtension); -$container = createContainer($compiler, ' -parameters: - param: test - -extensions: - foo: FooExtension - bar: BarExtension(%param%) - -foo: - key: value -'); - - -Assert::same('hello', $container->parameters['foo']); -Assert::same('test', $container->parameters['bar']); -Assert::same(['services', 'parameters', 'first', 'extensions', 'foo', 'bar'], $container->parameters['first']); diff --git a/tests/DI/ExtensionsExtension.error.phpt b/tests/DI/ExtensionsExtension.error.phpt deleted file mode 100644 index b22045dc8..000000000 --- a/tests/DI/ExtensionsExtension.error.phpt +++ /dev/null @@ -1,20 +0,0 @@ -addExtension('extensions', new Nette\DI\Extensions\ExtensionsExtension); - -Assert::exception(function () use ($compiler) { - createContainer($compiler, ' - extensions: - foo: stdClass - '); -}, Nette\DI\InvalidConfigurationException::class, "Extension 'stdClass' not found or is not Nette\\DI\\CompilerExtension descendant."); diff --git a/tests/DI/Helpers.convertType.phpt b/tests/DI/Helpers.convertType.phpt deleted file mode 100644 index 9d900cbc3..000000000 --- a/tests/DI/Helpers.convertType.phpt +++ /dev/null @@ -1,94 +0,0 @@ - '%%', 'key2' => '@@', '%%a%%' => 123, '@' => 123], - Helpers::escape(['key1' => '%', 'key2' => '@', '%a%' => 123, '@' => 123]) -); diff --git a/tests/DI/Helpers.expand().phpt b/tests/DI/Helpers.expand().phpt deleted file mode 100644 index 8942fcf42..000000000 --- a/tests/DI/Helpers.expand().phpt +++ /dev/null @@ -1,83 +0,0 @@ - 'item'])); -Assert::same(123, Helpers::expand('%key%', ['key' => 123])); -Assert::same('a123b123c', Helpers::expand('a%key%b%key%c', ['key' => 123])); -Assert::same(123, Helpers::expand('%key1.key2%', ['key1' => ['key2' => 123]])); -Assert::same('%key2%', Helpers::expand('%key1%', ['key1' => '%key2%', 'key2' => 123])); -Assert::same(123, Helpers::expand('%key1%', ['key1' => '%key2%', 'key2' => 123], true)); -Assert::same([123], Helpers::expand(['%key1%'], ['key1' => '%key2%', 'key2' => 123], true)); -Assert::same(['hello' => 123], Helpers::expand(['%key1%' => '%key2%'], ['key1' => 'hello', 'key2' => 123], true)); -Assert::same( - ['key1' => 123, 'key2' => 'abc'], - Helpers::expand('%keyA%', [ - 'keyA' => ['key1' => 123, 'key2' => '%keyB%'], - 'keyB' => 'abc', - ], true) -); -Assert::same( // no double expand - '%foo%', - Helpers::expand('%string%', ['string' => '%%foo%'], true) -); -Assert::same( // no double expand - '%foo%', - Helpers::expand('%ref.a%', [ - 'ref' => '%array%', - 'array' => ['a' => '%%foo%'], - ], true) -); - -Assert::equal(new PhpLiteral('func()'), Helpers::expand('%key%', ['key' => new PhpLiteral('func()')])); - -Assert::equal( - new DynamicParameter("func()['foo']"), - Helpers::expand('%key.foo%', ['key' => new DynamicParameter('func()')]) -); -Assert::equal( - new Statement('::implode', ['', ['text', new DynamicParameter('func()'), '']]), - Helpers::expand('text%key%', ['key' => new DynamicParameter('func()')]) -); - - -Assert::exception(function () { - Helpers::expand('%missing%', []); -}, Nette\InvalidArgumentException::class, "Missing parameter 'missing'."); - -Assert::exception(function () { - Helpers::expand('%key1%a', ['key1' => ['key2' => 123]]); -}, Nette\InvalidArgumentException::class, "Unable to concatenate non-scalar parameter 'key1' into '%key1%a'."); - -Assert::exception(function () { - Helpers::expand('%key1%', ['key1' => '%key2%', 'key2' => '%key1%'], true); -}, Nette\InvalidArgumentException::class, 'Circular reference detected for parameters: %key1%, %key2%'); - -Assert::exception(function () { - Helpers::expand('%exp%', [ - 'array' => ['a' => '%array%'], - 'exp' => '%array.a%', - ], true); -}, Nette\InvalidArgumentException::class, 'Circular reference detected for parameters: %exp%, %array.a%, %array%'); - - -Assert::same(['key1' => 'hello', 'key2' => '*%key1%*'], Helpers::expand('%parameters%', ['key1' => 'hello', 'key2' => '*%key1%*'])); -Assert::same(['key1' => 'hello', 'key2' => '*hello*'], Helpers::expand('%parameters%', ['key1' => 'hello', 'key2' => '*%key1%*'], true)); -Assert::same('own', Helpers::expand('%parameters%', ['key1' => 'hello', 'key2' => '*%key1%*', 'parameters' => 'own'])); diff --git a/tests/DI/Helpers.filterArguments.phpt b/tests/DI/Helpers.filterArguments.phpt deleted file mode 100644 index 4bd273280..000000000 --- a/tests/DI/Helpers.filterArguments.phpt +++ /dev/null @@ -1,33 +0,0 @@ - 'b', 'x']; -$arr2 = ['c' => 'd', 'y']; - - -function merge($left, $right) -{ - file_put_contents(getTempDir() . '/left.neon', $left); - file_put_contents(getTempDir() . '/right.neon', $right); - - $config = new Config\Loader; - return Config\Helpers::merge($config->load(getTempDir() . '/left.neon'), $config->load(getTempDir() . '/right.neon')); -} - - -// replace -Assert::same(['item' => []], merge('item!:', 'item:')); - -Assert::same(['item' => []], merge('item!:', 'item: 123')); - -Assert::same(['item' => []], merge('item!: []', 'item: []')); - -Assert::exception(function () { - merge('item!: 231', 'item:'); -}, Nette\DI\InvalidConfigurationException::class); - -Assert::exception(function () { - merge('item!: 231', 'item: 231'); -}, Nette\DI\InvalidConfigurationException::class); diff --git a/tests/DI/Helpers.parseAnnotation().phpt b/tests/DI/Helpers.parseAnnotation().phpt deleted file mode 100644 index 3406024bd..000000000 --- a/tests/DI/Helpers.parseAnnotation().phpt +++ /dev/null @@ -1,64 +0,0 @@ -getContainerBuilder()->addDefinition($this->prefix('one')) - ->setType(Service::class) - ->addSetup('$e', ['@\ConcreteDependencyA']) - ->addTag(Nette\DI\Extensions\InjectExtension::TagInject); - } -} - - -$compiler = new DI\Compiler; -$compiler->addExtension('inject', new Nette\DI\Extensions\InjectExtension); -$compiler->addExtension('extensions', new Nette\DI\Extensions\ExtensionsExtension); -$compiler->addExtension('last', new LastExtension); -$container = createContainer($compiler, ' -extensions: - ext: LastExtension - -services: - std: stdClass - a: ConcreteDependencyA - b: ConcreteDependencyB - two: - factory: Service - inject: true - setup: - - injectB(1) - - $e(@\ConcreteDependencyB) -'); - - -$builder = $compiler->getContainerBuilder(); - -Assert::equal([ - new Statement([new Reference('self'), 'injectA']), - new Statement([new Reference('self'), 'injectB']), - new Statement([new Reference('self'), 'injectC']), - new Statement([new Reference('self'), 'injectD']), - new Statement([new Reference('self'), '$e'], [new Reference('a')]), - new Statement([new Reference('self'), '$c'], [new Reference('std')]), - new Statement([new Reference('self'), '$a'], [new Reference('std')]), -], $builder->getDefinition('last.one')->getSetup()); - -Assert::equal([ - new Statement([new Reference('self'), 'injectA']), - new Statement([new Reference('self'), 'injectB']), - new Statement([new Reference('self'), 'injectC']), - new Statement([new Reference('self'), 'injectD']), - new Statement([new Reference('self'), '$e'], [new Reference('a')]), - new Statement([new Reference('self'), '$c'], [new Reference('std')]), - new Statement([new Reference('self'), '$a'], [new Reference('std')]), -], $builder->getDefinition('ext.one')->getSetup()); - -Assert::equal([ - new Statement([new Reference('self'), 'injectA']), - new Statement([new Reference('self'), 'injectB'], [1]), - new Statement([new Reference('self'), 'injectC']), - new Statement([new Reference('self'), 'injectD']), - new Statement([new Reference('self'), '$e'], [new Reference('b')]), - new Statement([new Reference('self'), '$c'], [new Reference('std')]), - new Statement([new Reference('self'), '$a'], [new Reference('std')]), -], $builder->getDefinition('two')->getSetup()); diff --git a/tests/DI/InjectExtension.errors.phpt b/tests/DI/InjectExtension.errors.phpt deleted file mode 100644 index e45b665d3..000000000 --- a/tests/DI/InjectExtension.errors.phpt +++ /dev/null @@ -1,110 +0,0 @@ -addExtension('inject', new Nette\DI\Extensions\InjectExtension); - createContainer($compiler, ' -services: - service: - factory: ServiceA - inject: yes -'); -}, InvalidStateException::class, "Service 'service' (type of ServiceA): Service of type DateTimeImmutable not found. Did you add it to configuration file?"); - - -Assert::exception(function () { - $compiler = new DI\Compiler; - $compiler->addExtension('inject', new Nette\DI\Extensions\InjectExtension); - createContainer($compiler, ' -services: - service: - factory: ServiceB - inject: yes -'); -}, InvalidStateException::class, "Class 'Unknown' not found. -Check the type of property ServiceB::\$a."); - - -Assert::exception(function () { - $compiler = new DI\Compiler; - $compiler->addExtension('inject', new Nette\DI\Extensions\InjectExtension); - createContainer($compiler, ' -services: - service: - factory: ServiceC - inject: yes -'); -}, InvalidStateException::class, 'Type of property ServiceC::$a is not declared.'); - - -Assert::error(function () { - $compiler = new DI\Compiler; - $compiler->addExtension('inject', new Nette\DI\Extensions\InjectExtension); - createContainer($compiler, ' -services: - service: - factory: ServiceD - inject: yes -'); -}, E_USER_WARNING, 'Property ServiceD::$a for injection must be public and non-static.'); - - -Assert::error(function () { - $compiler = new DI\Compiler; - $compiler->addExtension('inject', new Nette\DI\Extensions\InjectExtension); - createContainer($compiler, ' -services: - service: - factory: ServiceE - inject: yes -'); -}, E_USER_WARNING, 'Property ServiceE::$a for injection must be public and non-static.'); diff --git a/tests/DI/InjectExtension.getInjectMethods().phpt b/tests/DI/InjectExtension.getInjectMethods().phpt deleted file mode 100644 index 54d1fd494..000000000 --- a/tests/DI/InjectExtension.getInjectMethods().phpt +++ /dev/null @@ -1,70 +0,0 @@ - A\AInjected::class, - 'varC' => A\AInjected::class, - ], InjectExtension::getInjectProperties(A\AClass::class)); -} diff --git a/tests/DI/InjectExtension.getInjectProperties().php80.phpt b/tests/DI/InjectExtension.getInjectProperties().php80.phpt deleted file mode 100644 index 68c2a7ea7..000000000 --- a/tests/DI/InjectExtension.getInjectProperties().php80.phpt +++ /dev/null @@ -1,36 +0,0 @@ - 'stdClass', -], InjectExtension::getInjectProperties(EClass::class)); diff --git a/tests/DI/InjectExtension.getInjectProperties().phpt b/tests/DI/InjectExtension.getInjectProperties().phpt deleted file mode 100644 index 79c00b86e..000000000 --- a/tests/DI/InjectExtension.getInjectProperties().phpt +++ /dev/null @@ -1,98 +0,0 @@ - A\AInjected::class, - 'varB' => A\B\BInjected::class, - 'varC' => A\AInjected::class, - ], InjectExtension::getInjectProperties(A\AClass::class)); - - Assert::same([ - 'varA' => A\AInjected::class, - 'varB' => A\B\BInjected::class, - 'varC' => A\AInjected::class, - 'varF' => A\B\BInjected::class, - ], InjectExtension::getInjectProperties(A\B\BClass::class)); - - Assert::same([ - 'var1' => A\AInjected::class, - 'var2' => A\B\BInjected::class, - 'var3' => C\CInjected::class, - 'var4' => C\CInjected::class, - ], InjectExtension::getInjectProperties(C\CClass::class)); -} diff --git a/tests/DI/InjectExtension.getInjectProperties().traits.phpt b/tests/DI/InjectExtension.getInjectProperties().traits.phpt deleted file mode 100644 index 1fc6c211e..000000000 --- a/tests/DI/InjectExtension.getInjectProperties().traits.phpt +++ /dev/null @@ -1,47 +0,0 @@ - A\AInjected::class, - ], InjectExtension::getInjectProperties(C\CClass::class)); -} diff --git a/tests/DI/InjectExtension.implement.phpt b/tests/DI/InjectExtension.implement.phpt deleted file mode 100644 index 1104640ac..000000000 --- a/tests/DI/InjectExtension.implement.phpt +++ /dev/null @@ -1,50 +0,0 @@ -foo = $foo; - } -} - - -$compiler = new DI\Compiler; -$compiler->addExtension('inject', new Nette\DI\Extensions\InjectExtension); -$container = createContainer($compiler, ' -services: - - stdClass - sf: - implement: ServiceFactory - inject: true -'); - - -$builder = $compiler->getContainerBuilder(); - -Assert::equal([ - new Statement([new Reference('self'), 'injectFoo'], [new Reference('01')]), -], $builder->getDefinition('sf')->getResultDefinition()->getSetup()); diff --git a/tests/DI/InjectExtension.type1.phpt b/tests/DI/InjectExtension.type1.phpt deleted file mode 100644 index 1dcaa3436..000000000 --- a/tests/DI/InjectExtension.type1.phpt +++ /dev/null @@ -1,45 +0,0 @@ -addExtension('inject', new Nette\DI\Extensions\InjectExtension); -$container = createContainer($compiler, ' -services: - one: - type: IService - factory: Service - inject: true -'); - - -$builder = $compiler->getContainerBuilder(); - -Assert::equal([ - new Statement([new Reference('self'), 'injectFoo']), -], $builder->getDefinition('one')->getSetup()); diff --git a/tests/DI/InjectExtension.type2.phpt b/tests/DI/InjectExtension.type2.phpt deleted file mode 100644 index ebe3e0530..000000000 --- a/tests/DI/InjectExtension.type2.phpt +++ /dev/null @@ -1,52 +0,0 @@ -addExtension('inject', new Nette\DI\Extensions\InjectExtension); -$container = createContainer($compiler, ' -services: - one: - type: Service - factory: ServiceFactory::create - inject: true -'); - - -$builder = $compiler->getContainerBuilder(); - -Assert::equal([ - new Statement([new Reference('self'), 'injectFoo']), -], $builder->getDefinition('one')->getSetup()); diff --git a/tests/DI/Loader.errors.phpt b/tests/DI/Loader.errors.phpt deleted file mode 100644 index 844708755..000000000 --- a/tests/DI/Loader.errors.phpt +++ /dev/null @@ -1,24 +0,0 @@ -load('missing.neon'); -}, Nette\FileNotFoundException::class, "File 'missing.neon' is missing or is not readable."); - -Assert::exception(function () { - $config = new Config\Loader; - $config->load(__FILE__); -}, Nette\InvalidArgumentException::class, "Unknown file extension '%a%.phpt'."); diff --git a/tests/DI/Loader.include.nomerge.phpt b/tests/DI/Loader.include.nomerge.phpt deleted file mode 100644 index 689c5afc4..000000000 --- a/tests/DI/Loader.include.nomerge.phpt +++ /dev/null @@ -1,48 +0,0 @@ -load('files/loader.includes.neon', false); - -Assert::same([ - 'files/loader.includes.neon', - 'files/loader.includes.child.neon', - 'files/loader.includes.child.php', - __DIR__ . DIRECTORY_SEPARATOR . 'files/loader.includes.grandchild.neon', -], $config->getDependencies()); - -Assert::same([ - [ - 'parameters' => ['me' => ['loader.includes.child.neon'], 'scalar' => 3, 'list' => null], - 'services' => ['a' => 'stdClass'], - ], - ['parameters' => ['me' => ['loader.includes.grandchild.neon']]], - [ - 'parameters' => [ - 'me' => ['loader.includes.child.php'], - 'scalar' => 4, - 'list' => [5, 6], - 'force' => [5, 6], - ], - ], - [ - 'parameters' => [ - 'scalar' => 1, - 'list' => [1, 2], - 'force' => [1, 2, '_prevent_merging' => true], - ], - 'services' => ['a' => ['autowired' => false]], - ], -], $data); diff --git a/tests/DI/Loader.include.params.phpt b/tests/DI/Loader.include.params.phpt deleted file mode 100644 index ac1a216ab..000000000 --- a/tests/DI/Loader.include.params.phpt +++ /dev/null @@ -1,38 +0,0 @@ -load('files/loader.includes.params.neon'); -}, Nette\InvalidArgumentException::class, "Missing parameter 'name'."); - - -test('', function () { - $config = new Config\Loader; - $config->setParameters(['name' => 'loader.includes.params.child']); - $data = $config->load('files/loader.includes.params.neon'); - - Assert::same([ - 'files/loader.includes.params.neon', - 'files/loader.includes.params.child.neon', - ], $config->getDependencies()); - - Assert::same([ - 'parameters' => [ - 'foo' => 'bar', - 'name' => 'ignored', - ], - ], $data); -}); diff --git a/tests/DI/Loader.include.phpt b/tests/DI/Loader.include.phpt deleted file mode 100644 index 26b2b61ad..000000000 --- a/tests/DI/Loader.include.phpt +++ /dev/null @@ -1,38 +0,0 @@ -load('files/loader.includes.neon'); - -Assert::same([ - 'files/loader.includes.neon', - 'files/loader.includes.child.neon', - 'files/loader.includes.child.php', - __DIR__ . DIRECTORY_SEPARATOR . 'files/loader.includes.grandchild.neon', -], $config->getDependencies()); - -Assert::same([ - 'parameters' => [ - 'me' => [ - 'loader.includes.child.neon', - 'loader.includes.grandchild.neon', - 'loader.includes.child.php', - ], - 'scalar' => 1, - 'list' => [5, 6, 1, 2], - 'force' => [1, 2], - ], - 'services' => ['a' => ['autowired' => false]], -], $data); diff --git a/tests/DI/Loader.recursiveInclude.phpt b/tests/DI/Loader.recursiveInclude.phpt deleted file mode 100644 index 43ac2ff18..000000000 --- a/tests/DI/Loader.recursiveInclude.phpt +++ /dev/null @@ -1,19 +0,0 @@ -load('files/loader.recursiveInclude.neon'); -}, Nette\InvalidStateException::class, "Recursive included file 'files/loader.recursiveInclude.neon'"); diff --git a/tests/DI/NeonAdapter.basic.phpt b/tests/DI/NeonAdapter.basic.phpt deleted file mode 100644 index 8c5830fad..000000000 --- a/tests/DI/NeonAdapter.basic.phpt +++ /dev/null @@ -1,70 +0,0 @@ -load('files/neonAdapter.neon'); - -Assert::match(<<<'EOD' -# generated by Nette - -parameters: - type: Ipsum - -services: - referencedService: @one - referencedServiceWithSetup: - factory: @one - setup: - - $x(10) - - serviceAsParam: Ipsum(@one) - calledService: @one() - calledServiceWithArgs: @one(1) - calledServiceAsParam: Ipsum(@one()) - calledServiceWithArgsAsParam: Ipsum(@one(1)) - one: - type: %class% - arguments: - - 1 - - two: - factory: %class%(1) - - three: - type: Lorem - factory: Factory::createLorem - arguments: - - 1 - - four: - factory: Factory::createLorem(1) - - five: - factory: Factory::createLorem(1) - - six: Factory::createLorem(1) - seven: @factory - eight: @factory() - nine: - - @three - - foo - - stdClass: stdClass - factory: Lorem - rich1: Lorem(1)::foo() - rich2: - factory: Lorem(Ipsum(@one))::foo(1) - - rich3: Factory::createLorem(1)::foo() - rich4: Factory()::createLorem(1)::foo() - - Lorem(1)::foo() - -EOD - , $adapter->dump($data)); diff --git a/tests/DI/NeonAdapter.preprocess.phpt b/tests/DI/NeonAdapter.preprocess.phpt deleted file mode 100644 index f6ac73c1a..000000000 --- a/tests/DI/NeonAdapter.preprocess.phpt +++ /dev/null @@ -1,102 +0,0 @@ -load(Tester\FileMock::create(' -- ent(1) -- ent(2)inner(3, 4) -- ent(3)::inner(5) -', 'neon')); - -Assert::equal([ - new Statement('ent', [1]), - new Statement( - [ - new Statement('ent', [2]), - 'inner', - ], - [3, 4] - ), - new Statement( - [ - new Statement('ent', [3]), - 'inner', - ], - [5] - ), -], $data); - -Assert::match(<<<'EOD' -# generated by Nette - -- ent(1) -- ent(2)::inner(3, 4) -- ent(3)::inner(5) -EOD - , $adapter->dump($data)); - - -// references -$data = [ - 'a' => new Statement([new Reference('foo'), 'method'], [new Reference('bar')]), - 'b' => new Statement(new Reference('foo')), -]; - -Assert::match(<<<'EOD' -# generated by Nette - -a: @foo::method(@bar) -b: @foo() -EOD - , $adapter->dump($data)); - - -// _ -$data = $adapter->load(Tester\FileMock::create(' -- Class(arg1, _, [_]) -', 'neon')); - -Assert::equal( - [new Statement('Class', ['arg1', 2 => ['_']])], - $data -); - - -// ... deprecated -$data = @$adapter->load(Tester\FileMock::create(' -- Class(arg1, ..., [...]) -', 'neon')); - -Assert::equal( - [new Statement('Class', ['arg1', 2 => ['...']])], - $data -); - - -// @ escaping -$data = @$adapter->load(Tester\FileMock::create(' -- @@double -- "@@doublequoted" -- @simple -- "@simplequoted" -', 'neon')); - -Assert::equal( - [ - '@@double', - '@@doublequoted', - '@simple', - '@@simplequoted', // escaped - ], - $data -); diff --git a/tests/DI/PhpAdapter.phpt b/tests/DI/PhpAdapter.phpt deleted file mode 100644 index 29f5c79a0..000000000 --- a/tests/DI/PhpAdapter.phpt +++ /dev/null @@ -1,50 +0,0 @@ -load('files/phpAdapter.php'); -Assert::same([ - 'webname' => 'the example', - 'database' => [ - 'adapter' => 'pdo_mysql', - 'params' => [ - 'host' => 'db.example.com', - 'username' => 'dbuser', - 'password' => '*secret*', - 'dbname' => 'dbname', - ], - ], -], $data); - - -@$config->save($data, TEMP_FILE); // deprecated -Assert::match(<<<'EOD' - 'the example', - 'database' => [ - 'adapter' => 'pdo_mysql', - 'params' => [ - 'host' => 'db.example.com', - 'username' => 'dbuser', - 'password' => '*secret*', - 'dbname' => 'dbname', - ], - ], -]; -EOD - , file_get_contents(TEMP_FILE)); diff --git a/tests/DI/Resolver.autowireArguments.80.phpt b/tests/DI/Resolver.autowireArguments.80.phpt deleted file mode 100644 index 922b416be..000000000 --- a/tests/DI/Resolver.autowireArguments.80.phpt +++ /dev/null @@ -1,57 +0,0 @@ - 1, 'b' => 2, 'c' => 3], - Resolver::autowireArguments( - new ReflectionFunction(function (...$args) {}), - ['a' => 1, 'b' => 2, 'c' => 3], - function () {} - ) -); diff --git a/tests/DI/Resolver.autowireArguments.81.phpt b/tests/DI/Resolver.autowireArguments.81.phpt deleted file mode 100644 index 340da53e3..000000000 --- a/tests/DI/Resolver.autowireArguments.81.phpt +++ /dev/null @@ -1,43 +0,0 @@ - 10], - Resolver::autowireArguments( - new ReflectionFunction(function ($a = new stdClass, $b = null) {}), - [1 => 10], - function () {} - ), -); diff --git a/tests/DI/Resolver.autowireArguments.82.phpt b/tests/DI/Resolver.autowireArguments.82.phpt deleted file mode 100644 index 1258312b5..000000000 --- a/tests/DI/Resolver.autowireArguments.82.phpt +++ /dev/null @@ -1,33 +0,0 @@ - 1], - function () {} - ); -}, Nette\DI\ServiceCreationException::class, 'Parameter $args in {closure}() must be array, integer given.'); - - -// bad variadics (this is actually what PHP allows) -Assert::exception(function () { - Resolver::autowireArguments( - new ReflectionFunction(function (...$args) {}), - [1, 'args' => []], - function () {} - ); -}, Nette\DI\ServiceCreationException::class, 'Unable to pass specified arguments to {closure}%a?%.'); - - -// bad variadics -if (PHP_VERSION_ID >= 80000) { - Assert::exception(function () { - Resolver::autowireArguments( - new ReflectionFunction(function ($a = 1, ...$args) {}), - [1 => 'new1', 2 => 'new2'], - function () {} - ); - }, Nette\DI\ServiceCreationException::class, 'Cannot use positional argument after named or omitted argument in $args in {closure}%a?%.'); -} diff --git a/tests/DI/Resolver.autowireArguments.phpt b/tests/DI/Resolver.autowireArguments.phpt deleted file mode 100644 index c468137ea..000000000 --- a/tests/DI/Resolver.autowireArguments.phpt +++ /dev/null @@ -1,119 +0,0 @@ - 'new'], - Resolver::autowireArguments( - new ReflectionFunction(function ($a = 1, $b = 2) {}), - [1 => 'new'], - function () {} - ) -); - -// optional arguments + named -Assert::equal( - PHP_VERSION_ID < 80000 ? [1, 'new'] : ['b' => 'new'], - Resolver::autowireArguments( - new ReflectionFunction(function ($a = 1, $b = 2) {}), - ['b' => 'new'], - function () {} - ) -); - -// optional arguments + named variadics -Assert::equal( - PHP_VERSION_ID < 80000 ? [1, 'k1' => 'new1', 'k2' => 'new2'] : ['k1' => 'new1', 'k2' => 'new2'], - Resolver::autowireArguments( - new ReflectionFunction(function ($a = 1, ...$args) {}), - ['k1' => 'new1', 'k2' => 'new2'], - function () {} - ) -); - -// positional variadics -Assert::equal( - [1, 2, 3], - Resolver::autowireArguments( - new ReflectionFunction(function (...$args) {}), - [1, 2, 3], - function () {} - ) -); - -// named variadics -Assert::equal( - [1, 2, 3], - Resolver::autowireArguments( - new ReflectionFunction(function (...$args) {}), - ['args' => [1, 2, 3]], - function () {} - ) -); - -// named parameter intentionally overwrites the indexed one (due to overwriting in the configuration) -Assert::equal( - [2], - Resolver::autowireArguments( - new ReflectionFunction(function ($a) {}), - [1, 'a' => 2], - function () {} - ) -);