PHP code example of chustilla / cakephp-model-factory
1. Go to this page and download the library: Download chustilla/cakephp-model-factory 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/ */
chustilla / cakephp-model-factory example snippets
use App\Model\Entity\Bar;
use Faker\Generator as Faker;
$factory->define(Bar::class, function (Faker $faker) {
return [
'id' => $faker->numberBetween(1, 1000),
'name' => $faker->name,
];
});
# tests/bootstrap.php
use Chustilla\ModelFactory\Factory;
Factory::getInstance()->loadFactories('absolute/or/relative/path/to/models/definitions/directory');
# tests/TestCase/Unit/Service/FooServiceTest.php
use Cake\TestSuite\TestCase;
class FooServiceTest extends TestCase
{
public function testMethod()
{
// Arrange
$bar = factory(Bar::class)->create();
...
}
}
# tests/TestCase/Unit/Service/FooServiceTest.php
use Cake\TestSuite\TestCase;
use Chustilla\ModelFactory\DatabaseCleanUp;
class FooServiceTest extends TestCase
{
use DatabaseCleanUp;
public function testMethod()
{
// Arrange
$bar = factory(Bar::class)->create();
...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.