【发布时间】:2012-04-04 00:54:44
【问题描述】:
我正在编写一个 Magento 插件并尝试使用来自http://www.ecomdev.org 的 PHPUnit 测试集成对其进行测试。现在我正在尝试测试一种方法,该方法有两组不同的配置设置,但由于某种原因,第二个从未加载过,而第一个被再次使用,因此期望第二个夹具的测试失败。
这里的问题简化为重要的几行:
Modul.php(模型)
<?php
class MyModule_Module_Model_TestModel extends Mage_Payment_Model_Method_Abstract {
protected $sandbox;
public function __construct() {
$this->sandbox = $this->getConfigData('sandbox');
}
public function getSandboxSetting() {
return $this->sandbox;
}
}
?>
fixture config.yaml
config
default/payment/modul/sandbox: 0
fixture configSB.yaml
config
default/payment/modul/sandbox: 1
Modul.php(测试)
<?php
class MyModule_Module_Test_Model_TestModel extends EcomDev_PHPUnit_Test_Case {
public function setUp() {
parent::setUp();
$this->object = Mage::getModel('module/testmodel');
}
/**
* @test
* @loadFixture config
*/
public function testCorrectShopSettingsWithoutSandbox() {
$this->assertEquals('0', $this->object->getSandboxSetting());
}
/**
* @test
* @loadFixture configSB
*/
public function testCorrectShopSettingsWithSandbox() {
$this->assertEquals('1', $this->object->getSandboxSetting());
}
protected function tearDown() {
unset($this->object);
parent::tearDown();
}
}
?>
不幸的是,第二个测试失败了,无论它们是按什么顺序执行的。实际上,ecomdev 测试套件应该丢弃固定装置(我查看了 case.php 中的 tearDown()),但配置数据仍然存在并且不能被覆盖。是否有解决方法或者这是 Magento / 测试套件的问题?
【问题讨论】:
-
为什么不官方 magento taf
https://github.com/magento/taf? -
@Zyava 因为它用于基于 selenium 的功能测试(例如测试 html 而不是后端逻辑)。 EcomDev_PHPUnit 测试面向您的功能的特定单元(类方法),而不是 HTML 页面输出。
-
对不起,我不知道只有 taf 的 selenium 部分被公开了。
标签: php magento phpunit fixtures