Codeception: Codeception\Module\Yii2 can't open external URL though can be opened by browser
What are you trying to achieve?
I’m trying to get my REST endpoint working. The following url gets 200 response in REST clients.
http://sign-up-api.local/v1/user/info
What do you get instead?
I’m getting this exception.
Codeception\Module\Yii2 can’t open external URL
Provide console output if related. Use
-vvv
mode for more details.
➜ src git:(master) ✗ composer exec codecept run -vvv api <<<
Reading ./composer.json
Loading config file /Users/seng/.composer/config.json
Loading config file /Users/seng/.composer/auth.json
Loading config file ./composer.json
Checked CA file /private/etc/ssl/cert.pem: valid
Executing command (/Users/seng/projects/plum-flower/sign-up-api/src): git branch --no-color --no-abbrev -v
Reading /Users/seng/.composer/composer.json
Loading config file /Users/seng/.composer/config.json
Loading config file /Users/seng/.composer/auth.json
Loading config file /Users/seng/.composer/composer.json
Loading config file /Users/seng/.composer/auth.json
Reading /Users/seng/.composer/auth.json
Reading /Users/seng/projects/plum-flower/sign-up-api/src/vendor/composer/installed.json
Reading /Users/seng/.composer/vendor/composer/installed.json
Loading plugin yii\composer\Plugin
Loading plugin Fxp\Composer\AssetPlugin\FxpAssetPlugin
Running 1.2.2 (2016-11-03 17:43:15) with PHP 7.1.0 on Darwin / 16.3.0
> __exec_command: codecept 'run' 'api'
Executing command (CWD): codecept 'run' 'api'
Codeception PHP Testing Framework v2.2.6
Powered by PHPUnit 5.7-dev by Sebastian Bergmann and contributors.
Api Tests (1) ----------------------------------------------------------------
E InfoCept: Get the public information for the main page via api (0.00s)
------------------------------------------------------------------------------
Time: 170 ms, Memory: 10.00MB
There was 1 error:
---------
1) InfoCept: Get the public information for the main page via api
Test tests/api/InfoCept.php
[ExternalUrlException] Codeception\Module\Yii2 can't open external URL: http://plum-flower-sign-up-api.local/v1/info/v1/info
Scenario Steps:
2. $I->sendGET("/v1/info") at tests/api/InfoCept.php:7
1. $I->haveHttpHeader("Content-Type","application/json") at tests/api/InfoCept.php:6
#1 Codeception\Module\REST->sendGET
#2 /Users/seng/projects/plum-flower/sign-up-api/src/tests/_support/_generated/ApiTesterActions.php:305
#3 /Users/seng/projects/plum-flower/sign-up-api/src/tests/api/InfoCept.php:7
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Script codecept handling the __exec_command event returned with error code 1
Provide test source code if related
<?php
$I = new ApiTester($scenario);
$I->wantTo('Get the public information for the main page via API');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendGET('/v1/info');
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseContainsJson([
'success' => true,
'data' => [
'info' => 'Some information about the <b>company</b>.'
]
]);
Details
-
Codeception version: v2.2.6
-
PHP Version: 7.1.0 (also tried with PHP 5.6.x)
-
Operating System: Mac OS X
-
Installation type: Composer
-
List of installed packages (
composer show
) composer-packages.txt -
Suite configuration:
# tests/api.suite.yml
class_name: ApiTester
modules:
enabled:
- REST:
url: http://plum-flower-sign-up-api.local/v1/info
depends: Yii2
- Yii2:
# codeception.yml
include:
- tests/codeception/common
- tests/codeception/console
- tests/codeception/backend
- tests/codeception/frontend
paths:
log: tests/codeception/_output
settings:
colors: true
db:
dsn:
username:
password:
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (2 by maintainers)
Thank you very much for helping me out. I just ran my first functional test successfully after struggling with it for days!
I did not pay attention to config/test.php because I thought it is config/web.php who handles the app configuration. I copied my request, response & urlManager components from config/web.php to config/test.php and it succeeded.
Yii2 module doesn’t fetch the url - it processes requests without making HTTP request.
The external URL exception was introduced to prevent framework modules from serving request when a link to another website was clicked.
Framework modules process requests to localhost and to other domains that are configured in domain based routes.
You are on a right path and you have to make the path part of your URLs match Yii2 routes. Please share your route configuration if you can’t figure it out.
@senguttuvang Don’t use domain names in functional testing with Yii2 module unless you use domain based routes (if you had a matching domain route it would work).
Remove url option completely or change it to
url: /v1/info