Skip to content

Commit

Permalink
Merge pull request #232 from magento-performance/CICD-2390
Browse files Browse the repository at this point in the history
[PEROFRMANCE] Speed up L2
  • Loading branch information
Alexander Akimov authored Aug 10, 2016
2 parents c107794 + 1c691b7 commit 71c041a
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 39 deletions.
1 change: 0 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ return Symfony\CS\Config\Config::create()
'extra_empty_lines',
'include',
'join_function',
'multiline_array_trailing_comma',
'namespace_no_leading_whitespace',
'new_with_braces',
'object_operator',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected function _rollbackTransaction()
$this->_getConnection()->rollbackTransparentTransaction();
$this->_isTransactionActive = false;
$this->_eventManager->fireEvent('rollbackTransaction');
$this->_getConnection()->closeConnection();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ protected function endClass($name)
protected function doEndClass()
{
foreach ($this->tests as $name => $data) {
$check = $data['failure'] == 0 ? ' [x] ' : ' [ ] ';
$check = $data['failure'] == 0 ? ' - [x] ' : ' - [ ] ';
$this->write(
"\n" . $check . $name . ($data['failure'] + $data['success'] ==
0 ? ' (skipped)' : '') . ($data['time'] > 1 ? ' - ' . number_format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class StaticProperties
* @var array
*/
protected static $_classesToSkip = [
'Mage',
\Magento\Framework\App\ObjectManager::class,
\Magento\TestFramework\Helper\Bootstrap::class,
\Magento\TestFramework\Event\Magento::class,
Expand Down Expand Up @@ -107,14 +106,31 @@ protected static function _isClassInCleanableFolders($classFile)
return false; // File is not in an "include" directory
}

/**
* @var \ReflectionClass[]
*/
static protected $classes = [];

/**
* @param string $class
* @return \ReflectionClass
*/
private static function getReflectionClass($class)
{
if (!isset(self::$classes[$class])) {
self::$classes[$class] = new \ReflectionClass($class);
}
return self::$classes[$class];
}

/**
* Restore static variables (after running controller test case)
* @TODO: refactor all code where objects are stored to static variables to use object manager instead
*/
public static function restoreStaticVariables()
{
foreach (array_keys(self::$backupStaticVariables) as $class) {
$reflectionClass = new \ReflectionClass($class);
$reflectionClass = self::getReflectionClass($class);
$staticProperties = $reflectionClass->getProperties(\ReflectionProperty::IS_STATIC);
foreach ($staticProperties as $staticProperty) {
$staticProperty->setAccessible(true);
Expand All @@ -129,44 +145,48 @@ public static function restoreStaticVariables()
*/
public static function backupStaticVariables()
{
$classFiles = Files::init()->getPhpFiles(
Files::INCLUDE_APP_CODE
| Files::INCLUDE_LIBS
| Files::INCLUDE_TESTS
if (count(self::$backupStaticVariables) > 0) {
return;
}
$classFiles = array_filter(
Files::init()->getPhpFiles(
Files::INCLUDE_APP_CODE
| Files::INCLUDE_LIBS
| Files::INCLUDE_TESTS
),
function ($classFile) {
return StaticProperties::_isClassInCleanableFolders($classFile)
&& strpos(file_get_contents($classFile), ' static ') > 0;
}
);
$namespacePattern = '/namespace [a-zA-Z0-9\\\\]+;/';
$classPattern = '/\nclass [a-zA-Z0-9_]+/';
foreach ($classFiles as $classFile) {
if (self::_isClassInCleanableFolders($classFile)) {
$file = @fopen($classFile, 'r');
$code = fread($file, 4096);
preg_match($namespacePattern, $code, $namespace);
preg_match($classPattern, $code, $class);
if (!isset($namespace[0]) || !isset($class[0])) {
fclose($file);
continue;
}
// trim namespace and class name
$namespace = substr($namespace[0], 10, strlen($namespace[0]) - 11);
$class = substr($class[0], 7, strlen($class[0]) - 7);
$className = $namespace . '\\' . $class;

try {
$reflectionClass = new \ReflectionClass($className);
} catch (\Exception $e) {
fclose($file);
continue;
}
if (self::_isClassCleanable($reflectionClass)) {
$staticProperties = $reflectionClass->getProperties(\ReflectionProperty::IS_STATIC);
foreach ($staticProperties as $staticProperty) {
$staticProperty->setAccessible(true);
$value = $staticProperty->getValue();
self::$backupStaticVariables[$className][$staticProperty->getName()] = $value;
}
$code = file_get_contents($classFile);
preg_match($namespacePattern, $code, $namespace);
preg_match($classPattern, $code, $class);
if (!isset($namespace[0]) || !isset($class[0])) {
continue;
}
// trim namespace and class name
$namespace = substr($namespace[0], 10, strlen($namespace[0]) - 11);
$class = substr($class[0], 7, strlen($class[0]) - 7);
$className = $namespace . '\\' . $class;

try {
$reflectionClass = self::getReflectionClass($className);
} catch (\Exception $e) {
continue;
}
if (self::_isClassCleanable($reflectionClass)) {
$staticProperties = $reflectionClass->getProperties(\ReflectionProperty::IS_STATIC);
foreach ($staticProperties as $staticProperty) {
$staticProperty->setAccessible(true);
$value = $staticProperty->getValue();
self::$backupStaticVariables[$className][$staticProperty->getName()] = $value;
}
fclose($file);
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public function exportImportDataProvider()
*/
protected function assertEqualsSpecificAttributes($expectedProduct, $actualProduct)
{
$expectedAssociatedProducts = $expectedProduct->getTypeInstance()->getUsedProducts($expectedProduct);
$actualAssociatedProducts = $actualProduct->getTypeInstance()->getUsedProducts($actualProduct);
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $prooductType */
$prooductType = $expectedProduct->getTypeInstance();
$expectedAssociatedProducts = $prooductType->getUsedProductCollection($expectedProduct);
$actualAssociatedProducts = iterator_to_array($prooductType->getUsedProductCollection($actualProduct));

$expectedAssociatedProductSkus = [];
$actualAssociatedProductSkus = [];
Expand Down Expand Up @@ -92,4 +94,20 @@ public function importReplaceDataProvider()
}
return $data;
}

/**
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*
* @param array $fixtures
* @param string[] $skus
* @param string[] $skippedAttributes
* @dataProvider importReplaceDataProvider
*/
public function testImportReplace($fixtures, $skus, $skippedAttributes = [])
{
$this->markTestSkipped('MAGETWO-56530');
parent::testImportReplace($fixtures, $skus, $skippedAttributes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function setUp()
*/
public function testSetSaveHandler($deploymentConfigHandler, $iniHandler)
{
$this->markTestSkipped('MAGETWO-56529');
// Set expected session.save_handler config
if ($deploymentConfigHandler) {
if ($deploymentConfigHandler !== 'files') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ protected function tearDown()

/**
* @magentoDataFixture Magento/Newsletter/_files/newsletter_sample.php
* @magentoAppIsolation disabled
*/
public function testSaveActionQueueTemplateAndVerifySuccessMessage()
{
Expand Down

0 comments on commit 71c041a

Please sign in to comment.