2017 © Pedro Pelรกez
 

symfony-bundle functional-test-bundle

symfony bundle for optimised functional testing with alice and doctrine bundle

image

i22/functional-test-bundle

symfony bundle for optimised functional testing with alice and doctrine bundle

  • Friday, March 9, 2018
  • by nijusan
  • Repository
  • 6 Watchers
  • 0 Stars
  • 370 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 741 % Grown

The README.md

i22 Functional Test Bundle

A Symfony bundle to simplify functional testing with the help of AliceBundle., (*1)

Table of contents: - Installation - Basic usage - Seperate fixture files - Authorize User - Fake Translator - Disabling Csrf Form Protection, (*2)

Installation

  1. Download the Bundle, (*3)

    $ composer require --dev i22/functional-test-bundle
    
  2. Enable the Bundle, (*4)

    With Symfony 3.x adding the Bundle to app/AppKernel.php, (*5)

    <?php
    
    class AppKernel extends Kernel
    {
      public function registerBundles()
      {
          // ...
          if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
              // ...
              if ('test' === $this->getEnvironment()) {
                  $bundles[] = new I22\FunctionalTestBundle\I22FunctionalTestBundle();
              }
          }
    
          return $bundles;
      }
    
      // ...
    }
    

    With Symfony 4.x adding the Bundle to config/bundles.php\ (Should be done with auto-configuration, but activated for all environments), (*6)

    <?php 
    
    return [
      // ...
      I22\FunctionalTestBundle\I22FunctionalTestBundle::class => ['test' => true],
    ];
    
    

Basic usage

Loading fixtures for each test class

Instead of setting up the database with one big fixture file for all tests you can define seperate small fixture-sets customized for your test case., (*7)

Setup your Test Class to extend from WebTestCase, (*8)

```php <?php, (*9)

use I22\FunctionalTestBundle\Test\WebTestCase;, (*10)

class MyControllerTest extends WebTestCase {, (*11)

} ```, (*12)

In order to load your customized fixtures automatically place a fixture folder with your fixtures beneath your test file, (*13)

. โ””โ”€โ”€ tests/ โ”œโ”€โ”€ ... โ””โ”€โ”€ Controller/ โ””โ”€โ”€ MyControllerTest/ โ”œโ”€โ”€ fixtures/ โ”œ โ”œโ”€โ”€ users.yaml โ”œ โ”œโ”€โ”€ ... โ””โ”€โ”€ MyControllerTest.php, (*14)

If you want do define from where to load your fixtures, you can override the method getFixtureFilePaths(), (*15)

```php <?php, (*16)

use I22\FunctionalTestBundle\Test\WebTestCase;

class MyControllerTest extends WebTestCase
{
    protected function getFixtureFilePaths() : array
    {
        return [
            __DIR__.'/../../global-fixtures/users.yaml',                
        ];
    }
}

```, (*17)

Authorize User

in case u need to authorize a user for your functional test, you can use the UserAuthorizationTrait to login the user., (*18)

```php <?php, (*19)

  use I22\FunctionalTestBundle\Security\Authorization\UserAuthorizationTrait;
  use I22\FunctionalTestBundle\Test\WebTestCase;

  class MyControllerTest extends WebTestCase
  {
      use UserAuthorizationTrait;

      public function setUp()
          {
              parent::setUp();
              $user = $this->getDoctrine()->getRepository('App:User')->findOneBy(['email' => 'test@i22.de']);
              $this->login($user);
          }
  }

```, (*20)

the login method assumes that your firewall is named 'default'. in other cases use the second argument of the login method to specify how your firewall is named., (*21)

No Translator - working with translation keys

the bundle autoconfigures a FakeTranslator in test environment as the @default.translator service, so that instead of translating your translation keys, the translator will respond the original key., (*22)

for testing purpose it is usefull to test against the key instead of changing translations., (*23)

if you want to disable this feature, change the default configuration as follows:, (*24)

```yaml #config/packages/test/i22_functional_test.yaml, (*25)

i22_functional_test: use_fake_translator: false ```, (*26)

Disabled auto csrf protection for forms

the bundle autoconfigures the symfony form with disabling the auto protection of forms instead of disabling the whole csrf protection services. so you are able to still use the csrf token manager to generate and use tokens for validation, but it simplifies the form post handling, because you dont need to add the _token value, (*27)

if you want to disable this feature, change the default configuration as follows:, (*28)

```yaml #config/packages/test/i22_functional_test.yaml, (*29)

i22_functional_test:
    disable_csrf_form_protection: false

```, (*30)

The Versions

09/03 2018

dev-master

9999999-dev

symfony bundle for optimised functional testing with alice and doctrine bundle

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Dennis Langen

09/03 2018

v1.0.2

1.0.2.0

symfony bundle for optimised functional testing with alice and doctrine bundle

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Dennis Langen

09/03 2018

v1.0.1

1.0.1.0

symfony bundle for optimised functional testing with alice and doctrine bundle

  Sources   Download

proprietary

The Requires

 

The Development Requires

by Dennis Langen

09/03 2018