Giter Club home page Giter Club logo

shmock's People

Contributors

anthonybishopric avatar drobertduke avatar gms8994 avatar huggsboson avatar jmarrama avatar nzakas avatar swaroopb avatar theilig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shmock's Issues

Shmock doesn't work with PHPunit 5.4 due to change in interface

PHP Fatal error: Class Shmock\InvocationImpl contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (PHPUnit_Framework_MockObject_Invocation::generateReturnValue) in /vendor/box/shmock/src/Shmock/StaticSpec.php on line 572

Setting dont_preserve_original_methods interferes with mocking __call methods

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

Use dont_preserve_original_methods and order_matters together for ClassBuilderStaticClass yields unexpected result

Here is an example that illustrates the issue:

shmock_class( 'Box_Helper_URL', function ( $shmock /** @var Box_Helper_URL|\Shmock\ClassBuilderStaticClass $shmock */ ) { // Keep track of the order of calls made on this mock. $shmock->order_matters(); // Mock all methods, return null by default unless overwritten by the expectations below. $shmock->dont_preserve_original_methods(); $shmock->disable_original_constructor(); $mock = $shmock->url_is_box('ab.com'); /** @var $mock \Shmock\Spec */ $mock->return_value(true); } ); \Statics::overwrite('Box_Helper_URL', $mockBox_Helper_URL0); // Execute the method under test. $objectUnderTest = new \StaticsUsageExample(); $executionResult = $objectUnderTest->isBoxUrl('ab.com'); // Validate the execution result. $expected = true; $this->assertSame( $expected, $executionResult, 'Variable ( executionResult ) doesn\'t have the expected value.' ); ``` } } The test failed. The url_is_box call on the mock object returned null instead of true as I expected. # Here is my analysis of the issue: This is what I found that caused the failure: dont_preserve_original_methods calls $this->__call($method->getName(), [])->any()->return_null(); to overwrite the static method calls of the class being mocked. This has the same effect as specifying $shmock->url_is_box()->any()->return_value(null); in the mock object expectations. Since order_matter is set, in effect the expectation becomes that url_is_box will be called once first and return null and it should be called again and this time return true. This effect is not what I expected. And there is no documentation that I can find that describes this behavior. The non static class builder has a different implementation and doesn't seem to exhibit this behavior.

sebastian/diff 1.1 version requirement prevents newer version of phpunit to be used

I am using this library in my project called TestScribe

Because shmock currently requires 1.1 version of diff component, I got the following error when trying to use a newer version of phpunit.

Output below:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Conclusion: remove sebastian/diff 1.1.0
- box/shmock 2.0.0-alpha6 requires sebastian/diff 1.1 -> satisfiable by sebastian/diff[1.1.0].
- box/shmock 2.0.0-alpha6 requires sebastian/diff 1.1 -> satisfiable by sebastian/diff[1.1.0].
- Conclusion: don't install sebastian/diff 1.1.0|keep sebastian/diff 1.1.0
- Installation request for box/shmock 2.0.0-alpha6 -> satisfiable by box/shmock[2.0.0-alpha6].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.