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

Error in Patchwork: "Only variables should be passed by reference" #2

Closed
Spudley opened this issue Apr 2, 2012 · 2 comments
Closed

Comments

@Spudley
Copy link
Contributor

Spudley commented Apr 2, 2012

I have been trying to get going with Patchwork, in order to help me write unit tests to a legacy PHP codebase. Unfortunately, I have run into an error which I can't resolve.

Whenever I try to call an overridden method, I get the following error: "Only variables should be passed by reference"

I have a very simple test case that demonstrates this:

<?php
require_once('../build/patchwork/Patchwork.php');
require_once('../build/clsOverrideMe.php');

class patchworkTest extends PHPUnit_Framework_TestCase {
    public function testOverrideMe() {
        Patchwork\replace("clsOverrideMe::sayBar", function() { return "overridden"; });
        $result = clsOverrideMe::sayBar();  //standard $result='bar', but with Patchwork, $result='overridden'.
    }
}

...and clsOverrideMe.php:

<?php
class clsOverrideMe {
    public static function sayBar() {
        return "bar";
    }
}

Then at the command prompt, I get the following:

C:\DEVELOPMENT\_tests>phpunit patchworkTest.php
PHPUnit 3.5.14 by Sebastian Bergmann.

E

Time: 0 seconds, Memory: 6.75Mb

There was 1 error:

1) patchworkTest::testClsOverrideMe
Only variables should be passed by reference

C:\DEVELOPMENT\build\patchwork\lib\Stack.php:39
C:\DEVELOPMENT\build\patchwork\lib\Interceptor.php:68
C:\DEVELOPMENT\build\patchwork\lib\Interceptor.php:87
C:\DEVELOPMENT\build\patchwork\lib\Stack.php:27
C:\DEVELOPMENT\build\patchwork\lib\Interceptor.php:93
C:\DEVELOPMENT\build\clsOverrideMe.php:3
C:\DEVELOPMENT\_tests\patchworkTest.php:8

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

Any idea what I'm doing wrong here? Or have I found a bug in Patchwork?

The above is the simplest possible example I could come up with in the context of PHPUnit (ie how I want to use it). It also throws the same error when written as a simple PHP program.

PHP version 5.3.8 on Windows7.

@antecedent
Copy link
Owner

This seems to overlap with this other report of yours, which I've already addressed. Thanks!

@Spudley
Copy link
Contributor Author

Spudley commented Apr 10, 2012

It does indeed overlap -- it's the same issue: I posted this ticket first, and then decided to try fixing it myself; the second ticket was generated by Github when I posted the fix. :-)

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

2 participants