Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.

Commit 5e093a8

Browse files
committed
Compatibility with PHPUnit4.0, some changes in Reflection
1 parent bfa5970 commit 5e093a8

15 files changed

Lines changed: 128 additions & 20 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ before_script:
1717
# Installing EcomDev_PHPUnit module
1818
- bin/mage-ci install-module $MAGE_DIR $(pwd)
1919
# Configuring EcomDev_PHPUnit module
20-
- bin/mage-ci shell $MAGE_DIR ecomdev-phpunit.php -a magento-config --db-name magento --same-db 1 --base_url http://test.magento.com/
20+
- bin/mage-ci shell $MAGE_DIR ecomdev-phpunit.php -a magento-config --db-name magento --same-db 1 --base-url http://test.magento.com/
2121
# Configuring test suite
2222
- bin/mage-ci shell $MAGE_DIR ecomdev-phpunit.php -a change-status --enable
2323
# Copying phpunit.xml for travis builds

app/code/community/EcomDev/PHPUnit/Test/Case/Util.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,18 @@ public static function getModuleNameByClassName($className)
396396
// Try to find the module name by class name
397397
$moduleName = false;
398398
foreach (Mage::getConfig()->getNode('modules')->children() as $module) {
399-
if (strpos($className, $module->getName()) === 0) {
399+
if (strpos($className, $module->getName() . '_') === 0) {
400400
$moduleName = $module->getName();
401401
break;
402402
}
403403
}
404+
405+
// Add a possibility to override a module, for which this test is applicable
406+
$moduleAnnotations = self::getAnnotationByNameFromClass($className, 'module');
407+
408+
if ($moduleAnnotations) {
409+
$moduleName = current($moduleAnnotations);
410+
}
404411

405412
if (!$moduleName) {
406413
throw new RuntimeException('Cannot to find the module name for class name: ' . $className);

app/code/community/EcomDev/PHPUnit/Test/Listener.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,23 @@ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time
263263
// No action is required
264264
}
265265

266+
267+
/**
268+
* Risky test.
269+
*
270+
* @param PHPUnit_Framework_Test $test
271+
* @param Exception $e
272+
* @param float $time
273+
* @since Method available since Release 4.0.0
274+
*/
275+
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
276+
{
277+
Mage::dispatchEvent('phpunit_test_risky', array(
278+
'test' => $test,
279+
'exception' => $e,
280+
'time' => $time,
281+
'listener' => $this
282+
));
283+
// No action required
284+
}
266285
}

app/code/community/EcomDev/PHPUnit/bootstrap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
exit(1);
66
}
77

8-
$_baseDir = getcwd();
8+
if (isset($_SERVER['MAGENTO_DIRECTORY'])) {
9+
$_baseDir = $_SERVER['MAGENTO_DIRECTORY'];
10+
} else {
11+
$_baseDir = getcwd();
12+
}
913

1014
// Include Mage file by detecting app root
1115
require_once $_baseDir . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';

app/code/community/EcomDev/PHPUnitTest/Test/Lib/AbstractConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testCompareValues($expectedValue, $actualValue, $expectedResult)
2323
);
2424

2525
if (!$expectedResult) {
26-
$this->assertAttributeInstanceOf('PHPUnit_Framework_ComparisonFailure', '_comparisonFailure', $constraint);
26+
$this->assertAttributeInstanceOf('\SebastianBergmann\Comparator\ComparisonFailure', '_comparisonFailure', $constraint);
2727
}
2828
}
2929

app/code/community/EcomDev/PHPUnitTest/Test/Lib/Constraint/Config/Node.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ public function testEqualsXmlFailure($actualValue, $expectedValue)
7373

7474
$this->assertFalse($constraint->evaluate($actualValue, '', true));
7575
$this->assertAttributeNotEmpty('_comparisonFailure', $constraint);
76-
$this->assertAttributeInstanceOf('PHPUnit_Framework_ComparisonFailure', '_comparisonFailure', $constraint);
76+
$this->assertAttributeInstanceOf('\SebastianBergmann\Comparator\ComparisonFailure', '_comparisonFailure', $constraint);
7777
}
7878
}

