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

symbolic link trouble + PHPUnit unknown #778

Closed
ccwebdesign opened this issue Aug 31, 2019 · 26 comments · Fixed by #791 or #1288
Closed

symbolic link trouble + PHPUnit unknown #778

ccwebdesign opened this issue Aug 31, 2019 · 26 comments · Fixed by #791 or #1288

Comments

@ccwebdesign
Copy link

ccwebdesign commented Aug 31, 2019

Question Answer
Infection version 0.13.6
Test Framework version PHPUnit 7.5.15
PHP version 7.3.5
Platform Windows 10 Pro (using ConEmu)
Github Repo https://github.com/ccwebdesign/infection-temp

When run under a symbolic link in a terminal, infection creates all of the mutants, but claims they're all uncovered by tests.

To reproduce:

  • create a directory with some code, tests, and Infection
  • create a symbolic link to that directory
  • cd into the symbolic link and run tests then infection

Repository above contains samples and structure if you want it.

Infection was run from the test subdirectory with:

..\..\vendor\bin\infection --coverage=tmp -j=4

Separate issue is that the PHPUnit version is unknown, both in the symlink folder and the actual one. (Whether vendor/bin directory is or isn't in PATH.)

Left out the phpunit.junit.xml for brevity (and since it's probably not relevant).

Output with issue
You are running Infection with Xdebug enabled.
    ____      ____          __  _
   /  _/___  / __/__  _____/ /_(_)___  ____
   / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
 _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
/___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/

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

PHPUnit version: unknown

   1 [============================] < 1 secProcessing source code files:   0/585

Generate mutants...

Processing source code files: 585/585Creating mutated files and processes:    0/6999
Creating mutated files and processes: 6999/6999
...
6999 mutations were generated:
      0 mutants were killed
   6999 mutants were not covered by tests
      0 covered mutants were not detected
      0 errors were encountered
      0 time outs were encountered
@BackEndTea
Copy link
Member

Could you run infection with the --debug flag, and with -vvv, so we get extra information, this could help us find the underlying issue.

Also, what happends when you run infection from the root of the project, instead of the test sub directory?

@ccwebdesign
Copy link
Author

ccwebdesign commented Sep 2, 2019

Also, what happends when you run infection from the root of the project, instead of the test sub directory?

No change there.

Did notice that the composer bin sometimes generates with an absolute path on either phpunit or infection (completely randomly), but that's probably a composer issue from what I can find: composer/composer#5427.

Even changing these to the proper relative paths doesn't change the output:

  • from within symbolic link, mutants aren't covered
  • from actual path, mutants are killed
Debug output, subfolder (under symlink)
You are running Infection with Xdebug enabled.                                               
     ____      ____          __  _                                                           
    /  _/___  / __/__  _____/ /_(_)___  ____                                                 
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \                                                
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /                                                
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/                                                 
                                                                                             
Running initial test suite...                                                                
                                                                                             
PHPUnit version: unknown                                                                     
                                                                                             
    1 [============================] < 1 sec                                                 
                                                                                             
dir=$(cd "${0%[/\\]*}" > /dev/null)                                                          
                                                                                             
if [ -d /proc/cygdrive ]; then                                                               
    case $(which php) in                                                                     
        $(readlink -n /proc/cygdrive)/*)                                                     
            # We are in Cygwin using Windows php, so the path must be translated             
            dir=$(cygpath -m "$dir");                                                        
            ;;                                                                               
    esac                                                                                     
fi                                                                                           
                                                                                             
"${dir}/phpunit" "$@"                                                                        
                                                                                             
Processing source code files: 0/1                                                            
                                                                                             
Generate mutants...                                                                          
                                                                                             
Processing source code files: 1/1Creating mutated files and processes: 0/2                   
Creating mutated files and processes: 2/2                                                    
.: killed, M: escaped, S: uncovered, E: fatal error, T: timed out                            
                                                                                             
SS                                                   (2 / 2)                                 
                                                                                             
2 mutations were generated:                                                                  
       0 mutants were killed                                                                 
       2 mutants were not covered by tests                                                   
       0 covered mutants were not detected                                                   
       0 errors were encountered                                                             
       0 time outs were encountered                                                          
                                                                                             
Metrics:                                                                                     
         Mutation Score Indicator (MSI): 0%                                                  
         Mutation Code Coverage: 0%                                                          
         Covered Code MSI: 0%                                                                
                                                                                             
Please note that some mutants will inevitably be harmless (i.e. false positives).            
                                                                                             
Time: 0s. Memory: 10.00MB                                                                                                       
Output from root, actual
You are running Infection with Xdebug enabled.                                               
     ____      ____          __  _                                                           
    /  _/___  / __/__  _____/ /_(_)___  ____                                                 
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \                                                
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /                                                
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/                                                 
                                                                                             
    0 [>---------------------------] < 1 secRunning initial test suite...                    
                                                                                             
PHPUnit version: unknown                                                                     
                                                                                             
    1 [============================] < 1 sec                                                 
                                                                                             
dir=$(cd "${0%[/\\]*}" > /dev/null)                                                          
                                                                                             
if [ -d /proc/cygdrive ]; then                                                               
    case $(which php) in                                                                     
        $(readlink -n /proc/cygdrive)/*)                                                     
            # We are in Cygwin using Windows php, so the path must be translated             
            dir=$(cygpath -m "$dir");                                                        
            ;;                                                                               
    esac                                                                                     
fi                                                                                           
                                                                                             
"${dir}/phpunit" "$@"                                                                        
                                                                                             
                                                                                             
                                                                                             
Generate mutants...                                                                          
Processing source code files: 0/1                                                            
Processing source code files: 1/1Creating mutated files and processes: 0/2                   
Creating mutated files and processes: 2/2                                                    
.: killed, M: escaped, S: uncovered, E: fatal error, T: timed out                            
                                                                                             
..                                                   (2 / 2)                                 
                                                                                             
2 mutations were generated:                                                                  
       2 mutants were killed                                                                 
       0 mutants were not covered by tests                                                   
       0 covered mutants were not detected                                                   
       0 errors were encountered                                                             
       0 time outs were encountered                                                          
                                                                                             
Metrics:                                                                                     
         Mutation Score Indicator (MSI): 100%                                                
         Mutation Code Coverage: 100%                                                        
         Covered Code MSI: 100%                                                              
                                                                                             
Please note that some mutants will inevitably be harmless (i.e. false positives).            
                                                                                             
Time: 0s. Memory: 10.00MB                                                                                                                                
Output from root, symlink
You are running Infection with Xdebug enabled.                                           
     ____      ____          __  _                                                       
    /  _/___  / __/__  _____/ /_(_)___  ____                                             
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \                                            
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /                                            
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/                                             
                                                                                         
Running initial test suite...                                                            
                                                                                         
PHPUnit version: unknown                                                                 
                                                                                         
    1 [============================] < 1 sec                                             
                                                                                         
dir=$(cd "${0%[/\\]*}" > /dev/null)                                                      
                                                                                         
if [ -d /proc/cygdrive ]; then                                                           
    case $(which php) in                                                                 
        $(readlink -n /proc/cygdrive)/*)                                                 
            # We are in Cygwin using Windows php, so the path must be translated         
            dir=$(cygpath -m "$dir");                                                    
            ;;                                                                           
    esac                                                                                 
fi                                                                                       
                                                                                         
"${dir}/phpunit" "$@"                                                                    
                                                                                         
Processing source code files: 0/1                                                        
                                                                                         
Generate mutants...                                                                      
                                                                                         
Processing source code files: 1/1Creating mutated files and processes: 0/2               
Creating mutated files and processes: 2/2                                                
.: killed, M: escaped, S: uncovered, E: fatal error, T: timed out                        
                                                                                         
SS                                                   (2 / 2)                             
                                                                                         
2 mutations were generated:                                                              
       0 mutants were killed                                                             
       2 mutants were not covered by tests                                               
       0 covered mutants were not detected                                               
       0 errors were encountered                                                         
       0 time outs were encountered                                                      
                                                                                         
Metrics:                                                                                 
         Mutation Score Indicator (MSI): 0%                                              
         Mutation Code Coverage: 0%                                                      
         Covered Code MSI: 0%                                                            
                                                                                         
Please note that some mutants will inevitably be harmless (i.e. false positives).        
                                                                                         
Time: 0s. Memory: 10.00MB                     

@sanmai
Copy link
Member

sanmai commented Sep 17, 2019

Steps to reproduce:

git clone https://github.com/ccwebdesign/infection-temp
cd infection-temp/
git checkout 2a5990fc4827fc0d71bda2f7fed6813b152b8773
composer install
cd lib/App/test/
../../vendor/bin/phpunit
../../vendor/bin/infection

The last command outputs:

$ ../../vendor/bin/infection 
You are running Infection with Xdebug enabled.
     ____      ____          __  _
    /  _/___  / __/__  _____/ /_(_)___  ____
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/

Running initial test suite...

PHPUnit version: 7.5.15

    1 [============================] < 1 sec
                                                                                                                        
 [ERROR] Project tests must be in a passing state before running Infection.                                             
                                                                                                                        
         Infection runs the test suite in a RANDOM order. Make sure your tests do not have hidden dependencies.         
                                                                                                                        
         You can add these attributes to `phpunit.xml` to check it: <phpunit executionOrder="random"                    
         resolveDependencies="true" ...                                                                                 
                                                                                                                        
         If you don't want to let Infection run tests in a random order, set the `executionOrder` to some value, for    
         example <phpunit executionOrder="default"                                                                      
                                                                                                                        
         Check the executed command to identify the problem: '/tmp/infection-temp/lib/vendor/phpunit/phpunit/phpunit'   
         '--configuration'                                                                                              
         '/tmp/infection-temp/lib/App/test/tmp/infection/infection/phpunitConfiguration.initial.infection.xml'          
                                                                                                                        
         PHPUnit reported an exit code of 143.                                                                          
                                                                                                                        
         Refer to the PHPUnit's output below:                                                                           
                                                                                                                        
         STDERR:                                                                                                        
                                                                                                                        
         PHPUnit 7.5.15 by Sebastian Bergmann and contributors.                                                         
                                                                                                                        
         Runtime:       PHP 7.3.8-1 with Xdebug 2.7.2                                                                   
         Configuration:                                                                                                 
         /tmp/infection-temp/lib/App/test/tmp/infection/infection/phpunitConfiguration.initial.infection.xml            
         Random seed:   1568713992                                                                                      
                                                                                                                        
                                                                                                                        

@sanmai
Copy link
Member

sanmai commented Sep 17, 2019

Removing stderr="true" solves the problem.

 <phpunit colors="true"
     verbose="true"
-    stderr="true"
     beStrictAboutOutputDuringTests="true">

It is PHPUnit that exits with 143, do I don't think this is the exact problem of Infection. But it may make sense to remove this directive in our configuration file because we certainly do not need it.

https://phpunit.readthedocs.io/en/8.3/configuration.html#the-stderr-attribute

This attribute configures whether PHPUnit should print its output to stderr instead of stdout.

@maks-rafalko
Copy link
Member

maks-rafalko commented Sep 17, 2019

Does it mean that PHPUnit exits with non-zero code even if tests pass?

But it may make sense to remove this directive in our configuration file because we certainly do not need it.

Sounds good 👍

@sanmai
Copy link
Member

sanmai commented Sep 17, 2019

It didn't go as far as running tests, as I see it.

@ccwebdesign
Copy link
Author

ccwebdesign commented Sep 17, 2019

@sanmai
Removing stderr didn't work for me -- output came out the same (killed in actual directory, not covered in symbolic). But that got me thinking:

The issue seems to be the <project source> in coverage-xml/index.xml. When phpunit is run from either the actual or symbolic link directory, this is always the real path.

Changing project source to the symbolic path makes the symbolic link run work and actual directory run fail (and vice versa).

Tested with both PHPUnit 7.5.16 and 8.3.5.

To reproduce:

git clone https://github.com/ccwebdesign/infection-temp
cd infection-temp/
git checkout 2a5990fc4827fc0d71bda2f7fed6813b152b8773
composer install
cd lib/App/test/
../../vendor/bin/phpunit
*open /lib/App/test/tmp/coverage-xml/index.xml
*change <project> source to symbolic link
../../vendor/bin/infection

*For instance:

If the actual directory is C:\Apache24\htdocs\infection-temp, <project source="C:\Apache24\htdocs\infection-temp"> should be what shows up in the index.xml file (regardless of run location).

If the sym link is C:\Apache24\htdocs\infection-test, change <project> source to C:\Apache24\htdocs\infection-test and infection should succeed when run in the symbolic link directory. Note that this will cause it to skip mutants if run from the actual directory.

tl;dr - The hard-coded path in coverage-xml/index.xml is what seems to be causing the problem.

@sanmai
Copy link
Member

sanmai commented Sep 17, 2019 via email

@ccwebdesign
Copy link
Author

If you could make a reproducible case like I did above, this will be a big help. So far I cannot reproduce the issue, and I have my development copy of Infection symlinked from elsewhere, with no problems whatsoever.

@sanmai Added in previous comment.

@sanmai
Copy link
Member

sanmai commented Sep 19, 2019

*change source to symbolic link

Can you show a diff to this change? Where should the symbolic link point?

@ccwebdesign
Copy link
Author

ccwebdesign commented Sep 19, 2019

In this case, the actual directory is:
C:\Apache24\htdocs\infection-temp\lib\App\src

Symbolic link is:
C:\Apache24\htdocs\infection-test\lib\App\src

PHPUnit generated `tmp/coverage-xml/index.xml` from actual directory:
<?xml version="1.0"?>
<phpunit xmlns="https://schema.phpunit.de/coverage/1.0">
  <build time="Thu Sep 19 1:25:37 GMT+0000 2019" phpunit="7.5.16" coverage="6.1.4">
    <runtime name="PHP" version="7.3.5" url="https://secure.php.net/"/>
    <driver name="xdebug" version="2.7.2"/>
  </build>
 <project source="C:\Apache24\htdocs\infection-temp\lib\App\src">
    <tests>
      <test name="Test\CodeTest::getTest_returns_boolean" size="unknown" result="0" status="PASSED"/>
      <test name="Test\CodeTest::getTest_returns_constructed_value" size="unknown" result="0" status="PASSED"/>
    </tests>
    <directory name="/">
      <totals>
        <lines total="20" comments="0" code="20" executable="3" executed="3" percent="100.00"/>
        <methods count="2" tested="2" percent="100.00"/>
        <functions count="0" tested="0" percent="0"/>
        <classes count="1" tested="1" percent="100.00"/>
        <traits count="0" tested="0" percent="0"/>
      </totals>
      <file name="Code.php" href="Code.php.xml">
        <totals>
          <lines total="20" comments="0" code="20" executable="3" executed="3" percent="100.00"/>
          <methods count="2" tested="2" percent="100.00"/>
          <functions count="0" tested="0" percent="0"/>
          <classes count="1" tested="1" percent="100.00"/>
          <traits count="0" tested="0" percent="0"/>
        </totals>
      </file>
    </directory>
  </project>
</phpunit>

PHPUnit generated tmp/coverage-xml/index.xml from symbolic link directory is the same.

Making the following change lets it pass under the symbolic link, though mutants are skipped on the actual directory then.
<?xml version="1.0"?>
<phpunit xmlns="https://schema.phpunit.de/coverage/1.0">
  <build time="Thu Sep 19 1:25:37 GMT+0000 2019" phpunit="7.5.16" coverage="6.1.4">
    <runtime name="PHP" version="7.3.5" url="https://secure.php.net/"/>
    <driver name="xdebug" version="2.7.2"/>
  </build>
- <project source="C:\Apache24\htdocs\infection-temp\lib\App\src">
+ <project source="C:\Apache24\htdocs\infection-test\lib\App\src">
    <tests>
      <test name="Test\CodeTest::getTest_returns_boolean" size="unknown" result="0" status="PASSED"/>
      <test name="Test\CodeTest::getTest_returns_constructed_value" size="unknown" result="0" status="PASSED"/>
    </tests>
    <directory name="/">
      <totals>
        <lines total="20" comments="0" code="20" executable="3" executed="3" percent="100.00"/>
        <methods count="2" tested="2" percent="100.00"/>
        <functions count="0" tested="0" percent="0"/>
        <classes count="1" tested="1" percent="100.00"/>
        <traits count="0" tested="0" percent="0"/>
      </totals>
      <file name="Code.php" href="Code.php.xml">
        <totals>
          <lines total="20" comments="0" code="20" executable="3" executed="3" percent="100.00"/>
          <methods count="2" tested="2" percent="100.00"/>
          <functions count="0" tested="0" percent="0"/>
          <classes count="1" tested="1" percent="100.00"/>
          <traits count="0" tested="0" percent="0"/>
        </totals>
      </file>
    </directory>
  </project>
</phpunit>

As for where it should point, I'm not sure. /src/TestFramework/PhpUnit/Coverage/CoverageXmlParser.php line 227 seems to be where it's having trouble, but I haven't looked over the code-base well yet and couldn't say for sure.

@sanmai
Copy link
Member

sanmai commented Sep 19, 2019

Why would you want to change that file?

@ccwebdesign
Copy link
Author

ccwebdesign commented Sep 19, 2019

The coverage-xml file? I wouldn't. Your command when you ran infection and got the 143 error, then the stderr setting got me thinking on trying to figure out where the problem was originating, which seems to be the absolute/hard-coded directory in project source within coverage-xml/index.xml.

@sanmai
Copy link
Member

sanmai commented Sep 19, 2019

Well, it is kind of obvious that if you change things from under Infection, it'll go haywire. This is not the issue we can fix, because one should not change said files in the first place.

If you don't have the issue with the dev version of Infeciton, let's close this. Else, please give us something so we can reproduce the issue.

Install the dev version as follows:

composer require --dev infection/infection:dev-master

@ccwebdesign
Copy link
Author

ccwebdesign commented Sep 19, 2019

Infection dev version, actual directory:
$ ..\..\vendor\bin\infection --coverage=tmp -j=4 -vvv --debug                                   
You are running Infection with Xdebug enabled.                                                  
     ____      ____          __  _                                                              
    /  _/___  / __/__  _____/ /_(_)___  ____                                                    
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \                                                   
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /                                                   
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/                                                    
                                                                                                
    0 [>---------------------------] < 1 secRunning initial test suite...                       
                                                                                                
PHPUnit version: unknown                                                                        
                                                                                                
    1 [============================] < 1 sec                                                    
                                                                                                
dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../phpunit/phpunit" && pwd)                             
                                                                                                
if [ -d /proc/cygdrive ]; then                                                                  
    case $(which php) in                                                                        
        $(readlink -n /proc/cygdrive)/*)                                                        
            # We are in Cygwin using Windows php, so the path must be translated                
            dir=$(cygpath -m "$dir");                                                           
            ;;                                                                                  
    esac                                                                                        
fi                                                                                              
                                                                                                
"${dir}/phpunit" "$@"                                                                           
                                                                                                
Processing source code files: 0/1                                                               
                                                                                                
Generate mutants...                                                                             
                                                                                                
Processing source code files: 1/1Creating mutated files and processes: 0/2                      
Creating mutated files and processes: 2/2                                                       
.: killed, M: escaped, S: uncovered, E: fatal error, T: timed out                               
                                                                                                
..                                                   (2 / 2)                                    
                                                                                                
2 mutations were generated:                                                                     
       2 mutants were killed                                                                    
       0 mutants were not covered by tests                                                      
       0 covered mutants were not detected                                                      
       0 errors were encountered                                                                
       0 time outs were encountered                                                             
                                                                                                
Metrics:                                                                                        
         Mutation Score Indicator (MSI): 100%                                                   
         Mutation Code Coverage: 100%                                                           
         Covered Code MSI: 100%                                                                 
                                                                                                
Please note that some mutants will inevitably be harmless (i.e. false positives).               
                                                                                                
Time: 0s. Memory: 14.00MB                                                                                                                                
With the dev branch under the symbolic link:
$ ..\..\vendor\bin\infection --coverage=tmp -j=4 -vvv --debug                                 
You are running Infection with Xdebug enabled.                                                
     ____      ____          __  _                                                            
    /  _/___  / __/__  _____/ /_(_)___  ____                                                  
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \                                                 
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /                                                 
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/                                                  
                                                                                              
    0 [>---------------------------] < 1 secRunning initial test suite...                     
                                                                                              
PHPUnit version: unknown                                                                      
                                                                                              
    1 [============================] < 1 sec                                                  
                                                                                              
dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../phpunit/phpunit" && pwd)                           
                                                                                              
if [ -d /proc/cygdrive ]; then                                                                
    case $(which php) in                                                                      
        $(readlink -n /proc/cygdrive)/*)                                                      
            # We are in Cygwin using Windows php, so the path must be translated              
            dir=$(cygpath -m "$dir");                                                         
            ;;                                                                                
    esac                                                                                      
fi                                                                                            
                                                                                              
"${dir}/phpunit" "$@"                                                                         
                                                                                              
Processing source code files: 0/1                                                             
                                                                                              
Generate mutants...                                                                           
                                                                                              
Processing source code files: 1/1Creating mutated files and processes: 0/2                    
Creating mutated files and processes: 2/2                                                     
.: killed, M: escaped, S: uncovered, E: fatal error, T: timed out                             
                                                                                              
SS                                                   (2 / 2)                                  
                                                                                              
2 mutations were generated:                                                                   
       0 mutants were killed                                                                  
       2 mutants were not covered by tests                                                    
       0 covered mutants were not detected                                                    
       0 errors were encountered                                                              
       0 time outs were encountered                                                           
                                                                                              
Metrics:                                                                                      
         Mutation Score Indicator (MSI): 0%                                                   
         Mutation Code Coverage: 0%                                                           
         Covered Code MSI: 0%                                                                 
                                                                                              
Please note that some mutants will inevitably be harmless (i.e. false positives).             
                                                                                              
Time: 0s. Memory: 14.00MB                                                                                                                        

Issue exists with the dev branch.

To be clear: I didn't change the index.xml file until trying to figure out why when I mentioned this first, two comments back:

The issue seems to be the in coverage-xml/index.xml. When phpunit is run from either the actual or symbolic link directory, this is always the real path.

Changing the xml file is what led me to determine that the absolute path in project source within it may be the issue (which is always the real path, even under a symlink run of PHPUnit).

Since the project source is the absolute path, when infection runs, it doesn't seem to be finding the tests, since they're in a different (absolute) path.

*updated output with --debug (sorry, missed that command)

@sanmai
Copy link
Member

sanmai commented Sep 19, 2019

Since the project source is the absolute path, when infection runs, it doesn't seem to be finding the tests, since they're in a different (absolute) path.

Isn't that kind of expected? If you symlink something into entirely different hierarchy where you can't see the previously seen tests directory, then you obviously have no tests PHPUnit-wise, and no coverage too. Which is exactly what Infection is trying to say you: nothing is covered by tests.

The other question is why #602 didn't trigger.

@ccwebdesign
Copy link
Author

ccwebdesign commented Sep 19, 2019

If the entire directory structure is under a symbolic link (as it is for this), the tests are there (as is the code). PHPUnit finds it all, since it's there, but generates the coverage-xml/index.xml file with the actual (absolute) path, instead of the symlink.

Infection isn't finding those tests, because it's looking under the actual (absolute) path, which either doesn't match the current path and is ignored (?) or something else strange is going on.

Make sense? Or am I explaining this badly?

Or, since the files covered by tests are in the actual directory (according to the coverage-xml/index.xml file), Infection is saying the symlink src isn't covered, since the index.xml tests are pointing to the real files, instead of the ones under the symlink. (Maybe?)

@sanmai
Copy link
Member

sanmai commented Sep 19, 2019

If I do like this:

ln -s lib foobar
cd foobar/App/test/
mv unit/ unit2
ln -s unit2/ unit
../../vendor/bin/infection

The output is absolutely the same. Two layers of symlinks here if you note.

Can you tell exactly which symbolic links you make? Best if as in a script.

@ccwebdesign
Copy link
Author

ccwebdesign commented Sep 19, 2019

Mine are (Windows, unfortunately):

mklink /D .\infection-test .\infection-temp
cd infection-test
composer install
cd lib\App\test
..\..\vendor\bin\phpunit
..\..\vendor\bin\infection

In this case, it ends up with:

C:\Apache24\htdocs\infection-temp (real)
C:\Apache24\htdocs\infection-test (symlink)

With everything in the repository below that.

If it helps, I can test it in Linux to see if I get the same output you are. It could be, in part, a Windows issue.

@sanmai
Copy link
Member

sanmai commented Sep 19, 2019

Thank you for explaining the issue. With the same setup I cannot reproduce the exact issue under Linux, unfortunately. I'll keep trying though.

@ccwebdesign
Copy link
Author

@sanmai Anytime. XD I'll check in Linux, too, see if it's purely a matter of the paths generated in Windows runs and let you know (probably tomorrow).

@ccwebdesign
Copy link
Author

@sanmai It seems like it's just a Windows symbolic link problem.

Had to add a new test to make it so that no mutants escaped (using the dev branch on Linux), but you're right -- symbolic links all worked fine.

Let me know if you all need any additional log data or for me to check into anything on this end.

@DanielSiepmann
Copy link

I've a similar issue which might have the same root cause.

I nailed it down to the infection/include-interceptor component.
It turns out that PHPs is_link will return false instead of true for Symlinks (on Linux) once Infection\StreamWrapper\IncludeInterceptor::enable(); was called. I don't know the reason or solution.

But it is also a blocker for me, as this prevents functional test setup with TYPO3 CMS. You can use DanielSiepmann/tracking@41eb616 as a state to reprocude the issue. The associated action run is failing for that reason: https://github.com/DanielSiepmann/tracking/actions/runs/198375140

TYPO3 internally will remove file system files and checks for symlinks to unlink instead of remove. Due to the setup it will remove the project files themselves, as they are symlinked.

@DanielSiepmann
Copy link

That one is working for me, maybe someone can have a look, check and merge + release? :) Hopefully it will solve the issue: infection/include-interceptor#14

@maks-rafalko
Copy link
Member

Please check if the current master solves this issue.

@ccwebdesign
Copy link
Author

Happened to be checking back on this to delete the repository. The original issue is resolved (tested in both php 7.3 and 8.0). Thanks, all!

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