satthi / plugin-test-support
CakePHP PluginTestSupport
3.0
2015-07-06 06:40 UTC
Requires
- cakephp/cakephp: ~3.0
This package is auto-updated.
Last update: 2024-09-22 11:59:48 UTC
README
关于此插件
- 此插件是CakePHP3插件测试支持插件~~(有点复杂)~~
- 在编写插件测试时,如果进行常规测试,通常需要在app.php中的Datasources的test部分添加数据库连接,但如果想要单独测试插件,则没有这样的位置(应该是没有)。
- 看了bake的测试等,似乎是使用mock进行测试,但我想实际使用数据库进行测试,所以尝试制作了这个插件。
说实话,即使没有这个插件也可能能够做到同样的事情,但你怎么看呢?...
使用方法
① 在想要测试的插件的composer.json中添加以下内容,并执行update
{
"require-dev": {
"satthi/plugin-test-support": "dev-master"
},
}
② 在想要使用的测试中添加以下内容
<?php
namespace EncryptionSupport\Test\TestCase\Model\Table;
use App\Model\Table\AccountsTable;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
//以下をuse
use PluginTestSupport\Test\TestCase\AppTestCase;
/**
* App\Model\Table\AccountsTable Test Case
*/
//AppTestCaseをextendsする
class AccountsTableTest extends AppTestCase
{
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'plugin.encryption_support.accounts',
];
/**
* setUpBeforeClass method
* setUpBeforeClassをオーバーライドする
* @return void
*/
public static function setUpBeforeClass(){
//データベースの接続情報
$info = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Postgres',
'persistent' => false,
'host' => 'localhost',
//'port' => 'nonstandard_port_number',
'username' => 'postgres',
'password' => '',
'database' => 'cakephp_test',
'encoding' => 'utf8',
'timezone' => 'Asia/Tokyo',
'cacheMetadata' => false,
'quoteIdentifiers' => false,
];
parent::setConnectionInfo($info);
parent::setUpBeforeClass();
}
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
//fixtureManagerを呼び出し、fixtureを実行する
$this->fixtureManager->fixturize($this);
$this->fixtureManager->loadSingle('Accounts');
}
}