helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
99 stars 62 forks source link

List customers with query filter causes fatal error (again) #187

Closed matt-allan closed 5 years ago

matt-allan commented 5 years ago

Hello,

I previously reported an issue in #175, that was fixed by #176. #180 reverted #176 and it seems the issue I was experiencing originally is back. I tried updating to v2.3.9 and received the same error again:

PHP Warning:  array_map(): Expected parameter 2 to be an array, object given in /home/matt/code/helpscout-api-php/src/Http/Hal/HalDeserializer.php on line 62
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to HelpScout\Api\Http\Hal\HalPagedResources::__construct() must be of the type array, null given, called in /home/matt/code/helpscout-api-php/src/Http/Hal/HalDeserializer.php on line 73 and defined in /home/matt/code/helpscout-api-php/src/Http/Hal/HalPagedResources.php:19
Stack trace:
#0 /home/matt/code/helpscout-api-php/src/Http/Hal/HalDeserializer.php(73): HelpScout\Api\Http\Hal\HalPagedResources->__construct(NULL, Object(HelpScout\Api\Http\Hal\HalLinks), Object(HelpScout\Api\Http\Hal\HalPageMetadata))
#1 /home/matt/code/helpscout-api-php/src/Http/RestClient.php(159): HelpScout\Api\Http\Hal\HalDeserializer::deserializeResources('HelpScout\\Api\\C...', 'customers', Object(HelpScout\Api\Http\Hal\HalDocument))
#2 /home/matt/code/helpscout-api-php/src/Customers/CustomersEndpoint.php(98): HelpScout\Api\Http\RestClient->getResources('HelpScout\\Api\\C...', 'customers', '/v2/customers?q...')
#3 /home/matt/code/helpscout-api-php/src/Customers/CustomersEndpoint.php(82): HelpScou in /home/matt/code/helpscout-api-php/src/Http/Hal/HalPagedResources.php on line 19

The same reproduction script I included in #175 is able to reproduce the issue on master.

bkuhl commented 5 years ago

Sorry about this matt. I'm a bit confused to be honest. The PR that reverted the change didn't introduce any failing tests when reverting that change, so I believed the issue to be fixed by the adjustments made to hasEmbeddedEntities(). However looking at the test file now, I don't see any record of the test that should've been brought in when your PR to resolve this issue was merged.

The fix is up again with https://github.com/helpscout/helpscout-api-php/pull/188

bkuhl commented 5 years ago

I'm still digging into this to try to find a solution so embedded entities that aren't collections aren't forced to be collections.

bkuhl commented 5 years ago

Can you provide me with the CustomerId you're running into this with? I've been testing on a pool of data on my end and can't seem to reproduce the same circumstances you're running into. Giving me this ID should allow me to reproduce it exactly.

matt-allan commented 5 years ago

Do you mean the ID of the HelpScout account or the customer ID I'm searching for?

If you mean the HelpScout customer ID I made a test OAuth app under my user ID 387237. If you use those credentials you should be able to reproduce the error. The same error occurs with our actual OAuth credentials but I don't know off hand the HelpScout customer ID of the account those are under.

The error seems to only happen when searching by email and no matching results are found, so as long as you don't have a user with the email 'matt.allan@somedomain.com' the reproduction script I posted in #175 should reproduce the error. Does it not reproduce the issue with the account you are using?

bkuhl commented 5 years ago

Thanks for that info, just what I needed! This is fixed in https://github.com/helpscout/helpscout-api-php/pull/189

bkuhl commented 5 years ago

This is tagged as v2.3.10. Thanks again for bringing this up and I apologize we introduced this regression.