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

Call stack arguments, that were passed by reference, get modified by grabDataFromResponseByJsonPath debug #4402

Closed
alambe opened this Issue Jul 13, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@alambe
Contributor

alambe commented Jul 13, 2017

What are you trying to achieve?

Not have unexpected side effects when passing by reference in debug mode.

What do you get instead?

Some debug messages can change the value of call stack arguments that were passed by reference.

In the example case below when run with --debug, REST module's grabDataFromResponseByJsonPath has a side effect of stringifying the referenced value of an argument passed by reference, higher up in the call stack.

This exposes two potential bugs (or at least two features used together to cause this issue):

  1. grabDataFromResponseByJsonPath, when displaying debug messages, replaces meta step arg values with the stringified version. This could be intentional for performance or convenience but seems sloppy and exposes the next bug.
  2. meta steps are created from backtrace, but stack arguments are not dereferenced. This allows bug 1 to change the value of the referenced variable.

I have a quick fix for bug#2, which I will submit as a pull request.
I don't think bug#1 is specific to grabDataFromResponseByJsonPath, but my fix for bug#2 resolves the overall issue.

Example case:

class stackrefbugCest
{
    public function tryToTest(AcceptanceTester $I)
    {
        $r=[];
        var_dump($r);
        $I->sendGET('/ticket');//REST module, get some json response
        var_dump($r);//$r equals []
        $I->gjp('$.success',$r);//see below, AcceptanceTester wrapper for REST module's grabDataFromResponseByJsonPath, but with an extra argument
        var_dump($r);//bug: $r now equals '[]', if run with --debug
        $I->assertEquals([],$r);//fails, if run with --debug
    }
}

class AcceptanceTester extends \Codeception\Actor
{
    use _generated\AcceptanceTesterActions;
    function gjp($p,&$r){//grab json path
        return $this->grabDataFromResponseByJsonPath($p);
    }
}

Details

  • Codeception version: 2.3.4

  • PHP Version: 7.0.20

  • Operating System: Codeception docker image running on Mac OSX

  • Installation type: Composer

  • List of installed packages (composer show)
    behat/gherkin v4.4.5 Gherkin DSL parser for PHP 5.3
    codeception/codeception 2.3.4 BDD-style testing framework
    codeception/visualception 0.9.0 Visual regression tests for Codeception
    doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
    facebook/webdriver 1.4.1 A PHP client for Selenium WebDriver
    flow/jsonpath 0.3.4 JSONPath implementation for parsing, searching and flattening arrays
    guzzlehttp/guzzle 6.3.0 Guzzle is a PHP HTTP client library
    guzzlehttp/promises v1.3.1 Guzzle promises library
    guzzlehttp/psr7 1.4.2 PSR-7 message implementation that also provides common utility methods
    myclabs/deep-copy 1.6.1 Create deep copies (clones) of your objects
    phar-io/manifest 1.0.1 Component for reading phar.io manifest information from a PHP Archive (PHAR)
    phar-io/version 1.0.1 Library for handling version information and constraints
    phpdocumentor/reflection-common 1.0 Common reflection classes used by phpdocumentor to reflect the code structure
    phpdocumentor/reflection-docblock 3.1.1 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
    phpdocumentor/type-resolver 0.2.1
    phpspec/prophecy v1.7.0 Highly opinionated mocking framework for PHP 5.3+
    phpunit/php-code-coverage 5.2.1 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
    phpunit/php-file-iterator 1.4.2 FilterIterator implementation that filters files based on a list of suffixes.
    phpunit/php-text-template 1.2.1 Simple template engine.
    phpunit/php-timer 1.0.9 Utility class for timing
    phpunit/php-token-stream 1.4.11 Wrapper around PHP's tokenizer extension.
    phpunit/phpunit 6.2.3 The PHP Unit Testing framework.
    phpunit/phpunit-mock-objects 4.0.2 Mock Object library for PHPUnit
    psr/http-message 1.0.1 Common interface for HTTP messages
    psr/log 1.0.2 Common interface for logging libraries
    sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or method a line of code belongs to
    sebastian/comparator 2.0.0 Provides the functionality to compare PHP values for equality
    sebastian/diff 1.4.3 Diff implementation
    sebastian/environment 3.1.0 Provides functionality to handle HHVM/PHP environments
    sebastian/exporter 3.1.0 Provides the functionality to export PHP variables for visualization
    sebastian/global-state 2.0.0 Snapshotting of global state
    sebastian/object-enumerator 3.0.2 Traverses array structures and object graphs to enumerate all referenced objects
    sebastian/object-reflector 1.1.1 Allows reflection of object attributes, including inherited and non-public ones
    sebastian/recursion-context 3.0.0 Provides functionality to recursively process PHP variables
    sebastian/resource-operations 1.0.0 Provides a list of PHP built-in functions that operate on resources
    sebastian/version 2.0.1 Library that helps with managing the version number of Git-hosted PHP projects
    stecman/symfony-console-completion 0.7.0 Automatic BASH completion for Symfony Console Component based applications.
    symfony/browser-kit v3.3.4 Symfony BrowserKit Component
    symfony/console v3.3.4 Symfony Console Component
    symfony/css-selector v3.3.4 Symfony CssSelector Component
    symfony/debug v3.3.4 Symfony Debug Component
    symfony/dom-crawler v3.3.4 Symfony DomCrawler Component
    symfony/event-dispatcher v3.3.4 Symfony EventDispatcher Component
    symfony/finder v3.3.4 Symfony Finder Component
    symfony/polyfill-mbstring v1.4.0 Symfony polyfill for the Mbstring extension
    symfony/process v3.3.4 Symfony Process Component
    symfony/yaml v3.3.4 Symfony Yaml Component
    theseer/tokenizer 1.1.0 A small library for converting tokenized PHP source code into XML and potentially other formats
    webmozart/assert 1.2.0 Assertions to validate method input/output with nice error messages.

  • Suite configuration:

class_name: AcceptanceTester
modules:
    enabled:
        - Asserts
        - REST:
            url: 'https://127.0.0.1/api'
            depends: PhpBrowser
            part: Json
@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Sep 16, 2017

Member

Fixed by #4403

Member

Naktibalda commented Sep 16, 2017

Fixed by #4403

@Naktibalda Naktibalda closed this Sep 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment