2017 © Pedro Peláez
 

component sf-functional-test

Extra functionality for work with Symfony functional tests

image

php-solution/sf-functional-test

Extra functionality for work with Symfony functional tests

  • Thursday, July 26, 2018
  • by olesav
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1,003 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 32 Versions
  • 67 % Grown

The README.md

Symfony Functional Test

Install

bash $ composer require php-solution/sf-functional-test, (*1)

Load environment variables from files

Add to your phpunit.xml extension and configure paths (comma separated relative file paths from your phpunit.xml configuration file):, (*2)

<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunEnvLoaderExtension">
    <parameter name="paths" value="../.env,.env"/>
</bootstrap>

Load Doctrine fixtures before test cases

Add to your phpunit.xml extension:, (*3)

<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunCommandLauncherExtension">
     <parameter name="command" value="functional-test:fixtures:load"/>
    <!--Default is false. If true, if command's exit code > 0 then tests will fail immediately-->
    <parameter name="exitOnError" value="true" />
</bootstrap>

Run Doctrine migrations before test cases

Add to your phpunit.xml extension:, (*4)

<bootstrap class="\PhpSolution\FunctionalTest\PhpUnit\Extension\DoctrineMigrationExtension" />

Or simply:, (*5)

<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunCommandLauncherExtension">
    <parameter name="command" value="doctrine:migration:migrate --no-interaction"/>
    <parameter name="exitOnError" value="true" />
</bootstrap>

Run sf command with parameters

Add to your phpunit.xml extension:, (*6)

<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunCommandLauncherExtension">
    <parameter name="command" value="doctrine:mongodb:schema:drop --collection"/>
</bootstrap>

Run native command with parameters

Add to your phpunit.xml extension:, (*7)

<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunNativeCommandLauncherExtension">
    <parameter name="command" value="bin/console doctrine:mongodb:schema:drop --collection"/>
</bootstrap>

Using Test case additional functionallity PhpSolution\FunctionalTest\TestCase\AppTestCase

Using Authorization:

1) Add to your config_test.yml:, (*8)

security:
    firewalls:
        your_secured_category:
            http_basic: ~

2) Use on TestCase, (*9)

$client = $this->getAuthorizedClient('user_login', 'password');

Work with Doctrine (ORM, ODM)

  1. Add EntityTrait or DocumentTrait to your TestCase
$this->getDoctrine()
  1. Find Entity helper method:
protected function findEntity(string $entityClass, string $orderBy = 'id', array $findBy = [])
protected function findDocument(string $documentClass, array $criteria = [])
protected function findDocuments(string $documentClass, array $criteria = [], array $orderBy = [])
  1. Refresh Entity:
protected function refreshEntity($entity) 
protected function refreshDocument($document)

Test emails

  1. Add config
swiftmailer:
    disable_delivery: true
    spool:
        type: file
        path: '%kernel.project_dir%/var/spool'
    delivery_addresses: ~
  1. Add SpoolTrait and find methods
public function purgeSpool()
public function getSpooledEmails()
public function getEmailContent($file)
protected function getSpoolDir()

Example of correct project structure:

See correct project structure and configs for functional tests on link, (*10)

The Versions

06/02 2018

v4.0.2

4.0.2.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

15/12 2017

v4.0.1

4.0.1.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

15/12 2017

v4.1.0

4.1.0.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

14/12 2017

v4.0.0

4.0.0.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

30/11 2017

dev-master

9999999-dev

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

30/11 2017

v1.3

1.3.0.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

26/06 2017

v1.x-dev

1.9999999.9999999.9999999-dev

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

26/06 2017

v1.2.3

1.2.3.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

16/06 2017

v1.2.2

1.2.2.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

14/06 2017

v1.2.1

1.2.1.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

14/06 2017

v1.2

1.2.0.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

14/06 2017

v1.1

1.1.0.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

05/04 2017

v0.x-dev

0.9999999.9999999.9999999-dev

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

05/04 2017

v0.1.1

0.1.1.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

05/04 2017

v1.0

1.0.0.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko

05/04 2017

v0.1

0.1.0.0

Extra functionality for work with Symfony functional tests

  Sources   Download

MIT

The Requires

 

The Development Requires

by Oleksandr Savchenko