Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run functional or acceptance tests with --coverage #515

Closed
dmitry-grasevich opened this issue Aug 30, 2013 · 32 comments
Closed

Unable to run functional or acceptance tests with --coverage #515

dmitry-grasevich opened this issue Aug 30, 2013 · 32 comments

Comments

@dmitry-grasevich
Copy link

When I tried run functional test I got an error:
dmitry@dmitry:/var/www/lsp.local/httpdocs/protected$ codecept run functional AgencyCest.php --coverage
Codeception PHP Testing Framework v1.6.6
Powered by PHPUnit 3.7.24 by Sebastian Bergmann.

Suite functional started

[ErrorException]
file_get_contents(http://lsp.local/index.php/c3/report/clear): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found

run [-c|--config="..."] [--report] [--html] [--xml] [--tap] [--json] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage] [--no-exit] [--defer-flush] [-g|--group="..."] [-s|--skip="..."] [--skip-group="..."] [suite] [test]

In the older versions of Codeception this error was not occur. For example:
dmitry@dmitry:/var/www/lsp.local/httpdocs/protected$ codecept run functional AgencyCest.php --coverage
Codeception PHP Testing Framework v1.6.4.2
Powered by PHPUnit 3.7.22 by Sebastian Bergmann.

Suite functional started
Trying to create agency (AgencyCest.createAgency)
Scenario:

  • As a Admin
  • I am on page "/"
    ...

I used Yii1, my codeception.yml is:

