ProfilerTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * \Magento\Framework\DB\Profiler test case
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\DB\Test\Unit;
  9. class ProfilerTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * Profiler instance for test
  13. * @var \Magento\Framework\DB\Profiler
  14. */
  15. protected $_profiler;
  16. /**
  17. * Setup
  18. */
  19. protected function setUp()
  20. {
  21. $this->_profiler = new \Magento\Framework\DB\Profiler(true);
  22. }
  23. public function testSetHost()
  24. {
  25. $this->_profiler->setHost('localhost');
  26. $this->assertAttributeEquals('localhost', '_host', $this->_profiler);
  27. }
  28. public function testSetType()
  29. {
  30. $this->_profiler->setType('mysql');
  31. $this->assertAttributeEquals('mysql', '_type', $this->_profiler);
  32. }
  33. public function testQueryStart()
  34. {
  35. $lastQueryId = $this->_profiler->queryStart('SELECT * FROM table');
  36. $this->assertEquals(null, $lastQueryId);
  37. }
  38. public function testQueryEnd()
  39. {
  40. $lastQueryId = $this->_profiler->queryStart('SELECT * FROM table');
  41. $endResult = $this->_profiler->queryEnd($lastQueryId);
  42. $this->assertAttributeEquals(null, '_lastQueryId', $this->_profiler);
  43. $this->assertEquals(\Magento\Framework\DB\Profiler::STORED, $endResult);
  44. }
  45. public function testQueryEndLast()
  46. {
  47. $this->_profiler->queryStart('SELECT * FROM table');
  48. $endResult = $this->_profiler->queryEndLast();
  49. $this->assertAttributeEquals(null, '_lastQueryId', $this->_profiler);
  50. $this->assertEquals(\Magento\Framework\DB\Profiler::STORED, $endResult);
  51. $endResult = $this->_profiler->queryEndLast();
  52. $this->assertEquals(\Magento\Framework\DB\Profiler::IGNORED, $endResult);
  53. }
  54. }