Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress exception in case of empty curl response #79

Merged

Conversation

tractorcow
Copy link
Contributor

Fixes #78

@tractorcow
Copy link
Contributor Author

@robocoder if this build is successful, do you think you could please push out a 1.4.5?

tractorcow pushed a commit to open-sausages/silverstripe-framework that referenced this pull request Jun 30, 2017
@robocoder
Copy link
Member

Reviewing now...

@tractorcow
Copy link
Contributor Author

Yay thank you. :D I hope if I included good testing it would make the review decision easier. :)

@@ -103,6 +103,11 @@ public function setServiceClass($serviceName, $className)
$className = '\\' . $className;
}

// Flush outdated service cache
if (isset($this->serviceClasses[$serviceName]) && $this->serviceClasses[$serviceName] !== $className) {
unset($this->services[$serviceName]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version of php requires this? Looks like a refcount hack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not PHP version specific; ServiceFactory::getService() would ignore any updated serviceClass if an outdated service exists for any prior value. This is necessary to force the new $className to trigger in any subsequent getService() call.

I would replace with setService() to allow a mock to be directly injected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I understand what's going on now. I was skimming the code from my phone earlier.

*/
public function testNonJsonResponse()
{
ServiceFactory::getInstance()->setServiceClass('service.curl', '\\Test\\WebDriver\\TestCurlService');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly feel this should be served by a mock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes also, but I was hesitant to make any strong changes to an unrelated API. ServiceFactory would be good if you could inject a mock directly.

if ($result === null && json_last_error() != JSON_ERROR_NONE) {
throw WebDriverException::factory(WebDriverException::CURL_EXEC, 'Payload received from webdriver is not valid json: ' . substr($rawResult, 0, 1000));
}
if ($result === null && json_last_error() != JSON_ERROR_NONE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to rewrite this since we want to push a fix tonight while maintaining our coding standards (eg no nested if).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I apologise for the mis-standard! Your standard is a good one. :)

@robocoder robocoder merged commit 6a6063b into instaclick:master Jun 30, 2017
@tractorcow tractorcow deleted the pulls/allow-empty-response branch June 30, 2017 01:46
robocoder added a commit that referenced this pull request Jun 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants