Download the PHP package imatic/testing without Composer
On this page you can find all versions of the php package imatic/testing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download imatic/testing
More information about imatic/testing
Files in imatic/testing
Package testing
Short Description Library to make testing of Symfony bundles easier
License MIT
Homepage https://www.imatic.cz
Informations about the package 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
- Initialize testing project
- PHPUnit
- Usage
- Checking your testing project in browser
- Writing tests working with database
- Testing project configuration
Initialize testing project
- Add phpunit.xml.dist
- 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
- Create required files in your bundle
- Command above should create directory structure similar to
- Directory structure above is created based on template in TestsTemplate directory
PHPUnit
Additional constraints
All additinal constraints usable in WebTestCaseExtension to include our additional constraints in your WebTestCase.
ResponseHasCode
This constraint can be used to assert status codes in symfony functional tests. Usage:
- advantage in comparison with asserting 200 with
$client->getResponse()->getStatusCode()is that the special assert gives you information about what went wrong instead of giving you just wrong code of the response (e.g. 500)
Usage
Now if you have all configured, you can start writing tests or check your testing project in browser. In order to check your testing project in browser.
Checking your testing project in browser
- go to the testing project root and run web server
Using PHP's bult-in web server
- now open your browser at url reported by the last command (probably "http://127.0.0.1:8000/app.php")
- you will see exception now probably because you didn't configure any routes for your project yet
- you can find more details on the command in symfony documentation
Using other web servers
- see symfony documentation on how to configure each
Using symfony console
- as you may or may not notice when we talked about testing project directory structure, you have also available symfony console - so that you can run all commands that your bundle or bundles your testing project uses provide
- see symfony documentation on how to work with console command (note that in our case, the executable running console is called
consoleand is placed in root of the testing project
Writing tests working with database
- if you use our
WebTestCaseas parent of your tests, then each test will run in transaction so all your modifications to db are lost (so you have db in state before the test run) - see commented test below on how it works
- note that because of doctrine connection wrapper we use - you can write symfony funcional tests and after each test, transaction will still be rollbacked (which is not possible without using the wrapper
- you can see this connection wrapper in our config template
- if you want to load any fixtures, you need to require DoctrineFixturesBundle
and specify any fixture. Our
WebTestCaseload fixtures automatically whenDoctrineFixturesBundleis enabled. - before running tests database and fixtures is reloaded, if you want to disable this behavior, change env variable
TESTING_DATA_INITin your test configuration
Testing project configuration
- if you need to make changes to the configuration, just edit generated config file which you can find in
config/config.yml(relative to the testing project roor)
All versions of testing with dependencies
symfony/framework-bundle Version ^4.4 || ^5.4 || ^6.2
doctrine/doctrine-bundle Version ^2.0
symfony/monolog-bundle Version ^3.0
phpunit/phpunit Version ^9.5.0