如何在同一个插件中拥有与不同应用程序相关的两个测试套件?

发布于 2024-10-10 07:37:19 字数 1162 浏览 0 评论 0原文

我目前正在 sf 1.4 项目上使用 sfPhpUnitPlugin,并且遇到插件测试问题。

我有一个可在多个应用程序上使用的插件,并且我希望每个应用程序都有一个测试套件。如何组织我的测试,以便我可以轻松地将夹具和测试与特定应用程序相匹配?

我的套件是这个模板的副本,它是通过 sfPhpunitPlugin 提供的:

<?php

class {className} extends sfBasePhpunitTestSuite
  implements sfPhpunitContextInitilizerInterface
{
    /**
     * Dev hook for custom "setUp" stuff
     */
    protected function _start()
    {
      $this->_initFilters();
    }

    /**
     * Dev hook for custom "tearDown" stuff
     */
    protected function _end()
    {
    }

    protected function _initFilters()
    {
      $filters = sfConfig::get('app_sfPhpunitPlugin_filter', array());
      foreach ($filters as $filter) {
        PHPUnit_Util_Filter::addDirectoryToFilter($filter['path'], $filter['ext']);
      }
    }

    public function getApplication()
    {
      return '{application}';
    }
}

我想我必须在每个应用程序的 app.yml 中添加类似的内容:

testunit:
  sfPhpunitPlugin:
    filter:
      - {path: 'backend', ext: '.php'}

但我很难确定路径键是什么样子,我'我的印象是它应该是完整路径,因为 include_path 不包含调用 addDirectoryToFilter() 时我正在测试的插件的路径。 有什么建议吗? 有人这样做过吗?

I am currently working with sfPhpUnitPlugin on a sf 1.4 project, and I am facing a problem with plugin testing.

I have a plugin that can be used on several applications, and I would like to have a test suite per application. How can I organize my tests so that I can easily match fixtures and tests with a specific application?

My suites are copies of this template, which is delivered with the sfPhpunitPlugin:

<?php

class {className} extends sfBasePhpunitTestSuite
  implements sfPhpunitContextInitilizerInterface
{
    /**
     * Dev hook for custom "setUp" stuff
     */
    protected function _start()
    {
      $this->_initFilters();
    }

    /**
     * Dev hook for custom "tearDown" stuff
     */
    protected function _end()
    {
    }

    protected function _initFilters()
    {
      $filters = sfConfig::get('app_sfPhpunitPlugin_filter', array());
      foreach ($filters as $filter) {
        PHPUnit_Util_Filter::addDirectoryToFilter($filter['path'], $filter['ext']);
      }
    }

    public function getApplication()
    {
      return '{application}';
    }
}

I suppose I have to add something like this in the app.yml of each application:

testunit:
  sfPhpunitPlugin:
    filter:
      - {path: 'backend', ext: '.php'}

but I have difficulty determining what the path key is going to look like, I'm under the impression it should be a full path, because the include_path does not contain the path of the plugin I'm testing when addDirectoryToFilter() is called.
Any tips?
Has anyone done this yet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃素的狼 2024-10-17 07:37:19

实际上,您必须创建两个实现 sfPhpunitContextInitilizerInterface 接口并实现所有必需方法的套件类。

然后将这两个套件放在两个不同的文件夹中,例如:

SF_PLUGIN_DIR/YOUR_PLUGIN/test/phpunit/unit/app1/App1TestSuite.php
SF_PLUGIN_DIR/YOUR_PLUGIN/test/phpunit/unit/app2/App2TestSuite.php

目录 app1 或子目录中的所有测试都将在 App1TestSuite.php 中定义的 symfony 应用程序中运行,并且与 app2 目录的规则相同。

如果您想在不同的应用程序中动态运行测试,您可以在接口所需的方法(getEnviroment 和 getApplication)中定义此逻辑。

如果您还有任何疑问,请随时问我。

Actually You have to create two suite classes which implemented sfPhpunitContextInitilizerInterface interface and implement all required methods.

Then put those two suites in two different folders, for example:

SF_PLUGIN_DIR/YOUR_PLUGIN/test/phpunit/unit/app1/App1TestSuite.php
SF_PLUGIN_DIR/YOUR_PLUGIN/test/phpunit/unit/app2/App2TestSuite.php

All tests in directory app1 or subdirectories will be run in symfony app defined in App1TestSuite.php and the same rules for app2 directory.

If you want to run tests dynamically in different applications you can define this logic in methods required by interface (getEnviroment and getApplication).

Feel free to ask me if you still have any questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文