Log message #4052957

# At Username Text
# Jul 17th 2017, 15:23 jeremyharris unless you’re doing integration .. then … env vars I guess :)
# Jul 17th 2017, 15:23 jeremyharris maybe traditional mock is in order ($request->expects($this->any())->method(
# Jul 17th 2017, 15:21 neon1024 Ah well #care
# Jul 17th 2017, 15:19 neon1024 So all subsequent tests are now mobile
# Jul 17th 2017, 15:19 neon1024 Hah! It stays in global state as it’s static
# Jul 17th 2017, 15:16 neon1024 Thanks @jeremyharris just ‘mocking’ the detector works just fine
# Jul 17th 2017, 15:12 jeremyharris we’d be out of the job if whining was all it took :P programmers are expert whiners
# Jul 17th 2017, 15:11 neon1024 Although that would be nice
# Jul 17th 2017, 15:11 neon1024 Ah well, moaning about it won’t make the code write itsself
# Jul 17th 2017, 15:11 neon1024 Lé sigh.
# Jul 17th 2017, 15:10 jeremyharris and then maybe have one other test to test the mobile detect lib if you want
# Jul 17th 2017, 15:10 jeremyharris probably better just to expect it works and add a passing detector for the test
# Jul 17th 2017, 15:10 neon1024 Just a bit annoying as I’m building a data provider method, so shoe-horning all that logic into the array is horrid
# Jul 17th 2017, 15:08 jeremyharris looks like the UA like I thought
# Jul 17th 2017, 15:07 jeremyharris or, again, if you don’t care that the detector works properly (e.g., you trust MobileDetect to do its job), then mock / addDetector
# Jul 17th 2017, 15:06 neon1024 https://github.com/serbanghita/Mobile-Detect/blob/master/tests/BasicsTest.php#L27
# Jul 17th 2017, 15:06 jeremyharris yeah that’s where reading the library comes in :S
# Jul 17th 2017, 15:06 jeremyharris it doesn’t quite work like that because it checks various things, such as env, headers, etc
# Jul 17th 2017, 15:06 neon1024 I mean it’s config takes something from $_ENV, but I have no idea what I’d put in there
# Jul 17th 2017, 15:05 neon1024 I was hoping for `new ServerRequest(['type' => 'mobile']);` or something
# Jul 17th 2017, 15:04 neon1024 I need to unit test my code with a mobile request
# Jul 17th 2017, 15:04 jeremyharris do you want to test that the detector works, or just want to test what your page does if detection passes?
# Jul 17th 2017, 15:03 neon1024 https://github.com/serbanghita/Mobile-Detect/blob/master/namespaced/Detection/MobileDetect.php
# Jul 17th 2017, 15:03 neon1024 O_o
# Jul 17th 2017, 15:02 neon1024 If I knew how it ‘detected’ I could just mock it
# Jul 17th 2017, 15:02 jeremyharris such as setting an env var
# Jul 17th 2017, 15:02 jeremyharris at any rate, I think you can overwrite it by using addDetector again in this case. unless you want to test that the detector works, which in that case you’ll need to inspect how the `\Detection\MobileDetect()` library works (probably sniffs user agent) and set that
# Jul 17th 2017, 15:01 neon1024 Ah yes, thanks! https://github.com/cakephp/app/blob/master/config/bootstrap.php#L169
# Jul 17th 2017, 15:01 jeremyharris at least in the skeleton it is
# Jul 17th 2017, 15:00 jeremyharris I think it is added in bootstrap now
# Jul 17th 2017, 14:59 neon1024 Or has mobile gone now? https://github.com/cakephp/cakephp/blob/master/src/Http/ServerRequest.php#L141
# Jul 17th 2017, 14:59 neon1024 Speaking of testing, anyone know how I can make a new ServerRequest instance which will pass an `is('mobile')` check?
# Jul 17th 2017, 14:54 neon1024 Then there is no need to even execute the query, you can just assert on the resulting object
# Jul 17th 2017, 14:54 ericadeefox ^^that makes sense
# Jul 17th 2017, 14:53 neon1024 If I had code building a complex query object, I’d unit test the method building the object
# Jul 17th 2017, 14:52 neon1024 Testing a part of the response will mitigate the problem, but only partially
# Jul 17th 2017, 14:52 neon1024 Bearing in mind that testing a fixed response will make your tests extremely fragile
# Jul 17th 2017, 14:50 ericadeefox ^^I can do that then. testing responses will also suffice for what I'm doing, I was just curious, y'know?
# Jul 17th 2017, 14:49 neon1024 Unless you’re doing an integration test, in which case you should test the observable behaviour
# Jul 17th 2017, 14:49 neon1024 Or use fixtures and mock the database
# Jul 17th 2017, 14:49 neon1024 Or you need to test the generated SQL string, rather than letting it hit the database. As the Cake ORM already has tests