Hywan / atoum-instrumentation

The atoum\instrumentation library. Instrumentation for PHP (moles, code coverage…)
7 stars 2 forks source link

Instrumentation of members declarations #1

Closed jubianchi closed 10 years ago

jubianchi commented 10 years ago

I was working on integrating instrumentation to atoum and find a bug when instrumenting classes.

Given the following class:

<?php

use StdClass;

class Foo {
    public $foo;
    protected $bar;
    private $baz;

    public function foo($foo, $bar)
    {
        var_dump($foo, $bar);

        return $foo . $bar;
    }

    public function bar($bar, $baz)
    {
        return $bar . $baz;
    }
}

When running the Run.php script with the defined rules, we get the following result:

<?php

use StdClass;mark_line(__LINE__);

class Foo {
    public $foo;mark_line(__LINE__);
    protected $bar;mark_line(__LINE__);
    private $baz;mark_line(__LINE__);

    public function foo($foo, $bar)
    {
        var_dump($foo, $bar);mark_line(__LINE__);

        mark_line(__LINE__);return $foo . $bar;
    }

    public function bar($bar, $baz)
    {
        mark_line(__LINE__);return $bar . $baz;
    }
}

The following block should not be instrumented:

public $foo;mark_line(__LINE__);
protected $bar;mark_line(__LINE__);
private $baz;mark_line(__LINE__);
Hywan commented 10 years ago

Hello :-),

With the new sequence matcher, rules can be applied on specific events. It solved the problem. Sorry for that… Close the PR if you agree and think this is no longer useful to apply your patch.

jubianchi commented 10 years ago

Agree :+1: