Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MemoryTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Test\Helper;
7 
8 class MemoryTest extends \PHPUnit\Framework\TestCase
9 {
13  private $_shell;
14 
15  protected function setUp()
16  {
17  $this->_shell = $this->createPartialMock(\Magento\Framework\Shell::class, ['execute']);
18  }
19 
20  public function testGetRealMemoryUsageUnix()
21  {
22  $object = new \Magento\TestFramework\Helper\Memory($this->_shell);
23  $this->_shell->expects(
24  $this->at(0)
25  )->method(
26  'execute'
27  )->with(
28  $this->stringStartsWith('tasklist.exe ')
29  )->will(
30  $this->throwException(new \Magento\Framework\Exception\LocalizedException(__('command not found')))
31  );
32  $this->_shell->expects(
33  $this->at(1)
34  )->method(
35  'execute'
36  )->with(
37  $this->stringStartsWith('ps ')
38  )->will(
39  $this->returnValue('26321')
40  );
41  $this->assertEquals(26952704, $object->getRealMemoryUsage());
42  }
43 
44  public function testGetRealMemoryUsageWin()
45  {
46  $this->_shell->expects(
47  $this->once()
48  )->method(
49  'execute'
50  )->with(
51  $this->stringStartsWith('tasklist.exe ')
52  )->will(
53  $this->returnValue('"php.exe","12345","N/A","0","26,321 K"')
54  );
55  $object = new \Magento\TestFramework\Helper\Memory($this->_shell);
56  $this->assertEquals(26952704, $object->getRealMemoryUsage());
57  }
58 
64  public function testConvertToBytes($number, $expected)
65  {
66  $this->assertEquals($expected, \Magento\TestFramework\Helper\Memory::convertToBytes($number));
67  }
68 
72  public function convertToBytesDataProvider()
73  {
74  return [
75  'B' => ['1B', '1'],
76  'KB' => ['3K', '3072'],
77  'MB' => ['2M', '2097152'],
78  'GB' => ['1G', '1073741824'],
79  'regular spaces' => ['1 234 K', '1263616'],
80  'no-break spaces' => ["1\xA0234\xA0K", '1263616'],
81  'tab' => ["1\x09234\x09K", '1263616'],
82  'coma' => ['1,234K', '1263616'],
83  'dot' => ['1.234 K', '1263616']
84  ];
85  }
86 
93  {
95  }
96 
101  {
102  return [
103  'more than one unit of measure' => ['1234KB'],
104  'unknown unit of measure' => ['1234Z'],
105  'non-integer value' => ['1,234.56 K']
106  ];
107  }
108 
114  public function testConvertToBytes64($number, $expected)
115  {
116  if (PHP_INT_SIZE <= 4) {
117  $this->markTestSkipped('A 64-bit system is required to perform this test.');
118  }
119  $this->assertEquals($expected, \Magento\TestFramework\Helper\Memory::convertToBytes($number));
120  }
121 
126  {
127  return [
128  ['2T', '2199023255552'],
129  ['1P', '1125899906842624'],
130  ['2E', '2305843009213693952']
131  ];
132  }
133 
138  {
140  }
141 
146  {
147  if (PHP_INT_SIZE > 4) {
148  $this->markTestSkipped('A 32-bit system is required to perform this test.');
149  }
151  }
152 }
$number
Definition: details.phtml:22
testConvertToBytes64($number, $expected)
Definition: MemoryTest.php:114
__()
Definition: __.php:13
testConvertToBytes($number, $expected)
Definition: MemoryTest.php:64