Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OutputAbstractTest.php
Go to the documentation of this file.
1 <?php
9 
10 class OutputAbstractTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_output;
16 
17  protected function setUp()
18  {
19  $this->_output = $this->getMockForAbstractClass(
20  \Magento\Framework\Profiler\Driver\Standard\AbstractOutput::class
21  );
22  }
23 
27  public function testSetFilterPattern()
28  {
29  $this->assertAttributeEmpty('_filterPattern', $this->_output);
30  $filterPattern = '/test/';
31  $this->_output->setFilterPattern($filterPattern);
32  $this->assertEquals($filterPattern, $this->_output->getFilterPattern());
33  }
34 
38  public function testSetThreshold()
39  {
40  $thresholdKey = \Magento\Framework\Profiler\Driver\Standard\Stat::TIME;
41  $this->_output->setThreshold($thresholdKey, 100);
42  $thresholds = class_exists('PHPUnit_Util_Class')
43  ? \PHPUnit_Util_Class::getObjectAttribute($this->_output, '_thresholds')
44  : \PHPUnit\Framework\Assert::readAttribute($this->_output, '_thresholds');
45  $this->assertArrayHasKey($thresholdKey, $thresholds);
46  $this->assertEquals(100, $thresholds[$thresholdKey]);
47 
48  $this->_output->setThreshold($thresholdKey, null);
49  $this->assertArrayNotHasKey($thresholdKey, $this->_output->getThresholds());
50  }
51 
55  public function testConstructor()
56  {
57  $configuration = ['filterPattern' => '/filter pattern/', 'thresholds' => ['fetchKey' => 100]];
59  $output = $this->getMockForAbstractClass(
60  \Magento\Framework\Profiler\Driver\Standard\AbstractOutput::class,
62  );
63  $this->assertEquals('/filter pattern/', $output->getFilterPattern());
64  $thresholds = $output->getThresholds();
65  $this->assertArrayHasKey('fetchKey', $thresholds);
66  $this->assertEquals(100, $thresholds['fetchKey']);
67  }
68 
77  public function testRenderColumnValue($value, $columnKey, $expectedValue)
78  {
79  $method = new \ReflectionMethod($this->_output, '_renderColumnValue');
80  $method->setAccessible(true);
81  $this->assertEquals($expectedValue, $method->invoke($this->_output, $value, $columnKey));
82  }
83 
88  {
89  return [
90  ['someTimerId', \Magento\Framework\Profiler\Driver\Standard\Stat::ID, 'someTimerId'],
91  [10000.123, \Magento\Framework\Profiler\Driver\Standard\Stat::TIME, '10,000.123000'],
92  [200000.123456789, \Magento\Framework\Profiler\Driver\Standard\Stat::AVG, '200,000.123457'],
93  [1000000000.12345678, \Magento\Framework\Profiler\Driver\Standard\Stat::EMALLOC, '1,000,000,000'],
94  [2000000000.12345678, \Magento\Framework\Profiler\Driver\Standard\Stat::REALMEM, '2,000,000,000']
95  ];
96  }
97 
101  public function testRenderCaption()
102  {
103  $method = new \ReflectionMethod($this->_output, '_renderCaption');
104  $method->setAccessible(true);
105  $this->assertRegExp(
106  '/Code Profiler \(Memory usage: real - \d+, emalloc - \d+\)/',
107  $method->invoke($this->_output)
108  );
109  }
110 
114  public function testGetTimerIds()
115  {
116  $this->_output->setFilterPattern('/filter pattern/');
117 
118  $mockStat = $this->createMock(\Magento\Framework\Profiler\Driver\Standard\Stat::class);
119  $expectedTimerIds = ['test'];
120  $mockStat->expects(
121  $this->once()
122  )->method(
123  'getFilteredTimerIds'
124  )->with(
125  $this->_output->getThresholds(),
126  $this->_output->getFilterPattern()
127  )->will(
128  $this->returnValue($expectedTimerIds)
129  );
130 
131  $method = new \ReflectionMethod($this->_output, '_getTimerIds');
132  $method->setAccessible(true);
133  $this->assertEquals($expectedTimerIds, $method->invoke($this->_output, $mockStat));
134  }
135 
139  public function testRenderTimerId()
140  {
141  $method = new \ReflectionMethod($this->_output, '_renderTimerId');
142  $method->setAccessible(true);
143  $this->assertEquals('someTimerId', $method->invoke($this->_output, 'someTimerId'));
144  }
145 }
$configuration
Definition: index.php:33
$value
Definition: gender.phtml:16
$method
Definition: info.phtml:13