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

Need some help to make it running #24

Closed
3DFace opened this issue Aug 30, 2017 · 7 comments
Closed

Need some help to make it running #24

3DFace opened this issue Aug 30, 2017 · 7 comments

Comments

@3DFace
Copy link

3DFace commented Aug 30, 2017

Unfortunately I can't make it works:

D:\Projects\php\generic-storage>php D:\Tools\infection.phar

    0 [>---------------------------] < 1 secRunning initial test suite...


    1 [->--------------------------] < 1 sec

Generate mutants...

Processing source code files:  0/14
( .... 1-13 skipped ...)
Processing source code files: 14/14Creating mutated files and processes:   0/225

Warning: file_get_contents(C:\Users\oz\AppData\Local\Temp/infection/coverage-xml/index.xml): failed to open stream: No such file or directory in phar://D:/Tools/infection.phar/src/TestFramework/Coverage/CodeCoverageData.php on line 147

Call Stack:
    0.0035     681144   1. {main}() D:\Tools\infection.phar:0
    0.0045     687160   2. require('phar://D:/Tools/infection.phar/bin/infection') D:\Tools\infection.phar:10
    0.0160    1847160   3. Symfony\Component\Console\Application->run() phar://D:/Tools/infection.phar/bin/infection:33
    0.0525    2007496   4. Symfony\Component\Console\Application->doRun() phar://D:/Tools/infection.phar/vendor/symfony/console/Application.php:127
    0.0530    2073032   5. Symfony\Component\Console\Application->doRunCommand() phar://D:/Tools/infection.phar/vendor/symfony/console/Application.php:220
    0.0530    2073032   6. Symfony\Component\Console\Command\Command->run() phar://D:/Tools/infection.phar/vendor/symfony/console/Application.php:866
    0.0535    2078560   7. Infection\Command\InfectionCommand->execute() phar://D:/Tools/infection.phar/vendor/symfony/console/Command/Command.php:261
    0.0540    2131368   8. Infection\InfectionApplication->run() phar://D:/Tools/infection.phar/src/Command/InfectionCommand.php:115
    2.0333   10345128   9. Infection\Process\Runner\MutationTestingRunner->run() phar://D:/Tools/infection.phar/src/InfectionApplication.php:100
    2.0338   10347840  10. array_map() phar://D:/Tools/infection.phar/src/Process/Runner/MutationTestingRunner.php:73
    2.0338   10347896  11. Infection\Process\Runner\MutationTestingRunner->Infection\Process\Runner\{closure}() phar://D:/Tools/infection.phar/src/Process/Runner/MutationTestingRunner.php:73
    2.0338   10347896  12. Infection\Mutant\MutantCreator->create() phar://D:/Tools/infection.phar/src/Process/Runner/MutationTestingRunner.php:65
    2.0413   11533384  13. Infection\Mutant\MutantCreator->isCoveredByTest() phar://D:/Tools/infection.phar/src/Mutant/MutantCreator.php:66
    2.0413   11533384  14. Infection\TestFramework\Coverage\CodeCoverageData->hasExecutedMethodOnLine() phar://D:/Tools/infection.phar/src/Mutant/MutantCreator.php:88
    2.0413   11533384  15. Infection\TestFramework\Coverage\CodeCoverageData->getCoverage() phar://D:/Tools/infection.phar/src/TestFramework/Coverage/CodeCoverageData.php:83
    2.0413   11533480  16. file_get_contents() phar://D:/Tools/infection.phar/src/TestFramework/Coverage/CodeCoverageData.php:147


Fatal error: Uncaught TypeError: Argument 1 passed to Infection\TestFramework\PhpUnit\Coverage\CoverageXmlParser::parse() must be of the type string, boolean given, called in phar://D:/Tools/infection.phar/src/TestFramework/Coverage/CodeCoverageData.php on line 149 and defined in phar://D:/Tools/infection.phar/src/TestFramework/PhpUnit/Coverage/CoverageXmlParser.php on line 28