coverage:
    enabled: true
    include:
      - components/*.php
      - controllers/*.php
      - models/*.php
      - modules/*.php
      - extensions/DarwinApps/*.php
    exclude:
        - runtime/*
        - models/Pdf.php
        - models/Rtf.php
        - models/cfb.php
        - components/behaviors/WithRelatedBehavior.php
        - yiic
        - yiic.bat
        - yiic.php
paths:
    tests: tests/codeception
    log: tests/codeception/_log
    data: tests/codeception/_data
    helpers: tests/codeception/_helpers
    groups: tests/codeception/_groups
settings:
    bootstrap: _bootstrap.php
    suite_class: \PHPUnit_Framework_TestSuite
    colors: true
    memory_limit: 1024M
    log: true
@DavertMik
Copy link
Member

One bug fixed, one new added. Stability!

He-he, will provide a patch asap.

@DavertMik
Copy link
Member

Ok, you mean you use Yii1 module, or you are using PhpBrowser module?

@tiger-seo
Copy link
Member

Would be nice to have a regression test for this.

@DavertMik
Copy link
Member

Sure, I have few for PhpBrowser.

@tiger-seo
Copy link
Member

So, probably, this one is about the Yii1 module

@DavertMik
Copy link
Member

Not sure. I don't have Yii1+code coverage, but Laravel4 + code coverage works well. They are based on one Framework class.

@dmitry-grasevich
Copy link
Author

Sorry for the delay in replying.
Yes, it is PhpBrowser. functional.yml:

class_name: TestGuy
modules:
    enabled: [Yii1, Db, PhpBrowser, TestHelper]
    config:
        Db:
          dump: tests/codeception/_data/lsp_functional.sql

So, I fixed it by including c3.php and few changes. But I tested locally, not remotely. Why I should include c3? This is bug or new feature?

@tiger-seo
Copy link
Member

@elazar
Copy link
Contributor

elazar commented Oct 14, 2013

I get this too when I try to debug a different issue I'm having. Aside from those described in the Debug section of the c3 README, I've made no changes to c3.php. Here's the relevant section of my codeception.yml file:

coverage:                                                                                                         
    enabled: true                                                                                                 
    remote: true                                                                                                  
    whitelist:                                                                                                    
        include:                                                                                                  
            - ../public/routes/*                                                                                  
            - ../public/lib/*

@tiger-seo
Copy link
Member

@elazar what issues do you have ?

@elazar
Copy link
Contributor

elazar commented Oct 23, 2013

I believe this happens when c3tmp/codecoveragehtml does not exist or is not writable.

@tiger-seo
Copy link
Member

please do check permissions for c3tmp

@elazar
Copy link
Contributor

elazar commented Oct 24, 2013

Is there no way to have Codeception check for this condition when encountering this error, so that a more intuitive error message is output?

@tiger-seo
Copy link
Member

you can write one and provide as PR :)

@eddiejaoude
Copy link
Contributor

Was there a solution for this? I get the same issue. Trying to run Code Coverage locally but I get the following error:

vendor/bin/codecept run --coverage --coverage-xml
Codeception PHP Testing Framework v2.0.5
Powered by PHPUnit 4.3.0 by Sebastian Bergmann.

Acceptance Tests (0) ------------------------



  [ErrorException]                                                                                                              
  file_get_contents(http://localhost:8000/c3/report/clear): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found  



run [-c|--config="..."] [--report] [--html[="..."]] [--xml[="..."]] [--tap[="..."]] [--json[="..."]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage[="..."]] [--coverage-html[="..."]] [--coverage-xml[="..."]] [--coverage-text[="..."]] [--no-exit] [-g|--group="..."] [-s|--skip="..."] [-sg|--skip-group="..."] [--env="..."] [-f|--fail-fast] [suite] [test]

codeception.yml

coverage:
    remote: false
    enabled: true
    include:
        - module/Application/src/*

@bkuhl
Copy link

bkuhl commented Jan 14, 2015

I'm experiencing this error as well when attempting to run remote code coverage on my Laravel 4 application. According to the logs, Laravel doesn't know what to do with the route.

@adamwinn
Copy link

I have the same error too. codeception 2.0.11.

codecept run functional --coverage-html and codecept run unit --coverage-html work fine.

But if I don't include the suite name and include coverage it will fail. ie. codecept run --coverage-html fails with
[yii\base\ErrorException] file_get_contents(http://localhost/index-test.php//c3/report/clear): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

@nateritter
Copy link

@bkuhl @adamwinn and @eddiejaoude,

I just solved this problem myself. I'm using Laravel 4.2, and had to create a new route to point to the file like this:

Route::get('/c3.php', function () {
        include '../c3.php';
    });

And then in codeception.yml, I have this:

coverage:
    enabled: true
    remote: false
    c3_url: 'http://whatever.dev/c3.php'

(change whatever.dev to your local/testing environment domain)

Also, a gotcha for me was that I ended up opening up the entire _tests directory by chmod -R 0777 _tests and things finally started working for me.

@adamwinn
Copy link

adamwinn commented Apr 8, 2015

@nateritter That worked great for me using Yii2!

@nateritter
Copy link

Outstanding! Glad to hear it!

@bkuhl
Copy link

bkuhl commented Apr 15, 2015

@nateritter I'm still having trouble in the Laravel app where everything runs without errors but no coverage is generated. Would you mind posting more details about your overall config?

I'm seeing the below error when using the config you provided.

file_get_contents(http://mysite.dev/c3.php/c3/report/clear): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error 

I tried opening up the route so that it'd still map the route with the extra stuff in the URL after c3.php:

coverage:
    enabled: true
    remote: false
    c3_url: 'http://mysite.dev/c3.php'
Route::get('/c3.php/{extra}', function () {
    require base_path('c3.php');
})->where('extra', '.*');

I get the same error with this as well. If I access http://mysite.dev/c3.php/report/clear in the browser it shows a standard 200OK for this route.

Solution
For me the issue turned out to be in my __bootstrap.php... require_once was not returning an object (only while generating code coverage) so I've updated it to just use require:

$app = require __DIR__.'/../bootstrap/start.php';
$app->boot();

I did still use the route and remote configuration as defined at the beginning of this reply.

Note: After this step, you have full access to facades in your Codeception tests.

cc @jlaswell

@montogeek
Copy link

@nateritter I cant get this working, I setup the Laravel route, require the file, it runs but reports 0 in everything:

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
coverage:
    enabled: true
    remote: true
    include:
        - app/*
    exclude:
        - app/controllers/BaseController.php
        - app/views/*
        - app/storage/*
        - app/start/*
        - app/lang/*
        - app/database/*
        - app/config/*
modules:
    config:
        Db:
            dsn: ''
            user: ''
            password: ''
            dump: tests/_data/dump.sql
Route::get('/c3/{extra}', function () {
    require base_path('c3.php');
})->where('extra', '.*');

Obviously I have tests

screen shot 2015-05-05 at 00 20 51

Report

screen shot 2015-05-05 at 00 21 52

I am running the coverage tests inside a Vagrant VM with
Laravel 4.1
CentOS 6.2
PHP 5.4

Executing
vendor/bin/codecept run functional --coverage --coverage-html

@nateritter
Copy link

Hi @montogeek. I'm sorry, I am not sure how to debug your particular scenario. I had trouble troubleshooting my own setup. Perhaps @bkuhl's solution above might help? Or someone else? Sorry I can't be of more help at this point.

@montogeek
Copy link

:( I have already tried with the c3_url setting, xdebug.remote_enable is true, etc.. No idea why is not working :(

@montogeek
Copy link

Uhmm, I just tried it again in another VM:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty

PHP

PHP 5.6.0-1+deb.sury.org~trusty+1 (cli) (built: Aug 28 2014 14:55:42)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Getting 0% coverage again.

Can please somebody tell me what should I check or something? I am really frustrated :(

Using "codeception/codeception": "2.0.12",

@montogeek
Copy link

Ok, I upgraded to 2.0.13, run the test again and got 0%, then remove PHPBrowser module form functional tests and finally I got a nice report :D.

What is wrong with that package? Or do I need to add some extra config, this was my settings:

        PhpBrowser:
            url: 'http://new-monitores.app'

@rafaelbdb
Copy link

I have a fresh install of Codeception 2.1.0, and using a simple test page with only phpinfo() (no frameworks). When I run:

php codecept.phar run acceptance ExampleCest.php -f -d --coverage --coverage-html --html

I get this error message:

  [PHPUnit_Framework_Exception]
  file_get_contents(http://localhost/c3/report/clear): failed to open
  stream: HTTP request failed! HTTP/1.1 404 Not Found

My codeception.yml:

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
coverage:
        enabled: true
extensions:
    enabled:
        - Codeception\Extension\RunFailed
modules:
    config:
        Db:
            dsn: ''
            user: ''
            password: ''
            dump: tests/_data/dump.sql

My acceptance.suite.yml:

# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.

class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver
    config:
        WebDriver:
            url: 'http://localhost'
            browser: 'chrome'
            window_size: 1024x768
            coverage:
                enabled: true
                remote: false
                c3_url: 'http://localhost/c3.php'

My test.php file:

<?php
    include '../../c3.php';
    phpinfo();
?>

My ExampleCest.php:

<?php
use \AcceptanceTester;

class ExampleCest
{
    public function _before(AcceptanceTester $I)
    {
    }

    public function _after(AcceptanceTester $I)
    {
    }

    // tests
    public function tryToTest(AcceptanceTester $I)
    {
        $I->amOnPage('/test.php');
        $I->waitForText('PHP Version', 10);
    }
}

I'm using wamp in Windows 7, with xdebug and xdebug_remote ON.

What am I doing wrong?

@Naktibalda
Copy link
Member

You haven't uploaded c3.php to your server.

http://codeception.com/docs/11-Codecoverage#Remote-CodeCoverage

@rafaelbdb
Copy link

Thank you @Naktibalda!! It works!
The file was there, but I didn't use the "c3_url".

@rafaelbdb
Copy link

Now I'm facing another problem... Local tests worked perfectly, but when I try remote I get this error:

[PHPUnit_Framework_Exception]
  file_get_contents(http://myremoteapp.com/bootstrap.php/c3/report/clear): 
failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

Both codeception and acceptance ymls files are already configured with

coverage:
      enabled: true
      remote: true
      c3_url: 'http://myremoteapp.com/bootstrap.php'

And bootstrap.php has the include for c3.php. What can be wrong?

One detail: my app uses Phalcon2.

@Naktibalda
Copy link
Member

For debugging:

  • Open c3.php file
  • Find line "header('X-Codeception-CodeCoverage-Error: ' . str_replace("\n", ' ', $message), true, 500);"
  • Replace 500 with 200
  • Run your tests again.

@rafaelbdb
Copy link

Reproducing the same error locally, and replacing 500 by 200 in c3.php, I get:

[UnexpectedValueException]
  phar error: "C:\Users\MyUser\AppData\Local\Temp\C36A1Ctmp.tar" is a corrupted tar file 
(checksum mismatch of file "<br /> <font size='1'><table class='xdebug-error xe-notice' 
dir='ltr' border='1' cellspacing='0' cel")

Even deleting that file (and all alike in Temp folder), it happens again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests