PHPackages                             imatic/testing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. imatic/testing

ActiveLibrary[Testing &amp; Quality](/categories/testing)

imatic/testing
==============

Library to make testing of Symfony bundles easier

v6.0.4(3y ago)02.9k6MITPHPPHP ^7.4 || ^8.0CI failing

Since Jul 14Pushed 3y ago7 watchersCompare

[ Source](https://github.com/imatic/testing)[ Packagist](https://packagist.org/packages/imatic/testing)[ Docs](https://www.imatic.cz)[ RSS](/packages/imatic-testing/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (22)Used By (6)

[![Build Status](https://camo.githubusercontent.com/069f82ff1b049694d7b26bd53a4e65106062395b73bd1e0512b021409fb8d546/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f696d617469632f74657374696e672e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/imatic/testing)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)Testing
-------

[](#testing)

This library makes it easy to setup tests including testing project for reusable bundles. It will create all required files so that you can start writing your tests and visualise components of your bundle without necessity of including it into some application (as this library creates such application in testing namespace of your bundle).

Content
-------

[](#content)

- [Initialize testing project](#initialize-testing-project)
- [PHPUnit](#phpunit)
- [Usage](#usage)
- [Checking your testing project in browser](#checking-your-testing-project-in-browser)
- [Writing tests working with database](#writing-tests-working-with-database)
- [Testing project configuration](#testing-project-configuration)

Initialize testing project
--------------------------

[](#initialize-testing-project)

- Add [phpunit.xml.dist](https://phpunit.de/manual/current/en/appendixes.configuration.html) to your repository to configure [phpunit](https://phpunit.de/)
- Set KERNEL\_DIR server variable so that phpunit finds symfony kernel (example value nees to be modified based on bundle name)

```

```

- Add imatic-testing into your dev dependencies

```
$ composer require --dev 'imatic/testing'
```

- Create required files in your [`bundle &lt;bundle\_&gt;`\_](#id1)[ &lt;bundle\_&gt;](#id1)

```
$ ./vendor/bin/testingbundle-init
```

- Command above should create directory structure similar to

```
Tests
    Fixtures
        TestProject
            config
                config.yml
                routing.yml
            XYZBundle (same name as tested bundle)
                AppXYZBundle.php
            web
                app.php
            console
            TestKernel.php
            WebTestCase.php
    Functional
    Integration
    Unit
    bootstrap.php
```

- Directory structure above is created based on template in [TestsTemplate](Resources/skeleton/TestsTemplate) directory

PHPUnit
-------

[](#phpunit)

### Additional constraints

[](#additional-constraints)

All additinal constraints usable in [symfony functional tests](https://symfony.com/doc/current/testing.html#functional-tests) are included in our `WebTestCase` automatically. If you have your own `WebTestCase` implementation, you can use our trait [WebTestCaseExtension](Test/WebTestCaseExtension.php) to include our additional constraints in your `WebTestCase`.

#### ResponseHasCode

[](#responsehascode)

This constraint can be used to assert status codes in [symfony functional tests](https://symfony.com/doc/current/testing.html#functional-tests). Usage:

```
