K
K
knowledge2018-03-03 23:05:44
PHP
knowledge, 2018-03-03 23:05:44

Why doesn't this construction work in Codeception?

my application is launched through the index.php file, which looks like this
$container = new Container();
$app = new Application($container);
$app->run
The container contains configs, including a database connection.
For testing, I have my own database and the test environment starts when I pass the test string to the container
$container = new Container('test');
I was racking my brains on how to connect a test environment in Codeception and decided to use such a life hack, in index.php I wrote
$env = $_GET['env'] ?? '';
Accordingly, when I launch the site like this mysite.ru/?env=test
test settings are launched.
Next, I write in PhpBrowser
codeception settings:
url: mysite.ru/?env=test
But it still runs the standard settings, as if it just ignores the line ?env=test
how can this be solved, how do you solve the problem of replacing the config with a test one?
I don't use frameworks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Fedorov, 2018-03-04
@knowledge

?env=test
I can assume that further in the tests themselves you do not substitute this GET parameter,
for example, with such calls, your url is lost:

<?php
$I->amOnPage('/quickstart'); // moves to http://codeception.com/quickstart
?>

But you need to test...
The PhpBrowser module setup has Guzzle middlewear and Curl, try adding the parameter
https://codeception.com/docs/modules/PhpBrowser through them to all your GET calls
I looked in the source, the code is well documented there ( better than the dock)
Here's what I found - you can use the settings fields for Guzzle (they use auth in the dock) for example query
https://github.com/Codeception/Codeception/blob/2....
Here is an example of use:
https://github .com/Codeception/Codeception/blob/2....
As I understand it, right in your config after url: mysite.ruyou need to add query: ['env', 'test']
As a result, your config will look something like this:
modules:
   enabled:
       - PhpBrowser:
           url: 'http://localhost'
           query: ['env', 'test']

I'm afraid I didn't set the array correctly, you can try:
query: 
     env: test

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question