Skip to content

Commit 3823b63

Browse files
author
Dale Sikkema
committed
MAGETWO-35991: Profiling option #2 is broken
1 parent a307ea0 commit 3823b63

File tree

4 files changed

+109
-4
lines changed

4 files changed

+109
-4
lines changed

.htaccess

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,4 @@
189189
## http://developer.yahoo.com/performance/rules.html#etags
190190

191191
#FileETag none
192+
SetEnv MAGE_PROFILER 2

lib/internal/Magento/Framework/ObjectManager/Profiler/FactoryDecorator.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
class FactoryDecorator implements \Magento\Framework\ObjectManager\FactoryInterface
1010
{
11+
/**
12+
* Name of the class that generates logging wrappers
13+
*/
14+
const GENERATOR_NAME = 'Magento\Framework\ObjectManager\Profiler\Code\Generator\Logger';
15+
1116
/**
1217
* @var \Magento\Framework\ObjectManager\FactoryInterface
1318
*/
@@ -45,9 +50,12 @@ public function create($requestedType, array $arguments = [])
4550
{
4651
$this->log->startCreating($requestedType);
4752
$result = $this->subject->create($requestedType, $arguments);
48-
$loggerClassName = get_class($result) . "\\Logger";
49-
$wrappedResult = new $loggerClassName($result, $this->log);
50-
$this->log->stopCreating($result);
51-
return $wrappedResult;
53+
if ($requestedType !== self::GENERATOR_NAME) {
54+
$loggerClassName = get_class($result) . "\\Logger";
55+
$wrappedResult = new $loggerClassName($result, $this->log);
56+
$this->log->stopCreating($result);
57+
$result = $wrappedResult;
58+
}
59+
return $result;
5260
}
5361
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\ObjectManager\Test\Unit\Profiler;
8+
9+
class FactoryDecoratorTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* Name of the base class to wrap in logger
13+
*/
14+
const CLASS_NAME = 'Magento\Test\Di\WrappedClass';
15+
16+
/**
17+
* Name of the wrapper class that does logging
18+
*/
19+
const LOGGER_NAME = 'Magento\Test\Di\WrappedClass\Logger';
20+
21+
/**
22+
* Name of the class that generates wrappers - should not be wrapped by logger
23+
*/
24+
const GENERATOR_NAME = 'Magento\Framework\ObjectManager\Profiler\Code\Generator\Logger';
25+
26+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\ObjectManager\FactoryInterface*/
27+
private $objectManagerMock;
28+
29+
/** @var \Magento\Framework\ObjectManager\Profiler\FactoryDecorator */
30+
private $model;
31+
32+
public function setUp()
33+
{
34+
require_once __DIR__ . '/../_files/logger_classes.php';
35+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36+
37+
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\FactoryInterface')
38+
->disableOriginalConstructor()
39+
->getMock();
40+
41+
// Instantiate SUT
42+
$this->model = $objectManager->getObject(
43+
'Magento\Framework\ObjectManager\Profiler\FactoryDecorator',
44+
['subject' => $this->objectManagerMock]
45+
);
46+
}
47+
48+
public function testCreate()
49+
{
50+
$baseObjectName = self::CLASS_NAME;
51+
$baseObject = new $baseObjectName();
52+
53+
$arguments = [1, 2, 3];
54+
55+
$this->objectManagerMock->expects($this->once())
56+
->method('create')
57+
->with(self::CLASS_NAME, $arguments)
58+
->willReturn($baseObject);
59+
60+
$this->assertInstanceOf(self::LOGGER_NAME, $this->model->create(self::CLASS_NAME, $arguments));
61+
}
62+
63+
public function testCreateNeglectGenerator()
64+
{
65+
$arguments = [1, 2, 3];
66+
$loggerMock = $this->getMockBuilder(self::GENERATOR_NAME)->disableOriginalConstructor()->getMock();
67+
68+
$this->objectManagerMock->expects($this->once())
69+
->method('create')
70+
->with(self::GENERATOR_NAME, $arguments)
71+
->willReturn($loggerMock);
72+
73+
$this->assertSame($loggerMock, $this->model->create(self::GENERATOR_NAME, $arguments));
74+
}
75+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Test\Di {
8+
/**
9+
* Test classes used for \Magento\Framework\ObjectManager\Test\Unit\Profiler\FactoryDecoratorTest
10+
*/
11+
class WrappedClass
12+
{
13+
14+
}
15+
}
16+
namespace Magento\Test\Di\WrappedClass {
17+
class Logger
18+
{
19+
20+
}
21+
}

0 commit comments

Comments
 (0)