DecoratorTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_Service_StrikeIron
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 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. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /**
  27. * @see Zend_Service_StrikeIron_Decorator
  28. */
  29. require_once 'Zend/Service/StrikeIron/Decorator.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Service_StrikeIron
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Service
  37. * @group Zend_Service_StrikeIron
  38. */
  39. class Zend_Service_StrikeIron_DecoratorTest extends PHPUnit_Framework_TestCase
  40. {
  41. public function testNoNoticesWhenDecoratedObjectIsNotAnObject()
  42. {
  43. $decorator = new Zend_Service_StrikeIron_Decorator(3.1415);
  44. $this->assertSame(null, $decorator->foo);
  45. }
  46. public function testDecoratorReturnsNullWhenPropertyIsMissing()
  47. {
  48. $object = new stdclass();
  49. $decorator = new Zend_Service_StrikeIron_Decorator($object);
  50. $this->assertSame(null, $decorator->foo);
  51. }
  52. public function testDecoratorReturnsPropertyByItsName()
  53. {
  54. $object = (object)array('Foo' => 'bar',
  55. 'Baz' => 'qux');
  56. $decorator = new Zend_Service_StrikeIron_Decorator($object);
  57. $this->assertEquals('qux', $decorator->Baz);
  58. }
  59. public function testDecoratorReturnsPropertyByInflectedName()
  60. {
  61. $object = (object)array('Foo' => 'bar',
  62. 'Baz' => 'qux');
  63. $decorator = new Zend_Service_StrikeIron_Decorator($object);
  64. $this->assertEquals('qux', $decorator->baz);
  65. }
  66. public function testDecoratorTriesActualPropertyNameBeforeInflecting()
  67. {
  68. $object = (object)array('foo' => 'bar',
  69. 'Foo' => 'qux');
  70. $decorator = new Zend_Service_StrikeIron_Decorator($object);
  71. $this->assertEquals('bar', $decorator->foo);
  72. }
  73. public function testDecoratorReturnsAnotherDecoratorWhenValueIsAnObject()
  74. {
  75. $object = (object)array('Foo' => new stdclass);
  76. $decorator = new Zend_Service_StrikeIron_Decorator($object);
  77. $this->assertType(get_class($decorator), $decorator->Foo);
  78. }
  79. public function testDecoratorProxiesMethodCalls()
  80. {
  81. $decorator = new Zend_Service_StrikeIron_Decorator($this);
  82. $this->assertEquals('bar', $decorator->foo());
  83. }
  84. public function foo()
  85. {
  86. return 'bar';
  87. }
  88. public function testGettingTheDecoratedObject()
  89. {
  90. $decorator = new Zend_Service_StrikeIron_Decorator($this);
  91. $this->assertSame($this, $decorator->getDecoratedObject());
  92. }
  93. public function testGettingDecoratedObjectName()
  94. {
  95. $decorator = new Zend_Service_StrikeIron_Decorator($this, 'foo');
  96. $this->assertSame('foo', $decorator->getDecoratedObjectName());
  97. }
  98. }