# |
Jul 12th 2017, 15:23 |
ericadeefox |
^that's basically what's happening. the plugin checks to see if a session has been started, then 500s and throws an error when it isn't. |
# |
Jul 12th 2017, 15:23 |
jeremyharris |
perhaps an FB class is instantiated early and checks the session? |
# |
Jul 12th 2017, 15:22 |
jeremyharris |
you shouldn’t need session_start anywhere. other integration tests work successfully using the session, no? |
# |
Jul 12th 2017, 15:22 |
jeremyharris |
ok so this is the process: `$this->session` just stores what you want to write, `$this->post()` starts by building a request, it sees you want to write session data, so it creates a session object and `$session->write()`s to it. `$session->write()` sees the session isn’t started yet, so it starts it for you. the request is then dispatched |
# |
Jul 12th 2017, 15:19 |
ericadeefox |
hmm... my tests don't work unless I use `session_start()` at the top of the first test. but then using that, a few of the tests still don't work, because they have to write stuff using `$this->session()`. idk if there is any way to make them compatible. |
# |
Jul 12th 2017, 15:17 |
jlroberts |
word |
# |
Jul 12th 2017, 15:17 |
jeremyharris |
that’s why `$this->session` exists, to write into the session when the request is actually built |
# |
Jul 12th 2017, 15:17 |
ericadeefox |
ahhh. ::nod:: |
# |
Jul 12th 2017, 15:17 |
jeremyharris |
no it’s not, because the request isn’t built until the test method (e.g., get, post) executes |
# |
Jul 12th 2017, 15:16 |
ericadeefox |
I mean, is it _possible_ to write session data using `$this->request->session()->write()` in integration tests? because I just keep getting the error message `Undefined property: App\Test\TestCase\Controller\EventsControllerTest::$request` when I do this. |
# |
Jul 12th 2017, 15:09 |
jeremyharris |
np! |
# |
Jul 12th 2017, 15:09 |
jeremyharris |
I don’t think it makes sense for it to be a mysql field :slightly_smiling_face: |
# |
Jul 12th 2017, 15:09 |
pedroseco |
:) |
# |
Jul 12th 2017, 15:09 |
pedroseco |
thanks |
# |
Jul 12th 2017, 15:09 |
pedroseco |
ah ok that can work too |
# |
Jul 12th 2017, 15:09 |
jeremyharris |
ok, then I would do the fetch first, then just sum it up like $sum = $results->sum(‘totalhours’) |
# |
Jul 12th 2017, 15:09 |
pedroseco |
the sum gives the right answer, and your solution to get all fields works too. |
# |
Jul 12th 2017, 15:08 |
pedroseco |
yes |
# |
Jul 12th 2017, 15:06 |
jeremyharris |
but still want those records as well |
# |
Jul 12th 2017, 15:06 |
jeremyharris |
if I’m getting this correctly, you want the sum of totalhours on all the records of $this (dunno the table name) right? |
# |
Jul 12th 2017, 15:06 |
pedroseco |
maybe that’s the reason i’m only get 1 row of results? |
# |
Jul 12th 2017, 15:05 |
jeremyharris |
@pedroseco that looks ok to me, except it’s missing a group clause which you usually need for aggregate functions |
# |
Jul 12th 2017, 15:04 |
jeremyharris |
and the session is started if it needs to be during write() |
# |
Jul 12th 2017, 15:04 |
ericadeefox |
ok I'm gonna try to write this differently then... |
# |
Jul 12th 2017, 15:03 |
jeremyharris |
the request won’t be available until after the integration test method (e.g., get, post) runs so by then it will be too late. but here’s where it’s written: https://api.cakephp.org/3.4/source-class-Cake.TestSuite.IntegrationTestCase.html#546 |
# |
Jul 12th 2017, 15:02 |
pedroseco |
@jeremyharris sure: https://gist.github.com/pedroseco/7f2d0cb0e01361c98fc7cd346f24bc24 |
# |
Jul 12th 2017, 15:02 |
ericadeefox |
@jeremyharris wait does it? wouldn't that mean that one _could_ use `$this->session()` with `session_start()` and it would work? because it totally wasn't working for me so now I'm just trying to figure out how to use `$this->request->session()` |
# |
Jul 12th 2017, 15:00 |
jeremyharris |
@pedroseco maybe I misunderstood. can you gist your query that has the sum on it? |
# |
Jul 12th 2017, 15:00 |
jeremyharris |
@ericadeefox still dealing with FB stuff? :( I was reading the code and the integration test writes the data you pass in $this->session to the session right before dispatching the request |
# |
Jul 12th 2017, 15:00 |
pedroseco |
instead of manipulating the entity on the query object? |
# |
Jul 12th 2017, 14:59 |
pedroseco |
should I use a collection here? |
# |
Jul 12th 2017, 14:59 |
pedroseco |
humm, i did that but now it only returns the first item of the object |
# |
Jul 12th 2017, 14:59 |
jeremyharris |
@pedroseco you can re-select all fields with ->select($this->Table) |
# |
Jul 12th 2017, 14:58 |
pedroseco |
hi guys, im trying to do a sum() on a query object but the result only returns the select field that I appended sum() to. How can I achieve the result with all the fields? |
# |
Jul 12th 2017, 14:48 |
ericadeefox |
ok this is probably the dumbest question of 2017 but is there any way to use `$this->request->session()` in integration testing? because `$this->session()` doesn't actually set `$_SESSION` data or work with `session_start()`, which I need to do in order to test a certain plugin. |
# |
Jul 12th 2017, 14:43 |
sathomsen |
https://book.cakephp.org/3.0/en/orm/validation.html#creating-a-rules-checker |
# |
Jul 12th 2017, 14:42 |
jarard01 |
https://book.cakephp.org/3.0/en/core-libraries/validation.html#conditional-validation |
# |
Jul 12th 2017, 14:42 |
jarard01 |
this right? Westfalia Roof |
# |
Jul 12th 2017, 14:42 |
sathomsen |
You can go with a custom validation rule:) |
# |
Jul 12th 2017, 14:41 |
jarard01 |
how can I apply a validation rule when a foo_type_id = x |
# |
Jul 12th 2017, 14:38 |
sathomsen |
Hey guys, is there any build in way of flattening the error object returned from the entity validation? |