Download the PHP package tobento/app-testing without Composer
On this page you can find all versions of the php package tobento/app-testing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package app-testing
App Testing
Testing support for the app.
Table of Contents
- Getting Started
- Requirements
- Documentation
- Getting Started
- Config Tests
- Http Tests
- Request And Response
- Subsequent Requests
- File Uploads
- Crawl Response Content
- Json Response
- Response Macros
- Refresh Session
- Auth Tests
- File Storage Tests
- Queue Tests
- Event Tests
- Mail Tests
- Notifier Tests
- Database Tests
- Reset Databases
- Replace Databases
- Logging Tests
- Credits
Getting Started
Add the latest version of the app testing project running this command.
Requirements
- PHP 8.0 or greater
Documentation
Getting Started
To test your application extend the class.
Next, use the method to create the app for testing:
Tmp App
You may use the method, to create an app for testing individual boots only.
Finally, write tests using the available fakers.
By default, the app is not booted nor run yet. You will need to do it on each test method. Some faker methods will run the app automatically though such as the fakeHttp method.
App clearing
When creating a tmp app, you may call the method to delete the app directory.
Or you may use the method:
Config Tests
In some cases you may want to define or replace config values for specific tests:
Http Tests
Request And Response
If you have installed the App Http bundle you may test your application using the method.
Request method
Or you may prefer using methods:
Use the method to create a request with the following headers:
Response method
Calling the response method will automatically run the app.
withoutMiddleware
previousUri
You may set a previous uri if your controller uses the previous uri to redirect back if an error occurs for example.
Http Url
You may sometimes wish to modify the http url in order to have relative urls for instance;
Subsequent Requests
After making a request, subsequent requests will create a new app. Any fakers from the first request will be rebooted.
Following redirects
File Uploads
You can use the file factory to generate dummy files or images for testing purposes:
Create a fake image
Create a fake file
Crawl Response Content
You may crawl the response content using the Symfony Dom Crawler.
assertNodeExists
assertNodeMissing
Example Form Crawling
JSON Response
You may test JSON responses using the method.
Assertable Json
You may use the class to fluently test JSON responses.
Assert Key
Assert that the key exists:
Assert Value
Assert that the value matches:
Assert Key And Value
Assert that the value matches the key value:
Assert Items
Asserts that the items count matches.
Assert Passes
Asserts that passes evaluates to true.
Hasnt
Use the method asserting the opposite of the method.
Response Macros
You may want to write convenience helpers to the test response using macros.
Refresh Session
You may refresh your session after each test by using trait:
Auth Tests
If you have installed the App User bundle you may test your application using the method.
The next two examples assumes you have already seeded test users in some way:
Example With Token
You may want to authenticate a user by creating a token:
Example Seeding Users
This is one possible way of seeding users for testing. You could also seed users by creating and using Seeders.
You may check out the User Seeding to learn more about the .
File Storage Tests
If you have installed the App File Storage bundle you may test your application using the method which allows you to create a fake storage that mimics the behavior of a real storage, but doesn't actually send any files to the cloud. This way, you can test file uploads without worrying about accidentally sending real files to the cloud.
Example using a tmp app:
Storage Method
Storages Method
Queue Tests
If you have installed the App Queue bundle you may test your application using the method which allows you to create a fake queue to prevent jobs from being sent to the actual queue.
Example using a tmp app:
Clear Queue
Sometimes it may be useful to clear the queue using the method:
Run Jobs
Sometimes it may be useful to run jobs using the method:
Event Tests
If you have installed the App Event bundle you may test your application using the method which records all events that are dispatched and provides assertion methods that you can use to check if specific events were dispatched and how many times. Currently, only Default Events will be recorded. Specific Events are not supported yet.
Example using a tmp app:
Mail Tests
If you have installed the App Mail bundle you may test your application using the method which allows you to create a fake mailer to prevent messages from being sent.
Example using a tmp app:
Notifier Tests
If you have installed the App Notifier bundle you may test your application using the method which allows you to create a fake notifier to prevent notification messages from being sent.
Example using a tmp app:
Database Tests
If you have installed the App Database bundle you may interact with your databases.
Reset Databases
There are two strategies to reset your databases:
Refresh Strategy
This strategy cleans your database after each test.
Migrate Strategy
This strategy cleans your database after each test using migrations.
Replace Databases
You may replace your database to test different databases.
Example replacing the default storage database:
Logging Tests
If you have installed the App Logging bundle you may test your application using the method which allows you to create a fake logger to prevent logging with the actual logger.
Example using a tmp app:
Credits
All versions of app-testing with dependencies
tobento/app Version ^1.0.7
tobento/app-console Version ^1.0
tobento/app-seeding Version ^1.0
tobento/service-collection Version ^1.0
tobento/service-iterable Version ^1.0
tobento/service-macro Version ^1.0
mockery/mockery Version ^1.6
nyholm/psr7 Version ^1.4
symfony/mime Version ^6.0 || ^7.0
symfony/dom-crawler Version ^6.0
symfony/css-selector Version ^6.0