keios/oc-plugin-testsuite

测试 OctoberCMS 插件的中间件包

dev-master 2016-10-25 14:38 UTC

This package is not auto-updated.

Last update: 2024-09-25 15:13:09 UTC


README

Latest Version Software License Total Downloads

此包现在已弃用,因为 OctoberCMS 现在自带了插件单元测试用例。

测试中间件包:提供扩展的 PHPUnit 的 TestCase 类 - OctoberPluginTestCase,允许在 OctoberCMS / Laravel 环境中进行单元测试,并加载所有相关的 composer 自动加载器。

为 OctoberCMS Release Candidate 准备,不适用于测试版。

需求

OctoberCMS

安装

通过 Composer

$ composer require keios/oc-plugin-testsuite dev-master --dev

使用方法

phpunit.xml

插件 phpunit.xml 应该看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/keios/oc-plugin-testsuite/bootstrap/autoload.php"
         backupGlobals="false"
         backupStaticAttributes="false"
         colors="true"
         verbose="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false">
    <testsuites>
        <testsuite name="October Plugin Unit Test Suite">
            <directory>tests/unit</directory>
        </testsuite>
        <testsuite name="October Plugin Functional Test Suite">
            <directory>tests/functional</directory>
        </testsuite>
    </testsuites>
    <logging>
        <log type="tap" target="build/report.tap"/>
        <log type="junit" target="build/report.junit.xml"/>
        <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
        <log type="coverage-text" target="build/coverage.txt"/>
        <log type="coverage-clover" target="build/logs/clover.xml"/>
    </logging>
    <php>
        <env name="APP_ENV" value="plugin_testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
    </php>
</phpunit>

测试用例

该包提供 OctoberPluginTestCase 类,它准备在 Laravel 5 / OctoberCMS 环境中运行测试,并附带一些实用功能,如自动迁移。

您的测试用例应遵循以下规则

基本单元测试

<?php namespace Vendor\PluginName\Tests

class SomeClassTest extends \OctoberPluginTestCase {

    protected $someMockObjectUsedInAllTests;

    public function pluginTestSetUp () // PHPUnit's set up method is unavailable, use this instead
    {
        $this->someMockObjectUsedInAllTests = \Mockery::mock('Some\Other\Class');
    }

    public function testSomething() { 
        $instance = new SomeClass($this->someMockObjectUsedInAllTests);
        
        $this->assertEquals('result', $instance->getResult());
    }

}

需要 October 环境的功能测试,但不刷新插件

<?php namespace Vendor\PluginName\Tests

class AFunctionalTest extends \OctoberPluginTestCase {

    protected $requiresOctoberMigration = true; // test suite will migrate october

}

需要 October 环境且刷新插件 'Vendor.PluginName' 的功能测试

<?php namespace Vendor\PluginName\Tests

class AFunctionalTestRequiringMigrations extends \OctoberPluginTestCase {

    /*
     * Here you can add multiple plugin codes, ie.: your plugin and it's dependencies
     */
    protected $refreshPlugins = ['Vendor.PluginName', 'OtherVendor.OtherPlugin'];

}

鸣谢

许可证

MIT 许可证 (MIT)。请参阅许可证文件获取更多信息。