Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MemoryLimitTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Test;
7 
8 class MemoryLimitTest extends \PHPUnit\Framework\TestCase
9 {
10  public function testPrintHeader()
11  {
13  $this->assertNotEmpty($result);
14  $this->assertStringEndsWith(PHP_EOL, $result);
15  }
16 
17  public function testPrintStats()
18  {
19  $object = $this->_createObject(0, 0);
20  $result = $object->printStats();
21  $this->assertContains('Memory usage (OS):', $result);
22  $this->assertContains('1.00M', $result);
23  $this->assertContains('Estimated memory leak:', $result);
24  $this->assertContains('reported by PHP', $result);
25  $this->assertStringEndsWith(PHP_EOL, $result);
26 
27  $object = $this->_createObject('2M', 0);
28  $this->assertContains('50.00% of configured 2.00M limit', $object->printStats());
29 
30  $object = $this->_createObject(0, '500K');
31  $this->assertContains('% of configured 0.49M limit', $object->printStats());
32  }
33 
34  public function testValidateUsage()
35  {
36  $object = $this->_createObject(0, 0);
37  $this->assertNull($object->validateUsage());
38  }
39 
43  public function testValidateUsageException()
44  {
45  $object = $this->_createObject('500K', '2M');
46  $object->validateUsage();
47  }
48 
54  protected function _createObject($memCap, $leakCap)
55  {
56  $helper = $this->createPartialMock(\Magento\TestFramework\Helper\Memory::class, ['getRealMemoryUsage']);
57  $helper->expects($this->any())->method('getRealMemoryUsage')->will($this->returnValue(1024 * 1024));
58  return new \Magento\TestFramework\MemoryLimit($memCap, $leakCap, $helper);
59  }
60 }
$helper
Definition: iframe.phtml:13
_createObject($memCap, $leakCap)