DbMultiControllerTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class DbMultiControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
  3. {
  4. protected function setUp()
  5. {
  6. $this->bootstrap = new Zend_Application(
  7. APPLICATION_ENV,
  8. APPLICATION_PATH . '/configs/application.ini'
  9. );
  10. parent::setUp();
  11. }
  12. public function testType3MultipleDatabaseQueries()
  13. {
  14. $this->dispatch('/db-multi?queries=2');
  15. $this->assertResponseResultsEquals(2, $this->getResponse()->getBody());
  16. }
  17. /**
  18. * Helper assertion
  19. *
  20. * @param int $expectedCount
  21. * @param string $content
  22. */
  23. protected function assertResponseResultsEquals($expectedCount, $content)
  24. {
  25. $this->assertModule('default');
  26. $this->assertController('db-multi');
  27. $this->assertAction('index');
  28. $this->assertResponseCode(200);
  29. $this->assertHeaderRegex('Content-Type', '#^application/json$#');
  30. $results = json_decode($content, true);
  31. $this->assertTrue(json_last_error() === JSON_ERROR_NONE, 'Json decode failure');
  32. $this->assertCount($expectedCount, $results);
  33. $count = count($results);
  34. for ($i = 0; $i < $count; $i++) {
  35. $this->assertArrayHasKey('id', $results[$i]);
  36. $this->assertGreaterThan(0, $results[$i]['id']);
  37. $this->assertLessThan(10000, $results[$i]['id']);
  38. $this->assertArrayHasKey('randomNumber', $results[$i]);
  39. $this->assertGreaterThan(0, $results[$i]['randomNumber']);
  40. $this->assertLessThan(10000, $results[$i]['randomNumber']);
  41. }
  42. }
  43. }