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

ErrorException with code coverage in Symfony2 #236

Closed
brechtdewinne opened this issue Mar 27, 2013 · 21 comments

Comments

Projects
None yet
6 participants
@brechtdewinne
Copy link

commented Mar 27, 2013

Hi there,

When i enable code coverage in my configuration and I run my tests with the --coverage parameter, I keep getting the following error:

[ErrorException]
  unserialize(): Error at offset 0 of 240 bytes

In my configuration I have just added:

coverage:
  enabled: true

I'm on version 2.2.0 of Symfony2 BTW.

@brechtdewinne

This comment has been minimized.

Copy link
Author

commented Mar 27, 2013

Also, I get this error when Codeception starts on the acceptance suite.

Edit: Scratch that, the error happens after the acceptance tests.

trace:

Exception trace:
 () at /Users/brecht/Workspace/combell-test/vendor/Codeception/Codeception/src/Codeception/Subscriber/CodeCoverage.php:84
 Codeception\Subscriber\ErrorHandler::errorHandler() at n/a:n/a
 unserialize() at /Users/brecht/Workspace/combell-test/vendor/Codeception/Codeception/src/Codeception/Subscriber/CodeCoverage.php:84
 Codeception\Subscriber\CodeCoverage->afterSuite() at n/a:n/a
 call_user_func() at /Users/brecht/Workspace/combell-test/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:164
 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at /Users/brecht/Workspace/combell-test/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:53
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /Users/brecht/Workspace/combell-test/vendor/Codeception/Codeception/src/Codeception/SuiteManager.php:154
 Codeception\SuiteManager->run() at /Users/brecht/Workspace/combell-test/vendor/Codeception/Codeception/src/Codeception/Codecept.php:110
 Codeception\Codecept->runSuite() at /Users/brecht/Workspace/combell-test/vendor/Codeception/Codeception/src/Codeception/Command/Run.php:70
 Codeception\Command\Run->execute() at /Users/brecht/Workspace/combell-test/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:240
 Symfony\Component\Console\Command\Command->run() at /Users/brecht/Workspace/combell-test/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:193
 Symfony\Component\Console\Application->doRun() at /Users/brecht/Workspace/combell-test/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:106
 Symfony\Component\Console\Application->run() at /Users/brecht/Workspace/combell-test/vendor/Codeception/Codeception/codecept:40
@brechtdewinne

This comment has been minimized.

Copy link
Author

commented Mar 27, 2013

I've figured out that the c3 routes can't be found.

Edit: Nope it's not this as well

@brechtdewinne

This comment has been minimized.

Copy link
Author

commented Mar 28, 2013

I've changed the c3 file like this:

//if (!array_key_exists('HTTP_X_CODECEPTION_CODECOVERAGE', $_SERVER)) {
//    return;
//}

$_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE'] = 'Acceptance';
$_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG'] = 1;

And now i'm getting the following error when going to c3/report/html:

PharException: tar-based phar "/Users/brecht/Workspace/combell-test/c3tmp/codecoverage.tar" cannot be created, filename "vendor_doctrine_doctrine-bundle_Doctrine_Bundle_DoctrineBundle_DataCollector_DoctrineDataCollector.php.html" is too long for tar file format

Codeception is installed with composer (tried phar as well).

@DavertMik

This comment has been minimized.

Copy link
Member

commented Mar 28, 2013

Oh. Looks like a phar limitation.
Hey, @tiger-seo what do you think on that?

@brechtdewinne

This comment has been minimized.

Copy link
Author

commented Mar 28, 2013

@DavertMik @tiger-seo
Yep it definitely is a phar limitation: http://php.net/manual/en/phar.fileformat.tar.php

Not that it should make any difference, but i'm on a mac btw.

@brechtdewinne

This comment has been minimized.

Copy link
Author

commented Mar 28, 2013

@DavertMik @tiger-seo
After a long time i've finally managed to get it working by creating a bundle that contains all the routes + made a small change in the c3 file because the coverage file in the c3tmp folder gets only generated at the end of the first pass trough which else results in an error.

PR c3: Codeception/c3#2
CodeceptionSF2Bundle: https://github.com/brechtdewinne/CodeceptionSF2Bundle

BTW: I'm not saying this is a good solution, but at least I got it working.

@tiger-seo

This comment has been minimized.

Copy link
Member

commented Apr 3, 2013

our project is also build upon Symfony 2 and I don't have and of such problems

@brechtdewinne

This comment has been minimized.

Copy link
Author

commented Apr 3, 2013

It's really strange but I couldn't get it working on any other way. @tiger-seo are you also working in Symfony2 2.2.0?

@tiger-seo

This comment has been minimized.

Copy link
Member

commented Apr 4, 2013

yes

@ghost

This comment has been minimized.

Copy link

commented Jun 7, 2013

I am also getting this error when running tests with code coverage base on Laravel 4. Any fix ?

@DavertMik

This comment has been minimized.

Copy link
Member

commented Jun 7, 2013

Need to investigate that more deeply.
Maybe some problems occur because of changes in PHP_CodeCoverage of PHPUnit
#355

