Skip to content

Commit

Permalink
MAGETWO-42265: Fix code that depends on module location
Browse files Browse the repository at this point in the history
- fixing integration tests
- fixing integrity test
- fixing code style
  • Loading branch information
eddielau committed Sep 14, 2015
1 parent b08b20a commit 39abd59
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 60 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/Paypal/Block/Payflow/Advanced/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ class Iframe extends \Magento\Paypal\Block\Payflow\Link\Iframe
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Paypal\Helper\Hss $hssHelper
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
* @param \Magento\Framework\Module\Dir\Reader $reader
* @param \Magento\Payment\Helper\Data $paymentData
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Paypal\Helper\Hss $hssHelper,
\Magento\Payment\Helper\Data $paymentData,
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
\Magento\Framework\Module\Dir\Reader $reader,
\Magento\Payment\Helper\Data $paymentData,
array $data = []
) {
parent::__construct(
$context,
$orderFactory,
$checkoutSession,
$hssHelper,
$paymentData,
$readFactory,
$reader,
$paymentData,
$data
);
$this->_isScopePrivate = false;
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Paypal/Block/Payflow/Link/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ class Iframe extends \Magento\Paypal\Block\Iframe
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Paypal\Helper\Hss $hssHelper
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
* @param \Magento\Framework\Module\Dir\Reader $reader
* @param \Magento\Payment\Helper\Data $paymentData
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Paypal\Helper\Hss $hssHelper,
\Magento\Payment\Helper\Data $paymentData,
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
\Magento\Framework\Module\Dir\Reader $reader,
\Magento\Payment\Helper\Data $paymentData,
array $data = []
) {
$this->_paymentData = $paymentData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public function testCheckIsScopePrivate()
$this->orderFactoryMock,
$this->checkoutSessionMock,
$this->hssHelperMock,
$this->paymentDataMock,
$this->readFactory,
$this->reader
$this->reader,
$this->paymentDataMock
);

$this->assertFalse($block->isScopePrivate());
Expand Down Expand Up @@ -120,9 +120,9 @@ public function testGetTransactionUrlLive()
$this->orderFactoryMock,
$this->checkoutSessionMock,
$this->hssHelperMock,
$this->paymentDataMock,
$this->readFactory,
$this->reader
$this->reader,
$this->paymentDataMock
);
$this->assertEquals($expected, $block->getTransactionUrl());
}
Expand All @@ -149,9 +149,9 @@ public function testGetTransactionUrlTest()
$this->orderFactoryMock,
$this->checkoutSessionMock,
$this->hssHelperMock,
$this->paymentDataMock,
$this->readFactory,
$this->reader
$this->reader,
$this->paymentDataMock
);
$this->assertEquals($expected, $block->getTransactionUrl());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@ class FileResolverStub implements \Magento\Framework\Config\FileResolverInterfac
*/
public function get($filename, $scope)
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$readDirectory = $objectManager->create(
'Magento\Framework\Filesystem\Directory\Read',
[
'driver' => $objectManager->create('Magento\Framework\Filesystem\Driver\File'),
'path' => realpath(__DIR__ . '/../../_files/etc'),
]
);
$paths = ['search_request_1.xml', 'search_request_2.xml'];
return new \Magento\Framework\Config\FileIterator($readDirectory, $paths);
$path = realpath(__DIR__ . '/../../_files/etc');
$paths = [$path . '/search_request_1.xml', $path . '/search_request_2.xml'];
return new \Magento\Framework\Config\FileIterator(new \Magento\Framework\Filesystem\Driver\File, $paths);
}
}
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/App/Utility/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ public function classFileExists($class, &$path = '')
$fullPath = $dir . $path;
$trimmedFullPath = $dir . explode('/', $path, 3)[2];
if ($this->classFileExistsCheckContent($fullPath, $namespace, $className)
|| $this->classFileExistsCheckContent($trimmedFullPath, $namespace, $class)
|| $this->classFileExistsCheckContent($trimmedFullPath, $namespace, $className)
) {
return true;
}
Expand All @@ -1159,7 +1159,7 @@ public function classFileExists($class, &$path = '')
*
* @param string $fullPath
* @param string $namespace
* @param $className
* @param string $className
* @return bool
*/
private function classFileExistsCheckContent($fullPath, $namespace, $className)
Expand Down
16 changes: 5 additions & 11 deletions lib/internal/Magento/Framework/Autoload/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\Framework\Autoload;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Autoload\AutoloaderInterface;
use Magento\Framework\Filesystem\FileResolver;

