1. Go to this page and download the library: Download unionofrad/li3_fixtures library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
//app/models/Contact.php
namespace app\models;
class Contacts extends \lithium\data\Model {}
//app/tests/integration/Sample2Test.php
namespace app\tests\integration;
use li3_fixtures\test\Fixtures;
use app\models\Contacts;
use app\models\Images;
// and so on...
class Sample2Test extends \lithium\test\Unit {
public function setUp() {
Fixtures::config([
'db' => [
'adapter' => 'Connection',
'connection' => 'lithium_mysql_test',
'fixtures' => array(
'contacts' => 'app\tests\fixture\ContactsFixture',
'images' => 'app\tests\fixture\ImagesFixture'
// and so on...
)
]
]);
Fixtures::save('db');
}
public function tearDown() {
Fixtures::clear('db');
}
public function testFixture() {
var_export(Contacts::find('all')->data());
var_export(Images::find('all')->data());
}
}
Fixtures::save('db', array('contacts'));
//The line bellow is not needed since Contacts have been configured by ContactsFixture.
Contacts::config(['meta' => ['connection' => 'lithium_mysql_test']]);
var_export(Contacts::find('all')->data());
$fixture->alter('add', [
'name' => 'enabled',
'type' => 'boolean'
]); //Add a field
$fixture->alter('change', [
'name' => 'published',
'value' => function ($val) {
return new MongoDate(strtotime($val));
}
]); //Simple cast for fixture's values according the closure
$fixture->alter('change', [
'name' => 'id',
'to' => '_id',
'value' => function ($val) {
return new MongoId('4c3628558ead0e594' . (string) ($val + 1000000));
}
]); //Renaming the field 'id' to '_id' + cast fixture's values according the closure
$fixture->alter('change', [
'name' => 'bigintger',
'type' => 'integer',
'use' => 'bigint' //use db specific type
]); //Modifing a field type
$fixture->alter('drop', 'bigintger'); //Simply dropping a field
$fixture = Fixtures::get('db', 'contacts');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.