RepositoryTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Tool
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see TestHelper.php
  24. */
  25. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  26. /**
  27. * @see Zend_Tool_Framework_Action_Base
  28. */
  29. require_once 'Zend/Tool/Framework/Action/Repository.php';
  30. require_once 'Zend/Tool/Framework/Action/Base.php';
  31. require_once '_files/Foo.php';
  32. /**
  33. * @category Zend
  34. * @package Zend_Tool
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. *
  39. * @group Zend_Tool
  40. * @group Zend_Tool_Framework
  41. * @group Zend_Tool_Framework_Action
  42. */
  43. class Zend_Tool_Framework_Action_RepositoryTest extends PHPUnit_Framework_TestCase
  44. {
  45. /**
  46. * @var Zend_Tool_Framework_Action_Repository
  47. */
  48. protected $_repository = null;
  49. public function setup()
  50. {
  51. $this->_repository = new Zend_Tool_Framework_Action_Repository();
  52. }
  53. public function teardown()
  54. {
  55. $this->_repository = null;
  56. }
  57. public function testRepositoryIsEmpty()
  58. {
  59. $this->assertEquals(0, count($this->_repository));
  60. }
  61. public function testAddActionCanHandleActionObjects()
  62. {
  63. $fooAction = new Zend_Tool_Framework_Action_Base();
  64. $fooAction->setName('Foo');
  65. $this->_repository->addAction($fooAction);
  66. $this->assertEquals(1, count($this->_repository));
  67. $this->assertEquals('Zend_Tool_Framework_Action_Base', get_class($this->_repository->getAction('Foo')));
  68. }
  69. public function testAddActionWillParseNameFromClassNameOnExtendedActions()
  70. {
  71. $this->_repository->addAction(new Zend_Tool_Framework_Action_Foo());
  72. $this->assertEquals('Zend_Tool_Framework_Action_Foo', get_class($this->_repository->getAction('Foo')));
  73. }
  74. /**
  75. * @expectedException Zend_Tool_Framework_Action_Exception
  76. */
  77. public function testAddActionThrowsExceptionOnDuplicateNameAction()
  78. {
  79. $this->_repository->addAction(new Zend_Tool_Framework_Action_Foo());
  80. $this->_repository->addAction(new Zend_Tool_Framework_Action_Foo());
  81. }
  82. /**
  83. * @expectedException Zend_Tool_Framework_Action_Exception
  84. */
  85. public function testAddActionThrowsExceptionOnActionWithNoName()
  86. {
  87. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base());
  88. }
  89. public function testGetActionReturnsNullOnNonExistentAction()
  90. {
  91. $this->assertNull($this->_repository->getAction('Foo'));
  92. }
  93. public function testRepositoryIsCountable()
  94. {
  95. $this->assertTrue($this->_repository instanceof Countable);
  96. }
  97. public function testRepositoryIsIterable()
  98. {
  99. $this->assertTrue($this->_repository instanceof Traversable);
  100. }
  101. public function testRepositoryCanIterate()
  102. {
  103. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base('Foo'));
  104. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base('Bar'));
  105. $i=0;
  106. foreach ($this->_repository as $action) {
  107. $i++;
  108. $this->assertEquals('Zend_Tool_Framework_Action_Base', get_class($action));
  109. }
  110. $this->assertEquals(2, $i);
  111. }
  112. public function testGetActionsReturnsAnArrayOfActions()
  113. {
  114. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base('Foo'));
  115. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base('Bar'));
  116. $i=0;
  117. foreach ($this->_repository->getActions() as $action) {
  118. $i++;
  119. $this->assertEquals('Zend_Tool_Framework_Action_Base', get_class($action));
  120. }
  121. $this->assertEquals(2, $i);
  122. }
  123. public function testProcessMethodReturnsNull()
  124. {
  125. $this->assertNull($this->_repository->process());
  126. }
  127. }