Skip to content

Commit

Permalink
Merge pull request #24 from dcarbone/feature/guzzle_psr7_v2
Browse files Browse the repository at this point in the history
Updating to use guzzle/psr7 v2
  • Loading branch information
dcarbone authored Oct 4, 2021
2 parents f541ed8 + f667951 commit 2a6af3e
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 189 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dcarbone/gotime": "0.4.*",
"dcarbone/gohttp": "v0.3.*",
"guzzlehttp/guzzle": "~7",
"guzzlehttp/psr7": "~1"
"guzzlehttp/psr7": "~2"
},
"autoload": {
"files": [
Expand Down
299 changes: 183 additions & 116 deletions composer.lock

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions tests/ConsulManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
limitations under the License.
*/

use DCarbone\PHPConsulAPI\Config;

/**
* Class ConsulManager
*/
Expand Down Expand Up @@ -67,4 +69,14 @@ public static function stopSingle(): void
\sleep(1);
}
}

/**
* @return \DCarbone\PHPConsulAPI\Config
*/
public static function testConfig(): Config{
$conf = new Config();
$conf->Address = '127.0.0.1:8500';
$conf->Scheme = 'http';
return $conf;
}
}
5 changes: 2 additions & 3 deletions tests/Usage/ACL/ACLClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

use DCarbone\PHPConsulAPI\ACL\ACLClient;
use DCarbone\PHPConsulAPI\Config;
use DCarbone\PHPConsulAPI\QueryMeta;
use DCarbone\PHPConsulAPI\WriteMeta;
use DCarbone\PHPConsulAPITests\ConsulManager;
Expand All @@ -41,7 +40,7 @@ public function testCanBootstrapACL()
{
ConsulManager::startSingleDev('-bind="127.0.0.1"');

$client = new ACLClient(new Config());
$client = new ACLClient(ConsulManager::testConfig());

[$aclID, $wm, $err] = $client->Bootstrap();
static::assertNull($err, 'ACL::bootstrap() returned error: ' . $err);
Expand All @@ -57,7 +56,7 @@ public function testCanBootstrapACL()
*/
public function testCanGetBootstrappedACL(string $aclID): void
{
$client = new ACLClient(new Config());
$client = new ACLClient(ConsulManager::testConfig());

[$acls, $qm, $err] = $client->Info($aclID);
static::assertNull($err, 'ACL::info() return error: ' . $err);
Expand Down
22 changes: 11 additions & 11 deletions tests/Usage/Agent/AgentClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use DCarbone\PHPConsulAPI\Agent\AgentService;
use DCarbone\PHPConsulAPI\Agent\AgentServiceCheck;
use DCarbone\PHPConsulAPI\Agent\AgentServiceRegistration;
use DCarbone\PHPConsulAPI\Config;
use DCarbone\PHPConsulAPITests\ConsulManager;
use DCarbone\PHPConsulAPITests\Usage\AbstractUsageTests;
use PHPUnit\Framework\AssertionFailedError;

Expand All @@ -39,7 +39,7 @@ final class AgentClientTest extends AbstractUsageTests

public function testCanConstructAgentClient(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());
static::assertInstanceOf(AgentClient::class, $client);
}

Expand All @@ -48,7 +48,7 @@ public function testCanConstructAgentClient(): void
*/
public function testCanGetSelf(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());

[$self, $err] = $client->Self();
static::assertNull($err);
Expand All @@ -66,7 +66,7 @@ public function testCanGetSelf(): void
*/
public function testCanReloadSelf(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());
$err = $client->Reload();
static::assertNull($err, \sprintf('AgentClient::reload returned error: %s', $err));
}
Expand All @@ -76,7 +76,7 @@ public function testCanReloadSelf(): void
*/
public function testCanGetNodeName(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());

[$nodeName, $err] = $client->NodeName();
static::assertNull($err, \sprintf('Unable to get agent node name: %s', $err));
Expand All @@ -92,7 +92,7 @@ public function testCanGetNodeName(): void
*/
public function testCanGeMembers(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());

