5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cakephp3でのphpunitの備忘録

Last updated at Posted at 2017-02-27

自動テストをしてくれと頼まれてcakephp3&phpunitでコードを書いていたのですが、備忘録的に小ネタを。

セッションの引き継ぎ

HogeControllerTest.php
$this->post ( url1 );
$this->post ( url2 );

と書くとurl1で作ったセッションがurl2に渡らない、そんなときは

HogeControllerTest.php
$this->post ( url1 );
$this->session ( $this->_requestSession->read () );
$this->post ( url2 );

セッションに値を渡したい

HogeControllerTest.php
$this->session(['aaa'=>'bbb']);

セッションの検証

HogeControllerTest.php
$this->assertSession ( ['エラー'], 'errors');

セッションの取得

HogeControllerTest.php
$hoge = $this->_requestSession->read ('aaa');

set()された値の取得

HogeControllerTest.php
$hoge = $this->viewVariable ( 'aa' );

これで一通りのテストコードを書くことができます

5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?