Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into pull-request
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Korshenko committed May 6, 2016
2 parents bc77c1f + ffea3cd commit 85c31bf
Show file tree
Hide file tree
Showing 33 changed files with 1,085 additions and 438 deletions.
14 changes: 7 additions & 7 deletions app/code/Magento/Braintree/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</type>

<!-- Logger, initialized with BraintreeConfig -->
<virtualType name="BraintreeLogger" type="Magento\Payment\Model\Method\Logger">
<virtualType name="BraintreeLoggerForTransactionSale" type="Magento\Payment\Model\Method\Logger">
<arguments>
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\Config</argument>
</arguments>
Expand Down Expand Up @@ -164,22 +164,22 @@

<type name="Magento\Braintree\Gateway\Http\Client\TransactionSale">
<arguments>
<argument name="customLogger" xsi:type="object">BraintreeLogger</argument>
<argument name="customLogger" xsi:type="object">BraintreeLoggerForTransactionSale</argument>
</arguments>
</type>
<type name="Magento\Braintree\Gateway\Http\Client\TransactionSubmitForSettlement">
<arguments>
<argument name="customLogger" xsi:type="object">BraintreeLogger</argument>
<argument name="customLogger" xsi:type="object">BraintreeLoggerForTransactionSale</argument>
</arguments>
</type>
<type name="Magento\Braintree\Gateway\Http\Client\TransactionRefund">
<arguments>
<argument name="customLogger" xsi:type="object">BraintreeLogger</argument>
<argument name="customLogger" xsi:type="object">BraintreeLoggerForTransactionSale</argument>
</arguments>
</type>
<type name="Magento\Braintree\Gateway\Http\Client\TransactionVoid">
<arguments>
<argument name="customLogger" xsi:type="object">BraintreeLogger</argument>
<argument name="customLogger" xsi:type="object">BraintreeLoggerForTransactionSale</argument>
</arguments>
</type>

Expand Down Expand Up @@ -375,7 +375,7 @@
</arguments>
</virtualType>

<virtualType name="BraintreeTransactionsCollectionFactory" type="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<virtualType name="BraintreeTransactionsCollectionFactoryForReporting" type="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="braintree_report_data_source" xsi:type="string">Magento\Braintree\Model\Report\TransactionsCollection</item>
Expand All @@ -385,7 +385,7 @@

<virtualType name="BraintreeTransactionsReporting" type="Magento\Framework\View\Element\UiComponent\DataProvider\Reporting">
<arguments>
<argument name="collectionFactory" xsi:type="object">BraintreeTransactionsCollectionFactory</argument>
<argument name="collectionFactory" xsi:type="object">BraintreeTransactionsCollectionFactoryForReporting</argument>
</arguments>
</virtualType>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ protected function setUp()
* Test for afterImportData()
* Covers afterImportData() + protected methods used inside
*
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::afterImportData
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::_populateForUrlGeneration
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::isGlobalScope
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::populateGlobalProduct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@
class ConfigurableTest extends \PHPUnit_Framework_TestCase
{
/**
* @var VariationHandler|MockObject
* @var Magento\ConfigurableProduct\Model\Product\VariationHandler|MockObject
*/
private $variationHandler;

/**
* @var Http|MockObject
* @var Magento\Framework\App\Request\Http|MockObject
*/
private $request;

/**
* @var Factory|MockObject
* @var Magento\ConfigurableProduct\Helper\Product\Options\Factory|MockObject
*/
private $optionFactory;

/**
* @var Product|MockObject
* @var Magento\Catalog\Model\Product|MockObject
*/
private $product;

/**
* @var Helper|MockObject
* @var Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper|MockObject
*/
private $subject;

Expand Down Expand Up @@ -203,9 +203,6 @@ public function testAfterInitializeWithAttributesAndVariations()
$this->plugin->afterInitialize($this->subject, $this->product);
}

