LoginSignup
1
1

More than 5 years have passed since last update.

PHP5.3.3 + Symfony0.6 + Propel で PHPUnit

Last updated at Posted at 2015-12-07

symfony0.6 も protel も creole も もうドキュメントがない
でもバグ出したくないし「たぶん大丈夫です」とか言いたくないからテストしたい

PHPUnit

まず、PHPUnit は 4.8 (old) を使う 4.8 はぎりぎり PHP 5.3.3 以上で動く
https://phpunit.de/manual/4.8/ja/installation.html
phar を wget してくるのがとても簡単だけど、4.8 は old なので、 phpunit-old.phar なのできをつける

autoload

ほんでautoloadとかそのへんをやってもらう
project/web/app/index.php がエントリポイント
そっから project/apps/app/config/config.php でいろいろめんどくさいことをやっている
とりあえずこれでだいたいなんとかなる

Protel

よっしゃよっしゃ、actionもテストしやすいように機能分割したし、インスタンスつくって
Protel::getConnection() やで〜〜
とおもったらめっちゃエラーがでる
ここで詰みすぎてもう死ぬしかないと思ったけど救世主現れた
http://www.ecoop.net/memo/archives/2007-09-05-1.html
このサンプルはたぶん symfony1 だと思うのね、symfony0.6 には sfCore とかないから
適当に動くようになんとかする

<?php

define('SF_ROOT_DIR'   , '/path/to/project');
define('SF_APP'        , 'app');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG'      , false);

require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

if (sfConfig::get('cookie_secure')) {
    ini_set('session.cookie_secure', '1');
}

set_include_path($sf_symfony_lib_dir . '/vendor' . PATH_SEPARATOR . SF_ROOT_DIR . PATH_SEPARATOR . get_include_path());

define('SF_ENVIRONMENT', 'test');
define('SF_DEBUG', true);

sfContext::getInstance();
Propel::setConfiguration(sfPropelDatabase::getConfiguration());
Propel::initialize();

require_once('/path/to/action.class.php');

class hogeTest extends PHPUnit_Framework_TestCase
{
    public function testHoge()
    {
        $this->assertEquals(1, 1);
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1