TypeError: Argument 1 passed to Infection\TestFramework\PhpUnit\Coverage\CoverageXmlParser::parse() must be of the type string, boolean given, called in phar://D:/Tools/infection.phar/src/TestFramework/Coverage/CodeCoverageData.php on line 149 in phar://D:/Tools/infection.phar/src/TestFramework/PhpUnit/Coverage/CoverageXmlParser.php on line 28

Call Stack:
    0.0035     681144   1. {main}() D:\Tools\infection.phar:0
    0.0045     687160   2. require('phar://D:/Tools/infection.phar/bin/infection') D:\Tools\infection.phar:10
    0.0160    1847160   3. Symfony\Component\Console\Application->run() phar://D:/Tools/infection.phar/bin/infection:33

It seems like it's trying to read code coverage results but cant find them.

Dir C:\Users\oz\AppData\Local\Temp\infection contains only 3 files:

mutant.c386525a8f162700e34fd3cb5d419d64.infection.php
phpunit.junit.xml
phpunitConfiguration.initial.infection.xml

There is no ./coverage-xml/ subdir.

Here is my infection.json (generated):

{
    "timeout": 10,
    "source": {
        "directories": [
            "src"
        ]
    },
    "logs": {
        "text": "infection-log.txt"
    }
}

And phpunit.xml:

<phpunit bootstrap="bootstrap.php">
    <testsuites>
        <testsuite name="Unit Tests">
            <directory suffix="Test.php" phpVersion="7.1.0" phpVersionOperator=">=">tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist>
            <directory>src</directory>
        </whitelist>
    </filter>
</phpunit>

Should I add/fix some parameters? Or should I run phpunit code coverage by myself with specific options?

@corpsee
Copy link
Member

corpsee commented Aug 30, 2017

Can you run phpunit --coverage-text for your project and post output here?

@3DFace
Copy link
Author

3DFace commented Aug 30, 2017

Sure, here it is:

D:\Projects\php\generic-storage>phpunit --coverage-text
PHPUnit 6.4-ga1b5663 by Sebastian Bergmann and contributors.

...............................................................  63 / 134 ( 47%)
............................................................... 126 / 134 ( 94%)
........                                                        134 / 134 (100%)

Time: 6.03 seconds, Memory: 10.00MB

OK (134 tests, 232 assertions)

Code Coverage Report:       
  2017-08-30 14:28:41       
                            
 Summary:                   
  Classes: 100.00% (9/9)    
  Methods: 100.00% (76/76)  
  Lines:   100.00% (490/490)

\dface\GenericStorage\Memory::MemoryManyToMany
  Methods: 100.00% ( 6/ 6)   Lines: 100.00% ( 16/ 16)
\dface\GenericStorage\Memory::MemoryOrderDefComparator
  Methods: 100.00% ( 2/ 2)   Lines: 100.00% ( 13/ 13)
\dface\GenericStorage\Memory::MemorySet
  Methods: 100.00% ( 4/ 4)   Lines: 100.00% (  8/  8)
\dface\GenericStorage\Memory::MemoryStorage
  Methods: 100.00% (10/10)   Lines: 100.00% ( 42/ 42)
\dface\GenericStorage\Mysql::MyManyToMany
  Methods: 100.00% (10/10)   Lines: 100.00% ( 67/ 67)
\dface\GenericStorage\Mysql::MySet
  Methods: 100.00% ( 6/ 6)   Lines: 100.00% ( 41/ 41)
\dface\GenericStorage\Mysql::MyStorage
  Methods: 100.00% (27/27)   Lines: 100.00% (263/263)
\dface\GenericStorage\Mysql::MyStorageBuilder
  Methods: 100.00% (10/10)   Lines: 100.00% ( 32/ 32)
\dface\GenericStorage\Mysql::MyUniqueConstraintViolation
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  4/  4)

@maks-rafalko
Copy link
Member