/**
Expand All @@ -18,22 +18,16 @@ class Populator
/**
* @param AutoloaderInterface $autoloader
* @param DirectoryList $dirList
* @param ComponentRegistrar $componentRegistrar
* @return void
*/
public static function populateMappings(
AutoloaderInterface $autoloader,
DirectoryList $dirList,
ComponentRegistrar $componentRegistrar
) {
public static function populateMappings(AutoloaderInterface $autoloader, DirectoryList $dirList)
{
$modulesDir = $dirList->getPath(DirectoryList::ROOT) . '/app/code';
$generationDir = $dirList->getPath(DirectoryList::GENERATION);
$frameworkDir = $dirList->getPath(DirectoryList::LIB_INTERNAL);

foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $moduleDir) {
$autoloader->addPsr4(str_replace('_', '\\', $moduleName) . '\\', [$moduleDir . '/'], true);
}
$autoloader->addPsr4('Magento\\', [$modulesDir . '/Magento/', $generationDir . '/Magento/'], true);

$autoloader->addPsr4('Magento\\', [$generationDir . '/Magento/'], true);
$autoloader->addPsr0('Apache_', $frameworkDir, true);
$autoloader->addPsr0('Cm_', $frameworkDir, true);
$autoloader->addPsr0('Credis_', $frameworkDir, true);
Expand Down
39 changes: 13 additions & 26 deletions lib/internal/Magento/Framework/Autoload/Test/Unit/PopulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ class PopulatorTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Framework\App\Filesystem\DirectoryList | \PHPUnit_Framework_MockObject_MockObject */
protected $mockDirectoryList;

/**
* @var \Magento\Framework\Component\ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject
*/
protected $componentRegistrar;

public function setUp()
{
$this->mockDirectoryList = $this->getMockBuilder('\Magento\Framework\App\Filesystem\DirectoryList')
Expand All @@ -28,8 +23,6 @@ public function setUp()
$this->mockDirectoryList->expects($this->any())
->method('getPath')
->willReturnArgument(0);

$this->componentRegistrar = $this->getMock('Magento\Framework\Component\ComponentRegistrar', [], [], '', false);
}

public function testPopulateMappings()
Expand All @@ -38,38 +31,32 @@ public function testPopulateMappings()
->disableOriginalConstructor()
->getMock();

$mockAutoloader->expects($this->at(0))->method('addPsr4')->with('Magento\\A\\', ['/path/to/a/'], true);
$mockAutoloader->expects($this->at(1))->method('addPsr4')->with('Magento\\B\\', ['/path/to/b/'], true);
$mockAutoloader->expects($this->at(2))->method('addPsr4')->with('Magento\\C\\', ['/path/to/c/'], true);
$mockAutoloader->expects($this->at(3))
$mockAutoloader->expects($this->at(0))
->method('addPsr4')
->with('Magento\\', [DirectoryList::GENERATION . '/Magento/'], true);
$mockAutoloader->expects($this->at(4))
->with(
'Magento\\',
[DirectoryList::ROOT . '/app/code/Magento/', DirectoryList::GENERATION . '/Magento/'],
true
);
$mockAutoloader->expects($this->at(1))
->method('addPsr0')
->with('Apache_', DirectoryList::LIB_INTERNAL, true);
$mockAutoloader->expects($this->at(5))
$mockAutoloader->expects($this->at(2))
->method('addPsr0')
->with('Cm_', DirectoryList::LIB_INTERNAL, true);
$mockAutoloader->expects($this->at(6))
$mockAutoloader->expects($this->at(3))
->method('addPsr0')
->with('Credis_', DirectoryList::LIB_INTERNAL, true);
$mockAutoloader->expects($this->at(7))
$mockAutoloader->expects($this->at(4))
->method('addPsr0')
->with('Less_', DirectoryList::LIB_INTERNAL, true);
$mockAutoloader->expects($this->at(8))
$mockAutoloader->expects($this->at(5))
->method('addPsr0')
->with('Symfony\\', DirectoryList::LIB_INTERNAL, true);
$mockAutoloader->expects($this->at(9))
$mockAutoloader->expects($this->at(6))
->method('addPsr0')
->with('', [DirectoryList::GENERATION]);

$moduleDirs = [
'Magento_A' => '/path/to/a',
'Magento_B' => '/path/to/b',
'Magento_C' => '/path/to/c',
];
$this->componentRegistrar->expects($this->once())->method('getPaths')->willReturn($moduleDirs);

Populator::populateMappings($mockAutoloader, $this->mockDirectoryList, $this->componentRegistrar);
Populator::populateMappings($mockAutoloader, $this->mockDirectoryList);
}
}

0 comments on commit 39abd59

Please sign in to comment.