2017 © Pedro Peláez
 

library test-bundle

SeegnoTestBundle

image

seegno/test-bundle

SeegnoTestBundle

  • Monday, March 20, 2017
  • by fixe
  • Repository
  • 8 Watchers
  • 2 Stars
  • 809 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

SeegnoTestBundle

Latest Version Build Status Code Climate Test Coverage License, (*1)

Introduction

This Bundle provides base classes for unit and integration tests in order to assist in setting test databases and data fixtures., (*2)

Installation

1. Download SeegnoTestBundle using composer

Install SeegnoTestBundle by running the command:, (*3)

``` bash $ composer require --dev seegno/test-bundle, (*4)


#### 2. Enable the bundle Enable the bundle in the kernel: ``` php <?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), (*5)

Please add the following configuration in config_test.yml:, (*6)

seegno_test:
    database:
        driver: ORM # Types available: ORM (SQL) and ODM (MongoDB)

Warning!!, (*7)

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., (*8)

Usage

Unit tests

use Seegno\TestBundle\TestCase\BaseTestCase;

class SomeClassTest extends BaseTestCase
{
    //...
}

Available features:, (*9)

$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:, (*10)

$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:, (*11)

$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., (*12)

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:, (*13)

phpunit

The Versions