[$members, $err] = $client->Members();
static::assertNull($err, \sprintf('AgentClient::members returned error: %s', $err));
Expand All @@ -106,7 +106,7 @@ public function testCanGeMembers(): void
*/
public function testCanRegisterServiceNoChecks(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());

$svc = new AgentServiceRegistration();
$svc
Expand All @@ -123,7 +123,7 @@ public function testCanRegisterServiceNoChecks(): void
*/
public function testCanRegisterServiceWithOneCheck(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());

$svc = new AgentServiceRegistration();
$svc
Expand All @@ -145,7 +145,7 @@ public function testCanRegisterServiceWithOneCheck(): void
*/
public function testCanGetServiceList(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());

[$svcs, $err] = $client->Services();

Expand All @@ -170,7 +170,7 @@ public function testCanGetServiceList(): void
*/
public function testCanDeregisterService(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());

$err = $client->ServiceDeregister(self::Service1Name);
static::assertNull($err, \sprintf('AgentClient::serviceDeregister returned error: %s', $err));
Expand All @@ -196,7 +196,7 @@ public function testCanDeregisterService(): void
*/
public function testCanRegisterServiceWithCheck(): void
{
$client = new AgentClient(new Config());
$client = new AgentClient(ConsulManager::testConfig());

$svc = new AgentServiceRegistration();
$svc
Expand Down
22 changes: 11 additions & 11 deletions tests/Usage/Catalog/CatalogClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
use DCarbone\PHPConsulAPI\Catalog\CatalogRegistration;
use DCarbone\PHPConsulAPI\Catalog\CatalogService;
use DCarbone\PHPConsulAPI\Catalog\Node;
use DCarbone\PHPConsulAPI\Config;
use DCarbone\PHPConsulAPI\QueryMeta;
use DCarbone\PHPConsulAPI\WriteMeta;
use DCarbone\PHPConsulAPITests\ConsulManager;
use DCarbone\PHPConsulAPITests\Usage\AbstractUsageTests;
use PHPUnit\Framework\AssertionFailedError;

Expand All @@ -48,7 +48,7 @@ final class CatalogClientTest extends AbstractUsageTests

public function testCanConstructClient(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());
static::assertInstanceOf(CatalogClient::class, $client);
}

