PageRenderTime 25ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Service/Technorati/ResultSetTest.php

https://github.com/shevron/zf2
PHP | 116 lines | 64 code | 16 blank | 36 comment | 0 complexity | f70db7cf4e445b64e28cf5dcc1e06612 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_Service
  9. */
  10. namespace ZendTest\Service\Technorati;
  11. use Zend\Service\Technorati;
  12. /**
  13. * Test helper
  14. */
  15. /**
  16. * @see Technorati\AbstractResultSet
  17. */
  18. /**
  19. * @see Technorati\SearchResultSet
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Service_Technorati
  24. * @subpackage UnitTests
  25. * @group Zend_Service
  26. * @group Zend_Service_Technorati
  27. */
  28. class ResultSetTest extends TestCase
  29. {
  30. /**
  31. * Even if Zend_Service_Technorati_ResultSet is an abstract class
  32. * it's useful to check whether it correctly implements
  33. * SeekableIterator interface as requested.
  34. *
  35. * Any *AbstractResultSet class should be a child of AbstractResultSet
  36. * thus it's safe to test basic methods on such child class.
  37. */
  38. public function setUp()
  39. {
  40. $this->ref = new \ReflectionClass('Zend\Service\Technorati\AbstractResultSet');
  41. $this->dom = self::getTestFileContentAsDom('TestSearchResultSet.xml');
  42. $this->object = new Technorati\SearchResultSet($this->dom);
  43. $this->objectRef = new \ReflectionObject($this->object);
  44. }
  45. public function testResultSetIsAbstract()
  46. {
  47. $this->assertTrue($this->ref->isAbstract());
  48. }
  49. public function testResultSetImplementsSeekableIteratorInterface()
  50. {
  51. $this->assertTrue($this->ref->isIterateable());
  52. }
  53. /**
  54. * Security check
  55. */
  56. public function testResultSetIsParentOfThisObjectClass()
  57. {
  58. $this->assertTrue($this->objectRef->isSubclassOf($this->ref));
  59. }
  60. public function testResultSetSeek()
  61. {
  62. $this->assertEquals(0, $this->object->key());
  63. $this->object->seek(2);
  64. $this->assertEquals(2, $this->object->key());
  65. }
  66. public function testResultSetSeekThrowsOutOfBoundsExceptionWithInvalidIndex()
  67. {
  68. try {
  69. $this->object->seek(1000);
  70. $this->fail('Expected OutOfBoundsException not thrown');
  71. } catch (\OutOfBoundsException $e) {
  72. $this->assertContains('Illegal index', $e->getMessage());
  73. }
  74. }
  75. public function testResultSetKey()
  76. {
  77. $this->assertEquals(0, $this->object->key());
  78. $this->object->seek(2);
  79. $this->assertEquals(2, $this->object->key());
  80. // don't move forward
  81. $this->assertEquals(2, $this->object->key());
  82. }
  83. public function testResultSetNext()
  84. {
  85. $this->assertEquals(0, $this->object->key());
  86. $this->object->next();
  87. $this->assertEquals(1, $this->object->key());
  88. }
  89. public function testResultSetRewind()
  90. {
  91. $this->assertEquals(0, $this->object->key());
  92. $this->object->seek(2);
  93. $this->assertTrue($this->object->rewind());
  94. $this->assertEquals(0, $this->object->key());
  95. }
  96. public function testResultSetSerialization()
  97. {
  98. $this->_testResultSetSerialization($this->object);
  99. }
  100. }