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

"Undefined offset: 0 in /usr/local/zend/share/pear/PHPUnit/Util/Configuration.php on line 860" #466

Closed
bskendig opened this issue Jan 23, 2012 · 12 comments

Comments

@bskendig
Copy link

My configuration XML file contains this:

<testsuite name="DefaultTestSuite">
    <file>src/tests/application/controllers/AuthenticationControllerTest.php</file>

Previous versions of PHPUnit (through 3.6.7) worked fine, but this morning I upgraded to PHPUnit 3.6.8, and when I run it with my configuration file, it fails:

Call Stack:
0.0004 322840 1. {main}() /usr/local/zend/bin/phpunit:0
0.0056 695048 2. PHPUnit_TextUI_Command::main() /usr/local/zend/bin/phpunit:46
0.0057 695384 3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:125
0.0057 695384 4. PHPUnit_TextUI_Command->handleArguments() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:134
0.0536 3176768 5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:666
0.0537 3177312 6. PHPUnit_Util_Configuration->getTestSuite() /usr/local/zend/share/pear/PHPUnit/Util/Configuration.php:768

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Argument #1 of PHPUnit_Framework_TestSuite::addTestFile() must be a string' in /usr/local/zend/share/pear/PHPUnit/Util/InvalidArgumentHelper.php on line 69

InvalidArgumentException: Argument #1 of PHPUnit_Framework_TestSuite::addTestFile() must be a string in /usr/local/zend/share/pear/PHPUnit/Util/InvalidArgumentHelper.php on line 69

Call Stack:
0.0004 322840 1. {main}() /usr/local/zend/bin/phpunit:0
0.0056 695048 2. PHPUnit_TextUI_Command::main() /usr/local/zend/bin/phpunit:46
0.0057 695384 3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:125
0.0057 695384 4. PHPUnit_TextUI_Command->handleArguments() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:134
0.0536 3176768 5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:666
0.0537 3177312 6. PHPUnit_Util_Configuration->getTestSuite() /usr/local/zend/share/pear/PHPUnit/Util/Configuration.php:768
0.1290 3375148 7. PHPUnit_Framework_TestSuite->addTestFile() /usr/local/zend/share/pear/PHPUnit/Util/Configuration.php:878

The problem is line 859 of Configuration.php, which changes "getFilesAsArray($file)" to "getFilesAsArray($this->toAbsolutePath($file))". For my file, $this->toAbsolutePath($file) returns:

/path/to/my/project/main/src/tests/src/tests/application/controllers/AuthenticationControllerTest.php

"src/tests/" is duplicated in the path, which makes the path incorrect.

@edorian
Copy link
Contributor

edorian commented Jan 23, 2012

I broke this (sorry!) in 3.6.8.

If the file does not exist / can't be found it will generate this error. If the file does exist the error goes away.

Please note that the path is relative to the xml file location so changes are you need to remove the src/tests part.

The next phpunit release will have a fix for this.

Thanks for taking the time to report this!

@edorian edorian closed this as completed Jan 23, 2012
@edorian
Copy link
Contributor

edorian commented Jan 23, 2012

Fixed in 6009484

@bskendig
Copy link
Author

If I remove 'src/tests/', then it works for me but breaks for people on earlier versions of 3.6.x, which now can't find the files, so I can't check that fix in to my group's repository. (We've got a fairly lengthy process of approving new versions of tools.)

It looks like, in previous versions, the path was relative to the project's root directory; it also appears that other paths in the configuration XML files are still (in 3.6.8) relative to the project's root directory.

How do I express file paths in the config file in a way that's compatible with PHPUnit 3.6.8 as well as 3.6.7?

@bskendig
Copy link
Author

(Thank you for having responded so quickly, by the way!)

@edorian
Copy link
Contributor

edorian commented Jan 23, 2012

It wasn't supposed to change behavior and if it It did we are going to revert to the old behavior anyways so I'd say the best course of action for you would be to say at 3.6.7 for now if possible.

I'm going to test this and see what happend there. As far as I'm aware all pathes should be relative to the location of the phpunit.xml file.

So if your phpunit.xml is in /path/to/my/project/main/phpunit.xml than it should work.. nevertheless that should not change in a minor version and I'm going to revert that in 3.6.9 if it breaks things for you.

