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

Public Member Functions

 testGetInstanceEmptyProhibited ()
 
 testSetInstanceFirstAllowed ()
 
 testGetInstanceAllowed (\Magento\TestFramework\Helper\Bootstrap $expectedInstance)
 
 testSetInstanceChangeProhibited ()
 
 testCanTestHeaders ()
 
 testGetAppTempDir ()
 
 testGetAppInitParams ()
 
 testReinitialize ()
 
 testRunApp ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Protected Attributes

 $_object
 
 $_bootstrap
 
 $_application
 
 $_fixtureInitParams
 

Detailed Description

Definition at line 15 of file BootstrapTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Definition at line 44 of file BootstrapTest.php.

45  {
46  $this->_application = $this->createPartialMock(
47  \Magento\TestFramework\Application::class,
48  ['getTempDir', 'getInitParams', 'reinitialize', 'run']
49  );
50  $this->_bootstrap = $this->createPartialMock(
51  \Magento\TestFramework\Bootstrap::class,
52  ['getApplication', 'getDbVendorName']
53  );
54  $this->_bootstrap->expects(
55  $this->any()
56  )->method(
57  'getApplication'
58  )->will(
59  $this->returnValue($this->_application)
60  );
61  $this->_object = new \Magento\TestFramework\Helper\Bootstrap($this->_bootstrap);
62  }

◆ tearDown()

tearDown ( )
protected

Definition at line 64 of file BootstrapTest.php.

65  {
66  $this->_application = null;
67  $this->_bootstrap = null;
68  $this->_object = null;
69  }

◆ testCanTestHeaders()

testCanTestHeaders ( )

Definition at line 104 of file BootstrapTest.php.

105  {
106  if (!function_exists('xdebug_get_headers')) {
107  $this->assertFalse(
108  \Magento\TestFramework\Helper\Bootstrap::canTestHeaders(),
109  'Expected inability to test headers.'
110  );
111  return;
112  }
113  $expectedHeader = 'SomeHeader: header-value';
114  $expectedCookie = 'Set-Cookie: SomeCookie=cookie-value';
115 
116  /* Make sure that chosen reference samples are unique enough to rely on them */
117  $actualHeaders = xdebug_get_headers();
118  $this->assertNotContains($expectedHeader, $actualHeaders);
119  $this->assertNotContains($expectedCookie, $actualHeaders);
120 
121  /* Determine whether header-related functions can be in fact called with no error */
122  $expectedCanTest = true;
123  set_error_handler(
124  function () use (&$expectedCanTest) {
125  $expectedCanTest = false;
126  }
127  );
128  header($expectedHeader);
129  setcookie('SomeCookie', 'cookie-value');
130  restore_error_handler();
131 
132  $this->assertEquals($expectedCanTest, \Magento\TestFramework\Helper\Bootstrap::canTestHeaders());
133 
134  if ($expectedCanTest) {
135  $actualHeaders = xdebug_get_headers();
136  $this->assertContains($expectedHeader, $actualHeaders);
137  $this->assertContains($expectedCookie, $actualHeaders);
138  }
139  }

◆ testGetAppInitParams()

testGetAppInitParams ( )

Definition at line 147 of file BootstrapTest.php.

148  {
149  $this->_application->expects(
150  $this->once()
151  )->method(
152  'getInitParams'
153  )->will(
154  $this->returnValue($this->_fixtureInitParams)
155  );
156  $this->assertEquals($this->_fixtureInitParams, $this->_object->getAppInitParams());
157  }

◆ testGetAppTempDir()

testGetAppTempDir ( )

Definition at line 141 of file BootstrapTest.php.

142  {
143  $this->_application->expects($this->once())->method('getTempDir')->will($this->returnValue(__DIR__));
144  $this->assertEquals(__DIR__, $this->_object->getAppTempDir());
145  }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60

◆ testGetInstanceAllowed()

testGetInstanceAllowed ( \Magento\TestFramework\Helper\Bootstrap  $expectedInstance)

@depends testSetInstanceFirstAllowed

Definition at line 89 of file BootstrapTest.php.

90  {
91  $this->assertSame($expectedInstance, \Magento\TestFramework\Helper\Bootstrap::getInstance());
92  }

◆ testGetInstanceEmptyProhibited()

testGetInstanceEmptyProhibited ( )

@expectedException \Magento\Framework\Exception\LocalizedException @expectedExceptionMessage Helper instance is not defined yet.

Definition at line 75 of file BootstrapTest.php.

◆ testReinitialize()

testReinitialize ( )

Definition at line 159 of file BootstrapTest.php.

160  {
161  $this->_application->expects($this->once())->method('reinitialize')->with($this->_fixtureInitParams);
162  $this->_object->reinitialize($this->_fixtureInitParams);
163  }

◆ testRunApp()

testRunApp ( )

Definition at line 165 of file BootstrapTest.php.

166  {
167  $this->_application->expects($this->once())->method('run');
168  $this->_object->runApp();
169  }

◆ testSetInstanceChangeProhibited()

testSetInstanceChangeProhibited ( )

@depends testSetInstanceFirstAllowed @expectedException \Magento\Framework\Exception\LocalizedException @expectedExceptionMessage Helper instance cannot be redefined.

Definition at line 99 of file BootstrapTest.php.

100  {
102  }
static setInstance(\Magento\TestFramework\Helper\Bootstrap $instance)
Definition: Bootstrap.php:35

◆ testSetInstanceFirstAllowed()

testSetInstanceFirstAllowed ( )

Definition at line 80 of file BootstrapTest.php.

81  {
83  return $this->_object;
84  }
static setInstance(\Magento\TestFramework\Helper\Bootstrap $instance)
Definition: Bootstrap.php:35

Field Documentation

◆ $_application

$_application
protected

Definition at line 30 of file BootstrapTest.php.

◆ $_bootstrap

$_bootstrap
protected

Definition at line 25 of file BootstrapTest.php.

◆ $_fixtureInitParams

$_fixtureInitParams
protected
Initial value:

Definition at line 37 of file BootstrapTest.php.

◆ $_object

$_object
protected

Definition at line 20 of file BootstrapTest.php.


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