<p>I found a bootstrap that works for me apart from an issue with the database connection.</p>

<p>I can't find the link now but here is the code:</p>

<pre class="lang-php prettyprint-override"><code>&lt;?php
define("CRAFT_ENVIRONMENT", "dev");
// PHP sucks at resolving symlinked directories
define('CRAFT_BASE_PATH', realpath(str_replace("plugins/myplugin", '', dirname(__FILE__))).'/');

// Define app constants
defined('CRAFT_APP_PATH')          || define('CRAFT_APP_PATH',          CRAFT_BASE_PATH.'app/');
defined('CRAFT_CONFIG_PATH')       || define('CRAFT_CONFIG_PATH',       CRAFT_BASE_PATH.'config/');
defined('CRAFT_VENDOR_PATH')       || define('CRAFT_VENDOR_PATH',       CRAFT_BASE_PATH.'app/vendor/');
defined('CRAFT_FRAMEWORK_PATH') || define('CRAFT_FRAMEWORK_PATH', CRAFT_APP_PATH.'framework/');;
defined('CRAFT_PLUGINS_PATH')      || define('CRAFT_PLUGINS_PATH',      CRAFT_BASE_PATH.'plugins/');
defined('CRAFT_STORAGE_PATH')      || define('CRAFT_STORAGE_PATH',      CRAFT_BASE_PATH.'storage/');
defined('CRAFT_TEMPLATES_PATH')    || define('CRAFT_TEMPLATES_PATH',    CRAFT_BASE_PATH.'templates/');
defined('CRAFT_TRANSLATIONS_PATH') || define('CRAFT_TRANSLATIONS_PATH', CRAFT_BASE_PATH.'translations/');
defined('YII_TRACE_LEVEL')          || define('YII_TRACE_LEVEL', 3);
// Load Yii
require_once CRAFT_APP_PATH.'framework/yiit.php';
Yii::$enableIncludePath = false;
require_once CRAFT_APP_PATH.'Craft.php';
require_once CRAFT_APP_PATH.'etc/web/WebApp.php';
require_once CRAFT_APP_PATH.'Info.php';
// Craft shits itself if there is no server or request path
$_SERVER['HTTP_HOST'] = 'dev.copywheat';
$_SERVER['REQUEST_URI'] = '/';
// Load test database
$config = require_once CRAFT_APP_PATH.'etc/config/test.php';
$config['params']['dbConfig'] = array();

// Create app instance
$app = new \Craft\WebApp($config);
// Load plugin
require_once CRAFT_PLUGINS_PATH.'myplugin/mypluginPlugin.php';
</code></pre>

<p>I'm still having issues with the db connection.  Have had to resort to modifying the <code>craft/app/etc/config/defaults.db</code> in order to override the environment file which does work for me at the moment.</p>

CC BY-SA 3.0
2017-12-12T11:06:04.850Z
2017-12-15T20:28:10.463Z
2017-12-15T20:28:10.463Z
dorothy Dorothy
<p>Has Craft stopped shipping with unit tests? I'm trying to unit test a plugin and have noticed from several previous answers (e.g <a href="https://craftcms.stackexchange.com/questions/16324/phpunit-testing-for-craft-plugins-or-controllers">PHPUnit testing for Craft plugins or controllers</a>) that it was possible at some stage using Craft's local tests. Have these since been removed? There no longer seems to be a tests folder inside the latest download of Craft/app.</p>

<p>What is the current best practice for setting up Unit Tests using Craft 2 in a plugin?</p>

CC BY-SA 3.0
2017-08-25T22:42:52.467Z
That's correct, Craft no longer ships with PHPunit included. It was removed in [Craft 2.5.2750](https://craftcms.com/changelog#2-5-2750), which was released on Dec 1, 2015.
Lindsey D
CC BY-SA 3.0
2017-08-25T22:48:11.847Z
So whats the best way to bootstrap craft for unit testing in a plugin?
lowe_22
CC BY-SA 3.0
2017-08-25T22:50:01.300Z
That I don't know. Sorry.
Lindsey D
<plugin-development><tests>
Unit Testing with current version of Craft
# Unit Testing with current version of Craft

(Asked by: username_0 on 2017-08-25)

Has Craft stopped shipping with unit tests? I'm trying to unit test a plugin and have noticed from several previous answers (e.g [PHPUnit testing for Craft plugins or controllers](https://craftcms.stackexchange.com/questions/16324/phpunit-testing-for-craft-plugins-or-controllers)) that it was possible at some stage using Craft's local tests. Have these since been removed? There no longer seems to be a tests folder inside the latest download of Craft/app.

What is the current best practice for setting up Unit Tests using Craft 2 in a plugin?

**Tags:** plugin-development, tests
> **Comments:**
> **username_1**: That's correct, Craft no longer ships with PHPunit included. It was removed in [Craft 2.5.2750](https://craftcms.com/changelog#2-5-2750), which was released on Dec 1, 2015.  
> **username_0**: So whats the best way to bootstrap craft for unit testing in a plugin?  
> **username_1**: That I don't know. Sorry.  

---

## 1 answers

### Answer by username_2 on 2017-12-12. Score: 1

I found a bootstrap that works for me apart from an issue with the database connection.
I can't find the link now but here is the code:

I'm still having issues with the db connection.  Have had to resort to modifying the craft/app/etc/config/defaults.db in order to override the environment file which does work for me at the moment.


---

