PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/framework/Profiler/Test/Unit/Driver/StandardTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 160 lines | 111 code | 16 blank | 33 comment | 0 complexity | e6cfc68d6fca5d9639393caf41cf551d MD5 | raw file
  1. <?php
  2. /**
  3. * Test class for \Magento\Framework\Profiler\Driver\Standard
  4. *
  5. * Copyright © 2016 Magento. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\Profiler\Test\Unit\Driver;
  9. class StandardTest extends \PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @var \Magento\Framework\Profiler\Driver\Standard\Stat|PHPUnit_Framework_MockObject_MockObject
  13. */
  14. protected $_stat;
  15. /**
  16. * @var \Magento\Framework\Profiler\Driver\Standard
  17. */
  18. protected $_driver;
  19. protected function setUp()
  20. {
  21. $this->_stat = $this->getMock('Magento\Framework\Profiler\Driver\Standard\Stat');
  22. $this->_driver = new \Magento\Framework\Profiler\Driver\Standard(['stat' => $this->_stat]);
  23. }
  24. protected function tearDown()
  25. {
  26. \Magento\Framework\Profiler::reset();
  27. }
  28. /**
  29. * Test __construct method with no arguments
  30. */
  31. public function testDefaultConstructor()
  32. {
  33. $driver = new \Magento\Framework\Profiler\Driver\Standard();
  34. $this->assertAttributeInstanceOf('Magento\Framework\Profiler\Driver\Standard\Stat', '_stat', $driver);
  35. }
  36. /**
  37. * Test clear method
  38. */
  39. public function testClear()
  40. {
  41. $this->_stat->expects($this->once())->method('clear')->with('timer_id');
  42. $this->_driver->clear('timer_id');
  43. }
  44. /**
  45. * Test start method
  46. */
  47. public function testStart()
  48. {
  49. $this->_stat->expects(
  50. $this->once()
  51. )->method(
  52. 'start'
  53. )->with(
  54. 'timer_id',
  55. $this->greaterThanOrEqual(microtime(true)),
  56. $this->greaterThanOrEqual(0),
  57. $this->greaterThanOrEqual(0)
  58. );
  59. $this->_driver->start('timer_id');
  60. }
  61. /**
  62. * Test stop method
  63. */
  64. public function testStop()
  65. {
  66. $this->_stat->expects(
  67. $this->once()
  68. )->method(
  69. 'stop'
  70. )->with(
  71. 'timer_id',
  72. $this->greaterThanOrEqual(microtime(true)),
  73. $this->greaterThanOrEqual(0),
  74. $this->greaterThanOrEqual(0)
  75. );
  76. $this->_driver->stop('timer_id');
  77. }
  78. /**
  79. * Test _initOutputs method
  80. */
  81. public function testInitOutputs()
  82. {
  83. $outputFactory = $this->getMock('Magento\Framework\Profiler\Driver\Standard\Output\Factory');
  84. $config = [
  85. 'outputs' => [
  86. 'outputTypeOne' => ['baseDir' => '/custom/base/dir'],
  87. 'outputTypeTwo' => ['type' => 'specificOutputTypeTwo'],
  88. ],
  89. 'baseDir' => '/base/dir',
  90. 'outputFactory' => $outputFactory,
  91. ];
  92. $outputOne = $this->getMock('Magento\Framework\Profiler\Driver\Standard\OutputInterface');
  93. $outputTwo = $this->getMock('Magento\Framework\Profiler\Driver\Standard\OutputInterface');
  94. $outputFactory->expects(
  95. $this->at(0)
  96. )->method(
  97. 'create'
  98. )->with(
  99. ['baseDir' => '/custom/base/dir', 'type' => 'outputTypeOne']
  100. )->will(
  101. $this->returnValue($outputOne)
  102. );
  103. $outputFactory->expects(
  104. $this->at(1)
  105. )->method(
  106. 'create'
  107. )->with(
  108. ['type' => 'specificOutputTypeTwo', 'baseDir' => '/base/dir']
  109. )->will(
  110. $this->returnValue($outputTwo)
  111. );
  112. $driver = new \Magento\Framework\Profiler\Driver\Standard($config);
  113. $this->assertAttributeCount(2, '_outputs', $driver);
  114. $this->assertAttributeEquals([$outputOne, $outputTwo], '_outputs', $driver);
  115. }
  116. /**
  117. * Test display method
  118. */
  119. public function testDisplayAndRegisterOutput()
  120. {
  121. $outputOne = $this->getMock('Magento\Framework\Profiler\Driver\Standard\OutputInterface');
  122. $outputOne->expects($this->once())->method('display')->with($this->_stat);
  123. $outputTwo = $this->getMock('Magento\Framework\Profiler\Driver\Standard\OutputInterface');
  124. $outputTwo->expects($this->once())->method('display')->with($this->_stat);
  125. $this->_driver->registerOutput($outputOne);
  126. $this->_driver->registerOutput($outputTwo);
  127. \Magento\Framework\Profiler::enable();
  128. $this->_driver->display();
  129. \Magento\Framework\Profiler::disable();
  130. $this->_driver->display();
  131. }
  132. /**
  133. * Test _getOutputFactory method creating new object by default
  134. */
  135. public function testDefaultOutputFactory()
  136. {
  137. $method = new \ReflectionMethod($this->_driver, '_getOutputFactory');
  138. $method->setAccessible(true);
  139. $this->assertInstanceOf(
  140. 'Magento\Framework\Profiler\Driver\Standard\Output\Factory',
  141. $method->invoke($this->_driver)
  142. );
  143. }
  144. }