Skip to content

Commit e341daf

Browse files
committed
初期コミット
1 parent 7017ab0 commit e341daf

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/composer.phar
2+
/composer.lock
3+
/phpunit.xml
4+
/vendor

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "satthi/plugin-test-support",
3+
"description": "CakePHP PluginTestSupport",
4+
"type": "cakephp-plugin",
5+
"keywords": ["cakephp", "test", "plugin"],
6+
"homepage": "https://github.com/satthi/plugin-test-support",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Satoru Hagiwara",
11+
"role": "Author"
12+
}
13+
],
14+
"support": {
15+
"source": "https://github.com/satthi/plugin-test-support"
16+
},
17+
"require": {
18+
"cakephp/cakephp": "~3.0"
19+
},
20+
"require-dev": {
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"PluginTestSupport\\Test\\": "tests"
25+
}
26+
},
27+
"autoload-dev": {
28+
},
29+
"suggest": {
30+
},
31+
"extra": {
32+
}
33+
}

tests/TestCase/AppTestCase.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
namespace PluginTestSupport\Test\TestCase;
3+
4+
use Cake\TestSuite\TestCase;
5+
use Cake\Datasource\ConnectionManager;
6+
use Cake\TestSuite\Fixture\FixtureManager;
7+
use Cake\Core\Configure;
8+
use Cake\Cache\Cache;
9+
10+
/**
11+
* AppTestCase
12+
* テストのベース設定
13+
*/
14+
class AppTestCase extends TestCase
15+
{
16+
static protected $_connectionInfo = [
17+
'className' => 'Cake\Database\Connection',
18+
'driver' => 'Cake\Database\Driver\Postgres',
19+
'persistent' => false,
20+
'host' => 'localhost',
21+
//'port' => 'nonstandard_port_number',
22+
'username' => 'postgres',
23+
'password' => '',
24+
'database' => 'cakephp_test',
25+
'encoding' => 'utf8',
26+
'timezone' => 'Asia/Tokyo',
27+
'cacheMetadata' => false,
28+
'quoteIdentifiers' => false,
29+
];
30+
31+
static protected $_appInfo = 'App';
32+
33+
public static function setUpBeforeClass(){
34+
parent::setUpBeforeClass();
35+
//データベース接続設定
36+
$connectionInfo = self::$_connectionInfo;
37+
38+
//cacheの設定はしていないためcacheを無効にする
39+
Cache::disable();
40+
41+
//defaultは使わないがいないとエラーになるのでテストと同じものを設定する
42+
Configure::write('Datasources.default',$connectionInfo);
43+
Configure::write('Datasources.test',$connectionInfo);
44+
ConnectionManager::config(Configure::consume('Datasources'));
45+
46+
//APPが定義されていないとエラーになるため。(逆に何か設定してあればとりあえず動くみたい?)
47+
if (!defined('APP')){
48+
define('APP', self::$_appInfo);
49+
}
50+
}
51+
52+
/**
53+
* setUp method
54+
*
55+
* @return void
56+
*/
57+
public function setUp()
58+
{
59+
parent::setUp();
60+
//fixtureManagerを呼び出し、fixtureを実行する
61+
$this->fixtureManager = new FixtureManager();
62+
}
63+
64+
/**
65+
* tearDown method
66+
*
67+
* @return void
68+
*/
69+
public function tearDown()
70+
{
71+
//fixtureの終了
72+
$this->fixtureManager->shutdown();
73+
unset($this->fixtureManager);
74+
parent::tearDown();
75+
}
76+
77+
/**
78+
* tearDownsetConnectionInfo method
79+
*
80+
* @return void
81+
*/
82+
protected function setConnectionInfo($info){
83+
//接続情報を変更する
84+
self::$_connectionInfo = $info;
85+
}
86+
87+
protected function setAppInfo($info){
88+
//APP情報を変更する
89+
self::$_appInfo = $info;
90+
}
91+
92+
}

0 commit comments

Comments
 (0)