Expand All @@ -57,7 +57,7 @@ public function testCanConstructClient(): void
*/
public function testCanRegisterService(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

$registration = new CatalogRegistration([
'Node' => 'dc1',
Expand All @@ -80,7 +80,7 @@ public function testCanRegisterService(): void
*/
public function testCanGetService(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

[$service, $qm, $err] = $client->Service(self::ServiceName);
static::assertNull($err, 'CatalogClient::service returned error: ' . $err);
Expand All @@ -95,7 +95,7 @@ public function testCanGetService(): void
*/
public function testCanRegisterSecondServiceWithSameName(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

[$wm, $err] = $client->Register(new CatalogRegistration([
'Node' => 'dc1',
Expand All @@ -117,7 +117,7 @@ public function testCanRegisterSecondServiceWithSameName(): void
*/
public function testCanGetListOfService(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

[$service, $qm, $err] = $client->Service(self::ServiceName);
static::assertNull($err, 'CatalogClient::service returned error: ' . $err);
Expand All @@ -140,7 +140,7 @@ public function testCanGetListOfService(): void
*/
public function testCanGetListOfServices(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

[$services, $qm, $err] = $client->Services();

Expand All @@ -161,7 +161,7 @@ public function testCanGetListOfServices(): void
*/
public function testCanDeregisterService(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

[$wm, $err] = $client->Deregister(new CatalogDeregistration([
'Node' => 'dc1',
Expand All @@ -184,7 +184,7 @@ public function testCanDeregisterService(): void
*/
public function testCanGetDatacenters(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

[$dcs, $err] = $client->Datacenters();

Expand All @@ -204,7 +204,7 @@ public function testCanGetDatacenters(): void
*/
public function testCanGetListOfNodes(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

[$nodes, $qm, $err] = $client->Nodes();
try {
Expand All @@ -225,7 +225,7 @@ public function testCanGetListOfNodes(): void
*/
public function testCanGetNode(): void
{
$client = new CatalogClient(new Config());
$client = new CatalogClient(ConsulManager::testConfig());

[$nodes] = $client->Nodes();
try {
Expand Down
16 changes: 6 additions & 10 deletions tests/Usage/ConfigUsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ final class ConfigUsageTest extends TestCase
public const DEFAULT_ADDRESS = '127.0.0.1:8500';
public const DEFAULT_SCHEME = 'http';

/**
* @return \DCarbone\PHPConsulAPITests\Usage\Config
*/
public function testCanConstructConfig()
public function testCanConstructConfig(): void
{
$config = new Config();
static::assertInstanceOf(Config::class, $config);
return $config;
self::assertInstanceOf(Config::class, $config);
}

/**
Expand All @@ -51,18 +47,18 @@ public function testConfigDefaults(): void
$expectedAddress = $_ENV[Consul::HTTPAddrEnvName] ?: self::DEFAULT_ADDRESS;
$expectedScheme = $_ENV[Consul::HTTPSSLEnvName] ? 'https' : self::DEFAULT_SCHEME;

static::assertSame(
self::assertSame(
$expectedAddress,
$config->getAddress(),
\sprintf('Default address is not "%s"', $expectedAddress)
);
static::assertSame(
self::assertSame(
$expectedScheme,
$config->getScheme(),
\sprintf('Default scheme is not "%s"', $expectedScheme)
);
static::assertNotNull($config->getHttpClient(), 'HttpClient is null');
static::assertFalse($config->isInsecureSkipVerify(), 'InsecureSkipVerify is not false');
self::assertNotNull($config->getHttpClient(), 'HttpClient is null');
self::assertFalse($config->isInsecureSkipVerify(), 'InsecureSkipVerify is not false');
}

protected function setUp(): void
Expand Down
8 changes: 4 additions & 4 deletions tests/Usage/Coordinate/CoordinateClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
limitations under the License.
*/

use DCarbone\PHPConsulAPI\Config;
use DCarbone\PHPConsulAPI\Coordinate\CoordinateClient;
use DCarbone\PHPConsulAPI\QueryMeta;
use DCarbone\PHPConsulAPITests\ConsulManager;
use DCarbone\PHPConsulAPITests\Usage\AbstractUsageTests;

/**
Expand All @@ -33,7 +33,7 @@ final class CoordinateClientTest extends AbstractUsageTests

public function testCanConstructClient(): void
{
$client = new CoordinateClient(new Config());
$client = new CoordinateClient(ConsulManager::testConfig());
static::assertInstanceOf(CoordinateClient::class, $client);
}

Expand All @@ -42,7 +42,7 @@ public function testCanConstructClient(): void
*/
public function testDatacenters(): void
{
$client = new CoordinateClient(new Config());
$client = new CoordinateClient(ConsulManager::testConfig());

[$dcs, $err] = $client->Datacenters();
static::assertNull($err, \sprintf('CoordinateClient::datacenters() - %s', $err));
Expand All @@ -55,7 +55,7 @@ public function testDatacenters(): void
*/
public function testNodes(): void
{
$client = new CoordinateClient(new Config());
$client = new CoordinateClient(ConsulManager::testConfig());

[$nodes, $qm, $err] = $client->Nodes();
static::assertNull($err, \sprintf('CoordinateClient::nodes() - %s', $err));
Expand Down
4 changes: 2 additions & 2 deletions tests/Usage/Event/EventClientUsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
limitations under the License.
*/

use DCarbone\PHPConsulAPI\Config;
use DCarbone\PHPConsulAPI\Event\EventClient;
use DCarbone\PHPConsulAPITests\ConsulManager;
use DCarbone\PHPConsulAPITests\Usage\AbstractUsageTests;

/**
Expand All @@ -32,7 +32,7 @@ final class EventClientUsageTest extends AbstractUsageTests

public function testCanConstructClient(): void
{
$client = new EventClient(new Config());
$client = new EventClient(ConsulManager::testConfig());
static::assertInstanceOf(EventClient::class, $client);
}
}
Loading

0 comments on commit 2a6af3e

Please sign in to comment.