Skip to content

Commit

Permalink
Merge pull request zendframework#29 from weierophinney/feature/di-sha…
Browse files Browse the repository at this point in the history
…red-instance

Feature/di shared instance
  • Loading branch information
ralphschindler committed Mar 19, 2012
2 parents 4b2ec0c + 093e990 commit 8582592
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/Zend/Di/DiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,23 @@ public function testInjectionForSetterInjectionWillConsultSupertypeDefinitionInC
$this->assertInstanceOf('ZendTest\Di\TestAsset\SetterInjection\A', $c->a);
}

/**
* @group SharedInstance
*/
public function testMarkingClassAsNotSharedInjectsNewInstanceIntoAllRequestersButDependentsAreShared()
{
$di = new Di();
$di->configure(new Configuration(array(
'instance' => array(
'ZendTest\Di\TestAsset\SharedInstance\Lister' => array(
'shared' => false
)
)
)));
$movie = $di->get('ZendTest\Di\TestAsset\SharedInstance\Movie');
$venue = $di->get('ZendTest\Di\TestAsset\SharedInstance\Venue');

$this->assertNotSame($movie->lister, $venue->lister);
$this->assertSame($movie->lister->sharedLister, $venue->lister->sharedLister);
}
}
32 changes: 32 additions & 0 deletions tests/Zend/Di/TestAsset/SharedInstance/Lister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Di
* @subpackage UnitTest
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Di\TestAsset\SharedInstance;

class Lister
{
public $sharedLister;

public function setSharedLister(SharedLister $lister)
{
$this->sharedLister = $lister;
}
}
32 changes: 32 additions & 0 deletions tests/Zend/Di/TestAsset/SharedInstance/Movie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Di
* @subpackage UnitTest
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Di\TestAsset\SharedInstance;

class Movie
{
public $lister;

public function __construct(Lister $lister)
{
$this->lister = $lister;
}
}
26 changes: 26 additions & 0 deletions tests/Zend/Di/TestAsset/SharedInstance/SharedLister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Di
* @subpackage UnitTest
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Di\TestAsset\SharedInstance;

class SharedLister
{
}
32 changes: 32 additions & 0 deletions tests/Zend/Di/TestAsset/SharedInstance/Venue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Di
* @subpackage UnitTest
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Di\TestAsset\SharedInstance;

class Venue
{
public $lister;

public function __construct(Lister $lister)
{
$this->lister = $lister;
}
}

0 comments on commit 8582592

Please sign in to comment.