Code inside "specify" closure changes the value of the class attribute
kop opened this issue · 1 comments
kop commented
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.