init
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\TestFramework\Isolation;
|
||||
|
||||
use Magento\TestFramework\App\Config;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/**
|
||||
* A listener that watches for integrity of app configuration
|
||||
*/
|
||||
class AppConfig
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $testAppConfig;
|
||||
|
||||
/**
|
||||
* Clean memorized and cached setting values
|
||||
*
|
||||
* Assumption: this is done once right before executing very first test suite.
|
||||
* It is assumed that deployment configuration is valid at this point
|
||||
*
|
||||
* @param \PHPUnit\Framework\TestCase $test
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function startTest(\PHPUnit\Framework\TestCase $test)
|
||||
{
|
||||
$this->getTestAppConfig()->clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Test App Config
|
||||
*
|
||||
* @return Config
|
||||
*/
|
||||
private function getTestAppConfig()
|
||||
{
|
||||
if (!$this->testAppConfig) {
|
||||
$this->testAppConfig = ObjectManager::getInstance()->get(Config::class);
|
||||
}
|
||||
|
||||
return $this->testAppConfig;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\TestFramework\Isolation;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\App\DeploymentConfig\Reader;
|
||||
|
||||
/**
|
||||
* A listener that watches for integrity of deployment configuration
|
||||
*/
|
||||
class DeploymentConfig
|
||||
{
|
||||
/**
|
||||
* Deployment configuration reader
|
||||
*
|
||||
* @var Reader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* Initial value of deployment configuration
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Memorizes the initial value of configuration reader and the configuration value
|
||||
*
|
||||
* Assumption: this is done once right before executing very first test suite.
|
||||
* It is assumed that deployment configuration is valid at this point
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function startTestSuite()
|
||||
{
|
||||
if (null === $this->reader) {
|
||||
$this->reader = Bootstrap::getObjectManager()->get(\Magento\Framework\App\DeploymentConfig\Reader::class);
|
||||
$this->config = $this->reader->load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if deployment configuration has been changed by a test
|
||||
*
|
||||
* Changing deployment configuration violates isolation between tests, so further tests may become broken.
|
||||
* To fix this issue, find out why this test changes deployment configuration.
|
||||
* If this is intentional, then it must be reverted to the previous state within the test.
|
||||
* After that, the application needs to be wiped out and reinstalled.
|
||||
*
|
||||
* @param \PHPUnit\Framework\TestCase $test
|
||||
* @return void
|
||||
*/
|
||||
public function endTest(\PHPUnit\Framework\TestCase $test)
|
||||
{
|
||||
$config = $this->reader->load();
|
||||
if ($this->config != $config) {
|
||||
$error = "\n\nERROR: deployment configuration is corrupted. The application state is no longer valid.\n"
|
||||
. 'Further tests may fail.'
|
||||
. " This test failure may be misleading, if you are re-running it on a corrupted application.\n"
|
||||
. $test->toString() . "\n";
|
||||
$test->fail($error);
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\TestFramework\Isolation;
|
||||
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
|
||||
|
||||
/**
|
||||
* Test case hooks observer for data fixture storage
|
||||
*/
|
||||
class FlushDataFixtureStorage
|
||||
{
|
||||
/**
|
||||
* Flush data fixture storage before each test
|
||||
*
|
||||
* @param \PHPUnit\Framework\TestCase $test
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function startTest(\PHPUnit\Framework\TestCase $test)
|
||||
{
|
||||
DataFixtureStorageManager::getStorage()->flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Isolation of the current working directory changes between tests
|
||||
*/
|
||||
namespace Magento\TestFramework\Isolation;
|
||||
|
||||
class WorkingDirectory
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_currentWorkingDir;
|
||||
|
||||
/**
|
||||
* Handler for 'endTest' event
|
||||
*
|
||||
* @param \PHPUnit\Framework\TestCase $test
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function startTest(\PHPUnit\Framework\TestCase $test)
|
||||
{
|
||||
$this->_currentWorkingDir = getcwd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for 'startTest' event
|
||||
*
|
||||
* @param \PHPUnit\Framework\TestCase $test
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function endTest(\PHPUnit\Framework\TestCase $test)
|
||||
{
|
||||
if (getcwd() != $this->_currentWorkingDir) {
|
||||
chdir($this->_currentWorkingDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user