Skip to content

Instantly share code, notes, and snippets.

@gomasaba
Created October 3, 2011 03:54
Show Gist options
  • Save gomasaba/1258403 to your computer and use it in GitHub Desktop.
Save gomasaba/1258403 to your computer and use it in GitHub Desktop.
CakephpでテストデータにYamlを簡単に使う方法メモ

php-yaml がなければインストール

  • centos5
yum install php-pecl-yaml

Test/Case/Fixture/***Fixture.phpを変更

class PostFixture extends CakeTestFixture {
	public function __construct(){
		$yaml = dirname(__FILE__).DS.'yaml'.DS.__Class__.'.yml';
		$this->records = yaml_parse_file($yaml);
		parent::__construct();
	}

Test/Case/Fixture/yaml/***Fixture.yamlの中身

0:
id: 1
name: テスト投稿1
created: 1314937039
modified: 1315553097
1:
id: 2
name: テスト投稿2
created: 1314937039
modified: 1315553097

  • fieldsもyamlにするなら、
id :
	type: integer
	'null':
	default:
	key : primary
	collate :
	comment :
name :
	type: string
	'null':
	default:
	key : primary
	collate :
	comment :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment