Skip to content

Setting dont_preserve_original_methods interferes with mocking __call methods #8

@HappyRay

Description

@HappyRay

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.'
        );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions