sebastianbergmann / php-token-stream

Wrapper around PHP's tokenizer extension.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New feature : get Interfaces

llaville opened this issue · comments

Sebastian,

I proposed here a new feature that are still missing : getting interfaces implements from classes.

See my fork branch issue8
https://github.com/llaville/php-token-stream/commit/8937ca5dcbf62043cc50a06361c09503135ce51c

I've also fixed a bug on my previous proposal about docblock detection : because CLASS and INTERFACE tokens are not preceed by a token WHITESPACE.

Regards

Your patch no longer cleanly applies to my master branch. Please update it so that I can merge it, thanks!

I've resynchronized my copy with your master. Deleted all branches including issue8.

Now the fix for this new feature is included in my master branch. See last commit.

https://github.com/llaville/php-token-stream/commit/d95b6b9f60ce26e37f04b1dd8a4828554309dfc2

I merged your changes into my issue8 branch. The test suite for PHP_TokenStream passes, but the test suite for PHP_CodeCoverage fails:

sb@vmware code-coverage % phpunit
PHPUnit @package_version@ by Sebastian Bergmann.

............................................................ 60 / 73
...........F.

Time: 0 seconds, Memory: 11.50Mb

There was 1 failure:

1) PHP_CodeCoverage_Report_CloverTest::testCloverForBankAccountTest
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 <?xml version="1.0" encoding="UTF-8"?>
-<coverage generated="%i">
-  <project timestamp="%i" name="BankAccount">
-    <file name="%s/BankAccount.php">
+<coverage generated="1294333611">
+  <project timestamp="1294333611" name="BankAccount">
+    <file name="/usr/local/src/code-coverage/Tests/_files/BankAccount.php">
       <class name="BankAccount" namespace="global">
-        <metrics methods="4" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="5" elements="14" coveredelements="8"/>
+        <metrics methods="4" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="5" coveredstatements="3" elements="9" coveredelements="6"/>
       </class>
       <line num="6" type="method" name="getBalance" crap="1" count="2"/>
       <line num="8" type="stmt" count="2"/>
       <line num="11" type="method" name="setBalance" crap="6" count="0"/>
       <line num="13" type="stmt" count="0"/>
       <line num="14" type="stmt" count="0"/>
       <line num="15" type="stmt" count="0"/>
       <line num="16" type="stmt" count="0"/>
       <line num="18" type="stmt" count="0"/>
       <line num="20" type="method" name="depositMoney" crap="1" count="2"/>
       <line num="22" type="stmt" count="2"/>
       <line num="24" type="stmt" count="1"/>
       <line num="27" type="method" name="withdrawMoney" crap="1" count="2"/>
       <line num="29" type="stmt" count="2"/>
       <line num="31" type="stmt" count="1"/>
       <metrics loc="33" ncloc="33" classes="1" methods="4" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="5" elements="14" coveredelements="8"/>
     </file>
     <metrics files="1" loc="33" ncloc="33" classes="1" methods="4" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="5" elements="14" coveredelements="8"/>
   </project>
 </coverage>

/usr/local/src/code-coverage/Tests/PHP/CodeCoverage/Report/CloverTest.php:82

FAILURES!
Tests: 73, Assertions: 106, Failures: 1.

Writing code coverage data to XML file, this may take a moment.

Generating code coverage report, this may take a moment.

Please look into this. Thanks!

I found the problem in my latest commit, and I will push a new fix just after but in PHP_CodeCoverage test suite and especially PHP_CodeCoverage_Report_CloverTest there are some things I don't understand.

