Skip to content

Commit

Permalink
Merge pull request #533 from magento-ogre/PR_Branch
Browse files Browse the repository at this point in the history
[Ogres] Bug Fixes
  • Loading branch information
sdwright committed Apr 12, 2016
2 parents f53c16c + 7289b10 commit 3ccb057
Show file tree
Hide file tree
Showing 30 changed files with 541 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,30 @@ public function testIsPackageInComposerJson()
$packageName = 'magento/wrong-module-name';
$this->assertFalse($composerInfo->isPackageInComposerJson($packageName));
}

/**
* @param $composerDir string Directory under _files that contains composer files
*
* @dataProvider getRequiredPhpVersionDataProvider
*/
public function testGetRootRepositories($composerDir)
{
$this->setupDirectory($composerDir);

/** @var \Magento\Framework\Composer\ComposerInformation $composerInfo */
$composerInfo = $this->objectManager->create(
'Magento\Framework\Composer\ComposerInformation',
[
'applicationFactory' => new MagentoComposerApplicationFactory(
$this->composerJsonFinder,
$this->directoryList
)
]
);
if ($composerDir === 'testFromCreateProject') {
$this->assertEquals(['https://repo.magento.com/'], $composerInfo->getRootRepositories());
} else {
$this->assertEquals([], $composerInfo->getRootRepositories());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
"require": {
"magento/product-community-edition": "0.74.0-beta9"
},
"repositories": [
{
"type": "composer",
"url": "https://repo.magento.com/"
}
],
"require-dev": {
"phpunit/phpunit": "4.1.0",
"squizlabs/php_codesniffer": "1.5.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\Composer\ComposerJsonFinder;
use Magento\Framework\Composer\MagentoComposerApplicationFactory;
use Magento\Setup\Model\UpdatePackagesCache;

/**
* Tests Magento\Framework\ComposerInformation
Expand Down Expand Up @@ -81,12 +80,6 @@ public function testGetPackagesForUpdate()

$this->setupDirectory('testSkeleton');

$objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
$objectManagerProvider
->expects($this->any())
->method('get')
->willReturn($this->objectManager);

/** @var UpdatePackagesCache $updatePackagesCache|\PHPUnit_Framework_MockObject_MockObject */
$updatePackagesCache = $this->getMock('Magento\Setup\Model\UpdatePackagesCache', [], [], '', false);

Expand Down
113 changes: 0 additions & 113 deletions dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,117 +247,4 @@ public function testCopyPaste()
"PHP Copy/Paste Detector has found error(s):" . PHP_EOL . $output
);
}

public function testDeadCode()
{
if (!class_exists('SebastianBergmann\PHPDCD\Analyser')) {
$this->markTestSkipped('PHP Dead Code Detector is not available.');
}
$analyser = new \SebastianBergmann\PHPDCD\Analyser();
$declared = [];
$called = [];
$collectedFiles = Files::init()->getPhpFiles(
Files::INCLUDE_APP_CODE
| Files::INCLUDE_PUB_CODE
| Files::INCLUDE_LIBS
| Files::INCLUDE_TEMPLATES
| Files::INCLUDE_TESTS
| Files::AS_DATA_SET
| Files::INCLUDE_NON_CLASSES
);
foreach ($collectedFiles as $file) {
$file = array_pop($file);
$analyser->analyseFile($file);
foreach ($analyser->getFunctionDeclarations() as $function => $declaration) {
$declaration = $declaration; //avoid "unused local variable" error and non-effective array_keys call
if (strpos($function, '::') === false) {
$method = $function;
} else {
list($class, $method) = explode('::', $function);
}
$declared[$method] = $function;
}
foreach ($analyser->getFunctionCalls() as $function => $usages) {
$usages = $usages; //avoid "unused local variable" error and non-effective array_keys call
if (strpos($function, '::') === false) {
$method = $function;
} else {
list($class, $method) = explode('::', $function);
}
$called[$method] = 1;
}
}

foreach ($called as $method => $value) {
$value = $value; //avoid "unused local variable" error and non-effective array_keys call
unset($declared[$method]);
}
$declared = $this->filterUsedObserverMethods($declared);
$declared = $this->filterUsedPersistentObserverMethods($declared);
$declared = $this->filterUsedCrontabObserverMethods($declared);
if ($declared) {
$this->fail('Dead code detected:' . PHP_EOL . implode(PHP_EOL, $declared));
}
}

/**
* @param string[] $methods
* @return string[]
* @throws \Exception
*/
private function filterUsedObserverMethods($methods)
{
foreach (Files::init()->getConfigFiles('{*/events.xml,events.xml}') as $file) {
$file = array_pop($file);

$doc = new \DOMDocument();
$doc->load($file);
foreach ($doc->getElementsByTagName('observer') as $observer) {
/** @var \DOMElement $observer */
$method = $observer->getAttribute('method');
unset($methods[$method]);
}
}
return $methods;
}

/**
* @param string[] $methods
* @return string[]
* @throws \Exception
*/
private function filterUsedPersistentObserverMethods($methods)
{
foreach (Files::init()->getConfigFiles('{*/persistent.xml,persistent.xml}') as $file) {
$file = array_pop($file);

$doc = new \DOMDocument();
$doc->load($file);
foreach ($doc->getElementsByTagName('method') as $method) {
/** @var \DOMElement $method */
unset($methods[$method->textContent]);
}
}
return $methods;
}

/**
* @param string[] $methods
* @return string[]
* @throws \Exception
*/
private function filterUsedCrontabObserverMethods($methods)
{
foreach (Files::init()->getConfigFiles('{*/crontab.xml,crontab.xml}') as $file) {
$file = array_pop($file);

$doc = new \DOMDocument();
$doc->load($file);
foreach ($doc->getElementsByTagName('job') as $job) {
/** @var \DOMElement $job */
unset($methods[$job->getAttribute('method')]);
}
}
return $methods;
}
}
23 changes: 23 additions & 0 deletions lib/internal/Magento/Framework/Composer/ComposerInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class ComposerInformation
*/
const COMPONENT_PACKAGE_TYPE = 'magento2-component';

