seegno/test-bundle
最新稳定版本:2.0.1
Composer 安装命令:
composer require seegno/test-bundle
包简介
SeegnoTestBundle
README 文档
README
Introduction
This Bundle provides base classes for unit and integration tests in order to assist in setting test databases and data fixtures.
Installation
1. Download SeegnoTestBundle using composer
Install SeegnoTestBundle by running the command:
$ composer require --dev seegno/test-bundle
2. Enable the bundle
Enable the bundle in the kernel:
<?php // app/AppKernel.php public function registerBundles() { // ... if (in_array($this->getEnvironment(), array('test'))) { // ... $bundles[] = new Seegno\TestBundle\SeegnoTestBundle(); } }
3. Prepare your Application for tests
Integration (functional)
Please add the following configuration in config_test.yml:
seegno_test: database: driver: ORM # Types available: ORM (SQL) and ODM (MongoDB)
Warning!!
It's very important that you configure a different database for tests in your config_test.yml file since all data is purged from the database in integration tests.
Usage
Unit tests
use Seegno\TestBundle\TestCase\BaseTestCase; class SomeClassTest extends BaseTestCase { //... }
Available features:
$this->getFaker(); // Get a faker instance. $this->setReflectionProperty($class, $propertyName, $propertyValue); // Set a class property using reflection.
Integration tests
use Seegno\TestBundle\TestCase\IntegrationTestCase; class SomeClassTest extends IntegrationTestCase { //... }
Available features:
$this->getContainer(); // Get an instance of the dependency injection container. $this->getSession(); // Get session. $this->get('SERVICE'); // Get services. $this->initializeDatabase(); // Initialize test database (SQL or MongoDB).
Web tests
use Seegno\TestBundle\TestCase\WebTestCase; class SomeClassTest extends WebTestCase { //... }
Available features:
$this->authenticateUser($client, $user, $credentials, $roles, $firewall); // Authenticate a user. $this->getClient(); // Get client that simulates a browser and makes requests to a Kernel object. $this->assertResponseFields($response, $object, $groups); // Assert that object properties keys are in the response.
Run tests
Before running the tests, make sure you have the test database updated.
php app/console doctrine:database:drop --env=test --force php app/console doctrine:database:create --env=test php app/console doctrine:schema:create --env=test
To run the tests on your local machine, just use the phpunit command:
phpunit
统计信息
- 总下载量: 1.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-28