dakatsuka/blueprint-bundle
Composer 安装命令:
composer require dakatsuka/blueprint-bundle
包简介
The bundle provides a way to manage test data for the Doctrine ORM
关键字:
README 文档
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.
统计信息
- 总下载量: 7.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-05-11