2

I'm totally stucked. At first my code:

File sample000.phpt

--TEST--
Basic test
--DESCRIPTION--
Lowlevel basic test
--FILE--
<?php
echo 'Hello World!';
?>
--EXPECT--
Hello World!

File PhptTestCase.php

<?php
require_once 'PHPUnit/Extensions/PhptTestCase.php';

class PhptTestCase extends PHPUnit_Extensions_PhptTestCase
{
    public $result;

    public function __construct( $file ) {
        $options = array( 'include_path' => 'D:\\xampp\\php' );
        parent::__construct( $file, $options );
    }

}

File phptTest.php

<?php
class PhptTest extends PHPUnit_Framework_TestCase
{
    public $object;

    public function setUp() {}
    public function tearDown() {}

    public function testAll() {
        require_once 'phptTestCase.php';

        $file = __DIR__ . '/phpt-tests/sample000.phpt';

        $phpt = new PhptTestCase( $file );
        $result = $phpt->run();
        $this->assertTrue( $result->wasSuccessful() );

        var_dump( $result->failures() );

    }
}

Running pear run-tests sample000.phpt from the command line work fine. Running phpunit PhptTest.php will always fail.

After some research I dumped the result with var_dump( $result->failures() ); and see that the php executable couldn't be found:

array(1) {
  [0] =>
  class PHPUnit_Framework_TestFailure#441 (2) {
    protected $failedTest =>
    class PhptTestCase#434 (3) {
      public $result =>
      NULL
      protected $filename =>
      string(84) "D:\\htdocs\\[...]\\phpt/phpt-tests/sample000.phpt"
      protected $options =>
      array(1) {
        ...
      }
    }
    protected $thrownException =>
    class PHPUnit_Framework_ComparisonFailure#440 (12) {
      protected $expected =>
      string(12) "Hello World!"
      protected $actual =>
      string(94) "Der Befehl "C:\\php\\php.exe" ist entweder falsch geschrieben oder\nkonnte nicht gefunden werden."
<-- snip -->
      protected $file =>
      string(53) "D:\\xampp\\php\\pear\\PHPUnit\\Extensions\\PhptTestCase.php"
      protected $line =>
      int(209)
      private $trace =>
      array(17) {
        ...
      }
      private $previous =>
      NULL
    }
  }
}

I assume this is the line why the test fails when it runs with PHPUnit:
Der Befehl "C:\php\php.exe" ist entweder falsch geschrieben oder\nkonnte nicht gefunden werden.
translated: The "C: \ php \ php.exe" command is either misspelled or could not be found. My php executable is installes in D:/xampp/php

I try to setup the include path in XML configuration file for PHPUnit (phpunit.xml) and also try to pass the include path as option to the class PHPUnit_Extensions_PhptTestCase.

Can anybody tell me how to configure PHPUnit so it can find the php executable?

Ralf Albert
  • 139
  • 1
  • 7
  • Possible duplicate of [Integrate PHPT test cases with PHPUnit](http://stackoverflow.com/questions/4922207/integrate-phpt-test-cases-with-phpunit) – Gerard Roche Sep 13 '16 at 01:21

2 Answers2

2

PHPT support is bundled in phpunit. Can you try this:

phpunit.xml:

<phpunit>
  <testsuites>
    <testsuite name="PHPT tests">
      <directory suffix=".phpt">phpt-tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

Create directory phpt-tests and move your sample000.phpt to it.

Run phpunit. It will load configuration from phpunit.xml and run the testsuite testing all PHPT tests from the phpt-tests directory.

$ phpunit 
PHPUnit 3.7.8 by Sebastian Bergmann.

Configuration read from phpunit.xml    
.    
Time: 0 seconds, Memory: 3.25Mb    
OK (1 test, 1 assertion)
Goran Rakic
  • 1,789
  • 15
  • 26
  • I give you the bounty simply for the try to help. It was a very special question (windows, doh!) and very hard to solve. – Ralf Albert May 19 '13 at 09:33
0

After reading a lot of source files and searching the web, I found the reason why the php executable wasn't found.

PEAR uses some environment variables for pathes and some other things. This variables are stored in the windows registry. My registry was screwed up so I had to update the pathes.

I downloaded go-pear.phar (use go-pear.php for older php versions) and run it. This creates a file PEAR_ENV.reg. After importing the registry keys into the windows registry, everything works fine.

Ralf Albert
  • 139
  • 1
  • 7