dakatsuka / blueprint-bundle
The bundle provides a way to manage test data for the Doctrine ORM
Installs: 7 648
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- doctrine/orm: >=2.2.3,<2.5-dev
Requires (Dev)
- mockery/mockery: dev-master@dev
This package is not auto-updated.
Last update: 2024-11-18 16:06:53 UTC
README
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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Test
$ make phpunit
$ make test
Copyright
Copyright (C) 2013 Dai Akatsuka, released under the MIT License.