DecoratorTest.php 3.5 KB

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