ResultSetTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_Technorati
  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. * Test helper
  24. */
  25. require_once dirname(__FILE__) . DIRECTORY_SEPARATOR .'TestCase.php';
  26. /**
  27. * @see Zend_Service_Technorati_ResultSet
  28. */
  29. require_once 'Zend/Service/Technorati/ResultSet.php';
  30. /**
  31. * @see Zend_Service_Technorati_SearchResultSet
  32. */
  33. require_once 'Zend/Service/Technorati/SearchResultSet.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Service_Technorati
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Service
  41. * @group Zend_Service_Technorati
  42. */
  43. class Zend_Service_Technorati_ResultSetTest extends Zend_Service_Technorati_TestCase
  44. {
  45. /**
  46. * Even if Zend_Service_Technorati_ResultSet is an abstract class
  47. * it's useful to check whether it correctly implements
  48. * SeekableIterator interface as requested.
  49. *
  50. * Any *ResultSet class should be a child of ResultSet
  51. * thus it's safe to test basic methods on such child class.
  52. */
  53. public function setUp()
  54. {
  55. $this->ref = new ReflectionClass('Zend_Service_Technorati_ResultSet');
  56. $this->dom = self::getTestFileContentAsDom('TestSearchResultSet.xml');
  57. $this->object = new Zend_Service_Technorati_SearchResultSet($this->dom);
  58. $this->objectRef = new ReflectionObject($this->object);
  59. }
  60. public function testResultSetIsAbstract()
  61. {
  62. $this->assertTrue($this->ref->isAbstract());
  63. }
  64. public function testResultSetImplementsSeekableIteratorInterface()
  65. {
  66. $this->assertTrue($this->ref->isIterateable());
  67. }
  68. /**
  69. * Security check
  70. */
  71. public function testResultSetIsParentOfThisObjectClass()
  72. {
  73. $this->assertTrue($this->objectRef->isSubclassOf($this->ref));
  74. }
  75. public function testResultSetSeek()
  76. {
  77. $this->assertEquals(0, $this->object->key());
  78. $this->object->seek(2);
  79. $this->assertEquals(2, $this->object->key());
  80. }
  81. public function testResultSetSeekThrowsOutOfBoundsExceptionWithInvalidIndex()
  82. {
  83. try {
  84. $this->object->seek(1000);
  85. $this->fail('Expected OutOfBoundsException not thrown');
  86. } catch (OutOfBoundsException $e) {
  87. $this->assertContains('Illegal index', $e->getMessage());
  88. }
  89. }
  90. public function testResultSetKey()
  91. {
  92. $this->assertEquals(0, $this->object->key());
  93. $this->object->seek(2);
  94. $this->assertEquals(2, $this->object->key());
  95. // don't move forward
  96. $this->assertEquals(2, $this->object->key());
  97. }
  98. public function testResultSetNext()
  99. {
  100. $this->assertEquals(0, $this->object->key());
  101. $this->object->next();
  102. $this->assertEquals(1, $this->object->key());
  103. }
  104. public function testResultSetRewind()
  105. {
  106. $this->assertEquals(0, $this->object->key());
  107. $this->object->seek(2);
  108. $this->assertTrue($this->object->rewind());
  109. $this->assertEquals(0, $this->object->key());
  110. }
  111. public function testResultSetSerialization()
  112. {
  113. $this->_testResultSetSerialization($this->object);
  114. }
  115. }