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

Setting dont_preserve_original_methods interferes with mocking __call methods #8

Open
HappyRay opened this issue Mar 26, 2015 · 0 comments

Comments

@HappyRay
Copy link

e.g.


class MagicMethodTest
{
    /**
     * @param string $methodName
     * @param array  $argument
     *
     * @return string
     */
    public function __call($methodName, array $argument)
    {
        return $methodName;
    }
}

class MagicMethodUsage
{
    /**
     * @param \Box\PHPUnitTestGenerator\tests\_fixture\_input\MagicMethodTest $magicTest
     *
     * @return string
     */
    public function callMagicMethod(
        MagicMethodTest $magicTest
    )
    {
        $rc = $magicTest->foo();

        return $rc;
    }
}

<?php

class MagicMethodUsageGenTest extends \PHPUnit_Framework_TestCase
{
    use \Shmock\Shmockers;

    public function testCallMagicMethod()
    {
        // Setup mocks for parameters to the method under test.

        $mockMagicMethodTest0 = $this->shmock(
            'MagicMethodTest',
            function (
                $shmock
            ) {
//                $shmock->dont_preserve_original_methods();

                /** @var $mock \Shmock\Spec */
                $mock = $shmock->__call('foo', array (
                ));
                $mock->return_value('bar');
            }
        );

        // Execute the method under test.

        $objectUnderTest = new MagicMethodUsage();
        $executionResult = $objectUnderTest->callMagicMethod($mockMagicMethodTest0);

        // Validate the execution result.

        $expected = 'bar';
        $this->assertSame(
            $expected,
            $executionResult,
            'Variable ( executionResult ) doesn\'t have the expected value.'
        );
    }
}

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

1 participant