Skip to content

use guzzle globally through a helper#32505

Merged
phil-davis merged 1 commit into
masterfrom
guzzleHelper
Aug 31, 2018
Merged

use guzzle globally through a helper#32505
phil-davis merged 1 commit into
masterfrom
guzzleHelper

Conversation

@individual-it

@individual-it individual-it commented Aug 29, 2018

Copy link
Copy Markdown
Member

Description

  1. use Guzzle through a Helper class
  2. don't catch Guzzle exceptions all over the place, as there are not thrown any-more, but only check responses

Related Issue

owncloud/QA#586

Motivation and Context

have only one place where guzzle can be configured globally

How Has This Been Tested?

🤖

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Open tasks:

  • Backport (if applicable set "backport-request" label and remove when the backport was done)

public static function sendRequest(
$url, $method='GET', $user=null, $password=null, $headers=null, $body = null, $config = null, $cookies = null
) {
$client = new Client();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we inject parameters from behat.yml into the helper?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe, but what for?
The only thing that I can see that would make sense is the base part of the URL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes exactly - how do we define the server url currently?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Environment variable TEST_SERVER_URL and/or TEST_SERVER_FED_URL is set before running run.sh Then that is used to pass base_url in to Behat, and also BasicStructure constructor checks the 2 environment variables so it can set localBaseUrl and remoteBaseUrl to know where to find the local and remote (federated) server(s).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

from wherever sendRequest() is called is responsible to create the complete URL

@patrickjahns

Copy link
Copy Markdown
Contributor

Wondering if we should add a unit test to ensure the clientHelper works as designed?

@codecov

codecov Bot commented Aug 30, 2018

Copy link
Copy Markdown

Codecov Report

Merging #32505 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #32505   +/-   ##
=========================================
  Coverage     64.12%   64.12%           
  Complexity    18643    18643           
=========================================
  Files          1176     1176           
  Lines         70189    70189           
  Branches       1270     1270           
=========================================
  Hits          45007    45007           
  Misses        24812    24812           
  Partials        370      370
Flag Coverage Δ Complexity Δ
#javascript 52.89% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 65.4% <ø> (ø) 18643 <ø> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 001ddd6...77279b0. Read the comment docs.

@individual-it individual-it force-pushed the guzzleHelper branch 6 times, most recently from 4d7d01c to be88feb Compare August 30, 2018 11:24
$responseHeaders = $response->getHeaders();
$tagUrl = $responseHeaders['Content-Location'][0];
$lastTagId = \substr($tagUrl, \strrpos($tagUrl, '/') + 1);
return ['lastTagId' => $lastTagId, 'HTTPResponse' => $response];

@individual-it individual-it Aug 30, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

moved to Tags.php, so we always just return the response the whole way up till the place that cares


$client = new Client();
$this->response = $client->get($url, $options);
private function checkDownload(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

had to change that function to get the nice username & password

@individual-it individual-it changed the title [WIP] use guzzle globally through a helper use guzzle globally through a helper Aug 30, 2018
@individual-it

Copy link
Copy Markdown
Member Author

@phil-davis @patrickjahns please review
signal-attachment-2018-08-01-201208

'user' => $user,
'password' => $this->getPasswordForUser($user),
]);
$headers = ['Content-Type' => 'application/json'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess the previous $client->post() with that json array of values had been automagically setting this header.

@phil-davis phil-davis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like a great thing. It should help with the Guzzle6 PR, reducing the diff list a lot.

@phil-davis

Copy link
Copy Markdown
Contributor

I pushed a commit with code style changes to make our "informal" phpcs pass.
And added some missing spaces either side of = signs.

I couldn't see any issues with the actual code refactoring - good work.

$body =
'<c:mkcalendar xmlns:c="urn:ietf:params:xml:ns:caldav" ' .
$body
= '<c:mkcalendar xmlns:c="urn:ietf:params:xml:ns:caldav" ' .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the previous code looks fine, but phpcs has a different idea.

@individual-it

Copy link
Copy Markdown
Member Author

squashed and pushed again.
@patrickjahns for the unit tests I opened a new issue #32527

@individual-it

Copy link
Copy Markdown
Member Author

backport in #32528

@phil-davis phil-davis merged commit e5d3b88 into master Aug 31, 2018
@phil-davis phil-davis deleted the guzzleHelper branch August 31, 2018 04:22
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants