We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 9b85f00e authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

! Add Travis build information + new shell commands

parent 2b9963d5
language: php
php:
- 5.3
- 5.4
env:
- MAGE=1.7.0.2
- MAGE=1.6.2.0
- MAGE=1.5.1.0
before_script:
# Fixing Magento hackathon installer
- mkdir -p tests/magento
# Installing required composer packages
- composer update --dev
# Installing magento version with prepared DB dump
- bin/mage-ci install tests/magento $MAGE magento -c -t -r http://mage-ci.ecomdev.org
# Installing EcomDev_PHPUnit module
- bin/mage-ci install-module tests/magento $(pwd)
# Configuring EcomDev_PHPUnit module
- CURRENT_DIR=$(pwd)
- cd tests/magento/shell
- php ecomdev-phpunit.php -a magento-config --db-name magento --same-db 1 --base_url http://test.magento.com/
- php ecomdev-phpunit.php -a change-status --enable
- cd $CURRENT_DIR
script:
- bin/mage-ci phpunit tests/magento --colors --coverage-text
...@@ -236,13 +236,20 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config ...@@ -236,13 +236,20 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
protected function _loadTestConfig() protected function _loadTestConfig()
{ {
$merge = clone $this->_prototype; $merge = clone $this->_prototype;
try {
if ($merge->loadFile($this->_getLocalXmlForTest())) { if ($merge->loadFile($this->_getLocalXmlForTest())) {
$this->_checkDbCredentialForDuplicate($this, $merge); $this->_checkDbCredentialForDuplicate($this, $merge);
$this->_checkBaseUrl($this, $merge); $this->_checkBaseUrl($this, $merge);
$this->extend($merge); $this->extend($merge);
} else { } else {
throw new Exception('Unable to load local.xml.phpunit'); throw new RuntimeException('Unable to load local.xml.phpunit. Please run ecomdev-phpunit.php with install action.');
}
} catch (RuntimeException $e) {
echo $e->getMessage() . "\n";
exit(1);
} }
return $this; return $this;
} }
...@@ -275,8 +282,10 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config ...@@ -275,8 +282,10 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
$originalDbName = (string) $original->getNode('global/resources/default_setup/connection/dbname'); $originalDbName = (string) $original->getNode('global/resources/default_setup/connection/dbname');
$testDbName = (string) $test->getNode('global/resources/default_setup/connection/dbname'); $testDbName = (string) $test->getNode('global/resources/default_setup/connection/dbname');
if ($originalDbName == $testDbName) { if ($originalDbName == $testDbName && (string)$test->getNode('phpunit/allow_same_db') !== '1') {
throw new RuntimeException('Test DB cannot be the same as the live one'); throw new RuntimeException('Test DB cannot be the same as the live one. '
. 'You can change this option by running ecomdev-phpunit.php with'
. ' magento-config action.');
} }
return $this; return $this;
} }
...@@ -296,12 +305,8 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config ...@@ -296,12 +305,8 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
if (empty($baseUrlSecure) || empty($baseUrlUnsecure) if (empty($baseUrlSecure) || empty($baseUrlUnsecure)
|| $baseUrlSecure == self::CHANGE_ME || $baseUrlUnsecure == self::CHANGE_ME) { || $baseUrlSecure == self::CHANGE_ME || $baseUrlUnsecure == self::CHANGE_ME) {
echo sprintf( throw new RuntimeException('The base url is not set for proper controller tests. '
'Please change values in %s file for nodes %s and %s. ' . 'Please run ecomdev-phpunit.php with magento-config action.');
. 'It will help in setting up proper controller test cases',
'app/etc/local.xml.phpunit', self::XML_PATH_SECURE_BASE_URL, self::XML_PATH_UNSECURE_BASE_URL
);
exit();
} }
} }
...@@ -316,7 +321,8 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config ...@@ -316,7 +321,8 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
{ {
$filePath = $this->getOptions()->getEtcDir() . DS . 'local.xml.phpunit'; $filePath = $this->getOptions()->getEtcDir() . DS . 'local.xml.phpunit';
if (!file_exists($filePath)) { if (!file_exists($filePath)) {
throw new RuntimeException('There is no local.xml.phpunit file'); throw new RuntimeException('There is no local.xml.phpunit file. '
. 'Try running ecomdev-phpunit.php with install action.');
} }
return $filePath; return $filePath;
......
...@@ -25,4 +25,7 @@ ...@@ -25,4 +25,7 @@
</url> </url>
</web> </web>
</default> </default>
<phpunit>
<allow_same_db>0</allow_same_db>
</phpunit>
</config> </config>
...@@ -8,9 +8,15 @@ ...@@ -8,9 +8,15 @@
"magento-hackathon/magento-composer-installer": "*", "magento-hackathon/magento-composer-installer": "*",
"phpunit/phpunit": "3.7.*" "phpunit/phpunit": "3.7.*"
}, },
"require-dev": {
"ecomdev/mage-ci": "dev-master"
},
"authors":[ "authors":[
{ {
"name":"Ivan Chepurnyi" "name":"Ivan Chepurnyi"
} }
] ],
"extra": {
"magento-root-dir": "tests/magento"
}
} }
# EcomDev_PHPUnit definition # EcomDev_PHPUnit definition
app/etc/modules/EcomDev_*.xml app/etc/modules/ app/etc/modules/*.xml app/etc/modules/
app/code/community/EcomDev/* app/code/community/EcomDev/ app/code/community/EcomDev/* app/code/community/EcomDev/
lib/EcomDev/* lib/EcomDev/ lib/EcomDev/* lib/EcomDev/
lib/Spyc lib/Spyc lib/Spyc lib/Spyc
lib/vfsStream lib/vfsStream lib/vfsStream lib/vfsStream
shell/ecomdev-phpunit-install.php shell/ecomdev-phpunit-install.php shell/*.php shell/
# Run shell installer # Run shell installer
@shell cd $PROJECT/shell && php -f ecomdev-phpunit-install.php -- --module $MODULE --project $PROJECT @shell cd $PROJECT/shell && php -f ecomdev-phpunit.php -- --action install
# Disables built in tests for extension
@shell cd $PROJECT/shell && php -f ecomdev-phpunit.php -- --action change-status
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<directory suffix=".php">lib/EcomDev/Utils</directory> <directory suffix=".php">lib/EcomDev/Utils</directory>
<directory suffix=".php">lib/EcomDev/PHPUnit</directory> <directory suffix=".php">lib/EcomDev/PHPUnit</directory>
<directory suffix=".php">lib/Spyc</directory> <directory suffix=".php">lib/Spyc</directory>
<directory suffix=".php">lib/vfsStream</directory>
<!-- Exclude Mage.php file from code coverage --> <!-- Exclude Mage.php file from code coverage -->
<file>app/Mage.php</file> <file>app/Mage.php</file>
<!-- Exclude template files --> <!-- Exclude template files -->
......
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2013 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
require_once 'abstract.php';
/**
* Shell script for autoinstalling of required files for phpunit extension
*
*
*/
class EcomDev_PHPUnit_Install extends Mage_Shell_Abstract
{
const FILE_LOCAL_XML = 'app/etc/local.xml.phpunit';
const FILE_PHPUNIT_XML = 'phpunit.xml.dist';
const OLD_FILE_MATCH = '/\\<file\\>UnitTests.php\\<\\/file\\>/';
/**
* This script doesn't need initialization of Magento
*
* @var bool
*/
protected $_includeMage = false;
/**
* Runs scripts itself
*/
public function run()
{
if (!$this->getArg('module') || !$this->getArg('project')) {
die($this->usageHelp());
}
$this->_copyLocalXml();
$this->_copyPHPUnitXml();
$this->_cleanCache();
}
/**
* Copies local XML file from phpunit extension folder
*
*/
protected function _copyLocalXml()
{
if (!file_exists($this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_LOCAL_XML)) {
copy($this->getArg('module') . DIRECTORY_SEPARATOR . self::FILE_LOCAL_XML,
$this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_LOCAL_XML);
}
}
/**
* Checks existence of phpunit.xml.dist file, if file is outdated,
* it just replaces the content of it.
*
*/
protected function _copyPHPUnitXml()
{
if (!file_exists($this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_PHPUNIT_XML)
|| preg_match(self::OLD_FILE_MATCH,
file_get_contents($this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_PHPUNIT_XML))) {
copy($this->getArg('module') . DIRECTORY_SEPARATOR . self::FILE_PHPUNIT_XML,
$this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_PHPUNIT_XML);
}
}
/**
* Clears cache of the magento project
*
*
*/
protected function _cleanCache()
{
if (is_dir($this->getArg('project') . '/var/cache')) {
shell_exec('rm -rf ' . $this->getArg('project') . '/var/cache');
}
if (is_dir($this->getArg('project') . '/var/phpunit.cache')) {
shell_exec('rm -rf ' . $this->getArg('project') . '/var/phpunit.cache');
}
}
}
$shell = new EcomDev_PHPUnit_Install();
$shell->run();
\ No newline at end of file
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2013 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
require_once 'abstract.php';
/**
* Shell script for autoinstalling of required files for phpunit extension
*
*
*/
class EcomDev_PHPUnit_Install extends Mage_Shell_Abstract
{
const FILE_LOCAL_XML = 'app/etc/local.xml.phpunit';
const FILE_PHPUNIT_XML = 'phpunit.xml.dist';
const OLD_FILE_MATCH = '/\\<file\\>UnitTests.php\\<\\/file\\>/';
/**
* Config xml value map
*
* @var array[]
*/
protected $_valuesMap = array(
'db-host' => array(
'type' => 'string',
'nullable' => true,
'path' => '//global/resources/default_setup/connection/host'
),
'db-user' => array(
'type' => 'string',
'nullable' => true,
'path' => '//global/resources/default_setup/connection/username'
),
'db-pwd' => array(
'type' => 'string',
'nullable' => true,
'path' => '//global/resources/default_setup/connection/password'
),
'db-name' => array(
'type' => 'string',
'path' => '//global/resources/default_setup/connection/dbname'
),
'base-url' => array(
'type' => 'string',
'path' => array(
'//default/web/secure/base_url',
'//default/web/unsecure/base_url'
)
),
'same-db' => array(
'type' => 'boolean',
'path' => '//phpunit/allow_same_db'
),
'url-rewrite' => array(
'type' => 'boolean',
'path' => '//default/web/seo/use_rewrites'
)
);
/**
* This script doesn't need initialization of Magento
*
* @var bool
*/
protected $_includeMage = false;
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f ecomdev-phpunit.php -- -a <action> <options>
-h --help Shows usage
--action -a <action> Perform one of the defined actions below
Defined actions:
install Copies required extension files if they were not created before
-r --rewrite Overrides phpunit.xml.dist file, even if it exists
cache Clears magento and phpunit cache directories
phpunit-config Copies phpunit.xml.dist file from extension if it doesn't exist
-r --rewrite Overrides phpunit.xml.dist file, even if it exists
magento-config Updates settings in local.xml.phpunit file to change settings
--db-host <string> Changes test DB host
--db-name <string> Changes test DB name
--db-user <string> Changes test DB username
--db-pwd <string> Changes test DB password
--same-db <bool> Changes same db usage flag for unit tests
--url-rewrite <bool> Changes use of url rewrites for unit tests
--base_url <string> Changes base url for controller tests
change-status Changes status of EcomDev_PHPUnitTest module, that contains built in supplied tests
--enable Used to determine the status of it. If not specified, it will be disabled
USAGE;
}
/**
* Runs scripts itself
*/
public function run()
{
// We need only include mage, but not run app
require_once $this->_getRootPath() . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';
if (!$this->getArg('action') && !$this->getArg('a')) {
die($this->usageHelp());
}
$this->_args['module'] = dirname(dirname(__FILE__));
$this->_args['project'] = dirname(getcwd());
$action = $this->getArg('action') ?: $this->getArg('a');
switch ($action) {
case 'install':
// Installation is silent
$this->_copyLocalXml();
$this->_copyPHPUnitXml();
$this->_cleanCache();
break;
case 'cache':
$this->_cleanCache();
echo "Cache was cleared\n";
break;
case 'phpunit-config':
$this->_copyPHPUnitXml();
echo "phpunit.xml.dist file was copied/updated\n";
break;
case 'magento-config':
$this->_updateLocalXml();
break;
case 'change-status':
$this->_changeBuiltInTestStatus($this->getArg('enable'));
$this->_cleanCache();
echo "EcomDev_PHPUnitTest module status was changed\n";
break;
default:
$this->_showHelp();
break;
}
}
/**
* Copies local XML file from phpunit extension folder
*
*/
protected function _copyLocalXml()
{
if (!file_exists($this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_LOCAL_XML)) {
copy($this->getArg('module') . DIRECTORY_SEPARATOR . self::FILE_LOCAL_XML,
$this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_LOCAL_XML);
}
}
/**
* Checks existence of phpunit.xml.dist file, if file is outdated,
* it just replaces the content of it.
*
*/
protected function _copyPHPUnitXml()
{
if ($this->getArg('rewrite') || $this->getArg('r')
|| !file_exists($this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_PHPUNIT_XML)
|| preg_match(self::OLD_FILE_MATCH,
file_get_contents($this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_PHPUNIT_XML))) {
copy($this->getArg('module') . DIRECTORY_SEPARATOR . self::FILE_PHPUNIT_XML,
$this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_PHPUNIT_XML);
}
}
/**
* Clears cache of the magento project
*
*
*/
protected function _cleanCache()
{
if (is_dir($this->getArg('project') . '/var/cache')) {
shell_exec('rm -rf ' . $this->getArg('project') . '/var/cache');
}
if (is_dir($this->getArg('project') . '/var/phpunit.cache')) {
shell_exec('rm -rf ' . $this->getArg('project') . '/var/phpunit.cache');
}
}
/**
* Changes extension suite internal tests status
*
* @param bool $status
*/
protected function _changeBuiltInTestStatus($status)
{
if (!file_exists($this->getArg('project') . '/app/etc/modules/EcomDev_PHPUnitTest.xml')) {
die('Cannot find EcomDev_PHPUnitTest.xml file in app/etc/modules directory');
}
$disableFile = $this->getArg('project') . '/app/etc/modules/ZDisable_EcomDev_PHPUnitTest.xml';
if ($status && file_exists($disableFile)) {
unlink($disableFile);
} elseif (!$status && !file_exists($disableFile)) {
$fileContent = new Varien_Simplexml_Element('<config />');
$fileContent->addChild('modules')
->addChild('EcomDev_PHPUnitTest')
->addChild('active', 'false');
$fileContent->asNiceXml($disableFile);
}
}
/**
* Updates local.xml.phpunit values
*
*/
protected function _updateLocalXml()
{
$localXml = $this->getArg('project') . DIRECTORY_SEPARATOR . self::FILE_LOCAL_XML;
if (!file_exists($localXml)) {
die('Cannot find local.xml.phpunit file in app/etc directory');
}
/* @var $localXmlConfig Varien_Simplexml_Element */
$localXmlConfig = simplexml_load_file($localXml, 'Varien_Simplexml_Element');
foreach ($this->_args as $name => $value) {
if (isset($this->_valuesMap[$name])) {
$info = $this->_valuesMap[$name];
if (empty($info['nullable']) && $value === true) {
die("--$name value should be specified\n".$this->usageHelp());
}
if (!is_array($info['path'])) {
$info['path'] = array($info['path']);
}
foreach ($info['path'] as $path) {
/** @var $currentElement Varien_Simplexml_Element */
$currentElement = current($localXmlConfig->xpath($path));
if (!$currentElement) {
if ($value === true) {
continue;
}
$parents = explode('/', ltrim($path, '/'));
// Remove last item, since it is our element
$currentElementName = array_pop($parents);
$parentElement = $localXmlConfig;
foreach ($parents as $parent) {
if (!isset($parentElement->$parent)) {
$parentElement->$parent = null;
}
$parentElement = $parentElement->$parent;
}
} else {
$parentElement = $currentElement->getParent();
$currentElementName = $currentElement->getName();
}
if ($currentElement) {
unset($parentElement->$currentElementName);
}
if ($value !== true) {
if ($info['type'] === 'boolean') {
$value = $value ? '1' : '0';
}
$parentElement->$currentElementName = $value;
printf("Changed value to %s for %s node\n", $value, $path);
} else {
printf("Removed %s node\n", $path);
}
}
}
}
if (isset($currentElement)) {
$localXmlConfig->asNiceXml($localXml);
printf("Saved updated configuration at %s\n", $localXml);
}
}
}
$shell = new EcomDev_PHPUnit_Install();
$shell->run();
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment