【问题标题】:Fixtures in Magento & the eComDev Test Suite (discard one fixture and use a new one)Magento 和 eComDev 测试套件中的夹具(丢弃一个夹具并使用一个新夹具)
【发布时间】: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


【解决方案1】:

你试过 github 上的最新版本吗?我们看到一些与新 Magento 版本的配置相关的问题,因此在 dev 分支中已修复。

这是分支网址: https://github.com/IvanChepurnyi/EcomDev_PHPUnit/tree/dev

【讨论】:

  • 是的,我得到了最新版本,只是仔细检查了一遍。当我试图在第二次测试中获得 $this->object->getConfigData('sandbox') 的输出时,它又只是 0。把 $this->object = Mage::getModel('module/testmodel')进入测试也没有成功。 (猜想这将有助于在加载固定装置后创建对象......)
  • @user1230693 测试用例使用什么 Magento 版本?
  • Magento 版本 1.6.1.0 - 刚刚使它与 >> Mage::getConfig()->reinit();法师::app()->reinitStores(); > parent::setUp();
  • 您也可以为商店指定数据,我认为默认配置中的问题不会刷新商店配置缓存。在您的夹具中尝试这样的路径stores/default/payment/modul/sandbox
  • 第二次比较沙盒设置时再次失败,即使它不是默认配置。 reinit() 和 reinitStores() 减慢了测试速度,但最终它起作用了。谢谢你的帮助,伊万。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-17
  • 1970-01-01
  • 2018-11-22
  • 1970-01-01
  • 2019-07-17
  • 2020-11-19
相关资源
最近更新 更多