-
Notifications
You must be signed in to change notification settings - Fork 147
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
Short syntax for base assertions #384
Conversation
0d0c464
to
9e0c681
Compare
Whist I understand the goal and I like the idea, I might not like the fact there will be four syntaxes to define an assertion:
The last one is very confusing because we compare an integer with a string and it would work fine… I understand that Finally, I don't use IDE so I don't know if it would help people or not. And what about errors also? Do you solve the alias naming? |
The syntax with string could easily be removed ;) I agree with the fact that providing too much way of doing the same thing is not always good. I was basically playing and trying to port things I found in ruby for example. I know PHP is not Ruby and atoum is not rspec or whatever :) BTW, I don't mind if this PR gets rejected, I played with something and that was fun :) |
It's syntaxic sugar, so, like real sugar, some which not like it don't use it. |
+1 |
{ | ||
$assertion = null; | ||
|
||
if (is_numeric($method) === true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch (true)
{
case is_numeric($method):
$assertion = 'isEqualTo';
break;
case $method == '=<':
$assertion = 'isLessThanOrEqualTo';
break;
...
I removed the ambiguous syntax. So now, those lines won't work anymore: <?php
namespace tests\units;
use atoum;
class stdClass extends atoum
{
public function testFoo()
{
$this
->integer(42)->{42} // isEqualTo
->integer(42)->{'42'} // isEqualTo
;
}
} Why removing the two syntaxes when only the second seems invalid: because when using such syntax, PHP always casts the property/method name to a string. So we can't know if the user passed an integer or not. |
👍 for me now :-). |
👍 for me too |
f27e94f
to
07223e0
Compare
The inspection completed: 4 new issues, 3 updated code elements |
Short syntax for base assertions
Introducing new short syntax for base assertions:
I was reviewing some code and remembered what we did with @mageekguy on mock call asserter to allow things like
$this->mock($foo)->call('bar')->{3}
to test if thebar
method was called exactly three times on$foo
. I asked myself if we could apply similar things to some other asserters, basicallyvariable
andinteger
to cover assertions that have a native operator counterpart (i.eisEqualTo
,isIdenticalTo
, ...).As you have seen in the previous example, this is doable and works fine (I tested it from PHP 5.4 to 5.6). Let me know if you think it's useful ;)