Coder Social home page Coder Social logo

seegnotestbundle's Introduction

SeegnoTestBundle

Latest Version Build Status Code Climate Test Coverage License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.