defaultAsserter as static leading to problems??
flip111 opened this issue · 6 comments
Hi,
I'm running two tests. Each test has it's own Ruler
, but i think that both rulers share the same Asserter
because it is declared as static in the ruler class. This leads to operators being available in the second ruler which where defined in the first ruler.
A workaround would be to use the new getOperators()
method to get all the operators. And then call setOperator
with value null on them. But this is not so nice to do it this way.
Hello :-),
The default asserter is… the default asserter. Please, use setAsserter
with a new asserter for your test:
$ruler = new Hoa\Ruler\Ruler();
$rule = '…';
$context = new Hoa\Ruler\Context();
$context[…] = …;
$asserter = new Hoa\Ruler\Visitor\Asserter($context);
$ruler->setAsserter($asserter);
$ruler->assert($rule, $context);
The default asserter is present to only simplify common usage.
Is it ok for you?
Sorry i didn't have time to work again on my library and verify this solution + add readme as requested in #2
I'm a bit confused here. When making a new Asserter no context is required https://github.com/hoaproject/Ruler/blob/master/Visitor/Asserter.php#L91 but when getting the set Asserter from the ruler you explicitly must give the context https://github.com/hoaproject/Ruler/blob/master/Ruler.php#L184
Please make setting the context optional when getting the Asserter from the ruler ... If that is also possible to change then your solution works !!
Thx!