DbControllerTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class DbControllerTest 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 testType2SingleDatabaseQuery()
  13. {
  14. $this->dispatch('/db');
  15. $this->assertModule('default');
  16. $this->assertController('db');
  17. $this->assertAction('index');
  18. $this->assertResponseCode(200);
  19. $this->assertHeaderRegex('Content-Type', '#^application/json$#');
  20. $content = $this->getResponse()->getBody();
  21. $this->assertRegExp('#^{"id"\:"\d+","randomNumber":"\d+"}$#', $content);
  22. $decodedContent = json_decode($content, true);
  23. $this->assertTrue(json_last_error() === JSON_ERROR_NONE, 'Json decode failure');
  24. $this->assertArrayHasKey('id', $decodedContent);
  25. $this->assertGreaterThan(0, $decodedContent['id']);
  26. $this->assertLessThan(10000, $decodedContent['id']);
  27. $this->assertArrayHasKey('randomNumber', $decodedContent);
  28. $this->assertGreaterThan(0, $decodedContent['randomNumber']);
  29. $this->assertLessThan(10000, $decodedContent['randomNumber']);
  30. $this->assertCount(2, $decodedContent);
  31. }
  32. }