2017 © Pedro Peláez
 

cakephp-plugin file_fixture

FileFixture Plugin for CakePHP

image

kaz29/file_fixture

FileFixture Plugin for CakePHP

  • Thursday, February 20, 2014
  • by kaz29
  • Repository
  • 2 Watchers
  • 7 Stars
  • 3,344 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

FileFixture Plugin for CakePHP2.x

Build Status, (*1)

Feature

  • Load fixture data from csv(Comma-Separated Values)/tsv(TAB-Separated Values) file
  • Load master data from csv(Comma-Separated Values)/tsv(TAB-Separated Values) file

Requirements

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

Installation

Put 'FileFixture' directory on app/Plugin or plugins in your CakePHP application. Then, add the following code in bootstrap.php, (*2)

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

Usage

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');

Use with Migrations Plugin

<?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;
    }

…
}

License

The MIT License, (*3)

Copyright (c) 2013 Kaz Watanabe(https://github.com/kaz29/), (*4)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*5)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*6)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*7)

The Versions

20/02 2014

dev-master

9999999-dev https://github.com/kaz29/FileFixture

FileFixture Plugin for CakePHP

  Sources   Download

MIT

The Requires

 

debug migrations cakephp fixture

20/02 2014

1.0.2

1.0.2.0 https://github.com/kaz29/FileFixture

FileFixture Plugin for CakePHP

  Sources   Download

MIT

The Requires

 

debug migrations cakephp fixture

19/02 2014

1.0.1

1.0.1.0 https://github.com/kaz29/FileFixture

FileFixture Plugin for CakePHP

  Sources   Download

MIT

The Requires

 

debug migrations cakephp fixture

19/02 2014

1.0.0

1.0.0.0 https://github.com/kaz29/FileFixture

FileFixture Plugin for CakePHP

  Sources   Download

MIT

The Requires

 

debug migrations cakephp fixture