Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] Add expressionLanguage to ExpressionValidator constructor #16161

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

Merged
merged 1 commit into from
Oct 19, 2015

Conversation

enumag
Copy link
Contributor

@enumag enumag commented Oct 7, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

@enumag enumag force-pushed the patch-expression branch 3 times, most recently from d604110 to 81130b3 Compare October 7, 2015 08:37
@enumag enumag changed the title [Validator] Add optional expressionLanguage argument to ExpressionValidator [Validator] Add expressionLanguage to ExpressionValidator constructor Oct 7, 2015
@@ -38,17 +38,22 @@ class ExpressionValidator extends ConstraintValidator
private $expressionLanguage;

/**
* @param PropertyAccessorInterface|null $propertyAccessor Optional as of Symfony 2.5
* @param PropertyAccessorInterface|null $propertyAccessor Optional as of Symfony 2.5
* @param ExpressionLanguage $expressionLanguage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing |null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

@@ -38,17 +38,22 @@ class ExpressionValidator extends ConstraintValidator
private $expressionLanguage;

/**
* @param PropertyAccessorInterface|null $propertyAccessor Optional as of Symfony 2.5
* @param PropertyAccessorInterface|null $propertyAccessor Optional as of Symfony 2.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment Optional as of Symfony 2.5 does not bring any value and should be removed IMO. when looking at the phpdoc, we don't really care about which version made it optional. Someone wanting to know this will look at the changelog or the git history

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @param PropertyAccessorInterface|null $propertyAccessor Optional as of Symfony 2.5
*
* @throws UnexpectedTypeException If the property accessor is invalid
* @param PropertyAccessorInterface|null $propertyAccessor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I suggest removing the doc block, it provides no value, pure repetition of the signature

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.

@nicolas-grekas
Copy link
Member

We may have a test that expects the UnexpectedTypeException. If yes, it should be removed (I didn't check for it).

@enumag
Copy link
Contributor Author

enumag commented Oct 7, 2015

@nicolas-grekas If there is such test Travis is going to fail so I'll just wait for that.

@nicolas-grekas
Copy link
Member

👍
Status: reviewed

@stof
Copy link
Member

stof commented Oct 7, 2015

IMO, we should have a test ensuring that the ExpressionLanguage passed as argument is actually used, to avoid regressions

@enumag
Copy link
Contributor Author

enumag commented Oct 7, 2015

@stof Sounds reasonable (although there is no such test for propertyAccessor argument). I'm just not sure how to write it - I'd use Mockery for such tests, but symfony doesn't use it. Can you point me to a similar test in symfony?

@stof
Copy link
Member

stof commented Oct 7, 2015

@enumag there are lots of tests in Symfony using PHPUnit mocks. look for any usage of getMock in the testsuite

@enumag
Copy link
Contributor Author

enumag commented Oct 7, 2015

@stof Can you give me some advice how to run symfony tests locally? The guide from http://symfony.com/doc/current/contributing/code/tests.html doesn't work at all.

I run composer update and then:

php ./phpunit symfony throws many errors, last of which is Warning: unlink(E:\Git\Symfony/src/Symfony/Component/Yaml/phpunit.stderr): No such file or directory in E:\Git\Symfony\phpunit on line 140.

php ./phpunit src/Symfony/Component/Validator complains about a wrong path (without telling me what the path is - or maybe it means the "src/Symfony/Component/Validator" is wrong, which it obviously isn't, I've triple-checked for typos).

The only thing that sorf of worked was this. It let me know about some parse errors I've made and then failed:

E:\Git\Symfony>php .\.phpunit\phpunit-4.8\phpunit src\Symfony\Component\Validator

Fatal error: Class 'Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetAll' not found in E:\Git\Symfony\src\Symfony\C
omponent\Validator\vendor\doctrine\annotations\tests\Doctrine\Tests\Common\Annotations\DocParserTest.php on line 1351

I'm on Windows 7 and I installed msysgit with unix tools.

@nicolas-grekas
Copy link
Member

@enumag can you please post the full output so that we can figure out what's wrong with the tests?

@enumag
Copy link
Contributor Author

enumag commented Oct 10, 2015

I've checked the output and there is nothing that points to the cause. However it seems there is some kind of problem with arguments escaping. When I hack Symfony\Component\Process\ProcessUtils::escapeArgument($argument) to just return the argument without any change, the tests suddenly work, although some of them fail.

@enumag
Copy link
Contributor Author

enumag commented Oct 10, 2015

Can't figure out the arguments escaping problem but I now know why some of the tests were failing for me. The reason is autocrlf setting in git. My default is

git config --global core.autocrlf true

You should add a .gitattributes file to fix this.

There are still some other tests failing. In case of Validator see this:

E:\Git\Symfony>php .\phpunit src/Symfony/Component/Validator
PHPUnit 4.8.10 by Sebastian Bergmann and contributors.

............................................................   60 / 2185 (  2%)
............................................................  120 / 2185 (  5%)
............................................................  180 / 2185 (  8%)
............................................................  240 / 2185 ( 10%)
...........................................................S  300 / 2185 ( 13%)
........SSSSS...............................................  360 / 2185 ( 16%)
..........SSS.SSS...........................................  420 / 2185 ( 19%)
............................................................  480 / 2185 ( 21%)
.................F..........................................  540 / 2185 ( 24%)
.......................F....................SSS.SSS.........  600 / 2185 ( 27%)
....SSSSSS....SSSSSS........................................  660 / 2185 ( 30%)
............................................................  720 / 2185 ( 32%)
............................................................  780 / 2185 ( 35%)
............................................................  840 / 2185 ( 38%)
............................................................  900 / 2185 ( 41%)
................................SS.SS.......................  960 / 2185 ( 43%)
............................................................ 1020 / 2185 ( 46%)
............................................................ 1080 / 2185 ( 49%)
............................................................ 1140 / 2185 ( 52%)
............................................................ 1200 / 2185 ( 54%)
............................................................ 1260 / 2185 ( 57%)
...................................................S........ 1320 / 2185 ( 60%)
............................................................ 1380 / 2185 ( 63%)
.............SSS..SSS.............SSSSSS...SSSSSS........... 1440 / 2185 ( 65%)
....................................................SSS.SSS. 1500 / 2185 ( 68%)
..................S......................................... 1560 / 2185 ( 71%)
........................SSSSSSSSSSSSSSSS.................... 1620 / 2185 ( 74%)
............................................................ 1680 / 2185 ( 76%)
............................................................ 1740 / 2185 ( 79%)
............................................................ 1800 / 2185 ( 82%)
............................................................ 1860 / 2185 ( 85%)
................................................SSS......... 1920 / 2185 ( 87%)
............................................................ 1980 / 2185 ( 90%)
............................................................ 2040 / 2185 ( 93%)
............................................................ 2100 / 2185 ( 96%)
............................................................ 2160 / 2185 ( 98%)
.........................

Time: 24.67 seconds, Memory: 63.75Mb

There were 2 failures:

1) Symfony\Component\Validator\Tests\Constraints\FileValidatorObjectTest::testUploadedFileError with data set #8 (1, 'uploadIniSizeErrorMessage', array(1000, 'MiB'), '1000M')
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
 Symfony\Component\Validator\ConstraintViolation Object (
     'message' => null
     'messageTemplate' => 'myMessage'
     'parameters' => Array (
-        '{{ limit }}' => 1000
-        '{{ suffix }}' => 'MiB'
+        '{{ limit }}' => '1000'
+        '{{ suffix }}' => 'MB'
     )
     'plural' => null
     'root' => 'root'
     'propertyPath' => 'property.path'
     'invalidValue' => 'InvalidValue'
     'constraint' => Symfony\Component\Validator\Constraints\NotNull Object (...)
     'code' => 1
     'cause' => null
 )

E:\Git\Symfony\src\Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest.php:421
E:\Git\Symfony\src\Symfony\Component\Validator\Tests\Constraints\FileValidatorTest.php:431

2) Symfony\Component\Validator\Tests\Constraints\FileValidatorPathTest::testUploadedFileError with data set #8 (1, 'uploadIniSizeErrorMessage', array(1000, 'MiB'), '1000M')
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
 Symfony\Component\Validator\ConstraintViolation Object (
     'message' => null
     'messageTemplate' => 'myMessage'
     'parameters' => Array (
-        '{{ limit }}' => 1000
-        '{{ suffix }}' => 'MiB'
+        '{{ limit }}' => '1000'
+        '{{ suffix }}' => 'MB'
     )
     'plural' => null
     'root' => 'root'
     'propertyPath' => 'property.path'
     'invalidValue' => 'InvalidValue'
     'constraint' => Symfony\Component\Validator\Constraints\NotNull Object (...)
     'code' => 1
     'cause' => null
 )

E:\Git\Symfony\src\Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest.php:421
E:\Git\Symfony\src\Symfony\Component\Validator\Tests\Constraints\FileValidatorTest.php:431

FAILURES!
Tests: 2185, Assertions: 4557, Failures: 2, Skipped: 79.

Legacy deprecation notices (276)
KO src/Symfony/Component/Validator

@enumag
Copy link
Contributor Author

enumag commented Oct 10, 2015

Arguments escaping problem is caused by https://bugs.php.net/bug.php?id=49139. Adding additional double quotes into both proc_open calls in https://github.com/symfony/symfony/blob/2.8/phpunit fixed my problem. The second suggested workaround with bypass_shell option only works for one of the calls.

@enumag enumag force-pushed the patch-expression branch 2 times, most recently from 9e41727 to 64bb03e Compare October 10, 2015 12:24
@enumag
Copy link
Contributor Author

enumag commented Oct 10, 2015

@stof I've added the requested test. Not sure if this is the correct way to write such test though.

@fabpot
Copy link
Member

fabpot commented Oct 19, 2015

Thank you @enumag.

@fabpot fabpot merged commit 4ad1e20 into symfony:2.8 Oct 19, 2015
fabpot added a commit that referenced this pull request Oct 19, 2015
…tor constructor (enumag)

This PR was merged into the 2.8 branch.

Discussion
----------

[Validator] Add expressionLanguage to ExpressionValidator constructor

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

4ad1e20 [Validator] Add expressionLanguage to ExpressionValidator constructor
@fabpot fabpot mentioned this pull request Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants