Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
MemoryTest Class Reference
Inheritance diagram for MemoryTest:

Public Member Functions

 testGetRealMemoryUsageUnix ()
 
 testGetRealMemoryUsageWin ()
 
 testConvertToBytes ($number, $expected)
 
 convertToBytesDataProvider ()
 
 testConvertToBytesBadFormat ($number)
 
 convertToBytesBadFormatDataProvider ()
 
 testConvertToBytes64 ($number, $expected)
 
 convertToBytes64DataProvider ()
 
 testConvertToBytesInvalidArgument ()
 
 testConvertToBytesOutOfBounds ()
 

Protected Member Functions

 setUp ()
 

Detailed Description

Definition at line 8 of file MemoryTest.php.

Member Function Documentation

◆ convertToBytes64DataProvider()

convertToBytes64DataProvider ( )
Returns
array

Definition at line 125 of file MemoryTest.php.

126  {
127  return [
128  ['2T', '2199023255552'],
129  ['1P', '1125899906842624'],
130  ['2E', '2305843009213693952']
131  ];
132  }

◆ convertToBytesBadFormatDataProvider()

convertToBytesBadFormatDataProvider ( )
Returns
array

Definition at line 100 of file MemoryTest.php.

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  }

◆ convertToBytesDataProvider()

convertToBytesDataProvider ( )
Returns
array

Definition at line 72 of file MemoryTest.php.

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  }

◆ setUp()

setUp ( )
protected

Definition at line 15 of file MemoryTest.php.

16  {
17  $this->_shell = $this->createPartialMock(\Magento\Framework\Shell::class, ['execute']);
18  }

◆ testConvertToBytes()

testConvertToBytes (   $number,
  $expected 
)
Parameters
string$number
string$expected@dataProvider convertToBytesDataProvider

Definition at line 64 of file MemoryTest.php.

65  {
66  $this->assertEquals($expected, \Magento\TestFramework\Helper\Memory::convertToBytes($number));
67  }
$number
Definition: details.phtml:22

◆ testConvertToBytes64()

testConvertToBytes64 (   $number,
  $expected 
)
Parameters
string$number
string$expected@dataProvider convertToBytes64DataProvider

Definition at line 114 of file MemoryTest.php.

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  }
$number
Definition: details.phtml:22

◆ testConvertToBytesBadFormat()

testConvertToBytesBadFormat (   $number)
Parameters
string$number@dataProvider convertToBytesBadFormatDataProvider @expectedException \InvalidArgumentException

Definition at line 92 of file MemoryTest.php.

◆ testConvertToBytesInvalidArgument()

testConvertToBytesInvalidArgument ( )

@expectedException \InvalidArgumentException

Definition at line 137 of file MemoryTest.php.

◆ testConvertToBytesOutOfBounds()

testConvertToBytesOutOfBounds ( )

@expectedException \OutOfBoundsException

Definition at line 145 of file MemoryTest.php.

146  {
147  if (PHP_INT_SIZE > 4) {
148  $this->markTestSkipped('A 32-bit system is required to perform this test.');
149  }
151  }

◆ testGetRealMemoryUsageUnix()

testGetRealMemoryUsageUnix ( )

Definition at line 20 of file MemoryTest.php.

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  }
__()
Definition: __.php:13

◆ testGetRealMemoryUsageWin()

testGetRealMemoryUsageWin ( )

Definition at line 44 of file MemoryTest.php.

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  }

The documentation for this class was generated from the following file: