StrikeIronTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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
  24. */
  25. require_once 'Zend/Service/StrikeIron.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_StrikeIronTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function setUp()
  38. {
  39. // stub out SOAPClient instance
  40. $this->soapClient = new stdclass();
  41. $this->options = array('client' => $this->soapClient);
  42. $this->strikeIron = new Zend_Service_StrikeIron($this->options);
  43. }
  44. public function testFactoryThrowsOnBadName()
  45. {
  46. try {
  47. $this->strikeIron->getService(array('class' => 'BadServiceNameHere'));
  48. $this->fail();
  49. } catch (Zend_Service_StrikeIron_Exception $e) {
  50. $this->assertRegExp('/could not be loaded/i', $e->getMessage());
  51. $this->assertRegExp('/not found/i', $e->getMessage());
  52. }
  53. }
  54. public function testFactoryReturnsServiceByStrikeIronClass()
  55. {
  56. $base = $this->strikeIron->getService(array('class' => 'Base'));
  57. $this->assertTrue($base instanceof Zend_Service_StrikeIron_Base);
  58. $this->assertSame(null, $base->getWsdl());
  59. $this->assertSame($this->soapClient, $base->getSoapClient());
  60. }
  61. public function testFactoryReturnsServiceAnyUnderscoredClass()
  62. {
  63. $class = 'Zend_Service_StrikeIron_StrikeIronTest_StubbedBase';
  64. $stub = $this->strikeIron->getService(array('class' => $class));
  65. $this->assertTrue($stub instanceof $class);
  66. }
  67. public function testFactoryReturnsServiceByWsdl()
  68. {
  69. $wsdl = 'http://strikeiron.com/foo';
  70. $base = $this->strikeIron->getService(array('wsdl' => $wsdl));
  71. $this->assertEquals($wsdl, $base->getWsdl());
  72. }
  73. public function testFactoryPassesOptionsFromConstructor()
  74. {
  75. $class = 'Zend_Service_StrikeIron_StrikeIronTest_StubbedBase';
  76. $stub = $this->strikeIron->getService(array('class' => $class));
  77. $this->assertEquals($this->options, $stub->options);
  78. }
  79. public function testFactoryMergesItsOptionsWithConstructorOptions()
  80. {
  81. $options = array('class' => 'Zend_Service_StrikeIron_StrikeIronTest_StubbedBase',
  82. 'foo' => 'bar');
  83. $mergedOptions = array_merge($options, $this->options);
  84. unset($mergedOptions['class']);
  85. $stub = $this->strikeIron->getService($options);
  86. $this->assertEquals($mergedOptions, $stub->options);
  87. }
  88. }
  89. /**
  90. * Stub for Zend_Service_StrikeIron_Base
  91. *
  92. * @category Zend
  93. * @package Zend_Service_StrikeIron
  94. * @subpackage UnitTests
  95. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  96. * @license http://framework.zend.com/license/new-bsd New BSD License
  97. */
  98. class Zend_Service_StrikeIron_StrikeIronTest_StubbedBase
  99. {
  100. public function __construct($options)
  101. {
  102. $this->options = $options;
  103. }
  104. }