问题
I have a PHP project with Codeception on which several developers are working. Everyone have their own environment and different URL to their copy of the project. But in Codeception Functional/Acceptance yml config file we have to set up URL for acceptance and functional tests.
How could we have different URL to project and have main part of configs in repository? Thank you in advance.
回答1:
One way to solve this is to look at the $_SERVER['HOSTNAME']
value and select the appropriate url from that. I've currently got this in my tests/acceptance/_bootstrap.php
switch($_SERVER['HOSTNAME'])
{
case 'dev1':
$base_url = 'http://www.example.com.dev1';
break;
default:
$base_url = 'http://www.example.com';
break;
}
define("BASE_URL",$base_url);
You can then make use of this constant in a test
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that the a user can log in');
$I->amOnUrl(BASE_URL . "/home");
回答2:
I have same problem. I asked same question here. I used --environment
option to get this working.
here is the example configuration:
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- Yii1
- \Helper\Functional
- PhpBrowser
- Db
config:
Yii1:
appPath: '/Volumes/disk0s4/www/new-proj/trunk/test.php'
url: 'https://my.proj.local/test.php'
PhpBrowser:
url: 'https://my.proj.didin/'
Db:
dsn: 'mysql:host=127.0.0.1;dbname=test-proj-new'
user: 'root'
password: 'root'
env:
my_env:
modules:
enabled:
- Yii1
- \Helper\Functional
config:
Yii1:
appPath: 'path to index.php of my environment'
url: 'http://my.local/test.php'
production_env:
modules:
enabled:
- Yii1
- \Helper\Functional
config:
Yii1:
appPath: 'path to index.php of production environment'
url: 'http://my.local.com/test.php'
I know that config contains duplicated-lines and should be able to be simplified, I've tried to simplify by removing duplicate line at global modules
, but seems doesn't work to me.
So I let the config as you see above and I have created Issue for it, but still wondering if someone get this overriding
working.
I hope this helps to anyone.
来源:https://stackoverflow.com/questions/31874410/is-it-possible-to-store-functional-acceptance-config-url-of-codeception-outside