PHP code example of dakatsuka / blueprint-bundle
1. Go to this page and download the library: Download dakatsuka/blueprint-bundle 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/ */
dakatsuka / blueprint-bundle example snippets
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Dakatsuka\BlueprintBundle\DakatsukaBlueprintBundle();
}
namespace Acme\BlogBundle\Tests\Blueprints;
use Dakatsuka\BlueprintBundle\Blueprint;
Blueprint::register('post', 'Acme\BlogBundle\Entity\Post', function($post, $blueprint) {
$post->setTitle('Title'.$blueprint->sequence());
$post->setBody('BodyBodyBody');
});
namespace Acme\BlogBundle\Tests\Blueprints;
use Dakatsuka\BlueprintBundle\Blueprint;
Blueprint::register('comment', 'Acme\BlogBundle\Entity\Comment', function($comment, $blueprint) {
$comment->setPost($blueprint->create('post'));
$comment->setBody('CommentCommentComment');
});
static::$kernel = static::createKernel();
static::$kernel->boot();
static::$container = static::$kernel->getContainer();
$blueprint = static::$container->get('dakatsuka.blueprint');
$blueprint->loadFromDirectory(static::$kernel->getRootDir() . '/../src/Acme/BlogBundle/Tests/Blueprints');
$post = $blueprint->create('post');
$this->assertEquals('Title1', $post->getTitle());
$this->assertEquals('BodyBodyBody', $post->getBody());
$comment = $blueprint->create('comment');
$this->assertEquals('CommentCommentComment', $comment->getBody());
$this->assertEquals('Title2', $comment->getPost()->getTitle());
// optional
$comment2 = $blueprint->create('comment', array('post' => $post));
$this->assertSame($post, $comment2->getPost());
Blueprint::register('post', 'Acme\BlogBundle\Entity\Post', function($post, $blueprint) {
$post->setTitle('Title'.$blueprint->sequence());
$post->setBody('BodyBodyBody');
$post->getComments()->add($blueprint->build('comment', array('post' => $post));
$post->getComments()->add($blueprint->build('comment', array('post' => $post));
$post->getComments()->add($blueprint->build('comment', array('post' => $post));
});
bash
$ php composer.phar install