Add a maxLength rule for text columns#335
Conversation
c3c128d to
c50a2e6
Compare
Codecov Report
@@ Coverage Diff @@
## master #335 +/- ##
============================================
+ Coverage 92.12% 92.19% +0.07%
- Complexity 664 672 +8
============================================
Files 25 25
Lines 2184 2205 +21
============================================
+ Hits 2012 2033 +21
Misses 172 172
Continue to review full report at Codecov.
|
markstory
left a comment
There was a problem hiding this comment.
Looking good, just wondering if we should fix the possible args issue now.
src/Template/Bake/Model/table.ctp
Outdated
| if ($rule['rule'] && !isset($rule['provider']) && !isset($rule['args'])): | ||
| $validationMethods[] = sprintf("->%s('%s')", $rule['rule'], $field); | ||
| elseif ($rule['rule'] && !isset($rule['provider'])): | ||
| $validationMethods[] = sprintf("->%s('%s', %s)", $rule['rule'], $field, implode(', ', $rule['args'])); |
There was a problem hiding this comment.
Won't this have issues if the arguments are strings?
b94cf73 to
208a4ca
Compare
|
@markstory String values are now wrapped with quotes. Tests are failing because each DBMS has different length limits for string-type fields. |
src/View/Helper/BakeHelper.php
Outdated
| public function escapeArguments($args) | ||
| { | ||
| return array_map(function ($v) { | ||
| if (!is_numeric($v)) { |
There was a problem hiding this comment.
You should probably escape ' inside strings 😄
|
Tests will need to be passing before we can get this merged. |
bb3761c to
68347e8
Compare
|
Ok, I'll change the code. |
e1c5e08 to
68347e8
Compare
68347e8 to
afe3e12
Compare
|
Tests still failing. |
c5e35b7 to
7b6b8f6
Compare
|
My changes fails to pass validation on some DBMS, because of some inconsistency between them. E.g. in SQLite, text fields can have infinite length, while in MySQL, it's not. To work around this, I am thinking about two possible approaches:
@ADmad @markstory Which one is better? Or maybe you can suggest a better solutions? |
|
Could we test this validator against varchar columns instead of text ones? Those should have more stable lengths across different db vendors. |
7d92a67 to
d315b22
Compare
|
Depends on cakephp/cakephp/issues/11295 |
d315b22 to
900f52c
Compare
| * | ||
| * Generates a tree of data for use testing the tree behavior | ||
| */ | ||
| class NumberTreesFixture extends TestFixture |
There was a problem hiding this comment.
Overall it's a copy of CakePHP's core NumberTreesFixture, but with a change: "name" column now has a length attribute. Since the length attribute is not needed in CakePHP core, and is not covered with tests, it is a subject to change in the future. So I decided to copy it into the repository.
This fixture is used in ModelTaskTest.php::testGetValidationTree().
There was a problem hiding this comment.
I didn't see where the fixture was used. My mistake.
7719309 to
8675cf5
Compare
8675cf5 to
f10333c
Compare
f10333c to
f60967d
Compare
|
Now with TWIG support. |
#284
This pull-request depends on cakephp/cakephp/issues/11295 .