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
[Parameter] Deprecate names starting or ending with a colon #6880
[Parameter] Deprecate names starting or ending with a colon #6880
Conversation
Requires a test case |
@Ocramius As I said in my comment I need help for this test. |
@fancyweb Just construct the class with a faulty string, and watch what happens.
|
I tried that and it was just marked as a risky test since there was no assertion. No exception was thrown. |
Probably because you use the @ operator, I'll try to checkout your branch and have a look. |
Please wait until #6869 is merged (after 2.6 is released), it will add the infrastructure for testing deprecations. |
Just missing the test so I'll keep on 2.7.0 and we can easily test it with things added in #7901 |
1deb37b
to
1712fc1
Compare
@fancyweb thanks, I've updated things to add the test. I'm just struggling on explaining the value of this deprecation in |
Thanks for adding the tests.
Maybe describe it as a clear information about how a parameter has to look like and being less ambiguous? |
@SenseException focusing on the ambiguity is a good idea. I guess what made me hesitate too was doing the check using regex. We could do the trim and then compare with the original value, sending the deprecation notice when they are different. |
@@ -67,6 +69,10 @@ class Parameter | |||
*/ | |||
public function __construct($name, $value, $type = null) | |||
{ | |||
if (preg_match('/^:|:$/', $name)) { | |||
@trigger_error('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0', E_USER_DEPRECATED); |
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.
Let's add the package name and use some linebreaks:
@trigger_error('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0', E_USER_DEPRECATED); | |
@trigger_error( | |
'Starting or ending a parameter name with ":" is deprecated since Doctrine ORM 2.7 and will cause an error in 3.0', | |
E_USER_DEPRECATED | |
); |
*/ | ||
public function deprecationMustBeTriggeredWhenUsingColonInParameterNames() : void | ||
{ | ||
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0'); |
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.
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0'); | |
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since Doctrine ORM 2.7 and will cause an error in 3.0'); |
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.
It should be 2.8 too :)
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0'); | ||
new Parameter(':user_name', 'Testing'); | ||
|
||
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0'); |
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.
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0'); | |
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since Doctrine ORM 2.7 and will cause an error in 3.0'); |
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0'); | ||
new Parameter('user_name:', 'Testing'); | ||
|
||
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0'); |
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.
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since 2.7 and will cause an error in 3.0'); | |
$this->expectDeprecationMessage('Starting or ending a parameter name with ":" is deprecated since Doctrine ORM 2.7 and will cause an error in 3.0'); |
@@ -67,6 +69,10 @@ class Parameter | |||
*/ | |||
public function __construct($name, $value, $type = null) | |||
{ | |||
if (preg_match('/^:|:$/', $name)) { |
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.
As @lcobucci wrote:
We could do the trim and then compare with the original value, sending the deprecation notice when they are different.
Can we pick this up for 2.13? |
As requested by @Majkl578 in #5996
I wasn't able to make a test as I don't know how to test a deprecation message without the @expectedDeprecation annotation of the Symfony PHPUnit Bridge ^^