Why do I have to set PHPUNIT_MINK_TUNNEL_ID as environment variable?
It seems I have to do a
putenv('PHPUNIT_MINK_TUNNEL_ID=' . $tunnel_id);
before creating my browser configuration which feels a little bit weird for me.
You don't. Creating a tunnel is an optional feature of both SauceLabs and BrowserStack.
Yeah. Sorry, that it's an optional feature is clear to me. I meant: Why can't I set tunnel id not via desired capabilities or something else?
It feels a little bit hacky to do a putenv()
The env-way is created mostly for build servers, where:
- several tunnels can exist in parallel (usual stuff, when running tests on multiple PHP versions/browsers from build server like Travis CI)
- tunnel is linked to IP starting it and attempt to use same tunnel from multiple IPs might fail
If you'll look at actual places where this env variable is used, then you'll see that in fact it's used exactly to populate desired capabilities in current browser configuration.
Sauce Labs
https://github.com/minkphp/phpunit-mink/blob/master/library/aik099/PHPUnit/BrowserConfiguration/SauceLabsBrowserConfiguration.php#L57-L59
$desired_capabilities['tunnel-identifier'] = getenv('PHPUNIT_MINK_TUNNEL_ID');
BrowserStack
https://github.com/minkphp/phpunit-mink/blob/master/library/aik099/PHPUnit/BrowserConfiguration/BrowserStackBrowserConfiguration.php#L59-L62
$desired_capabilities['browserstack.local'] = 'true';
$desired_capabilities['browserstack.localIdentifier'] = getenv('PHPUNIT_MINK_TUNNEL_ID');
So you can that as well.