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

Code inside "specify" closure changes the value of the class attribute #6

Closed
kop opened this issue Jul 31, 2014 · 1 comment
Closed

Comments

@kop
Copy link

kop commented Jul 31, 2014

Hello. I have the following test class:

class ValidatorTest extends \Codeception\TestCase\Test
{
    use \Codeception\Specify;

    /**
     * @var \mb\tools\url\Validator $instance ;
     */
    public $instance;

    /**
     * @var \UnitTester
     */
    protected $tester;

    /**
     * @inheritdoc
     */
    protected function _before()
    {
        $this->instance = new \mb\tools\url\Validator();
        $this->assertInstanceOf('\mb\tools\url\Validator', $this->instance);
    }

    /**
     * @covers \mb\tools\url\Validator::url
     */
    public function testUrl()
    {
        $dataDir = \Codeception\Configuration::dataDir();
        $urlSamples = include("{$dataDir}/url_samples.php");

        var_dump($this->instance->validSchemes);

        $this->specify('check URLs with invalid scheme if $validSchemes property is set', function ($testData) {
            $this->instance->validSchemes = ['https', 'ftps'];
            verify($this->instance->url($testData))->false();
        }, ['examples' => $urlSamples['restrictedScheme']]);

        var_dump($this->instance->validSchemes);
        die;
    }
}

The results are:

array(2) {
  [0] => string(4) "http"
  [1] => string(5) "https"
}
array(2) {
  [0] => string(5) "https"
  [1] => string(4) "ftps"
}

Means that $this->instance class attribute has been changed. What am I doing wrong?

For now, I was able to workaround this with help of

        $this->beforeSpecify(function() {
            $this->instance = new \mb\tools\url\Validator();
        });

But it doesn't looks like correct solution.

@DavertMik
Copy link
Member

Fixed in f040e2e

DavertMik added a commit that referenced this issue Oct 15, 2014
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

2 participants