So First, as all unit tests are not included in each package release (probably you've a reason to do that), I get it from your git repository.

I've tried each test case individually and I got only problem with PHP_CodeCoverage_Report_CloverTest

With this command

phpunit 
 --bootstrap C:\UwAmp\apache\php_5.3.2\includes\PHP\Token\Stream\Autoload.php 
 --verbose 
 PHP_CodeCoverage_Report_CloverTest C:\Temp\sebastianbergmann-php-code-coverage-8851e29\Tests\PHP\CodeCoverage\Report\CloverTest.php

I got

Warning: require_once(C:\Temp\sebastianbergmann-php-code-coverage-8851e29\Tests\PHP\_files\../TestCase.php): 
failed to open stream: No such file or directory in
 C:\Temp\sebastianbergmann-php-code-coverage-8851e29\Tests\PHP\CodeCoverage\Report\CloverTest.php on line 55

Fatal error: require_once(): Failed opening required 'C:\Temp\sebastianbergmann-php-code-coverage-8851e29\Tests\PHP\_files\../TestCase.php' 
(include_path='.;C:\UwAmp\apache\php_5.3.2\includes;C:\UwAmp\apache\php_5.3.2\PEAR') 
in C:\Temp\sebastianbergmann-php-code-coverage-8851e29\Tests\PHP\CodeCoverage\Report\CloverTest.php on line 55

Then I patch it with (notice differences)

if (!defined('TEST_FILES_PATH')) {
    define(
      'TEST_FILES_PATH',
      dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR .
      '_files' . DIRECTORY_SEPARATOR
    );
}

require_once TEST_FILES_PATH . '../TestCase.php';
require_once TEST_FILES_PATH . 'BankAccount.php';
require_once TEST_FILES_PATH . 'BankAccountTest.php';

require_once 'PHP/CodeCoverage/Report/Clover.php';

And finally I got these results (with my future fix on PHP_Token)

PHPUnit 3.5.6 by Sebastian Bergmann.

C:\Temp\sebastianbergmann-php-code-coverage-8851e29\Tests\PHP\CodeCoverage\Report
 PHP_CodeCoverage_Report_CloverTest
 F

Time: 2 seconds, Memory: 4.75Mb

There was 1 failure:

1) PHP_CodeCoverage_Report_CloverTest::testCloverForBankAccountTest
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 <?xml version="1.0" encoding="UTF-8"?>
-<coverage generated="%i">
-  <project timestamp="%i" name="BankAccount">
-    <file name="%s/BankAccount.php">
+<coverage generated="1294399494">
+  <project timestamp="1294399494" name="BankAccount">
+    <file name="C:\Temp\sebastianbergmann-php-code-coverage-8851e29\Tests\_files\BankAccount.php">
       <class name="BankAccount" namespace="global">
         <metrics methods="4" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="5" elements="14" coveredelements="8"/>
       </class>
       <line num="6" type="method" name="getBalance" crap="1" count="2"/>
       <line num="8" type="stmt" count="2"/>
       <line num="11" type="method" name="setBalance" crap="6" count="0"/>
       <line num="13" type="stmt" count="0"/>
       <line num="14" type="stmt" count="0"/>
       <line num="15" type="stmt" count="0"/>
       <line num="16" type="stmt" count="0"/>
       <line num="18" type="stmt" count="0"/>
       <line num="20" type="method" name="depositMoney" crap="1" count="2"/>
       <line num="22" type="stmt" count="2"/>
       <line num="24" type="stmt" count="1"/>
       <line num="27" type="method" name="withdrawMoney" crap="1" count="2"/>
       <line num="29" type="stmt" count="2"/>
       <line num="31" type="stmt" count="1"/>
       <metrics loc="33" ncloc="33" classes="1" methods="4" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="5" elements="14" coveredelements="8"/>
     </file>
     <metrics files="1" loc="33" ncloc="33" classes="1" methods="4" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="10" coveredstatements="5" elements="14" coveredelements="8"/>
   </project>
 </coverage>

C:\Temp\sebastianbergmann-php-code-coverage-8851e29\Tests\PHP\CodeCoverage\Report\CloverTest.php:86

FAILURES!
Tests: 1, Assertions: 2, Failures: 1.

My question is: how do you replace on the fly the request time in "BankAccount-clover.xml"

My FIX is available at
https://github.com/llaville/php-token-stream/commit/0178e3d1600826b4e0559532da49dac7504e15c7

Pulled, thanks.