Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TestCasePropertiesTest.php
Go to the documentation of this file.
1 <?php
11 
12 class TestCasePropertiesTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $_fixtureProperties = [
18  ['name' => 'testPublic', 'is_static' => false],
19  ['name' => '_testPrivate', 'is_static' => false],
20  ['name' => '_testPropertyBoolean', 'is_static' => false],
21  ['name' => '_testPropertyInteger', 'is_static' => false],
22  ['name' => '_testPropertyFloat', 'is_static' => false],
23  ['name' => '_testPropertyString', 'is_static' => false],
24  ['name' => '_testPropertyArray', 'is_static' => false],
25  ['name' => '_testPropertyObject', 'is_static' => false],
26  ['name' => 'testPublicStatic', 'is_static' => true],
27  ['name' => '_testProtectedStatic', 'is_static' => true],
28  ['name' => '_testPrivateStatic', 'is_static' => true],
29  ];
30 
31  public function testEndTestSuiteDestruct()
32  {
33  $phpUnitTestSuite = new \PHPUnit\Framework\TestSuite();
34  $phpUnitTestSuite->addTestFile(__DIR__ . '/TestCasePropertiesTest/DummyTestCase.php');
35  // Because addTestFile() adds classes from file to tests array, use first testsuite
37  $testSuite = $phpUnitTestSuite->testAt(0);
38  $testSuite->run();
40  $testClass = $testSuite->testAt(0);
41 
42  $propertyObjectMock = $this->createPartialMock(\stdClass::class, ['__destruct']);
43  $propertyObjectMock->expects($this->atLeastOnce())->method('__destruct');
44  $testClass->setPropertyObject($propertyObjectMock);
45 
46  foreach ($this->_fixtureProperties as $property) {
47  if ($property['is_static']) {
48  $this->assertAttributeNotEmpty($property['name'], get_class($testClass));
49  } else {
50  $this->assertAttributeNotEmpty($property['name'], $testClass);
51  }
52  }
53 
54  $clearProperties = new \Magento\TestFramework\Workaround\Cleanup\TestCaseProperties();
55  $clearProperties->endTestSuite($testSuite);
56 
57  foreach ($this->_fixtureProperties as $property) {
58  if ($property['is_static']) {
59  $this->assertAttributeEmpty($property['name'], get_class($testClass));
60  } else {
61  $this->assertAttributeEmpty($property['name'], $testClass);
62  }
63  }
64  }
65 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60