/**
* @covers Configurable::afterInitialize
*/
public function testAfterInitializeWithAttributesAndWithoutVariations()
{
$attributes = [
Expand Down Expand Up @@ -268,9 +265,6 @@ public function testAfterInitializeWithAttributesAndWithoutVariations()
$this->plugin->afterInitialize($this->subject, $this->product);
}

/**
* @covers Configurable::afterInitialize
*/
public function testAfterInitializeIfAttributesEmpty()
{
$this->product->expects(static::once())
Expand All @@ -291,9 +285,6 @@ public function testAfterInitializeIfAttributesEmpty()
$this->plugin->afterInitialize($this->subject, $this->product);
}

/**
* @covers Configurable::afterInitialize
*/
public function testAfterInitializeForNotConfigurableProduct()
{
$this->product->expects(static::once())
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Marketplace/Test/Unit/Helper/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function setUp()
}

/**
* @covers \Magento\Marketplace\Helper::loadPartnersFromCache
* @covers \Magento\Marketplace\Helper\Cache::loadPartnersFromCache
*/
public function testLoadPartnersFromCache()
{
Expand All @@ -36,7 +36,7 @@ public function testLoadPartnersFromCache()
}

/**
* @covers \Magento\Marketplace\Helper::savePartnersToCache
* @covers \Magento\Marketplace\Helper\Cache::savePartnersToCache
*/
public function testSavePartnersToCache()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Class Date.
*
* Data keys:
* - pattern (Format a local time/date with delta, e.g. 'm-d-Y -3 days' = current day - 3 days)
* - pattern (Format a local time/date with delta, e.g. 'm/d/Y -3 days' = current day - 3 days)
*/
class Date extends DataSource
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,13 @@ public function testCoversAnnotation()
{
$files = Files::init();
$errors = [];
foreach ($files->getFiles([BP . '/dev/tests/{integration,unit}'], '*') as $file) {
$filesToTest = $files->getPhpFiles(Files::INCLUDE_TESTS);

if (($key = array_search(__FILE__, $filesToTest)) !== false) {
unset($filesToTest[$key]);
}

foreach ($filesToTest as $file) {
$code = file_get_contents($file);
if (preg_match('/@covers(DefaultClass)?\s+([\w\\\\]+)(::([\w\\\\]+))?/', $code, $matches)) {
if ($this->isNonexistentEntityCovered($matches)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/Magento/Framework/App/ObjectManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\ObjectManager\Definition\Compiled\Serialized;
use Magento\Framework\App\ObjectManager\Environment;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Code\GeneratedFiles;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -108,6 +109,10 @@ public function __construct(DirectoryList $directoryList, DriverPool $driverPool
*/
public function create(array $arguments)
{
$writeFactory = new \Magento\Framework\Filesystem\Directory\WriteFactory($this->driverPool);
$generatedFiles = new GeneratedFiles($this->directoryList, $writeFactory);
$generatedFiles->regenerate();

$deploymentConfig = $this->createDeploymentConfig($this->directoryList, $this->configFilePool, $arguments);
$arguments = array_merge($deploymentConfig->get(), $arguments);
$definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory(
Expand Down
74 changes: 74 additions & 0 deletions lib/internal/Magento/Framework/Code/GeneratedFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Code;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Directory\WriteFactory;
use Magento\Framework\Filesystem\Directory\WriteInterface;

/**
* Regenerates generated code and DI configuration
*/
class GeneratedFiles
{
/**
* Separator literal to assemble timer identifier from timer names
*/
const REGENERATE_FLAG = '/var/.regenerate';

/**
* @var DirectoryList
*/
private $directoryList;

/**
* @var WriteInterface
*/
private $write;

/**
* Constructor
*
* @param DirectoryList $directoryList
* @param WriteFactory $writeFactory
*/
public function __construct(DirectoryList $directoryList, WriteFactory $writeFactory)
{
$this->directoryList = $directoryList;
$this->write = $writeFactory->create(BP);
}

/**
* Clean generated code and DI configuration
*
* @return void
*/
public function regenerate()
{
if ($this->write->isExist(self::REGENERATE_FLAG)) {
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));

if ($this->write->isDirectory($generationPath)) {
$this->write->delete($generationPath);
}
if ($this->write->isDirectory($diPath)) {
$this->write->delete($diPath);
}
$this->write->delete(self::REGENERATE_FLAG);
}
}

/**
* Create flag for regeneration of code and di
*
* @return void
*/
public function requestRegeneration()
{
$this->write->touch(self::REGENERATE_FLAG);
}
}
110 changes: 110 additions & 0 deletions lib/internal/Magento/Framework/Code/Test/Unit/GeneratedFilesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\Code\Test\Unit;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Code\GeneratedFiles;

class GeneratedFilesTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Magento\Framework\App\Filesystem\DirectoryList | \PHPUnit_Framework_MockObject_MockObject
*/
private $directoryList;

/**
* @var Magento\Framework\Filesystem\Directory\WriteInterface | \PHPUnit_Framework_MockObject_MockObject
*/
private $writeInterface;

/**
* @var \Magento\Framework\Code\GeneratedFiles
*/
private $model;

protected function setUp()
{
$this->directoryList = $this->getMock('\Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
$writeFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteFactory', [], [], '', false);
$this->writeInterface = $this->getMock(
'\Magento\Framework\Filesystem\Directory\WriteInterface',
[],
[],
'',
false
);
$writeFactory->expects($this->once())->method('create')->willReturn($this->writeInterface);
$this->model = new GeneratedFiles($this->directoryList, $writeFactory);
}

/**
* @param array $getPathMap
* @param array $isDirectoryMap
* @param array $deleteMap
* @dataProvider regenerateDataProvider
*/
public function testRegenerate($getPathMap, $isDirectoryMap, $deleteMap)
{

$this->writeInterface
->expects($this->once())
->method('isExist')
->with(GeneratedFiles::REGENERATE_FLAG)
->willReturn(true);
$this->directoryList->expects($this->exactly(2))->method('getPath')->willReturnMap($getPathMap);
$this->writeInterface->expects($this->exactly(2))->method('getRelativePath')->willReturnMap($getPathMap);
$this->writeInterface->expects($this->exactly(2))->method('isDirectory')->willReturnMap($isDirectoryMap);
$this->writeInterface->expects($this->exactly(1))->method('delete')->willReturnMap($deleteMap);
$this->model->regenerate();
}

/**
* @return array
*/
public function regenerateDataProvider()
{
$pathToGeneration = 'path/to/generation';
$pathToDi = 'path/to/di';

$getPathMap = [[DirectoryList::GENERATION, $pathToGeneration],
[DirectoryList::DI, $pathToDi]];
$deleteMap = [[BP . '/' . $pathToGeneration, true],
[BP . '/' . $pathToDi, true],
[BP . GeneratedFiles::REGENERATE_FLAG, true],
];

return [
'runAll' => [ $getPathMap, [[BP . '/' . $pathToGeneration, true],
[BP . '/' . $pathToDi, true]], $deleteMap ],
'noDIfolder' => [ $getPathMap, [[BP . '/' . $pathToGeneration, true],
[BP . '/' . $pathToDi, false]], $deleteMap],
'noGenerationfolder' => [$getPathMap, [[BP . '/' . $pathToGeneration, false],
[BP . '/' . $pathToDi, true]], $deleteMap],
'nofolders' => [ $getPathMap, [[BP . '/' . $pathToGeneration, false],
[BP . '/' . $pathToDi, false]], $deleteMap],
];
}

public function testRegenerateWithNoFlag()
{
$this->writeInterface
->expects($this->once())
->method('isExist')
->with(GeneratedFiles::REGENERATE_FLAG)
->willReturn(false);
$this->directoryList->expects($this->never())->method('getPath');
$this->writeInterface->expects($this->never())->method('getPath');
$this->writeInterface->expects($this->never())->method('delete');
$this->model->regenerate();
}

public function testRequestRegeneration()
{
$this->writeInterface->expects($this->once())->method("touch");
$this->model->requestRegeneration();
}
}
Loading

0 comments on commit 85c31bf

Please sign in to comment.