9

I'm trying (for quite a while, with help from fellas at the PHP chat room) to succesfully integrate PHPUnit with PhpStorm.

I've set up the phpunit.xml file as follows:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
        backupGlobals               = "false"
        backupStaticAttributes      = "false"
        colors                      = "true"
        convertErrorsToExceptions   = "true"
        convertNoticesToExceptions  = "true"
        convertWarningsToExceptions = "true"
        processIsolation            = "false"
        stopOnFailure               = "false"
        syntaxCheck                 = "false"
        bootstrap                   = "bootstrap.php" >

    <testsuites>
        <testsuite name="Lamed Test Suite">
            <directory>Custom/*</directory>
        </testsuite>
    </testsuites>

</phpunit>

And configured PHP storm successfully to read from that file.

The problem is, I get the following error in PhpStorm's console upon running the tests:

D:\Websites\php\php.exe C:\fakepath\ide-phpunit.php --bootstrap D:\Websites\htdocs\lamed\tests\boostrap.php --configuration D:\Websites\htdocs\lamed\tests\phpunit.xml
Testing started at 23:51 ...

Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "Lamed Test Suite.php" nor "Lamed Test Suite.php" could be opened.' in D:\Websites\php\pear\PHPUnit\Util\Skeleton\Test.php:100
Stack trace:
#0 D:\Websites\php\pear\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('Lamed Test Suit...', '')
#1 C:\Users\Dor\AppData\Local\Temp\ide-phpunit.php(95): PHPUnit_TextUI_Command->run(Array, true)
#2 C:\Users\Dor\AppData\Local\Temp\ide-phpunit.php(434): IDE_PHPUnit_TextUI_Command::main()
#3 {main}
  thrown in D:\Websites\php\pear\PHPUnit\Util\Skeleton\Test.php on line 100

Process finished with exit code 255

It's obviously reading that from the name= attribute on the testsuite element. The question is, why?

UPDATES

  • I am running Windows Seven x64 SP1 and PHPStorm 4.0.3. PHPUnit version is 3.6.12.
  • Typing phpunit -c "D:\Websites\htdocs\lamed\tests\phpunit.xml" in the CLI actually gives the same results.
  • My Custom directory is found in the same folder as the phpunit.xml file.

I'm baffled. Would appreciate any sort of help.

4

3 に答える 3

10

Drop the /* from the <directory> element. This element's text content should point to a directory—not a file glob.

<directory>Custom</directory>

See the PHPUnit configuration documentation for more details on specifying individual files and inclusion patterns.

By default all files ending in Test.php (e.g. UserTest.php) will be inspected for test cases. If you have a different naming convention you can either switch or add the suffix attribute. For example, if you name your tests like User.test.php use this:

<directory suffix=".test.php">Custom</directory>
于 2012-08-08T07:07:49.753 に答える
1

What you experience is a fallback. It looks like your testsuite is empty (and there is not other additional non-empty testsuite as well).

In that case PHPUnit will to also try to just open something fitting, which does not work. Then you see an error.

  • If you have only one empty testsuite, you will see the exception with the name of the testsuite and php added for the try of it.

    Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "Empty-Testuite.php" nor "Empty-Testuite.php" could be opened.'
    
  • If you have more than one empty testsuite and no working testsuite, you will see and error about the php only, no name added.

    Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither ".php" nor ".php" could be opened.'
    
  • If you have at least a working testsuite but one or more empty testsuites, you will see a short report for each empty testsuite but no error:

    Empty test suite.
    

When I write that this is a fallback it must not mean that this behaviour is intended by PHPUnit. Seeing the error in your case is okay because before you start with tests, you need at least have one running. And before you start with configuring testsuites, the same.

Fix the underlying problem that the test is missing and the error goes away.

The wildcard * as mentioned in the other answer - even I'm sure it's correct to not have it - plays no role with your problem as far as I could see.


The information in this answer is based on

  • PHPUnit 3.6.7 by Sebastian Bergmann.
  • PHP 5.4.5 by php.net
于 2012-08-08T15:17:28.463 に答える
1

Had the same problem changed the value for directory to an absolute path instead of a relative path and it worked. For example I changed tests into C:\eclipse\Workspace\testweb

Too bad I had to go through a lot of non information and this isn't mentioned in the documentation, neither is it documented how to start the command line interface with a configuration xml file.

phpunit -c tests/all.xml

The php test files have to end with test as well like myTest.php even when you're adding file elements C:\eclipse\Workspace\testweb\tests\classes\something.php would not work but C:\eclipse\Workspace\testweb\tests\classes\somethingtest.php would work

于 2012-09-02T14:26:42.633 に答える