ProfilerTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Test case for \Magento\Framework\Profiler
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework;
  9. class ProfilerTest extends \PHPUnit\Framework\TestCase
  10. {
  11. protected function tearDown()
  12. {
  13. \Magento\Framework\Profiler::reset();
  14. }
  15. /**
  16. * @dataProvider applyConfigDataProvider
  17. * @param array $config
  18. * @param array $expectedDrivers
  19. */
  20. public function testApplyConfigWithDrivers(array $config, array $expectedDrivers)
  21. {
  22. \Magento\Framework\Profiler::applyConfig($config, '');
  23. $this->assertAttributeEquals($expectedDrivers, '_drivers', \Magento\Framework\Profiler::class);
  24. }
  25. /**
  26. * @return array
  27. */
  28. public function applyConfigDataProvider()
  29. {
  30. return [
  31. 'Empty config does not create any driver' => ['config' => [], 'drivers' => []],
  32. 'Integer 0 does not create any driver' => [
  33. 'config' => ['drivers' => [0]],
  34. 'drivers' => [],
  35. ],
  36. 'Integer 1 does creates standard driver' => [
  37. 'config' => ['drivers' => [1]],
  38. 'drivers' => [new \Magento\Framework\Profiler\Driver\Standard()],
  39. ],
  40. 'Config array key sets driver type' => [
  41. 'configs' => ['drivers' => ['standard' => 1]],
  42. 'drivers' => [new \Magento\Framework\Profiler\Driver\Standard()],
  43. ],
  44. 'Config array key ignored when type set' => [
  45. 'config' => ['drivers' => ['custom' => ['type' => 'standard']]],
  46. 'drivers' => [new \Magento\Framework\Profiler\Driver\Standard()],
  47. ],
  48. 'Config with outputs element as integer 1 creates output' => [
  49. 'config' => [
  50. 'drivers' => [['outputs' => ['html' => 1]]],
  51. 'baseDir' => '/some/base/dir',
  52. ],
  53. 'drivers' => [
  54. new \Magento\Framework\Profiler\Driver\Standard(
  55. ['outputs' => [['type' => 'html', 'baseDir' => '/some/base/dir']]]
  56. ),
  57. ],
  58. ],
  59. 'Config with outputs element as integer 0 does not create output' => [
  60. 'config' => ['drivers' => [['outputs' => ['html' => 0]]]],
  61. 'drivers' => [new \Magento\Framework\Profiler\Driver\Standard()],
  62. ],
  63. 'Config with shortly defined outputs element' => [
  64. 'config' => ['drivers' => [['outputs' => ['foo' => 'html']]]],
  65. 'drivers' => [
  66. new \Magento\Framework\Profiler\Driver\Standard(['outputs' => [['type' => 'html']]]),
  67. ],
  68. ],
  69. 'Config with fully defined outputs element options' => [
  70. 'config' => [
  71. 'drivers' => [
  72. [
  73. 'outputs' => [
  74. 'foo' => [
  75. 'type' => 'html',
  76. 'filterName' => '/someFilter/',
  77. 'thresholds' => ['someKey' => 123],
  78. 'baseDir' => '/custom/dir',
  79. ],
  80. ],
  81. ],
  82. ],
  83. ],
  84. 'drivers' => [
  85. new \Magento\Framework\Profiler\Driver\Standard(
  86. [
  87. 'outputs' => [
  88. [
  89. 'type' => 'html',
  90. 'filterName' => '/someFilter/',
  91. 'thresholds' => ['someKey' => 123],
  92. 'baseDir' => '/custom/dir',
  93. ],
  94. ],
  95. ]
  96. ),
  97. ],
  98. ],
  99. 'Config with shortly defined output' => [
  100. 'config' => ['drivers' => [['output' => 'html']]],
  101. 'drivers' => [
  102. new \Magento\Framework\Profiler\Driver\Standard(['outputs' => [['type' => 'html']]]),
  103. ],
  104. ]
  105. ];
  106. }
  107. }