# |
Jun 1st 2021, 21:35 |
corey.taylor.fl |
test |
# |
Jun 1st 2021, 21:30 |
greg138 |
Would your encoded JSON not have something more like `"first_name":"John"` in it anyway? |
# |
Jun 1st 2021, 21:19 |
tyler.adam.lazenby |
Thank you for that solution |
# |
Jun 1st 2021, 21:17 |
tyler.adam.lazenby |
That is really very helpful thank you |
# |
Jun 1st 2021, 21:17 |
tyler.adam.lazenby |
very interesting |
# |
Jun 1st 2021, 21:16 |
thomas465 |
```$responseData = json_decode((string)$this->_response->getBody(), true)``` |
# |
Jun 1st 2021, 21:15 |
kevin.pfeifer |
and assert that with some json you expect |
# |
Jun 1st 2021, 21:15 |
kevin.pfeifer |
after the `$this->post` |
# |
Jun 1st 2021, 21:15 |
kevin.pfeifer |
try ```$response = $this->_response->getBody()->__toString();``` |
# |
Jun 1st 2021, 21:14 |
tyler.adam.lazenby |
but the third assertion fails even though the fixture is set to have the first name as John |
# |
Jun 1st 2021, 21:13 |
tyler.adam.lazenby |
this is my test right now |
# |
Jun 1st 2021, 21:13 |
tyler.adam.lazenby |
```public function testAddToExisting(): void { $data = ['account_id' => 1]; $this->enableCsrfToken(); $this->post('/accounts/add-to-existing/1', $data); $this->assertResponseOk(); $this->assertResponseNotEmpty(); $this->assertResponseContains('first_name: John'); }``` |
# |
Jun 1st 2021, 21:13 |
tyler.adam.lazenby |
Let me make my question more specific. If I expect to json_encode a user entity with a first_name property valued as "john", how would I unit test that? |
# |
Jun 1st 2021, 21:09 |
greg138 |
I've done that. This is what `removeBehavior` is for. :) |
# |
Jun 1st 2021, 21:08 |
kevin.pfeifer |
sorry, haven’t dealt with that till now. Can’t answer that right now ,:) |
# |
Jun 1st 2021, 21:06 |
thomas465 |
tags is linked to products with a `through` class, that class is also defined. again, everything works, but i’d like it not update the modified field :) |
# |
Jun 1st 2021, 21:04 |
thomas465 |
but tag_id = 10 will also have it’s modified date updated (TimeStampBehavoir) |
# |
Jun 1st 2021, 21:03 |
thomas465 |
and its creating a tag_id = 10, product_id = 99 in the link table along with the comment (and other cols for the join table) |
# |
Jun 1st 2021, 21:03 |
tyler.adam.lazenby |
On unit tests, I want to test to see if the response contains a new account id, since I return it in application/json form. How can I do that? |
# |
Jun 1st 2021, 21:02 |
thomas465 |
well, here the tag id is 10 |
# |
Jun 1st 2021, 21:02 |
kevin.pfeifer |
ah ok your junction table has an id |
# |
Jun 1st 2021, 21:01 |
thomas465 |
https://book.cakephp.org/4/en/orm/saving-data.html#saving-additional-data-to-the-join-table |
# |
Jun 1st 2021, 21:01 |
thomas465 |
it looks like the example in the docs ``` 'tags' => [ [ 'id' => 10, '_joinData' => [ 'comment' => '123123' ] ], // Other courses.``` |
# |
Jun 1st 2021, 20:57 |
kevin.pfeifer |
and it does look like that? ```$entity['tags'] = [ '_ids' => [ '23' ] ];``` where 23 is one valid tag id |
# |
Jun 1st 2021, 20:52 |
thomas465 |
(the import script is just doing pathEntity on handcrafted arrays so i would not think it makes a difference) |
# |
Jun 1st 2021, 20:51 |
thomas465 |
let me give it a try |
# |
Jun 1st 2021, 20:47 |
kevin.pfeifer |
does it also happen when you add that entry “normally” via your template or does it just happen with your import script |
# |
Jun 1st 2021, 20:45 |
thomas465 |
My issue is that when running a import/sync it keeps touching the same 5 tags resulting in deadlock errors after a while |
# |
Jun 1st 2021, 20:45 |
thomas465 |
(ok that was terrible english) I’m creating a new link in the link table, (with some extra joindata) all that works fine, but it updates the modified date of the `tag` i’m linking to, is that expected behaviour ? |
# |
Jun 1st 2021, 20:43 |
thomas465 |
Question when saving belongsToMany() association with _joinData … is it expected that the modified date of the target table? So if `products -> products_tags -> tags` it updates the modifed col of `tags` |
# |
Jun 1st 2021, 20:43 |
kevin.pfeifer |
well you get the parsed json data via ```$data = $this->getRequest()->getData()``` if you want the raw body you could try look at your $_POST Variable (if you sent your data via POST) |
# |
Jun 1st 2021, 20:06 |
rightscoreanalysis |
is $this->request->input() the best way to read raw json body |
# |
Jun 1st 2021, 19:10 |
tyler.adam.lazenby |
right, that is what I just did now, but the issue is that I have to add that to the table class itself as a method and I can reuse that |
# |
Jun 1st 2021, 19:05 |
richard |
makes more sense to add something like that to $validator |
# |
Jun 1st 2021, 19:04 |
richard |
@tyler.adam.lazenby you wouldn’t see the error until you attempt a save on buildRules |
# |
Jun 1st 2021, 18:34 |
kevin.pfeifer |
is it the developer mentioned in the comments at the start of the style.css in the theme? |
# |
Jun 1st 2021, 18:33 |
jonathan086 |
Understood Kevin! This is frustrating when I am directed to the wrong avenue. |
# |
Jun 1st 2021, 18:28 |
kevin.pfeifer |
Just FYI: CakePHP is a complete MVC Framework in which you build whole websites with it, not "just" some little library you use to build themes with |
# |
Jun 1st 2021, 18:25 |
jonathan086 |
I am reaching back out to the developer Kevin. Thanks for your time and appreciate it. |
# |
Jun 1st 2021, 18:17 |
kevin.pfeifer |
+ i find it very suspect, that a theme developer tells you (a customer) to update a "library" the theme developer used to build the theme (which I still doubt) This should in my opinion always be the job of the theme developer, not the customer |
# |
Jun 1st 2021, 18:11 |
kevin.pfeifer |
do you have a composer.json inside your theme |