From a1f55e34066a9bfd8370710d3f4f9c0fcf018d63 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 27 Mar 2015 18:21:15 +0100 Subject: [PATCH 1/7] travis: added HHVM nightly --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 41fae722e..fe58d7283 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,13 @@ php: - 5.6 - 7.0 - hhvm + - hhvm-nightly matrix: allow_failures: - php: 7.0 - php: hhvm + - php: hhvm-nightly script: - vendor/bin/tester tests -s -p php -c tests/php-unix.ini From c658314b1bb9b289e1e989d6f257b49d8f8f6373 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 29 Mar 2015 17:23:40 +0200 Subject: [PATCH 2/7] InjectExtension: fixed exception type --- src/DI/Extensions/InjectExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DI/Extensions/InjectExtension.php b/src/DI/Extensions/InjectExtension.php index a16acd767..a662175d1 100644 --- a/src/DI/Extensions/InjectExtension.php +++ b/src/DI/Extensions/InjectExtension.php @@ -125,7 +125,7 @@ private static function checkType($class, $name, $type, $container) } elseif (!class_exists($type) && !interface_exists($type)) { throw new Nette\InvalidStateException("Class or interface '$type' used in @var annotation at $fullname not found. Check annotation and 'use' statements."); } elseif (!$container->getByType($type, FALSE)) { - throw new ServiceCreationException("Service of type {$type} used in @var annotation at $fullname not found. Did you register it in configuration file?"); + throw new Nette\InvalidStateException("Service of type {$type} used in @var annotation at $fullname not found. Did you register it in configuration file?"); } } From a5709bba0e5810472fdc3caa3657fa8b7f2fdf84 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 29 Mar 2015 17:29:10 +0200 Subject: [PATCH 3/7] PhpReflection::parseAnnotation accepts `@annotation*` --- src/DI/PhpReflection.php | 2 +- tests/DI/PhpReflection.parseAnnotation().phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DI/PhpReflection.php b/src/DI/PhpReflection.php index 200ff158a..13bcb96d8 100644 --- a/src/DI/PhpReflection.php +++ b/src/DI/PhpReflection.php @@ -36,7 +36,7 @@ public static function parseAnnotation(\Reflector $ref, $name) } $ok = TRUE; } - if (preg_match("#[\\s*]@$name\\s++([^@]\\S*)?#", trim($ref->getDocComment(), '/*'), $m)) { + if (preg_match("#[\\s*]@$name(?:\\s++([^@]\\S*)?|$)#", trim($ref->getDocComment(), '/*'), $m)) { return isset($m[1]) ? $m[1] : ''; } } diff --git a/tests/DI/PhpReflection.parseAnnotation().phpt b/tests/DI/PhpReflection.parseAnnotation().phpt index e44bfa2af..3badb11b9 100644 --- a/tests/DI/PhpReflection.parseAnnotation().phpt +++ b/tests/DI/PhpReflection.parseAnnotation().phpt @@ -24,7 +24,7 @@ Assert::same('type', PhpReflection::parseAnnotation($rc, 'var')); Assert::same('bool|int', PhpReflection::parseAnnotation($rc, 'return')); -/** @return */ +/** @return*/ class TestClass2 {} $rc = new ReflectionClass('TestClass2'); From 46a3eccf61ce6de0fa2055473e4fe58cdac9d3de Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 1 Apr 2015 19:20:11 +0200 Subject: [PATCH 4/7] composer: removed --dev --- .travis.yml | 2 +- tests/bootstrap.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fe58d7283..a69791c68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,5 +24,5 @@ after_failure: before_script: # Install Nette Tester & Code Checker - - composer install --no-interaction --dev --prefer-source + - composer install --no-interaction --prefer-source - composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 37da41c96..ffdf9abbf 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,7 +4,7 @@ // invoked through the command: ../vendor/bin/tester . if (@!include __DIR__ . '/../vendor/autoload.php') { - echo 'Install Nette Tester using `composer update --dev`'; + echo 'Install Nette Tester using `composer install`'; exit(1); } From 73bcbabbec2b884746b246e2cfc7e69fbf3be8b8 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 8 Apr 2015 15:43:22 +0200 Subject: [PATCH 5/7] tests: added ContainerBuilder::findByType tests --- src/DI/ContainerBuilder.php | 8 ++-- tests/DI/Container.getByType.phpt | 48 ++++++++++++++++++++++++ tests/DI/ContainerBuilder.getByType.phpt | 27 +++++-------- 3 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 tests/DI/Container.getByType.phpt diff --git a/src/DI/ContainerBuilder.php b/src/DI/ContainerBuilder.php index 28fd67e23..f4dab8c62 100644 --- a/src/DI/ContainerBuilder.php +++ b/src/DI/ContainerBuilder.php @@ -120,8 +120,8 @@ public function hasDefinition($name) /** - * @param string - * @param string + * @param string + * @param string */ public function addAlias($alias, $service) { @@ -206,7 +206,7 @@ public function getByType($class) /** * Gets the service names and definitions of the specified type. - * @param string + * @param string * @return ServiceDefinition[] */ public function findByType($class) @@ -489,7 +489,7 @@ private function checkCase($class) /** - * @param string[] + * @param string[] * @return self */ public function addExcludedClasses(array $classes) diff --git a/tests/DI/Container.getByType.phpt b/tests/DI/Container.getByType.phpt new file mode 100644 index 000000000..97323bf19 --- /dev/null +++ b/tests/DI/Container.getByType.phpt @@ -0,0 +1,48 @@ +addDefinition('one') + ->setClass('Service'); +$two = $builder->addDefinition('two') + ->setClass('Service2'); +$three = $builder->addDefinition('three') + ->setClass('Service2') + ->setAutowired(FALSE); + +$container = createContainer($builder); + +Assert::type( 'Service', $container->getByType('Service') ); +Assert::null( $container->getByType('unknown', FALSE) ); + +Assert::exception(function() use ($container) { + $container->getByType('unknown'); +}, 'Nette\DI\MissingServiceException', 'Service of type unknown not found.'); + +Assert::exception(function() use ($container) { + $container->getByType('Nette\Object'); +}, 'Nette\DI\MissingServiceException', 'Multiple services of type Nette\Object found: one, two, container.'); + + +Assert::same( array('one'), $container->findByType('Service') ); +Assert::same( array('two', 'three'), $container->findByType('Service2') ); +Assert::same( array(), $container->findByType('unknown') ); diff --git a/tests/DI/ContainerBuilder.getByType.phpt b/tests/DI/ContainerBuilder.getByType.phpt index 1a3c3e919..4b6f75464 100644 --- a/tests/DI/ContainerBuilder.getByType.phpt +++ b/tests/DI/ContainerBuilder.getByType.phpt @@ -1,7 +1,7 @@ addDefinition('three') ->setAutowired(FALSE); -// compile-time +Assert::null( $builder->getByType('\Service') ); + $builder->prepareClassList(); Assert::same( 'one', $builder->getByType('\Service') ); @@ -40,19 +41,9 @@ Assert::exception(function() use ($builder) { }, 'Nette\DI\ServiceCreationException', 'Multiple services of type Nette\Object found: one, two, container'); -$container = createContainer($builder); - -Assert::type( 'Service', $container->getByType('Service') ); -Assert::null( $container->getByType('unknown', FALSE) ); - -Assert::same( array('one'), $container->findByType('Service') ); -Assert::same( array('two', 'three'), $container->findByType('Service2') ); -Assert::same( array(), $container->findByType('unknown') ); - -Assert::exception(function() use ($container) { - $container->getByType('unknown'); -}, 'Nette\DI\MissingServiceException', 'Service of type unknown not found.'); - -Assert::exception(function() use ($container) { - $container->getByType('Nette\Object'); -}, 'Nette\DI\MissingServiceException', 'Multiple services of type Nette\Object found: one, two, container.'); +Assert::same( array('one' => $builder->getDefinition('one')), $builder->findByType('Service') ); +Assert::same( + array('two' => $builder->getDefinition('two'), 'three' => $builder->getDefinition('three')), + $builder->findByType('Service2') +); +Assert::same( array(), $builder->findByType('unknown') ); From 702e770bc6c232eba8be7f772f2400d961783e83 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 3 May 2015 17:44:54 +0200 Subject: [PATCH 6/7] ContainerBuilder: fixed reseting of $currentService [Closes #70] --- src/DI/ContainerBuilder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DI/ContainerBuilder.php b/src/DI/ContainerBuilder.php index f4dab8c62..f2e741c2d 100644 --- a/src/DI/ContainerBuilder.php +++ b/src/DI/ContainerBuilder.php @@ -617,6 +617,7 @@ private function generateService($name) } $code .= $this->formatStatement($setup) . ";\n"; } + $this->currentService = NULL; $code .= 'return $service;'; From 72319c90b23437f2397bf533dc8ce6204b2b75bf Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 3 May 2015 18:16:30 +0200 Subject: [PATCH 7/7] typo --- tests/DI/ContainerBuilder.getByType.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/DI/ContainerBuilder.getByType.phpt b/tests/DI/ContainerBuilder.getByType.phpt index 4b6f75464..26f278398 100644 --- a/tests/DI/ContainerBuilder.getByType.phpt +++ b/tests/DI/ContainerBuilder.getByType.phpt @@ -31,7 +31,7 @@ $three = $builder->addDefinition('three') Assert::null( $builder->getByType('\Service') ); - + $builder->prepareClassList(); Assert::same( 'one', $builder->getByType('\Service') );