Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Hotfix for #2482 #3008

Closed
wants to merge 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  library/Zend/Di/Definition/CompilerDefinition.php
@@ -213,7 +213,7 @@ protected function processClass($class)
$methodName = $rMethod->getName();
- if ($rMethod->getName() === '__construct') {
+ if ($rMethod->getName() === '__construct' || $rMethod->isStatic()) {
continue;
}
View
2  library/Zend/Di/Definition/RuntimeDefinition.php
@@ -260,7 +260,7 @@ protected function processClass($class)
$methodName = $rMethod->getName();
- if ($rMethod->getName() === '__construct') {
+ if ($rMethod->getName() === '__construct' || $rMethod->isStatic()) {
continue;
}
View
12 tests/ZendTest/Di/Definition/CompilerDefinitionTest.php
@@ -107,4 +107,16 @@ public function testCompilerAllowReflectionException()
// The exception gets caught before the parameter's class is set
$this->assertCount(1, current($parameters));
}
+
+ /**
+ * @group ZF2-308
+ */
+ public function testStaticMethodsNotIncludedInDefinitions()
+ {
+ $definition = new CompilerDefinition;
+ $definition->addDirectory(__DIR__ . '/../TestAsset/SetterInjection');
+ $definition->compile();
+ $this->assertTrue($definition->hasMethod('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', 'setFoo'));
+ $this->assertFalse($definition->hasMethod('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', 'setName'));
+ }
}
View
12 tests/ZendTest/Di/Definition/RuntimeDefinitionTest.php
@@ -12,10 +12,18 @@
use PHPUnit_Framework_TestCase as TestCase;
+use Zend\Di\Definition\RuntimeDefinition;
+
class RuntimeDefinitionTest extends TestCase
{
- public function testStub()
+
+ /**
+ * @group ZF2-308
+ */
+ public function testStaticMethodsNotIncludedInDefinitions()
{
- $this->markTestIncomplete();
+ $definition = new RuntimeDefinition;
+ $this->assertTrue($definition->hasMethod('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', 'setFoo'));
+ $this->assertFalse($definition->hasMethod('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', 'setName'));
}
}
View
11 tests/ZendTest/Di/DiTest.php
@@ -709,4 +709,15 @@ public function testDiWillInjectClassNameAsStringAtCallTime()
$this->assertSame($d->a, 'ZendTest\Di\TestAsset\SetterInjection\A');
}
+ /**
+ * @group ZF2-308
+ */
+ public function testWillNotCallStaticInjectionMethods()
+ {
+ $di = new Di;
+ $di->definitions()->addDefinition(new Definition\RuntimeDefinition(), false);
+ $di->newInstance('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', array('name' => 'testName'));
+
+ $this->assertSame(\ZendTest\Di\TestAsset\SetterInjection\StaticSetter::$name, 'originalName');
+ }
}
View
34 tests/ZendTest/Di/TestAsset/SetterInjection/StaticSetter.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Di
+ */
+
+namespace ZendTest\Di\TestAsset\SetterInjection;
+
+class StaticSetter
+{
+ /**
+ * @var string
+ */
+ public static $name = 'originalName';
+
+ /**
+ * @param string $name
+ */
+ public static function setName($name)
+ {
+ self::$name = $name;
+ }
+
+ /**
+ *
+ */
+ public function setFoo()
+ {
+ }
+}
Something went wrong with that request. Please try again.