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
10 namespace Magento\Test\Bootstrap;
11 
12 class MemoryTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $_object;
18 
22  protected $_memoryLimit;
23 
27  protected $_activationPolicy;
28 
29  protected function setUp()
30  {
31  $this->_memoryLimit = $this->createPartialMock(\Magento\TestFramework\MemoryLimit::class, ['printStats']);
32  $this->_activationPolicy = $this->createPartialMock(\stdClass::class, ['register_shutdown_function']);
33  $this->_object = new \Magento\TestFramework\Bootstrap\Memory(
34  $this->_memoryLimit,
35  [$this->_activationPolicy, 'register_shutdown_function']
36  );
37  }
38 
39  protected function tearDown()
40  {
41  $this->_memoryLimit = null;
42  $this->_activationPolicy = null;
43  $this->_object = null;
44  }
45 
50  public function testConstructorException()
51  {
52  new \Magento\TestFramework\Bootstrap\Memory($this->_memoryLimit, 'non_existing_callable');
53  }
54 
55  public function testDisplayStats()
56  {
57  $eol = PHP_EOL;
58  $this->expectOutputString("{$eol}=== Memory Usage System Stats ==={$eol}Dummy Statistics{$eol}");
59  $this->_memoryLimit->expects(
60  $this->once()
61  )->method(
62  'printStats'
63  )->will(
64  $this->returnValue('Dummy Statistics')
65  );
66  $this->_object->displayStats();
67  }
68 
69  public function testActivateStatsDisplaying()
70  {
71  $this->_activationPolicy->expects(
72  $this->once()
73  )->method(
74  'register_shutdown_function'
75  )->with(
76  $this->identicalTo([$this->_object, 'displayStats'])
77  );
78  $this->_object->activateStatsDisplaying();
79  }
80 
81  public function testActivateLimitValidation()
82  {
83  $this->_activationPolicy->expects(
84  $this->once()
85  )->method(
86  'register_shutdown_function'
87  )->with(
88  $this->identicalTo([$this->_memoryLimit, 'validateUsage'])
89  );
90  $this->_object->activateLimitValidation();
91  }
92 }