Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3008'
Browse files Browse the repository at this point in the history
Close #3008
Fix #2482
  • Loading branch information
weierophinney committed Nov 19, 2012
2 parents 5c38e47 + 3519174 commit 1f1df70
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/Zend/Di/Definition/CompilerDefinition.php
Expand Up @@ -213,7 +213,7 @@ protected function processClass($class)

$methodName = $rMethod->getName();

if ($rMethod->getName() === '__construct') {
if ($rMethod->getName() === '__construct' || $rMethod->isStatic()) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Di/Definition/RuntimeDefinition.php
Expand Up @@ -260,7 +260,7 @@ protected function processClass($class)

$methodName = $rMethod->getName();

if ($rMethod->getName() === '__construct') {
if ($rMethod->getName() === '__construct' || $rMethod->isStatic()) {
continue;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/ZendTest/Di/Definition/CompilerDefinitionTest.php
Expand Up @@ -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'));
}
}
12 changes: 10 additions & 2 deletions tests/ZendTest/Di/Definition/RuntimeDefinitionTest.php
Expand Up @@ -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'));
}
}
11 changes: 11 additions & 0 deletions tests/ZendTest/Di/DiTest.php
Expand Up @@ -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');
}
}
34 changes: 34 additions & 0 deletions 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()
{
}
}

0 comments on commit 1f1df70

Please sign in to comment.