Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Blueprint Bundle Laravel Package

dakatsuka/blueprint-bundle

View on GitHub
Deep Wiki
Context7

Blueprint Bundle Build Status

The bundle provides a way to manage test data for the Doctrine ORM.

Installation

Add this lines to your composer.json:

{
    "require": {
        "dakatsuka/blueprint-bundle": "1.1.0"
    },
}

And then execute:

$ php composer.phar install

And import a BlueprintBundle to AppKernel.php:

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
    $bundles[] = new Dakatsuka\BlueprintBundle\DakatsukaBlueprintBundle();
}

Usage

src/Acme/BlogBundle/Tests/Blueprints/post.php:

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

src/Acme/BlogBundle/Tests/Blueprints/comment.php:

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

How to use:

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

Tips

Nested blueprint (required cascade={"persist"} option):

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

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Test

$ make phpunit
$ make test

Copyright

Copyright (C) 2013 Dai Akatsuka, released under the MIT License.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle