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

Enable default base uri to be overridden #137

Merged
merged 8 commits into from
Mar 28, 2021

Conversation

grasmash
Copy link
Collaborator

This enables testing of non production instances of Cloud API.

@typhonius
Copy link
Owner

typhonius commented Jan 28, 2021

Thanks for this - GH Actions looks to be degraded currently so it might take some time to run tests. Is there a way we can add tests for this change too please?

@codecov
Copy link

codecov bot commented Feb 4, 2021

Codecov Report

Merging #137 (26ffe09) into master (a861c0a) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##              master      #137   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       237       239    +2     
===========================================
  Files             82        82           
  Lines           1178      1183    +5     
===========================================
+ Hits            1178      1183    +5     
Impacted Files Coverage Δ Complexity Δ
src/Connector/Connector.php 100.00% <100.00%> (ø) 7.00 <3.00> (+2.00)

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 a861c0a...26ffe09. Read the comment docs.

@@ -39,6 +44,10 @@ class Connector implements ConnectorInterface
*/
public function __construct(array $config)
{
$this->baseUri = ConnectorInterface::BASE_URI;
if (getenv('ACQUIA_CLOUD_API_BASE_URI')) {
$this->baseUri = getenv('ACQUIA_CLOUD_API_BASE_URI');
Copy link

Choose a reason for hiding this comment

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

While reading this and looking through ConnectorInterface::BASE_URI, I was really starting to wonder why this wouldn't be taken one step further. Thing is, its really hard to mock a environment variable in tests if you wanted to write a unittest for Connector.

Wouldn't it make more sense to add a optional and secundary constructor parameter here?

public function __construct(array $config, $base_uri = NULL)

That would decouple this from environment variables entirely and put the responsibility of what to connect to, upon the consumer of the API.

Copy link
Owner

@typhonius typhonius Feb 11, 2021

Choose a reason for hiding this comment

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

Thing is, its really hard to mock a environment variable in tests if you wanted to write a unittest for Connector.

I've successfully tested environment variables in a unit test over here. I think I pulled this as an example from somewhere in Symfony as they do similar over there.

https://github.com/typhonius/acquia_cli/blob/master/tests/AcquiaCliApplicationTest.php#L47-L81

Wouldn't it make more sense to add a optional and secundary constructor parameter here?

As the usecase here is for a tiny subset of the users of the library, I'm not sure what the best practice would be. 99.9% of users would never change this, but I'm really not sure whether it would be better injected or as an environment var. If there's precedence somewhere or a similar library that we can follow then that would help guide the approach.

@grasmash grasmash changed the title Enable base uri to be set via environmental variable Enable default base uri to be overridden Mar 10, 2021
@grasmash
Copy link
Collaborator Author

@typhonius How's this?

@grasmash
Copy link
Collaborator Author

@typhonius 👀

@typhonius
Copy link
Owner

Thanks @grasmash at a glimpse this looks great. Let me merge it over the next couple days.

@typhonius typhonius merged commit a48bc1b into typhonius:master Mar 28, 2021
@danepowell
Copy link
Collaborator

danepowell commented Nov 2, 2022

Did this ever actually work for any of y'all? I don't see how it could have, since you would have still been authenticating against the production Accounts endpoint. You wouldn't be authenticated against the stage realm, so how could you be making stage API calls?

#283

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.

4 participants