RepositoryTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see TestHelper.php
  23. */
  24. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  25. /**
  26. * @see Zend_Tool_Framework_Action_Base
  27. */
  28. require_once 'Zend/Tool/Framework/Action/Repository.php';
  29. require_once 'Zend/Tool/Framework/Action/Base.php';
  30. require_once '_files/Foo.php';
  31. /**
  32. * @category Zend
  33. * @package Zend_Tool
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. *
  38. * @group Zend_Tool_Framework
  39. * @group Zend_Tool_Framework_Action
  40. */
  41. class Zend_Tool_Framework_Action_RepositoryTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * @var Zend_Tool_Framework_Action_Repository
  45. */
  46. protected $_repository = null;
  47. public function setup()
  48. {
  49. $this->_repository = new Zend_Tool_Framework_Action_Repository();
  50. }
  51. public function teardown()
  52. {
  53. $this->_repository = null;
  54. }
  55. public function testRepositoryIsEmpty()
  56. {
  57. $this->assertEquals(0, count($this->_repository));
  58. }
  59. public function testAddActionCanHandleActionObjects()
  60. {
  61. $fooAction = new Zend_Tool_Framework_Action_Base();
  62. $fooAction->setName('Foo');
  63. $this->_repository->addAction($fooAction);
  64. $this->assertEquals(1, count($this->_repository));
  65. $this->assertEquals('Zend_Tool_Framework_Action_Base', get_class($this->_repository->getAction('Foo')));
  66. }
  67. public function testAddActionWillParseNameFromClassNameOnExtendedActions()
  68. {
  69. $this->_repository->addAction(new Zend_Tool_Framework_Action_Foo());
  70. $this->assertEquals('Zend_Tool_Framework_Action_Foo', get_class($this->_repository->getAction('Foo')));
  71. }
  72. /**
  73. * @expectedException Zend_Tool_Framework_Action_Exception
  74. */
  75. public function testAddActionThrowsExceptionOnDuplicateNameAction()
  76. {
  77. $this->_repository->addAction(new Zend_Tool_Framework_Action_Foo());
  78. $this->_repository->addAction(new Zend_Tool_Framework_Action_Foo());
  79. }
  80. /**
  81. * @expectedException Zend_Tool_Framework_Action_Exception
  82. */
  83. public function testAddActionThrowsExceptionOnActionWithNoName()
  84. {
  85. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base());
  86. }
  87. public function testGetActionReturnsNullOnNonExistentAction()
  88. {
  89. $this->assertNull($this->_repository->getAction('Foo'));
  90. }
  91. public function testRepositoryIsCountable()
  92. {
  93. $this->assertTrue($this->_repository instanceof Countable);
  94. }
  95. public function testRepositoryIsIterable()
  96. {
  97. $this->assertTrue($this->_repository instanceof Traversable);
  98. }
  99. public function testRepositoryCanIterate()
  100. {
  101. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base('Foo'));
  102. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base('Bar'));
  103. $i=0;
  104. foreach ($this->_repository as $action) {
  105. $i++;
  106. $this->assertEquals('Zend_Tool_Framework_Action_Base', get_class($action));
  107. }
  108. $this->assertEquals(2, $i);
  109. }
  110. public function testGetActionsReturnsAnArrayOfActions()
  111. {
  112. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base('Foo'));
  113. $this->_repository->addAction(new Zend_Tool_Framework_Action_Base('Bar'));
  114. $i=0;
  115. foreach ($this->_repository->getActions() as $action) {
  116. $i++;
  117. $this->assertEquals('Zend_Tool_Framework_Action_Base', get_class($action));
  118. }
  119. $this->assertEquals(2, $i);
  120. }
  121. public function testProcessMethodReturnsNull()
  122. {
  123. $this->assertNull($this->_repository->process());
  124. }
  125. }