Commit 33493107 authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

+ Added unitest for reproducing setup script issue and fixing it

parent 07d89667
<?php
/**
* A test case for testing script assertions
*
* @loadSharedFixture files
*/
class EcomDev_PHPUnitTest_Test_Lib_Constraint_Config_Resource_Script extends EcomDev_PHPUnit_Test_Case
{
/**
* @var EcomDev_PHPUnit_Constraint_Config_Resource_Script
*/
protected $constraint = null;
protected function setUp()
{
$this->constraint = $this->getMockBuilder('EcomDev_PHPUnit_Constraint_Config_Resource_Script')
->disableOriginalConstructor()
->setMethods(null)
->getMock();
}
/**
* Returns path within vfs stream
*
* @param string[]|string $directories
* @return string[]|string
*/
protected function getVirtualPath($directories)
{
if (!is_array($directories)) {
$directories = array($directories);
}
$virtualPath = array();
foreach ($directories as $directory) {
$virtualPath[] = $this->getFixture()->getVfs()->url($directory);
}
if (count($virtualPath) === 1) {
$virtualPath = current($virtualPath);
}
return $virtualPath;
}
/**
*
* @param $directory
* @dataProvider dataProvider
*/
public function testParseVersions($directories)
{
$virtualPath = $this->getVirtualPath($directories);
$result = EcomDev_Utils_Reflection::invokeRestrictedMethod($this->constraint, 'parseVersions', array($virtualPath));
$this->assertEquals($this->expected('auto')->getVersions(), $result);
}
/**
* Test version
*
* @param string[]|string $directories
* @param string $type
* @param string $from
* @param string $to
*
* @return void
* @dataProvider dataProvider
*/
public function testGetVersionScriptsDiff($directories, $type, $from, $to)
{
$virtualPath = $this->getVirtualPath($directories);
$versions = EcomDev_Utils_Reflection::invokeRestrictedMethod($this->constraint, 'parseVersions', array(
$virtualPath
));
$result = EcomDev_Utils_Reflection::invokeRestrictedMethod($this->constraint, 'getVersionScriptsDiff', array(
$versions[$type], $from, $to, $type === 'data' ? 'data-' : ''
));
$this->assertEquals($this->expected('auto')->getDiff(), $result);
}
}
\ No newline at end of file
from_1.0.0_to_1.0.1_one:
diff:
expected:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
actual:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
from_1.0.0_to_1.0.5_one:
diff:
expected:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
- upgrade-1.0.1-1.0.5.php
actual:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
to_1.0.5_one:
diff:
expected:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
- upgrade-1.0.1-1.0.5.php
actual:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
from_1.0.0_one:
diff:
expected:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
actual:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
from_1.0.0_to_1.0.1_one_invalid:
diff:
expected:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
actual:
- upgrade-1.0.0-1.0.1.php
from_1.0.0_to_1.0.5_one_invalid:
diff:
expected:
- install-1.0.0.php
- upgrade-1.0.0-1.0.1.php
- upgrade-1.0.1-1.0.5.php
actual:
- upgrade-1.0.0-1.0.1.php
\ No newline at end of file
directory_one_valid:
versions:
scheme:
install:
- filename: install-1.0.0.php
prefix: install
from: 1.0.0
to: null
- filename: mysql4-install-0.8.0.php
prefix: mysql4-install
from: 0.8.0
to: null
upgrade:
- filename: upgrade-1.0.0-1.0.1.php
prefix: upgrade
from: 1.0.0
to: 1.0.1
- filename: mysql4-upgrade-0.8.0-0.8.1.php
prefix: mysql4-upgrade
from: 0.8.0
to: 0.8.1
data:
install: []
upgrade: []
directory_two_valid:
versions:
scheme:
install:
- filename: install-1.0.0.php
prefix: install
from: 1.0.0
to: null
- filename: mysql4-install-0.8.0.php
prefix: mysql4-install
from: 0.8.0
to: null
upgrade:
- filename: upgrade-1.0.0-1.0.1.php
prefix: upgrade
from: 1.0.0
to: 1.0.1
- filename: upgrade-1.0.1-1.0.2.php
prefix: upgrade
from: 1.0.1
to: 1.0.2
- filename: upgrade-1.0.2-1.0.3.php
prefix: upgrade
from: 1.0.2
to: 1.0.3
- filename: upgrade-1.0.3-1.0.4.php
prefix: upgrade
from: 1.0.3
to: 1.0.4
- filename: mysql4-upgrade-0.8.0-0.8.1.php
prefix: mysql4-upgrade
from: 0.8.0
to: 0.8.1
- filename: mysql4-upgrade-0.8.1-0.8.2.php
prefix: mysql4-upgrade
from: 0.8.1
to: 0.8.2
- filename: mysql4-upgrade-0.8.2-0.8.3.php
prefix: mysql4-upgrade
from: 0.8.2
to: 0.8.3
- filename: mysql4-upgrade-0.8.3-0.8.4.php
prefix: mysql4-upgrade
from: 0.8.3
to: 0.8.4
data:
install: []
upgrade: []
directory_one_data_scheme_valid:
versions:
scheme:
install:
- filename: install-1.0.0.php
prefix: install
from: 1.0.0
to: null
upgrade:
- filename: upgrade-1.0.0-1.0.1.php
prefix: upgrade
from: 1.0.0
to: 1.0.1
- filename: upgrade-1.0.1-1.0.2.php
prefix: upgrade
from: 1.0.1
to: 1.0.2
- filename: upgrade-1.0.2-1.0.3.php
prefix: upgrade
from: 1.0.2
to: 1.0.3
- filename: upgrade-1.0.3-1.0.4.php
prefix: upgrade
from: 1.0.3
to: 1.0.4
data:
install:
- filename: data-install-1.0.0.php
prefix: data-install
from: 1.0.0
to: null
upgrade:
- filename: data-upgrade-1.0.0-1.0.1.php
prefix: data-upgrade
from: 1.0.0
to: 1.0.1
- filename: data-upgrade-1.0.1-1.0.2.php
prefix: data-upgrade
from: 1.0.1
to: 1.0.2
- filename: data-upgrade-1.0.2-1.0.3.php
prefix: data-upgrade
from: 1.0.2
to: 1.0.3
- filename: data-upgrade-1.0.3-1.0.4.php
prefix: data-upgrade
from: 1.0.3
to: 1.0.4
directory_one_invalid:
versions:
scheme:
install: []
upgrade:
- filename: upgrade-1.0.0-1.0.1.php
prefix: upgrade
from: 1.0.0
to: 1.0.1
data:
install: []
upgrade: []
directory_two_invalid:
versions:
scheme:
install:
- filename: install-1.0.0.php
prefix: install
from: 1.0.0
to: null
upgrade:
- filename: upgrade-1.0.1-1.0.2.php
prefix: upgrade
from: 1.0.1
to: 1.0.2
- filename: upgrade-1.0.2-1.0.3.php
prefix: upgrade
from: 1.0.2
to: 1.0.3
- filename: upgrade-1.0.3-1.0.4.php
prefix: upgrade
from: 1.0.3
to: 1.0.4
data:
install: []
upgrade: []
directory_one_data_scheme_invalid:
versions:
scheme:
install:
- filename: install-1.0.0.php
prefix: install
from: 1.0.0
to: null
upgrade:
- filename: upgrade-1.0.0-1.0.1.php
prefix: upgrade
from: 1.0.0
to: 1.0.1
- filename: upgrade-1.0.1-1.0.2.php
prefix: upgrade
from: 1.0.1
to: 1.0.2
- filename: upgrade-1.0.2-1.0.3.php
prefix: upgrade
from: 1.0.2
to: 1.0.3
- filename: upgrade-1.0.3-1.0.4.php
prefix: upgrade
from: 1.0.3
to: 1.0.4
data:
install:
- filename: data-install-1.0.0.php
prefix: data-install
from: 1.0.0
to: null
upgrade:
- filename: data-upgrade-1.0.1-1.0.2.php
prefix: data-upgrade
from: 1.0.1
to: 1.0.2
- filename: data-upgrade-1.0.2-1.0.3.php
prefix: data-upgrade
from: 1.0.2
to: 1.0.3
- filename: data-upgrade-1.0.3-1.0.4.php
prefix: data-upgrade
from: 1.0.3
to: 1.0.4
\ No newline at end of file
vfs:
directory_one_valid:
install-1.0.0.php: <?php // file
upgrade-1.0.0-1.0.1.php: <?php // file
mysql4-install-0.8.0.php: <?php // file
mysql4-upgrade-0.8.0-0.8.1.php: <?php // file
directory_two_valid:
install-1.0.0.php: <?php // file
upgrade-1.0.0-1.0.1.php: <?php // file
upgrade-1.0.1-1.0.2.php: <?php // file
upgrade-1.0.2-1.0.3.php: <?php // file
upgrade-1.0.3-1.0.4.php: <?php // file
mysql4-install-0.8.0.php: <?php // file
mysql4-upgrade-0.8.0-0.8.1.php: <?php // file
mysql4-upgrade-0.8.1-0.8.2.php: <?php // file
mysql4-upgrade-0.8.2-0.8.3.php: <?php // file
mysql4-upgrade-0.8.3-0.8.4.php: <?php // file
directory_one_data_valid:
data-install-1.0.0.php: <?php // file
data-upgrade-1.0.0-1.0.1.php: <?php // file
data-upgrade-1.0.1-1.0.2.php: <?php // file
data-upgrade-1.0.2-1.0.3.php: <?php // file
data-upgrade-1.0.3-1.0.4.php: <?php // file
directory_one_scheme_valid:
install-1.0.0.php: <?php // file
upgrade-1.0.0-1.0.1.php: <?php // file
upgrade-1.0.1-1.0.2.php: <?php // file
upgrade-1.0.2-1.0.3.php: <?php // file
upgrade-1.0.3-1.0.4.php: <?php // file
directory_one_invalid:
instal-1.0.0.php: <?php // file # error in install script file name
upgrade-1.0.0-1.0.1.php: <?php // file
directory_two_invalid:
install-1.0.0.php: <?php // file
update-1.0.0-1.0.1.php: <?php // file # error in upgrade script file name
upgrade-1.0.1-1.0.2.php: <?php // file
upgrade-1.0.2-1.0.3.php: <?php // file
upgrade-1.0.3-1.0.4.php: <?php // file
directory_one_data_invalid:
data-install-1.0.0.php: <?php // file
data-upgade-1.0.0-1.0.1.php: <?php // file # error in the filename
data-upgrade-1.0.1-1.0.2.php: <?php // file
data-upgrade-1.0.2-1.0.3.php: <?php // file
data-upgrade-1.0.3-1.0.4.php: <?php // file
\ No newline at end of file
from_1.0.0_to_1.0.1_one:
- directory_one_valid
- scheme
- 1.0.0
- 1.0.1
from_1.0.0_to_1.0.5_one:
- directory_one_valid
- scheme
- 1.0.0
- 1.0.5
to_1.0.5_one:
- directory_one_valid
- scheme
- null
- 1.0.5
from_1.0.0_one:
- directory_one_valid
- scheme
- 1.0.0
- null
from_1.0.0_to_1.0.1_one_invalid:
- directory_one_invalid
- scheme
- 1.0.0
- 1.0.1
from_1.0.0_to_1.0.5_one_invalid:
- directory_one_invalid
- scheme
- 1.0.0
- 1.0.5
directory_one_valid:
- directory_one_valid
directory_two_valid:
- directory_two_valid
directory_one_data_scheme_valid:
-
- directory_one_data_valid
- directory_one_scheme_valid
directory_one_invalid:
- directory_one_invalid
directory_two_invalid:
- directory_two_invalid
directory_one_data_scheme_invalid:
-
- directory_one_data_invalid
- directory_one_scheme_valid
\ No newline at end of file
<config>
<phpunit>
<suite>
<modules>
<EcomDev_PHPUnitTest />
</modules>
<groups>
<lib>Lib</lib>
</groups>
</suite>
</phpunit>
</config>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* 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>
*/
-->
<config>
<modules>
<EcomDev_PHPUnitTest>
<codePool>community</codePool>
<active>true</active>
</EcomDev_PHPUnitTest>
</modules>
</config>
\ No newline at end of file
...@@ -154,6 +154,7 @@ class EcomDev_PHPUnit_Constraint_Config_Resource_Script ...@@ -154,6 +154,7 @@ class EcomDev_PHPUnit_Constraint_Config_Resource_Script
self::FILE_UPGRADE_DATA => array('data', 'upgrade') self::FILE_UPGRADE_DATA => array('data', 'upgrade')
); );
foreach ($directoryIterator as $entry) { foreach ($directoryIterator as $entry) {
/* @var $entry SplFileInfo */ /* @var $entry SplFileInfo */
// We do not support scheme upgrade scripts with .sql // We do not support scheme upgrade scripts with .sql
...@@ -206,6 +207,9 @@ class EcomDev_PHPUnit_Constraint_Config_Resource_Script ...@@ -206,6 +207,9 @@ class EcomDev_PHPUnit_Constraint_Config_Resource_Script
*/ */
protected function getVersionScriptsDiff($versions, $from = null, $to = null, $scriptPrefix = '') protected function getVersionScriptsDiff($versions, $from = null, $to = null, $scriptPrefix = '')
{ {
usort($versions['install'], array($this, 'compareVersions'));
usort($versions['upgrade'], array($this, 'compareVersions'));
if ($from === null && end($versions['install'])) { if ($from === null && end($versions['install'])) {
$version = end($versions['install']); $version = end($versions['install']);
$from = $version['from']; $from = $version['from'];
...@@ -227,7 +231,7 @@ class EcomDev_PHPUnit_Constraint_Config_Resource_Script ...@@ -227,7 +231,7 @@ class EcomDev_PHPUnit_Constraint_Config_Resource_Script
$latestVersionFound = null; $latestVersionFound = null;
if (empty($versions['install']) && $from !== null) { if (empty($versions['install']) && $from !== null) {
$expectedVersions[] = sprintf('install-%s.php', $scriptPrefix, $from); $expectedVersions[] = sprintf('%sinstall-%s.php', $scriptPrefix, $from);
$latestVersionFound = $from; $latestVersionFound = $from;
} elseif ($from !== null) { } elseif ($from !== null) {
foreach ($versions['install'] as $index=>$version) { foreach ($versions['install'] as $index=>$version) {
......
# EcomDev_PHPUnit definition # EcomDev_PHPUnit definition
app/etc/modules/EcomDev_PHPUnit.xml app/etc/modules/EcomDev_PHPUnit.xml app/etc/modules/EcomDev_*.xml app/etc/modules/
app/code/community/EcomDev/PHPUnit app/code/community/EcomDev/PHPUnit app/code/community/EcomDev/* app/code/community/EcomDev/
lib/EcomDev/PHPUnit lib/EcomDev/PHPUnit lib/EcomDev/* lib/EcomDev/
lib/EcomDev/Utils lib/EcomDev/Utils
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/ecomdev-phpunit-install.php shell/ecomdev-phpunit-install.php
......
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