@ghost

This comment has been minimized.

Copy link

commented Jun 7, 2013

After a little investigation it seems that line 84 of class Codeception\Subscriber\CodeCoverage is generating the error :

$coverage = unserialize($externalCoverage);

Looking like $externalCoverage variable content is invalid and the error is coming from PHP_CodeCoverage code itself.

@clouddueling

This comment has been minimized.

Copy link

commented Jun 29, 2013

I get a:

[ErrorException]                                
  unserialize(): Error at offset 0 of 5961 bytes

running: codecept run --coverage --html

@LionArt I did a little investigation:
screen shot 2013-06-29 at 11 17 23 am

and got while running my test. for some reason it's trying to unserialize the html from the site it's viewing. during an acceptance test.

Note the string length is 5961
screen shot 2013-06-29 at 11 17 36 am

@clouddueling

This comment has been minimized.

Copy link

commented Jun 29, 2013

Ok unserialize returns:

The converted value is returned, and can be a boolean, integer, float, string, array or object.

In case the passed string is not unserializeable, FALSE is returned and E_NOTICE is issued.

Noting the E_NOTICE I added an @ to see what would happen:
Line 84: @$coverage = unserialize($externalCoverage);

I am now getting the _log/report.html _log/report.xml files.

@clouddueling

This comment has been minimized.

Copy link

commented Jun 29, 2013

Ok with that @ added to the line that throws the E_NOTICE when I run:

codecept run acceptance --coverage --html

I get:

screen shot 2013-06-29 at 11 55 29 am

With all files generated.
screen shot 2013-06-29 at 11 56 08 am

@tiger-seo

This comment has been minimized.

Copy link
Member

commented Jul 1, 2013

Ok with that @ added to the line that throws the E_NOTICE when I run:

we cannot fix the problem using silence-operator, because that is a bad practice

Maybe some problems occur because of changes in PHP_CodeCoverage of PHPUnit

as for me, my code coverage job on Jenkins works same good as before - without errors

@tiger-seo

This comment has been minimized.

Copy link
Member

commented Jul 1, 2013

if only someone could provide us with test which will reproduce the problem...

@tedslittlerobot

This comment has been minimized.

Copy link

commented Aug 2, 2013

OK, so I'm having the same issue when using Laravel 4, and I believe I've found a possibly source of the problem.

I should say that i am testing all this locally - ie. i have not enabled remote coverage. ( as in, i getting this error while trying to test my project locally (testing a testing framework - the word test is going to get used a lot ;) ))

Here's my trace.

I've been getting the same unserialize() error at 0 bytes error

it comes from the afterSuite method of Codeception\Subscriber\CodeCoverage as @LionArt said. Again, this was being caused by the 404 page being passed as the argument to unserialize, rather than a serializable string.

A few lines before, there is the following code:

$remoteModule = $this->getRemoteConnectionModule();
if (!$remoteModule) {
  $this->coverage->merge($coverage);
  return;
};

As I am developing locally, and have not specified any remote connection modules, I would assume that this should cause the method to return, and hence not call the unserialize function later.

So I traced the getRemoteConnectionModule method, to see what remote module is being returned.

I get the PhpBrowser module - which extends Mink, which implements RemoteInterface.

Therefore, this gets returned by the getRemoteConnectionModule method to afterSuite even when not using remote coverage, hence not calling the code inside the if block to return the method, and calling the code that is meant to be called to get remote coverage data and causing the error.

I would happily write a test / fix for this, but i think it needs some discussion first:

  • is a RemoteInterface the right thing to be checking for (ie. a class might have more than one responsibility (i know it shouldn't in most cases, but it could - ie. phpbrowser?), including RemoteInterface)?
  • should afterSuite be checking for something else (ie. a config option) to see if remote coverage is enabled / disabled?
  • is my analysis of the problem even correct?
@FnTm

This comment has been minimized.

Copy link
Contributor

commented Aug 5, 2013

Can't comment on the issue or the proposal, but I too have this same issue

@DavertMik

This comment has been minimized.

Copy link
Member

commented Aug 8, 2013

It looks like this unserialize error is quite obvious, yet, it can't be completely fixed in Codeception.

Let me explain this: when we deal with client->server testing (PhpBrowser, Selenium modules) we are collecting remote code coverage. Yes, the local code coverage is collected for classes executed in the same PHP process, and if we execute scripts on server we need to count code coverage there, and finally fetch report from server.

File is fetched via /c3/report/serizlied url, which is generated by c3.php script.
If you included c3.php file into your front controller, you probably get the results.
If not, server returns regular HTML page, like in case of @clouddueling

Please check that c3.php is included into your application front controller, according to manual.

I will block this error, but you should check if server really returns the serilized coverage data from getRemoteCoverageFile . If not - you need to investigate why.

@DavertMik

This comment has been minimized.

Copy link
Member

commented Aug 8, 2013

I'm closing this ticket because I added @unserialize, thus it should not throw errors anymore.

If you got issues similar to @brechtdewinne please open another ticket. It looks liks phar archive has limited capabilities in performing remote code coverage collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.