/**
* Default composer repository key
*/
const COMPOSER_DEFAULT_REPO_KEY = 'packagist';

/**#@+
* Composer command
*/
Expand Down Expand Up @@ -286,4 +291,22 @@ public function getPackageRequirements($name, $version)
$package = $this->composer->getRepositoryManager()->findPackage($name, $version);
return $package->getRequires();
}

/**
* Returns all repository URLs, except local and packagists.
*
* @return string[]
*/
public function getRootRepositories()
{
$repositoryUrls = [];

foreach ($this->composer->getConfig()->getRepositories() as $key => $repository) {
if ($key !== self::COMPOSER_DEFAULT_REPO_KEY) {
$repositoryUrls[] = $repository['url'];
}
}

return $repositoryUrls;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ObjectManager implements \Magento\Framework\ObjectManagerInterface
protected $_sharedInstances = [];

/**
* @var Config\Config
* @var ConfigInterface
*/
protected $_config;

Expand Down
42 changes: 27 additions & 15 deletions setup/src/Magento/Setup/Controller/BackupActionItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Magento\Framework\Backup\Factory;
use Magento\Framework\Backup\Filesystem;
use Magento\Framework\Setup\BackupRollback;
use Magento\Setup\Model\ObjectManagerProvider;
use Magento\Setup\Model\WebLogger;
use Zend\Json\Json;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
Expand All @@ -21,47 +19,61 @@ class BackupActionItems extends AbstractActionController
/**
* Handler for BackupRollback
*
* @var BackupRollback
* @var \Magento\Framework\Setup\BackupRollback
*/
private $backupHandler;

/**
* Filesystem
*
* @var Filesystem
* @var \Magento\Framework\Backup\Filesystem
*/
private $fileSystem;

/**
* Filesystem Directory List
*
* @var DirectoryList
* @var \Magento\Framework\App\Filesystem\DirectoryList
*/
private $directoryList;

/**
* Constructor
*
* @param ObjectManagerProvider $objectManagerProvider
* @param WebLogger $logger
* @param DirectoryList $directoryList
* @param Filesystem $fileSystem
* @param \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider
* @param \Magento\Setup\Model\WebLogger $logger
* @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
* @param \Magento\Framework\Backup\Filesystem $fileSystem
*/
public function __construct(
ObjectManagerProvider $objectManagerProvider,
WebLogger $logger,
DirectoryList $directoryList,
Filesystem $fileSystem
\Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider,
\Magento\Setup\Model\WebLogger $logger,
\Magento\Framework\App\Filesystem\DirectoryList $directoryList,
\Magento\Framework\Backup\Filesystem $fileSystem
) {
$objectManager = $objectManagerProvider->get();
$this->backupHandler = $objectManager->create('Magento\Framework\Setup\BackupRollback', ['log' => $logger]);
$this->directoryList = $directoryList;
$this->fileSystem = $fileSystem;
}

/**
* No index action, return 404 error page
*
* @return \Zend\View\Model\ViewModel
*/
public function indexAction()
{
$view = new \Zend\View\Model\ViewModel;
$view->setTemplate('/error/404.phtml');
$this->getResponse()->setStatusCode(\Zend\Http\Response::STATUS_CODE_404);
return $view;
}

/**
* Checks disk space availability
*
* @return JsonModel
* @return \Zend\View\Model\JsonModel
*/
public function checkAction()
{
Expand Down Expand Up @@ -99,7 +111,7 @@ public function checkAction()
/**
* Takes backup for code, media or DB
*
* @return JsonModel
* @return \Zend\View\Model\JsonModel
*/
public function createAction()
{
Expand Down
10 changes: 7 additions & 3 deletions setup/src/Magento/Setup/Controller/ComponentGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Setup\Controller;

use Magento\Setup\Model\DateTime\TimezoneProvider;

/**
* Controller for component grid tasks
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -54,14 +56,16 @@ class ComponentGrid extends \Zend\Mvc\Controller\AbstractActionController
/**
* @param \Magento\Framework\Composer\ComposerInformation $composerInformation
* @param \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider
* @param \Magento\Setup\Model\MarketplaceManager $marketplaceManager
* @param \Magento\Setup\Model\UpdatePackagesCache $updatePackagesCache
* @param \Magento\Setup\Model\MarketplaceManager $marketplaceManager
* @param TimezoneProvider $tzProvider
*/
public function __construct(
\Magento\Framework\Composer\ComposerInformation $composerInformation,
\Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider,
\Magento\Setup\Model\UpdatePackagesCache $updatePackagesCache,
\Magento\Setup\Model\MarketplaceManager $marketplaceManager
\Magento\Setup\Model\MarketplaceManager $marketplaceManager,
TimezoneProvider $tzProvider
) {
$this->composerInformation = $composerInformation;
$objectManager = $objectManagerProvider->get();
Expand All @@ -70,7 +74,7 @@ public function __construct(
$this->packageInfo = $objectManager->get('Magento\Framework\Module\PackageInfoFactory')->create();
$this->marketplaceManager = $marketplaceManager;
$this->updatePackagesCache = $updatePackagesCache;
$this->timezone = $objectManager->get('Magento\Framework\Stdlib\DateTime\TimezoneInterface');
$this->timezone = $tzProvider->get();
}

/**
Expand Down
Loading

0 comments on commit 3ccb057

Please sign in to comment.