# |
Jul 17th 2017, 15:26 |
neon1024 |
I thought so too, with deleteDetectorCache(), but it seems not |
# |
Jul 17th 2017, 15:26 |
jeremyharris |
I thought there was a way to remove detectors, guess not |
# |
Jul 17th 2017, 15:26 |
neon1024 |
Might refactor the tests once I’ve written the code to pass them |
# |
Jul 17th 2017, 15:25 |
neon1024 |
But yes, a proper mock is probably in order |
# |
Jul 17th 2017, 15:25 |
neon1024 |
I just set the detector to return true for mobile tests and false for not mobile test cases :P |
# |
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 |