DecoratorTest.php 3.5 KB

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