# |
Apr 17th 2019, 14:44 |
neon1024 |
Otherwise you’d need to write a fixture for the data |
# |
Apr 17th 2019, 14:44 |
Coddyx |
My code looks like this |
# |
Apr 17th 2019, 14:44 |
neon1024 |
Or maybe a query param |
# |
Apr 17th 2019, 14:43 |
neon1024 |
Perhaps pass it into the controller |
# |
Apr 17th 2019, 14:43 |
neon1024 |
Perhaps read from a session or cookie |
# |
Apr 17th 2019, 14:43 |
neon1024 |
So you’ll need to just set that manually |
# |
Apr 17th 2019, 14:43 |
neon1024 |
Well you must use the value somewhere right? |
# |
Apr 17th 2019, 14:43 |
Coddyx |
I can show you what I have so far |
# |
Apr 17th 2019, 14:43 |
Coddyx |
I understand, can yo uplease define «set it manually» |
# |
Apr 17th 2019, 14:42 |
neon1024 |
Writing tests for bad code is super hard work |
# |
Apr 17th 2019, 14:42 |
neon1024 |
If you can’t do that then you need to refactor your code to make it more testable |
# |
Apr 17th 2019, 14:42 |
neon1024 |
As I don’t see any value in creating a fixture for it and testing the ORM as well |
# |
Apr 17th 2019, 14:42 |
neon1024 |
Then you’ll probably want to set it manually |
# |
Apr 17th 2019, 14:41 |
Coddyx |
With a boolean in it |
# |
Apr 17th 2019, 14:41 |
Coddyx |
No, the maintenance is actually stored in a database field |
# |
Apr 17th 2019, 14:41 |
neon1024 |
So you could just change that in your test case before dispatching your request |
# |
Apr 17th 2019, 14:41 |
neon1024 |
Well I’d presume you have it as a `Configure::write('maintenance', false)` right? |
# |
Apr 17th 2019, 14:40 |
neon1024 |
So you’ll need a response to assert against |
# |
Apr 17th 2019, 14:40 |
neon1024 |
Which is a response code |
# |
Apr 17th 2019, 14:40 |
neon1024 |
But you said you wanted to assert a 503 |
# |
Apr 17th 2019, 14:40 |
Coddyx |
How should I go about changing the settings? (I'm sorry I am very new to this) |
# |
Apr 17th 2019, 14:40 |
neon1024 |
Which might be boolean for is in maintenance |
# |
Apr 17th 2019, 14:40 |
neon1024 |
If you want to unit test your maintenance method you’d just call it with expected output |
# |
Apr 17th 2019, 14:40 |
neon1024 |
Hence just sending a request and asserting the response |
# |
Apr 17th 2019, 14:39 |
neon1024 |
You’ll want an integration test |
# |
Apr 17th 2019, 14:39 |
neon1024 |
Well that’s a unit test |
# |
Apr 17th 2019, 14:39 |
Coddyx |
In my specific case, the isInMaintenance is a private function called in the beforeFilter of the AppController which is extended by the PagesController (what i want to test) |
# |
Apr 17th 2019, 14:39 |
neon1024 |
Then change the setting and asserts in each |
# |
Apr 17th 2019, 14:39 |
neon1024 |
Create those two test-case methods |
# |
Apr 17th 2019, 14:38 |
Coddyx |
How do I test for a isInMaintenance and isNotInMaintenance |
# |
Apr 17th 2019, 14:38 |
Coddyx |
What I didn't get is |
# |
Apr 17th 2019, 14:38 |
neon1024 |
When you upgrade the IntegrationTestCase is replaced with a Trait, so keep an eye out for that |
# |
Apr 17th 2019, 14:38 |
Coddyx |
That is what I understood from the documentation as well |
# |
Apr 17th 2019, 14:37 |
neon1024 |
Or similar |
# |
Apr 17th 2019, 14:37 |
neon1024 |
`$this->get('/'); $this->assertResponseCode(503)` |
# |
Apr 17th 2019, 14:37 |
neon1024 |
I tend to use the IntegrationTestCase for that, set the settings and do a get request |
# |
Apr 17th 2019, 14:36 |
Coddyx |
3.4.14* sorry |
# |
Apr 17th 2019, 14:36 |
Coddyx |
3.4.11 |
# |
Apr 17th 2019, 14:36 |
neon1024 |
What version of Cake are you using? |
# |
Apr 17th 2019, 14:36 |
Coddyx |
How should I approach this kind of test? |
# |
Apr 17th 2019, 14:35 |
Coddyx |
In the PagesController I want to test that I correctly get a 503 if the app is in maintenance |