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

Comments

Projects
None yet
2 participants
@Spudley
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

This comment has been minimized.

Show comment
Hide comment
@antecedent

antecedent Apr 5, 2012

Owner

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

Owner

antecedent commented Apr 5, 2012

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

@antecedent antecedent closed this Apr 5, 2012

@Spudley

This comment has been minimized.

Show comment
Hide comment
@Spudley

Spudley Apr 10, 2012

Contributor

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. :-)

Contributor

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