From da7b59804b9f373c09eedc5ac8a299a116914333 Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Mon, 17 Apr 2017 22:52:57 +0200 Subject: [PATCH 1/6] Replace Zend_Log with Psr\Log\LoggerInterface --- lib/internal/Magento/Framework/Shell.php | 8 ++++---- lib/internal/Magento/Framework/Test/Unit/ShellTest.php | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/internal/Magento/Framework/Shell.php b/lib/internal/Magento/Framework/Shell.php index 450916f18d7e5..8940903da81ee 100644 --- a/lib/internal/Magento/Framework/Shell.php +++ b/lib/internal/Magento/Framework/Shell.php @@ -15,7 +15,7 @@ class Shell implements ShellInterface /** * Logger instance * - * @var \Zend_Log + * @var \Psr\Log\LoggerInterface */ protected $logger; @@ -26,11 +26,11 @@ class Shell implements ShellInterface /** * @param CommandRendererInterface $commandRenderer - * @param \Zend_Log $logger Logger instance to be used to log commands and their output + * @param \Psr\Log\LoggerInterface $logger Logger instance to be used to log commands and their output */ public function __construct( CommandRendererInterface $commandRenderer, - \Zend_Log $logger = null + \Psr\Log\LoggerInterface $logger = null ) { $this->logger = $logger; $this->commandRenderer = $commandRenderer; @@ -76,7 +76,7 @@ public function execute($command, array $arguments = []) protected function log($message) { if ($this->logger) { - $this->logger->log($message, \Zend_Log::INFO); + $this->logger->info($message); } } } diff --git a/lib/internal/Magento/Framework/Test/Unit/ShellTest.php b/lib/internal/Magento/Framework/Test/Unit/ShellTest.php index 6736250a4cbc7..015557f9d1838 100644 --- a/lib/internal/Magento/Framework/Test/Unit/ShellTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/ShellTest.php @@ -16,14 +16,13 @@ class ShellTest extends \PHPUnit_Framework_TestCase protected $commandRenderer; /** - * @var \Zend_Log|\PHPUnit_Framework_MockObject_MockObject + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $logger; protected function setUp() { - $this->logger = $this->getMockBuilder(\Zend_Log::class) - ->setMethods(['log']) + $this->logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->commandRenderer = new \Magento\Framework\Shell\CommandRenderer(); @@ -72,8 +71,8 @@ public function testExecuteLog($command, $commandArgs, $expectedResult, $expecte foreach ($expectedLogRecords as $logRecordIndex => $expectedLogMessage) { $expectedLogMessage = str_replace('`', $quoteChar, $expectedLogMessage); $this->logger->expects($this->at($logRecordIndex)) - ->method('log') - ->with($expectedLogMessage, \Zend_Log::INFO); + ->method('info') + ->with($expectedLogMessage); } $this->_testExecuteCommand( new \Magento\Framework\Shell($this->commandRenderer, $this->logger), From 255da6233d07965d3a18871d17b1efb4bd13a59b Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Fri, 21 Apr 2017 19:36:10 +0200 Subject: [PATCH 2/6] Replace Zend_Log with Monolog\Logger in dev/tests bootstrap files --- .../api-functional/framework/bootstrap.php | 126 ++++++++++-------- dev/tests/integration/framework/bootstrap.php | 9 +- dev/tests/integration/phpunit.xml.dist | 2 + 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/dev/tests/api-functional/framework/bootstrap.php b/dev/tests/api-functional/framework/bootstrap.php index 11996dbd7a21c..b1574c01b564d 100644 --- a/dev/tests/api-functional/framework/bootstrap.php +++ b/dev/tests/api-functional/framework/bootstrap.php @@ -14,70 +14,84 @@ $integrationTestsDir = realpath("{$testsBaseDir}/../integration"); $fixtureBaseDir = $integrationTestsDir . '/testsuite'; -setCustomErrorHandler(); +try { + setCustomErrorHandler(); -$logWriter = new \Zend_Log_Writer_Stream('php://output'); -$logWriter->setFormatter(new \Zend_Log_Formatter_Simple('%message%' . PHP_EOL)); -$logger = new \Zend_Log($logWriter); + /* Bootstrap the application */ + $settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants()); -$testFrameworkDir = __DIR__; -require_once __DIR__ . '/../../integration/framework/deployTestModules.php'; + if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { + $filesystem = new \Magento\Framework\Filesystem\Driver\File(); + $loggerHandlers = [ + 'system' => new \Magento\Framework\Logger\Handler\System($filesystem), + 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem) + ]; + $shell = new \Magento\Framework\Shell( + new \Magento\Framework\Shell\CommandRenderer(), + new \Monolog\Logger('main', $loggerHandlers) + ); + } else { + $shell = new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer()); + } -/* Bootstrap the application */ -$settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants()); -$shell = new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer(), $logger); + $testFrameworkDir = __DIR__; + require_once __DIR__ . '/../../integration/framework/deployTestModules.php'; -$installConfigFile = $settings->getAsConfigFile('TESTS_INSTALL_CONFIG_FILE'); -if (!file_exists($installConfigFile)) { - $installConfigFile = $installConfigFile . '.dist'; -} -$globalConfigFile = $settings->getAsConfigFile('TESTS_GLOBAL_CONFIG_FILE'); -if (!file_exists($installConfigFile)) { - $installConfigFile = $installConfigFile . '.dist'; -} -$dirList = new \Magento\Framework\App\Filesystem\DirectoryList(BP); -$application = new \Magento\TestFramework\WebApiApplication( - $shell, - $dirList->getPath(DirectoryList::VAR_DIR), - $installConfigFile, - $globalConfigFile, - BP . '/app/etc/', - $settings->get('TESTS_MAGENTO_MODE'), - AutoloaderRegistry::getAutoloader() -); + $installConfigFile = $settings->getAsConfigFile('TESTS_INSTALL_CONFIG_FILE'); + if ( ! file_exists($installConfigFile)) { + $installConfigFile = $installConfigFile . '.dist'; + } + $globalConfigFile = $settings->getAsConfigFile('TESTS_GLOBAL_CONFIG_FILE'); + if ( ! file_exists($installConfigFile)) { + $installConfigFile = $installConfigFile . '.dist'; + } + $dirList = new \Magento\Framework\App\Filesystem\DirectoryList(BP); + $application = new \Magento\TestFramework\WebApiApplication( + $shell, + $dirList->getPath(DirectoryList::VAR_DIR), + $installConfigFile, + $globalConfigFile, + BP . '/app/etc/', + $settings->get('TESTS_MAGENTO_MODE'), + AutoloaderRegistry::getAutoloader() + ); -if (defined('TESTS_MAGENTO_INSTALLATION') && TESTS_MAGENTO_INSTALLATION === 'enabled') { - if (defined('TESTS_CLEANUP') && TESTS_CLEANUP === 'enabled') { - $application->cleanup(); + if (defined('TESTS_MAGENTO_INSTALLATION') && TESTS_MAGENTO_INSTALLATION === 'enabled') { + if (defined('TESTS_CLEANUP') && TESTS_CLEANUP === 'enabled') { + $application->cleanup(); + } + $application->install(); } - $application->install(); -} -$bootstrap = new \Magento\TestFramework\Bootstrap( - $settings, - new \Magento\TestFramework\Bootstrap\Environment(), - new \Magento\TestFramework\Bootstrap\WebapiDocBlock("{$integrationTestsDir}/testsuite"), - new \Magento\TestFramework\Bootstrap\Profiler(new \Magento\Framework\Profiler\Driver\Standard()), - $shell, - $application, - new \Magento\TestFramework\Bootstrap\MemoryFactory($shell) -); -$bootstrap->runBootstrap(); -$application->initialize(); + $bootstrap = new \Magento\TestFramework\Bootstrap( + $settings, + new \Magento\TestFramework\Bootstrap\Environment(), + new \Magento\TestFramework\Bootstrap\WebapiDocBlock("{$integrationTestsDir}/testsuite"), + new \Magento\TestFramework\Bootstrap\Profiler(new \Magento\Framework\Profiler\Driver\Standard()), + $shell, + $application, + new \Magento\TestFramework\Bootstrap\MemoryFactory($shell) + ); + $bootstrap->runBootstrap(); + $application->initialize(); -\Magento\TestFramework\Helper\Bootstrap::setInstance(new \Magento\TestFramework\Helper\Bootstrap($bootstrap)); -$dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\Framework\Component\DirSearch::class); -$themePackageList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class); -\Magento\Framework\App\Utility\Files::setInstance( - new \Magento\Framework\App\Utility\Files( - new \Magento\Framework\Component\ComponentRegistrar(), - $dirSearch, - $themePackageList - ) -); -unset($bootstrap, $application, $settings, $shell); + \Magento\TestFramework\Helper\Bootstrap::setInstance(new \Magento\TestFramework\Helper\Bootstrap($bootstrap)); + $dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create(\Magento\Framework\Component\DirSearch::class); + $themePackageList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class); + \Magento\Framework\App\Utility\Files::setInstance( + new \Magento\Framework\App\Utility\Files( + new \Magento\Framework\Component\ComponentRegistrar(), + $dirSearch, + $themePackageList + ) + ); + unset($bootstrap, $application, $settings, $shell); +} catch (\Exception $e) { + echo $e . PHP_EOL; + exit(1); +} /** * Set custom error handler diff --git a/dev/tests/integration/framework/bootstrap.php b/dev/tests/integration/framework/bootstrap.php index 986b107086f94..2043329fce40b 100644 --- a/dev/tests/integration/framework/bootstrap.php +++ b/dev/tests/integration/framework/bootstrap.php @@ -25,11 +25,14 @@ $settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants()); if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { - $logWriter = new \Zend_Log_Writer_Stream('php://output'); - $logWriter->setFormatter(new \Zend_Log_Formatter_Simple('%message%' . PHP_EOL)); + $filesystem = new \Magento\Framework\Filesystem\Driver\File(); + $loggerHandlers = [ + 'system' => new \Magento\Framework\Logger\Handler\System($filesystem), + 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem) + ]; $shell = new \Magento\Framework\Shell( new \Magento\Framework\Shell\CommandRenderer(), - new \Zend_Log($logWriter) + new \Monolog\Logger('main', $loggerHandlers) ); } else { $shell = new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer()); diff --git a/dev/tests/integration/phpunit.xml.dist b/dev/tests/integration/phpunit.xml.dist index 7820eb746da5d..bf79f77975c43 100644 --- a/dev/tests/integration/phpunit.xml.dist +++ b/dev/tests/integration/phpunit.xml.dist @@ -61,6 +61,8 @@ + + From ee40290ce862b02052b98b51295d712e4212f595 Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Fri, 21 Apr 2017 19:47:28 +0200 Subject: [PATCH 3/6] Add missing exception handler to dev/tests bootstrap files --- dev/tests/api-functional/framework/bootstrap.php | 5 +++-- dev/tests/integration/framework/bootstrap.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dev/tests/api-functional/framework/bootstrap.php b/dev/tests/api-functional/framework/bootstrap.php index b1574c01b564d..63a6da9bc2e55 100644 --- a/dev/tests/api-functional/framework/bootstrap.php +++ b/dev/tests/api-functional/framework/bootstrap.php @@ -22,9 +22,10 @@ if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { $filesystem = new \Magento\Framework\Filesystem\Driver\File(); + $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception(); $loggerHandlers = [ - 'system' => new \Magento\Framework\Logger\Handler\System($filesystem), - 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem) + 'system' => new \Magento\Framework\Logger\Handler\System($filesystem, $exceptionHandler), + 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem, $exceptionHandler) ]; $shell = new \Magento\Framework\Shell( new \Magento\Framework\Shell\CommandRenderer(), diff --git a/dev/tests/integration/framework/bootstrap.php b/dev/tests/integration/framework/bootstrap.php index 2043329fce40b..8b9e456854804 100644 --- a/dev/tests/integration/framework/bootstrap.php +++ b/dev/tests/integration/framework/bootstrap.php @@ -26,9 +26,10 @@ if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { $filesystem = new \Magento\Framework\Filesystem\Driver\File(); + $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception(); $loggerHandlers = [ - 'system' => new \Magento\Framework\Logger\Handler\System($filesystem), - 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem) + 'system' => new \Magento\Framework\Logger\Handler\System($filesystem, $exceptionHandler), + 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem, $exceptionHandler) ]; $shell = new \Magento\Framework\Shell( new \Magento\Framework\Shell\CommandRenderer(), From a79e81862c9e57ff9ea74ee4c0d857fecb502c2a Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Fri, 21 Apr 2017 19:52:36 +0200 Subject: [PATCH 4/6] Fix wrong initialization of debug logger in dev/tests bootstrap files --- dev/tests/api-functional/framework/bootstrap.php | 2 +- dev/tests/integration/framework/bootstrap.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/framework/bootstrap.php b/dev/tests/api-functional/framework/bootstrap.php index 63a6da9bc2e55..ecf2efd2e84eb 100644 --- a/dev/tests/api-functional/framework/bootstrap.php +++ b/dev/tests/api-functional/framework/bootstrap.php @@ -25,7 +25,7 @@ $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception(); $loggerHandlers = [ 'system' => new \Magento\Framework\Logger\Handler\System($filesystem, $exceptionHandler), - 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem, $exceptionHandler) + 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem) ]; $shell = new \Magento\Framework\Shell( new \Magento\Framework\Shell\CommandRenderer(), diff --git a/dev/tests/integration/framework/bootstrap.php b/dev/tests/integration/framework/bootstrap.php index 8b9e456854804..20e43bd9a2c6a 100644 --- a/dev/tests/integration/framework/bootstrap.php +++ b/dev/tests/integration/framework/bootstrap.php @@ -29,7 +29,7 @@ $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception(); $loggerHandlers = [ 'system' => new \Magento\Framework\Logger\Handler\System($filesystem, $exceptionHandler), - 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem, $exceptionHandler) + 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem) ]; $shell = new \Magento\Framework\Shell( new \Magento\Framework\Shell\CommandRenderer(), From 7e725ec27a819a1ad70b221fbc02ab03e9c29bc0 Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Fri, 21 Apr 2017 19:59:49 +0200 Subject: [PATCH 5/6] Fix wrong initialization of exception logger in dev/tests bootstrap files --- dev/tests/api-functional/framework/bootstrap.php | 2 +- dev/tests/integration/framework/bootstrap.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/framework/bootstrap.php b/dev/tests/api-functional/framework/bootstrap.php index ecf2efd2e84eb..56c0b6cf19b7c 100644 --- a/dev/tests/api-functional/framework/bootstrap.php +++ b/dev/tests/api-functional/framework/bootstrap.php @@ -22,7 +22,7 @@ if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { $filesystem = new \Magento\Framework\Filesystem\Driver\File(); - $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception(); + $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception($filesystem); $loggerHandlers = [ 'system' => new \Magento\Framework\Logger\Handler\System($filesystem, $exceptionHandler), 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem) diff --git a/dev/tests/integration/framework/bootstrap.php b/dev/tests/integration/framework/bootstrap.php index 20e43bd9a2c6a..f3d0eae79eb2c 100644 --- a/dev/tests/integration/framework/bootstrap.php +++ b/dev/tests/integration/framework/bootstrap.php @@ -26,7 +26,7 @@ if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { $filesystem = new \Magento\Framework\Filesystem\Driver\File(); - $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception(); + $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception($filesystem); $loggerHandlers = [ 'system' => new \Magento\Framework\Logger\Handler\System($filesystem, $exceptionHandler), 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem) From cea5471acf4326f660d4e2985128f257d1858117 Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Wed, 26 Apr 2017 18:33:04 +0200 Subject: [PATCH 6/6] Fix whitespaces in api-functional bootstrap file --- dev/tests/api-functional/framework/bootstrap.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dev/tests/api-functional/framework/bootstrap.php b/dev/tests/api-functional/framework/bootstrap.php index 56c0b6cf19b7c..188933ac6dd37 100644 --- a/dev/tests/api-functional/framework/bootstrap.php +++ b/dev/tests/api-functional/framework/bootstrap.php @@ -39,11 +39,11 @@ require_once __DIR__ . '/../../integration/framework/deployTestModules.php'; $installConfigFile = $settings->getAsConfigFile('TESTS_INSTALL_CONFIG_FILE'); - if ( ! file_exists($installConfigFile)) { + if (!file_exists($installConfigFile)) { $installConfigFile = $installConfigFile . '.dist'; } $globalConfigFile = $settings->getAsConfigFile('TESTS_GLOBAL_CONFIG_FILE'); - if ( ! file_exists($installConfigFile)) { + if (!file_exists($installConfigFile)) { $installConfigFile = $installConfigFile . '.dist'; } $dirList = new \Magento\Framework\App\Filesystem\DirectoryList(BP); @@ -77,10 +77,10 @@ $application->initialize(); \Magento\TestFramework\Helper\Bootstrap::setInstance(new \Magento\TestFramework\Helper\Bootstrap($bootstrap)); - $dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\Framework\Component\DirSearch::class); + $dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create(\Magento\Framework\Component\DirSearch::class); $themePackageList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class); + ->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class); \Magento\Framework\App\Utility\Files::setInstance( new \Magento\Framework\App\Utility\Files( new \Magento\Framework\Component\ComponentRegistrar(),