Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StandardTest.php
Go to the documentation of this file.
1 <?php
9 
10 class StandardTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_stat;
16 
20  protected $_driver;
21 
22  protected function setUp()
23  {
24  $this->_stat = $this->createMock(\Magento\Framework\Profiler\Driver\Standard\Stat::class);
25  $this->_driver = new \Magento\Framework\Profiler\Driver\Standard(['stat' => $this->_stat]);
26  }
27 
28  protected function tearDown()
29  {
31  }
32 
36  public function testDefaultConstructor()
37  {
38  $driver = new \Magento\Framework\Profiler\Driver\Standard();
39  $this->assertAttributeInstanceOf(\Magento\Framework\Profiler\Driver\Standard\Stat::class, '_stat', $driver);
40  }
41 
45  public function testClear()
46  {
47  $this->_stat->expects($this->once())->method('clear')->with('timer_id');
48  $this->_driver->clear('timer_id');
49  }
50 
54  public function testStart()
55  {
56  $this->_stat->expects(
57  $this->once()
58  )->method(
59  'start'
60  )->with(
61  'timer_id',
62  $this->greaterThanOrEqual(microtime(true)),
63  $this->greaterThanOrEqual(0),
64  $this->greaterThanOrEqual(0)
65  );
66  $this->_driver->start('timer_id');
67  }
68 
72  public function testStop()
73  {
74  $this->_stat->expects(
75  $this->once()
76  )->method(
77  'stop'
78  )->with(
79  'timer_id',
80  $this->greaterThanOrEqual(microtime(true)),
81  $this->greaterThanOrEqual(0),
82  $this->greaterThanOrEqual(0)
83  );
84  $this->_driver->stop('timer_id');
85  }
86 
90  public function testInitOutputs()
91  {
92  $outputFactory = $this->createMock(\Magento\Framework\Profiler\Driver\Standard\Output\Factory::class);
93  $config = [
94  'outputs' => [
95  'outputTypeOne' => ['baseDir' => '/custom/base/dir'],
96  'outputTypeTwo' => ['type' => 'specificOutputTypeTwo'],
97  ],
98  'baseDir' => '/base/dir',
99  'outputFactory' => $outputFactory,
100  ];
101 
102  $outputOne = $this->createMock(\Magento\Framework\Profiler\Driver\Standard\OutputInterface::class);
103  $outputTwo = $this->createMock(\Magento\Framework\Profiler\Driver\Standard\OutputInterface::class);
104 
105  $outputFactory->expects(
106  $this->at(0)
107  )->method(
108  'create'
109  )->with(
110  ['baseDir' => '/custom/base/dir', 'type' => 'outputTypeOne']
111  )->will(
112  $this->returnValue($outputOne)
113  );
114 
115  $outputFactory->expects(
116  $this->at(1)
117  )->method(
118  'create'
119  )->with(
120  ['type' => 'specificOutputTypeTwo', 'baseDir' => '/base/dir']
121  )->will(
122  $this->returnValue($outputTwo)
123  );
124 
125  $driver = new \Magento\Framework\Profiler\Driver\Standard($config);
126  $this->assertAttributeCount(2, '_outputs', $driver);
127  $this->assertAttributeEquals([$outputOne, $outputTwo], '_outputs', $driver);
128  }
129 
134  {
135  $outputOne = $this->createMock(\Magento\Framework\Profiler\Driver\Standard\OutputInterface::class);
136  $outputOne->expects($this->once())->method('display')->with($this->_stat);
137  $outputTwo = $this->createMock(\Magento\Framework\Profiler\Driver\Standard\OutputInterface::class);
138  $outputTwo->expects($this->once())->method('display')->with($this->_stat);
139 
140  $this->_driver->registerOutput($outputOne);
141  $this->_driver->registerOutput($outputTwo);
143  $this->_driver->display();
145  $this->_driver->display();
146  }
147 
151  public function testDefaultOutputFactory()
152  {
153  $method = new \ReflectionMethod($this->_driver, '_getOutputFactory');
154  $method->setAccessible(true);
155  $this->assertInstanceOf(
156  \Magento\Framework\Profiler\Driver\Standard\Output\Factory::class,
157  $method->invoke($this->_driver)
158  );
159  }
160 }
$config
Definition: fraud_order.php:17
$method
Definition: info.phtml:13