cakephp

モデルのスタブ

getMockBuilder('Post') ->setConstructorArgs(array(false, 'posts', 'test')) ->setMethods(array('doSomething')) ->getMock(); $stub->expects($this->any()) ->method('doSomething') ->will($this->returnValue('foo'));

JenkinsでCakeBehat

Behat/Minkのテストはブラウザでアクセスされるので、テスト時はtestデータソースを使用するように工夫が必要。 The Opera blog あと、アクセス先のテスト用DBの初期化、後始末が必要。も一つ、ciサーバ内で完結するなら、ciサーバ上でのwebサーバ設定が必要…

CakeBehat

https://github.com/oppara/CakeBehat もろもろ動かなかったのでとりあえずフォーク インストールとか 直の場合 % cd /path/to/cake_root/app/Plugin % git clone https://github.com/oppara/CakeBehat.gitsubmoduleの場合 % cd /path/to/cake_root % git su…

Set::extract()

http://book.cakephp.org/2.0/en/core-utility-libraries/set.html Deprecated since version 2.2: The Set class has been deprecated in 2.2 in favour of the Hash class. It offers a more consistent interface and API.

テスト毎にfixtureを用意する

http://book.cakephp.org/2.0/en/development/testing.html#dynamic-data-and-fixtures 作成済みのテーブルからスキーマを読み込む 手動でfixtureロード

Migrations Plugin for CakePHP

GitHub - CakeDC/migrations: Migrations Plugin for CakePHP Migrationsプラグインの実践的運用 - 24時間CakePHP インストール % cd /path/to/CAKE_ROOT % git submodule add https://github.com/CakeDC/migrations.git app/Plugin/Migrations % git subm…

unite-cake.vim

https://github.com/oppara/vim-unite-cake(unite-rails をパク参考にしました) ただし、見様見真似なため、emptyファイルを無視できず... できた!

Paginator::prev(), Paginator::next()のバグ?

1ページしかない時、disabledOptionsがemptyでない場合、escape => false が無視される。 escapeさせる場合は、disabledOptionsにescapeの設定を追加する必要がある。 false ); $disabled_options = array( 'class' => 'disabled' ); echo $this->Paginator…

.htaccessで相対パス対応

例えば ../img/foobar/hoge.png を img/foobar/hoge.png にしたい 画像は、webroot/img/の中に全て入ってるという条件 RewriteRule ^.*\/((img|js|css)\/.*\.(png|gif|jp?g|js|css))$ $1 [NC,L]

Controllerのテスト(redirect)

CakePHP 1.3.8 testAction()すると、モノホンのdispatcherが呼ばれる模様。 なので、テストケースのファイルにテストコントローラを書いても、testAction()時は無視されるし、 routing書き換えても、testAction()時のコントローラと、startTest()時のコント…

Router::connect

CakePHP 1.3.6お題:UsersController::mobile_hoge()を呼び出す以下のurlを出力してみる /m/139c765e92697cb6b5cb096066d462d5/hoge?foo=bar routes.php 'users', 'action' => 'hoge', 'prefix' => 'mobile', 'mobile' => true), array('var' => '[a-zA-Z0-…

バリデーションメッセージをDryにしつつ国際化

id:cakephper:20090727メッセージは別ファイルで管理してみる。 config/error_messages.php __( 'hoge', true ), 'email_invalid' => __( 'moge', true ), 'between' => __( 'hage', true ), ); config/bootstrap.php

プラグイン三段活用

id:slywalker:20090523 スライドを見た理解 HogeComponentを以下に置いて/path/to/plugins/tools/hoge.php config/bootstrap.phpに設定すると $pluginPaths = array( '/path/to/plugins' . DS ); あら、不思議。 var $components = array( 'Plugin.Hoge' ); …