@edorian edorian reopened this Jan 23, 2012
@bskendig
Copy link
Author

I see you have PHPUnit 3.6.9 out now, but that fails for me with a different error. "DefaultTestSuite" is the test suite name in my config file (see the two lines I pasted above), but previously I haven't had any DefaultTestSuite.php file.

Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "DefaultTestSuite.php" nor "DefaultTestSuite.php" could be opened.' in /usr/local/zend/share/pear/PHPUnit/Util/Skeleton/Test.php on line 100

PHPUnit_Framework_Exception: Neither "DefaultTestSuite.php" nor "DefaultTestSuite.php" could be opened. in /usr/local/zend/share/pear/PHPUnit/Util/Skeleton/Test.php on line 100

Call Stack:
0.0003 322840 1. {main}() /usr/local/zend/bin/phpunit:0
0.1222 695048 2. PHPUnit_TextUI_Command::main() /usr/local/zend/bin/phpunit:46
0.1223 695384 3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:125
0.2712 3820888 4. PHPUnit_Util_Skeleton_Test->__construct() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:152

@bskendig
Copy link
Author

Another interesting detail. I get the above error if I have this in the "testsuite" section of my configuration XML file:

<testsuite name="DefaultTestSuite">
    <file>src/tests/application/controllers/AuthenticationControllerTest.php</file>
    <file>src/tests/application/controllers/CartControllerTest.php</file>
    <file>src/tests/application/controllers/CompareControllerTest.php</file>
    ...

But if I change the first "src/tests" to a period, the tests run without errors:

<testsuite name="DefaultTestSuite">
    <file>./application/controllers/AuthenticationControllerTest.php</file>
    <file>src/tests/application/controllers/CartControllerTest.php</file>
    <file>src/tests/application/controllers/CompareControllerTest.php</file>
    ...

FYI, if it helps: my project is in a directory named "main", all source code is in "main/src", and the directory "main/src/tests" contains the configuration XML files as well as all test files.

@bskendig
Copy link
Author

(Actually, "the tests run without errors" is a bit optimistic. phpunit completes without errors, but no tests actually get run.)

@edorian
Copy link
Contributor

edorian commented Jan 27, 2012

Should be fixed in 3.6.10 once released. The old behavior was restored in 93279fb & 21051ec

Thanks again for the report

@edorian edorian closed this as completed Jan 27, 2012
sebastianbergmann added a commit that referenced this issue Jan 27, 2012
@bskendig
Copy link
Author

Verified. PHPUnit 3.6.10 fixes the problems and lets me run my tests again. Thank you very much!

On a related note, if PHPUnit can't find one of the files named in the config XML, I'd prefer it display a helpful message rather than silently ignoring the file, since if the config names a file that doesn't exist it's probably due to a mistake on the user's part.

@edorian
Copy link
Contributor

edorian commented Jan 27, 2012

Chances are you will get an error message with phpunit 3.7 as there is a configuration parsing re-factoring in progress. For 3.6 we can't nicely provide error output without possible breaking more stuff :)

@woodcockjosh
Copy link

Just change the file Util/Configuration.php

Add

        if($path == '')
        {
            return $path;
        }

To the top of the toAbsolutePath function. like so.

/**
     * @param  string  $path
     * @param  boolean $useIncludePath
     * @return string
     * @since  Method available since Release 3.5.0
     */
    protected function toAbsolutePath($path, $useIncludePath = FALSE)
    {
        // check if the path is empty
        if($path == '')
        {
            return $path;
        }

        // Check whether the path is already absolute.
        if ($path[0] === '/' || $path[0] === '\\' ||
            (strlen($path) > 3 && ctype_alpha($path[0]) &&
             $path[1] === ':' && ($path[2] === '\\' || $path[2] === '/'))) {
            return $path;
        }

        // Check whether a stream is used.
        if (strpos($path, '://') !== FALSE) {
            return $path;
        }

        $file = dirname($this->filename) . DIRECTORY_SEPARATOR . $path;

        if ($useIncludePath && !file_exists($file)) {
            $includePathFile = stream_resolve_include_path($path);

            if ($includePathFile) {
                $file = $includePathFile;
            }
        }

        return $file;
    }

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