kaz29/file_fixture

CakePHP 文件测试插件

安装次数: 5,095

依赖者: 1

建议者: 0

安全: 0

星标: 7

关注者: 3

分支: 0

开放问题: 0

类型:cakephp-plugin

1.0.2 2014-02-20 02:37 UTC

This package is auto-updated.

Last update: 2024-09-23 10:21:37 UTC


README

Build Status

特性

  • 从 csv(逗号分隔值)/tsv(制表符分隔值)文件加载数据
  • 从 csv(逗号分隔值)/tsv(制表符分隔值)文件加载数据

需求

  • PHP >= 5.3.x
  • CakePHP >= 2.0

安装

将 'FileFixture' 目录放置在 CakePHP 应用程序的 app/Plugin 或 plugins 中。然后,在 bootstrap.php 中添加以下代码

<?php
    CakePlugin::load('FileFixture');

用法

FileTestFixture

app/Test/Fixture/PostFixture.php
<?php
App::uses('FileTestFixture', 'FileFixture.TestSuite/Fixture');
/**
 * PostFixture
 *
 */
class PostFixture extends FileTestFixture {

/**
 * Fields
 *
 * @var array
 */
		public $fields = array(
		'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 11, 'key' => 'primary'),
		'title' => array('type' => 'string', 'null' => true, 'length' => 50),
		'body' => array('type' => 'text', 'null' => true, 'length' => 1073741824),
		'created' => array('type' => 'datetime', 'null' => true),
		'modified' => array('type' => 'datetime', 'null' => true),
		'indexes' => array(
			'PRIMARY' => array('unique' => true, 'column' => 'id')
		),
		'tableParameters' => array()
	);

	public $importRecords = array(
		// 'path' => [path to Fixture File Path], // Optional(default is 'app/Test/Fixture/Data/')
		'file' => 'posts.csv',
	);
}

app/Test/Fixture/Data/posts.csv
title,body,created,modified
"The title","This is the post body.","2011-06-20 23:10:57","2011-06-20 23:10:57"
"A title once again","And the post body follows.","2011-06-20 23:10:57","2011-06-20 23:10:57"
"Title strikes back","This is really exciting! Not.","2011-06-20 23:10:57","2011-06-20 23:10:57"

FileImporter

<?php
	$result = FileImporter::load('Prefecture', TESTS.'Fixture'.DS.'Data'.DS.'prefectures.csv');

迁移插件 一起使用

<?php
class AddPrefectures extends CakeMigration {

...

	public function after($direction) {
		if ($direction === 'up') {
			App::uses('Post', 'Model');
			return FileImporter::load('Prefecture', TESTS.'Fixture'.DS.'Data'.DS.'prefectures.csv');
		}

		return true;
	}
	
…
}

许可证

MIT 许可证

版权所有 (c) 2013 Kaz Watanabe(https://github.com/kaz29/)

以下条件下,任何人有权免费获得本软件及其相关文档的副本(“软件”),自由使用该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许提供软件的个人这样做,前提是必须遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何形式的保证,无论是明示的、暗示的还是法定的,包括但不限于适销性、特定用途的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论该责任是因合同、侵权或其他原因产生,并源于、涉及或与软件或软件的使用或其他交易有关。