# |
Apr 12th 2019, 15:17 |
ricksaccous |
what you might want is nested validation |
# |
Apr 12th 2019, 15:16 |
slackebot |
display on the users_information.X I have tried to add this rule in the UserInformations table but I don't have access in the context to the parent table Users ... |
# |
Apr 12th 2019, 15:16 |
louisviart |
I'm trying to solve a problem but I don't know if I'm doing great. I have a User entity wich has one UserInformations that contains a field X This field is in my add / edit form of a user. I would like to perform, conditional validation (https://book.cakephp.org/3.0/en/core-libraries/validation.html#conditional-validation) The problem is that the condition is on the value of the `role` field of the user entity and the message should |
# |
Apr 12th 2019, 15:01 |
ricksaccous |
hello |
# |
Apr 12th 2019, 14:56 |
louisviart |
Hello everyone |
# |
Apr 12th 2019, 14:56 |
josbeir |
yeah as your solution would give a php notice if the key doesn't exist |
# |
Apr 12th 2019, 14:54 |
neon1024 |
Hash is a good shout though @josbeir :ok_hand: |
# |
Apr 12th 2019, 14:54 |
slackebot |
<neon1024> |
# |
Apr 12th 2019, 14:54 |
neon1024 |
Yeah, I went similar |
# |
Apr 12th 2019, 14:45 |
josbeir |
@neon1024 $this->assertArrayHasKey('call.features', Hash::flatten(json_decode('{ "call": { "features": "" } }'))); :rolling_on_the_floor_laughing: |
# |
Apr 12th 2019, 14:43 |
ricksaccous |
too bad we don't account for it in our budgets though |
# |
Apr 12th 2019, 14:43 |
ricksaccous |
hehe |
# |
Apr 12th 2019, 14:43 |
ricksaccous |
as of now the only one who has written a test is me and i just wanted to to be sure some of my logic was correct |
# |
Apr 12th 2019, 14:43 |
ricksaccous |
if i head a project i might make people write some tests |
# |
Apr 12th 2019, 14:42 |
ricksaccous |
hahaha |
# |
Apr 12th 2019, 14:42 |
neon1024 |
Don’t worry, it took me three test suites to figure this stuff out! |
# |
Apr 12th 2019, 14:42 |
neon1024 |
..and if you rebake your fixtures your test -case will fail |
# |
Apr 12th 2019, 14:42 |
ricksaccous |
oh alright |
# |
Apr 12th 2019, 14:42 |
neon1024 |
Which might be out of scope for your test-case |
# |
Apr 12th 2019, 14:41 |
neon1024 |
As you’d be comparing all the keys in the response |
# |
Apr 12th 2019, 14:41 |
neon1024 |
No, you can’t do that either |
# |
Apr 12th 2019, 14:41 |
neon1024 |
You re-bake a fixture with imports, and your test suite will fail |
# |
Apr 12th 2019, 14:41 |
ricksaccous |
lollll |
# |
Apr 12th 2019, 14:41 |
ricksaccous |
you can just do array_keys or something on it and then compare the array of array_keys? |
# |
Apr 12th 2019, 14:41 |
neon1024 |
Asserting values will suffer the same fate |
# |
Apr 12th 2019, 14:41 |
ricksaccous |
oh |
# |
Apr 12th 2019, 14:41 |
neon1024 |
No, you only want to assert the keys exist |
# |
Apr 12th 2019, 14:40 |
neon1024 |
and regenerating all your json fixtures |
# |
Apr 12th 2019, 14:40 |
ricksaccous |
comparing two php arrays is a lot easier |
# |
Apr 12th 2019, 14:40 |
neon1024 |
Any schema change requires rebaking all your fixtures |
# |
Apr 12th 2019, 14:40 |
ricksaccous |
yeah that makes sense |
# |
Apr 12th 2019, 14:40 |
neon1024 |
Because it’s far too fragile |
# |
Apr 12th 2019, 14:40 |
ricksaccous |
i am just thinking aloud as to why |
# |
Apr 12th 2019, 14:40 |
ricksaccous |
yeah |
# |
Apr 12th 2019, 14:39 |
ricksaccous |
actually trimming white space would ruin some stuff |
# |
Apr 12th 2019, 14:39 |
neon1024 |
No, as I said, you don’t want to do that |
# |
Apr 12th 2019, 14:39 |
neon1024 |
Well that’s what `$this->assertResponseContains()` can do for you, but it doesn’t understand nesting |
# |
Apr 12th 2019, 14:39 |
ricksaccous |
you might be able to do assertEqual if you trim whitespace, not sure about that |
# |
Apr 12th 2019, 14:38 |
ricksaccous |
hehe, yeah i suppose, json as arrays seem the easiest in php |
# |
Apr 12th 2019, 14:38 |
neon1024 |
Even with fixtures |
# |
Apr 12th 2019, 14:38 |
neon1024 |
But you don’t want to to `$this->assertEqual($response, $json)` as it’s too fragile |