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
This diff is collapsed.
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