Bogdan  Dubyk
Bogdan Dubyk

Reputation: 5540

Codeception. Test database for acceptance tests, or functional tests for pure PHP

Is there a way to run acceptance or functional Codeception tests for the application written on pure PHP and using test database???

Depends on documentation it's impossible to use test database for acceptance testing

In acceptance tests, your tests are interacting with the application through a web server. This means that the test and the application work with the same database. You should provide the same credentials in the Db module that your application uses, then you can access the database for assertions (seeInDatabase actions) and to perform automatic clean-ups.

Source

And from another hand looks like it's not possible to run functional tests on pure PHP because of functional tests require to use one of the framework modules.

I only start learning Codeception and can miss something?

thank you for any help!

Upvotes: 0

Views: 551

Answers (1)

sunomad
sunomad

Reputation: 1793

Yes, you can have your acceptance tests use your test database. You will need to setup your application to use the test database in your testing environment.

For example, if your application runs on the local url www.mywebsite.dev, you can configure it in such a way that it used the test database when accessed through www.mywebsite.test Somewhere in your application you can check the host, and if the host is www.mywebsite.test let the application connect to the test database, otherwise connect to the development database.

Or even better, if you are using a config like .env, you can set up an environment variable APP_ENV=test and check the value of it in your application before connection to the database.

Upvotes: 1

Related Questions