2
0

RepositoryTest.php 4.3 KB

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