dev-master
9999999-devTesting middleware package for OctoberCMS Plugins
MIT
The Requires
Wallogit.com
2017 © Pedro PelĂĄez
Testing middleware package for OctoberCMS Plugins
Testing middleware package: provides extended PHPUnit's TestCase class - OctoberPluginTestCase, which allows for unit testing in OctoberCMS / Laravel context and loads all related composer autoloaders., (*2)
Prepared for OctoberCMS Release Candidate, won't work with beta releases., (*3)
OctoberCMS, (*4)
Via Composer, (*5)
``` bash $ composer require keios/oc-plugin-testsuite dev-master --dev, (*6)
## Usage #### phpunit.xml Plugin's phpunit.xml should look somewhat like this: ``` xml <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>
Package provides class OctoberPluginTestCase, which is prepared to run tests in Laravel 5 / OctoberCMS environment and comes with handy features like automatic migrations., (*7)
Your test cases should follow these rules:, (*8)
basic unit test ``` php <?php namespace Vendor\PluginName\Tests, (*9)
class SomeClassTest extends \OctoberPluginTestCase {, (*10)
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());
}
}, (*11)
**functional test requiring October environment, but not refreshing plugins** ``` php <?php namespace Vendor\PluginName\Tests class AFunctionalTest extends \OctoberPluginTestCase { protected $requiresOctoberMigration = true; // test suite will migrate october }
functional test requiring October environment AND refreshing plugin 'Vendor.PluginName' ``` php <?php namespace Vendor\PluginName\Tests, (*12)
class AFunctionalTestRequiringMigrations extends \OctoberPluginTestCase {, (*13)
/* * Here you can add multiple plugin codes, ie.: your plugin and it's dependencies */ protected $refreshPlugins = ['Vendor.PluginName', 'OtherVendor.OtherPlugin'];
} ```, (*14)
The MIT License (MIT). Please see License File for more information., (*15)
Testing middleware package for OctoberCMS Plugins
MIT