app/etc/modules/EcomDev_PHPUnitTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<EcomDev_PHPUnitTest>
2323
<codePool>community</codePool>
2424
<active>true</active>
25+
<depends>
26+
<EcomDev_PHPUnit />
27+
</depends>
2528
</EcomDev_PHPUnitTest>
2629
</modules>
2730
</config>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"homepage": "http://www.ecomdev.org/shop/code-testing/php-unit-test-suite.html",
77
"require": {
88
"magento-hackathon/magento-composer-installer": "*",
9-
"phpunit/phpunit": "3.7.*"
9+
"phpunit/phpunit": "4.1.*"
1010
},
1111
"authors":[
1212
{

lib/EcomDev/PHPUnit/AbstractConstraint.php

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424
abstract class EcomDev_PHPUnit_AbstractConstraint
2525
extends PHPUnit_Framework_Constraint
2626
{
27+
/**
28+
* Comparator factory
29+
*
30+
* @var \SebastianBergmann\Comparator\Factory
31+
*/
32+
static protected $_comparatorFactory;
33+
34+
/**
35+
* String exporter for variables
36+
*
37+
* @var \SebastianBergmann\Exporter\Exporter
38+
*/
39+
static protected $_exporter;
40+
2741
/**
2842
* List of validation rules for expected value
2943
* It is an associative array with key as type and value
@@ -76,7 +90,7 @@ abstract class EcomDev_PHPUnit_AbstractConstraint
7690
/**
7791
* Comparison failure for nice failure messages
7892
*
79-
* @var PHPUnit_Framework_ComparisonFailure
93+
* @var \SebastianBergmann\Comparator\ComparisonFailure
8094
*/
8195
protected $_comparisonFailure = null;
8296

@@ -128,6 +142,35 @@ public function __construct($type, $expectedValue = null)
128142
$this->_expectedValue = $expectedValue;
129143
}
130144

145+
/**
146+
* Comparator factory instance
147+
*
148+
* @return \SebastianBergmann\Comparator\Factory
149+
*/
150+
public static function getComparatorFactory()
151+
{
152+
if (self::$_comparatorFactory === null) {
153+
self::$_comparatorFactory = new \SebastianBergmann\Comparator\Factory();
154+
}
155+
156+
return self::$_comparatorFactory;
157+
}
158+
159+
/**
160+
* Exporter instance for variables
161+
*
162+
* @return \SebastianBergmann\Exporter\Exporter
163+
*/
164+
public static function getExporter()
165+
{
166+
if (self::$_exporter === null) {
167+
self::$_exporter = new \SebastianBergmann\Exporter\Exporter();
168+
}
169+
170+
return self::$_exporter;
171+
}
172+
173+
131174
/**
132175
* Set actual value that will be used in the fail message
133176
*
@@ -190,7 +233,7 @@ public function evaluate($other, $description = '', $returnResult = false)
190233
* (non-PHPdoc)
191234
* @see PHPUnit_Framework_Constraint::fail()
192235
*/
193-
public function fail($other, $description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL)
236+
public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL)
194237
{
195238
$failureDescription = sprintf('Failed asserting that %s', $this->failureDescription($other));
196239

@@ -269,12 +312,12 @@ public function exportAsString($value)
269312
if (is_array($value) && preg_match('/^\d+$/', implode('', array_keys($value)))) {
270313
$stringValue = '';
271314
foreach ($value as $val) {
272-
$stringValue .= (is_string($val) ? $val : PHPUnit_Util_Type::export($val)) . "\n";
315+
$stringValue .= (is_string($val) ? $val : self::getExporter()->export($val)) . "\n";
273316
}
274317

275318
return $stringValue;
276319
} else {
277-
return PHPUnit_Util_Type::export($value);
320+
return self::getExporter()->export($value);
278321
}
279322
}
280323

@@ -287,7 +330,7 @@ public function exportAsString($value)
287330
*/
288331
public function compareValues($expectedValue, $actualValue)
289332
{
290-
$comparatorFactory = PHPUnit_Framework_ComparatorFactory::getDefaultInstance();
333+
$comparatorFactory = self::getComparatorFactory();
291334

292335
try {
293336
$comparator = $comparatorFactory->getComparatorFor(
@@ -300,7 +343,7 @@ public function compareValues($expectedValue, $actualValue)
300343
);
301344
}
302345

303-
catch (PHPUnit_Framework_ComparisonFailure $f) {
346+
catch (\SebastianBergmann\Comparator\ComparisonFailure $f) {
304347
$this->_comparisonFailure = $f;
305348
return false;
306349
}
@@ -316,7 +359,7 @@ public function compareValues($expectedValue, $actualValue)
316359
* @param mixed $expectedValue
317360
* @param mixed $actualValue
318361
*
319-
* @return PHPUnit_Framework_ComparisonFailure
362+
* @return \SebastianBergmann\Comparator\ComparisonFailure
320363
*/
321364
public function getComparisonFailure($expectedValue, $actualValue)
322365
{
@@ -326,7 +369,7 @@ public function getComparisonFailure($expectedValue, $actualValue)
326369
return $failure;
327370
}
328371

329-
return new PHPUnit_Framework_ComparisonFailure(
372+
return new \SebastianBergmann\Comparator\ComparisonFailure(
330373
$expectedValue,
331374
$actualValue,
332375
$this->exportAsString($expectedValue),

lib/EcomDev/PHPUnit/Constraint/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public function __construct($constraint)
5959
*
6060
* @param mixed $other
6161
* @param string $description
62-
* @param PHPUnit_Framework_ComparisonFailure $comparisonFailure
62+
* @param \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure
6363
*/
64-
public function fail($other, $description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL)
64+
public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL)
6565
{
6666
$nodeValue = $this->getNodeValue($other);
6767

0 commit comments

Comments
 (0)