CodeIgniter 3.0ã§PHPUnitã使ã
CodeIgniter 2.xã®æ代ã«ã¯CIUnitã¨ãããã¼ã«ã使ããCodeIgniterã§PHPUnitã«ãããã¹ããæ¸ãã¦ãã¾ããã
CodeIgniter 3.0æ代ã«ãªãç¶æ³ãã©ãå¤ãã£ããã¨ããã¨ãCodeIgniteræ¬ä½ã®ãã¹ãã¯é²ãã ããã§ãããã¢ããªã±ã¼ã·ã§ã³ã®ãã¹ããã©ããããã¨ããåé¡ã¯å ¬å¼ã«ã¯ã¨ãã«å¤åã¯ãªãããã§ãã
ããã¦ãå®éã«ã©ã®ããã«ãã¦ãããã«ã¤ãã¦ã¯ãå²ã¨æ··æ²ã¨ãã¦ãã¾ããã
- fmalk/codeigniter-phpunit ... ä¸çªäººæ°ï¼
- Celc/CIUnit ... my-ciunitã®forkã3.0æªå¯¾å¿ï¼
- RodolfoSilva/CIUnit-for-CI3 ... CIUnit-for-CI2ã®fork
- NEKOGET/CIUnit-for-CI3 ... CIUnit-for-CI2ã®fork
- PHPUnit and CodeIgniter 3.0 | SpiderSoft
以ä¸ã®ãããªæ¹æ³ã»ãã¼ã«ãããããã§ãã
å人çã«ã§ããã ãCodeIgniteræ¬ä½ã«æãå ¥ããã«PHPUnitã使ãããã¨èãã¦ãã¾ããããããã ã¨ãããã®ã¯ããã¾ããã§ããã
ci-phpunit-test
ããã§ãci-phpunit-testãã¨ãããã¼ã«ãä½æãã¾ããã
ã¤ã³ã¹ãã¼ã«æ¹æ³
ãã¦ã³ãã¼ã
(2015-06-12 æ´æ°)
GitHubããææ°çï¼https://github.com/kenjis/ci-phpunit-test/releasesï¼ããã¦ã³ãã¼ããã¦å±éãã¾ãã
以ä¸ã®ãããªãã©ã«ãæ§æã«ãªã£ã¦ãã¾ãããã®application/tests
ãã©ã«ããèªåã®CodeIgniterããã¸ã§ã¯ãã®application/tests
ã¨ãã¦ã³ãã¼ãã¾ãã
ci-phpunit-test/
âââ application/
â  âââ database/
â  âââ helpers/
â  âââ libraries/
â  âââ tests/
âââ bin/
âââ docs/
application
ãã©ã«ãã®ãã®ä»ã®ãã¡ã¤ã«ã¯ãµã³ãã«ã§ããå¿
è¦ã«å¿ãã¦CodeIgniterããã¸ã§ã¯ãã«ã³ãã¼ãã¦ãã ããï¼å¾è¿°ï¼ã
ãã¹ã®èª¿æ´
(2015-06-15 追è¨) ãã®æé ã¯ci-phpunit-test v0.1.1以éä¸è¦ã«ãªãã¾ããã
ci-phpunit-testã¯ããã©ã«ãã§ã¯ãCodeIgniter Composer Installerã«ãã以ä¸ã®ãã©ã«ãæ§æãåæã¨ãã¦ãã¾ãã
codeigniter/
âââ application/
âââ public/
â âââ index.php
âââ vendor/
âââ codeigniter/
âââ framework/
âââ system/
ãã©ã«ãæ§æãéãå ´åï¼CodeIgniterã®ããã©ã«ãã®ãã©ã«ãæ§æã®å ´åãå«ãï¼ãapplication/tests/Bootstrap.php
ãã¡ã¤ã«ãã¨ãã£ã¿ã§éãã以ä¸ã®ãã¹ã調æ´ãã¦ãã ããã
$system_path = '../../vendor/codeigniter/framework/system';
$application_folder = '../../application';
define('FCPATH', realpath(dirname(__FILE__).'/../../public').'/');
FCPATH
ã¯index.php
ããããã©ã«ãã§ãã
(2015-06-12 追è¨)
CodeIgniteræ¨æºã®ãã©ã«ãæ§æã®å ´åã¯ã以ä¸ã®ããã«å¤æ´ãã¾ãã
--- a/application/tests/Bootstrap.php
+++ b/application/tests/Bootstrap.php
@@ -102,7 +102,7 @@ switch (ENVIRONMENT)
* Include the path if the folder is not in the same directory
* as this file.
*/
- $system_path = '../../vendor/codeigniter/framework/system';
+ $system_path = '../../system';
/*
*---------------------------------------------------------------
@@ -230,7 +230,7 @@ switch (ENVIRONMENT)
define('BASEPATH', str_replace('\\', '/', $system_path));
// Path to the front controller (this file)
- define('FCPATH', realpath(dirname(__FILE__).'/../../public').'/');
+ define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');
// Name of the "system folder"
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
ããã§ã¤ã³ã¹ãã¼ã«å®äºã§ãã
ãã¹ãã®å®è¡æ¹æ³
PHPUnitã¯å¥éã¤ã³ã¹ãã¼ã«ãã¦ãã ããã
$ cd /path/to/codeigniter/
$ cd application/tests/
$ phpunit
PHPUnit 4.1.6 by Sebastian Bergmann.
Configuration read from /.../codeigniter/application/tests/phpunit.xml
.
Time: 470 ms, Memory: 3.50Mb
OK (1 test, 1 assertion)
Generating code coverage report in Clover XML format ... done
Generating code coverage report in HTML format ... done
ãã¹ãã®æ¸ãæ¹
ã¢ãã«
(2015-08-15 追è¨) setUp()ã¡ã½ããã®ã³ã¼ããæ´æ°ãã¾ããã
tests/models/Inventory_model_test.php
<?php
class Inventory_model_test extends TestCase
{
public function setUp()
{
$this->resetInstance();
$this->CI->load->model('shop/Inventory_model');
$this->obj = $this->CI->Inventory_model;
}
public function test_get_category_list()
{
$expected = [
1 => 'Book',
2 => 'CD',
3 => 'DVD',
];
$list = $this->obj->get_category_list();
foreach ($list as $category) {
$this->assertEquals($expected[$category->id], $category->name);
}
}
public function test_get_category_name()
{
$actual = $this->obj->get_category_name(1);
$expected = 'Book';
$this->assertEquals($expected, $actual);
}
}
ãã¹ãã±ã¼ã¹ã¯ã©ã¹ã¯TestCase
ã¯ã©ã¹ãç¶æ¿ãã¾ãã
setUpBeforeClass()
ã¡ã½ããããªã¼ãã¼ã©ã¤ãããå ´åã¯ãå¿ããã«parent::setUpBeforeClass();
ã追å ãã¦ãã ããã
ãã¼ã¿ãã¼ã¹ã·ã¼ãã£ã³ã°
ãã¦ã³ãã¼ããããã¡ã¤ã«ã®application/libraries/Seeder.php
ã¨application/database/seeds/CategorySeeder.php
ã«ãµã³ãã«ã³ã¼ããå«ã¾ãã¦ãã¾ãã
ã¤ã³ã¹ãã¼ã«ããã¦ãªãã®ã§ã使ãããå ´åã¯æåã§ã³ãã¼ãã¦ãã ããã
Seeder
ã¯ã©ã¹ã¯ä»¥ä¸ã®ããã«ä½¿ç¨ãã¾ãã
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$CI =& get_instance();
$CI->load->library('Seeder');
$CI->seeder->call('CategorySeeder');
}
ã³ã³ããã¼ã©
(2017-02-15 追è¨) ãã¹ãã³ã¼ããæ´æ°ãã¾ããã
tests/controllers/Welcome_test.php
<?php
class Welcome_test extends TestCase
{
public function test_index()
{
$output = $this->request('GET', 'welcome/index');
$this->assertContains('<title>Welcome to CodeIgniter</title>', $output);
}
}
TestCase
ã¯ã©ã¹ã«ã¯$this->request()
ã¡ã½ãããå®ç¾©ããã¦ãã¾ãã
ä»ã®ãµã³ãã«
ãã£ã¨ãã¹ããè¦ããå ´åã¯ã以ä¸ã®ã¢ããªã®ãã¹ããåç §é¡ãã¾ãã
ãªãããã®ã¢ããªã®ã³ã¼ãã¬ãã¥ã¼ãåéãã¦ãã¾ãã
ã¾ã¨ã
- ci-phpunit-testã使ãã¨ç°¡åã«CodeIgniter 3.0ã§PHPUnitã®ãã¹ããæ¸ããã¨ãã§ãã¾ã
- CodeIgniteræ¬ä½ã®ãã¡ã¤ã«ã¯ä¸åå¤æ´ãã¾ãã
ï¼ã¨ã¯ãããå®ã¯å é¨çã«ã¯CodeIgniterã®ã¯ã©ã¹ãé¢æ°ãä¸é¨å¤æ´ãã¦ãã¾ãï¼
ãã£ã¨ç¥ãã«ã¯ï¼
(2015-08-25 追è¨)
CodeIgniter 3.0ã§ã®PHPUnitããã³ci-phpunit-testã®ä½¿ãæ¹ã«ã¤ãã¦ããã£ã¨ç¥ãããæ¹ã¯ä»¥ä¸ã®è¨äºãã覧ä¸ããã
- ã¤ãããã®CodeIgniterã§PHPUnitå ¥é - Qiita
- ã¤ãããã®CodeIgniterã§PHPUnitå ¥éï¼Composerä¸ä½¿ç¨ç·¨ï¼ - Qiita
- CodeIgniterã¨PHPUnitã§ãã¹ããé£ããã³ã¼ããç°¡åã«ãã¹ãããï¼ãªãã¸ã§ã¯ãã¡ã½ããã®ç½®æï¼
- ci-phpunit-testã使ã£ã¦åç°å人ããã®ãç¾å¨æå»ã«ä¾åãããã¹ãããæ¸ãã¦ã¿ã
- ci-phpunit-testã§singletonãªã¯ã©ã¹ãå¼ã³åºãã¦ãã¡ã½ããããã¹ããã - Qiita
- ci-phpunit-test v0.4.0ããªãªã¼ã¹ãã¾ãã
- ci-phpunit-testã®ã¢ã³ãã¼ãããæ©è½ã§exitãä¾å¤ã«å¤æããã¨ãã®ãããã°æ¹æ³
é¢é£
- CodeIgniter 3.0ã®ã¢ããªãã³ã¼ãã¬ãã¥ã¼ãã¦ãã ãã
- Codeigniter 3.0ã§ãã¤ã°ã¬ã¼ã·ã§ã³ãCLIããæä½ããCli for CodeIgniter
- Codeigniter 3.0ãã³ãã³ãä¸çºã§ã¤ã³ã¹ãã¼ã«ããCodeIgniter Composer Installer
- CodeIgniter 3ã®ã©ã¤ã»ã³ã¹ãMITã©ã¤ã»ã³ã¹ã«å¤æ´ãããããããã©ã¤ã»ã³ã¹åé¡ã¯å®å ¨ã«è§£æ¶
- CodeIgniterã®æ°åãCodeIgniter Web Application Blueprintsããåºã¦ã¾ãã
- 2015å¹´ææ°PHPãã¬ã¼ã ã¯ã¼ã¯ï¼9ã¤ï¼ã®ãã³ããã¼ã¯
Date: 2015/05/19