I tried to run Infection for your project (https://github.com/3DFace/generic-storage, commit 3DFace/generic-storage@6ad7556) with disabled MySQL-related tests, and it works (I'm using MacOS, not Windows).

Also, noticed that phpunit.xml has been changed since your last message, so I'm not sure I've tested the same code as you.

Could you please try to run infection on the same commit on windows and unix and post results here?

@3DFace
Copy link
Author

3DFace commented Aug 31, 2017

@borNfreee Thank you for investigation!

Just tried it on Unix and it seems to be working.

I have tested both - HEAD and commit referenced by you. Result is the same - it works on Unix but not on Windows (errors from first message).

Not sure if unix output matters... here it is:

Running initial test suite...                                                    
                                                                                 
  147 [============================] 4 secs                                      
                                                                                 
Generate mutants...                                                              
                                                                                 
Processing source code files: 14/14                                              
Creating mutated files and processes: 225/225                                    
.: killed, M: escaped, S: uncovered, E: fatal error, T: timed out                
                                                                                 
SS...M...M..MM.M.M..M.M.M.M..M.......S.MM.SMM..MM.   ( 50 / 225)                 
....MM.MMMMTT..MMTTMMTTM..M..T.M..T.M...M........M   (100 / 225)                 
M.T.....M.........M..T.....M.....S..M..M..M..M....   (150 / 225)                 
.......SSSSM.M...M..M.M.M.........S.M.SSS.........   (200 / 225)                 
......SSSSSSSSSSSSSSSSSSS                            (225 / 225)                 
                                                                                 
225 mutations were generated:                                                    
     135 mutants were killed                                                     
      32 mutants were not covered by tests                                       
      48 covered mutants were not detected                                       
      10 time outs were encountered                                              
                                                                                 
Metrics:                                                                         
         Mutation Score Indicator (MSI): 64%                                     
         Mutation Code Coverage: 86%                                             
         Covered Code MSI: 75%                                                   
                                                                                 
Please note that some mutants will inevitably be harmless (i.e. false positives).

@3DFace
Copy link
Author

3DFace commented Aug 31, 2017

To my shame, I found old (3.x) phpunit.phar on my PATH :(

After removing it infection told me Unable to locate a phpunit executable on local system. Ensure that phpunit is installed and available. Although I have phpunit as dev-dependency in my project, and have installed it by composer global require. Phpunit from root of my project works correctly.

After downloading phpunit.phar and putting it on my PATH all seems working now.

Should it work when phpunit is project dev-dependency or installed as composer global require?

@maks-rafalko
Copy link
Member

maks-rafalko commented Aug 31, 2017

Should it work when phpunit is project dev-dependency

yes, it should and it works. Please see the following code where vendor bin folder is added to PATH.

private function addVendorFolderToPath()
{
$vendorPath = null;
try {
$composer = $this->findComposer();
$process = new Process(sprintf('%s %s', $composer, 'config bin-dir'));
$process->run();
$vendorPath = trim($process->getOutput());
} catch (\RuntimeException $e) {
$candidate = getcwd() . '/vendor/bin';
if (file_exists($candidate)) {
$vendorPath = $candidate;
}
}
if (!is_null($vendorPath)) {
putenv('PATH=' . $vendorPath . PATH_SEPARATOR . getenv('PATH'));
}
}

or installed as composer global require

If your composer global bin dir is already in PATH, it should work out of the box. But infection does not search this folder itself.

E.g. I've added global composer bin dir to path on my machine:

echo $PATH # outputs "...;/Users/user/.composer/vendor/bin;..."

I'm closing this issue since there is no bug :)

Please feel free to open a separate one about any issues with executable finder.

@3DFace
Copy link
Author

3DFace commented Aug 31, 2017

Indeed it was again due to my weak environment.

My composer.bat was written by hand and it was lacked a line @echo OFF. This led to pollution of composer config bin-dir output by command itself.

Sorry for wasting your time and thank you for help!

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

3 participants