Skip to content

Commit

Permalink
Merge branch 'master' of github.com:osiset/Basic-Shopify-API
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikyt committed Jul 8, 2021
2 parents eeefa57 + 3043ef7 commit a626260
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
normalize: true
validate: true

name: PHP ${{ matrix.php-versions }}
name: PHP ${{ matrix.php }}

steps:
- name: Checkout
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php: ${{ matrix.php-versions }}
php: ${{ matrix.php }}
coverage: ${{ matrix.coverage }}
extensions: json, mbstring

Expand Down
82 changes: 44 additions & 38 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
{
"name": "osiset/basic-shopify-api",
"type": "library",
"description": "A basic Shopify API wrapper with REST and GraphQL support, powered by Guzzle.",
"keywords": [
"api",
"shopify",
"rest",
"graphql"
],
"license": "MIT",
"authors": [
{
"name": "Tyler King",
"email": "[email protected]"
"name": "osiset/basic-shopify-api",
"type": "library",
"description": "A basic Shopify API wrapper with REST and GraphQL support, powered by Guzzle.",
"keywords": [
"api",
"graphql",
"rest",
"shopify",
"wrapper"
],
"license": "MIT",
"authors": [
{
"name": "Tyler King",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.3.0",
"ext-json": "*",
"caseyamcl/guzzle_retry_middleware": "^2.3",
"guzzlehttp/guzzle": "^6.5 || ^7.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.8",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^6.2 || ^9.3"
},
"config": {
"sort-packages": true
},
"autoload": {
"psr-4": {
"Osiset\\BasicShopifyAPI\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Osiset\\BasicShopifyAPI\\Test\\": "test/"
}
},
"support": {
"issues": "https://github.com/osiset/basic-shopify-api/issues",
"source": "https://github.com/osiset/basic-shopify-api"
}
],
"require": {
"php": ">=7.2.0",
"caseyamcl/guzzle_retry_middleware": "^2.3",
"guzzlehttp/guzzle": "^6.5 || ^7.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.8",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^6.2 || ^9.3"
},
"autoload": {
"psr-4": {
"Osiset\\BasicShopifyAPI\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Osiset\\BasicShopifyAPI\\Test\\": "test/"
}
},
"scripts": {
"test": "bin/phpunit"
}
}
2 changes: 1 addition & 1 deletion src/Clients/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function extractLinkHeader(string $header): ResponseAccess

foreach (array_keys($links) as $type) {
preg_match(str_replace('{type}', $type, $regex), $header, $matches);
$links[$type] = isset($matches[1]) ? $matches[1] : null;
$links[$type] = $matches[1] ?? null;
}

return new ResponseAccess($links);
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/RateLimiting.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function handleGraph(BasicShopifyAPI $api): bool
// Get current, last request time, and time difference
$currentTime = $td->getCurrentTime();
$lastTime = $ts->get($api->getSession());
$lastTime = isset($lastTime[0]) ? $lastTime[0] : 0;
$lastTime = $lastTime[0] ?? 0;

// Get the last request cost
/** @var int $lastCost */
Expand Down
2 changes: 1 addition & 1 deletion src/ResponseAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,6 @@ public function getErrors()
return;
}

return isset($this->container['errors']) ? $this->container['errors'] : $this->container['error'];
return $this->container['errors'] ?? $this->container['error'];
}
}
2 changes: 1 addition & 1 deletion src/Store/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function get(Session $session): array
{
$shop = $session->getShop();

return isset($this->container[$shop]) ? $this->container[$shop] : [];
return $this->container[$shop] ?? [];
}

/**
Expand Down
10 changes: 5 additions & 5 deletions test/BasicShopifyAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function testSetClient(): void
$client = new Client();
$api->setClient($client);

$this->assertEquals($client, $api->getClient());
$this->assertEquals($client, $api->getGraphClient()->getClient());
$this->assertEquals($client, $api->getRestClient()->getClient());
$this->assertSame($client, $api->getClient());
$this->assertSame($client, $api->getGraphClient()->getClient());
$this->assertSame($client, $api->getRestClient()->getClient());
}

public function testSetAndGetOptions(): void
Expand All @@ -34,7 +34,7 @@ public function testSetAndGetOptions(): void
$opts->setType(false);
$api->setOptions($opts);

$this->assertEquals($opts, $api->getOptions());
$this->assertSame($opts, $api->getOptions());
}

public function testSetAndGetSession(): void
Expand All @@ -46,7 +46,7 @@ public function testSetAndGetSession(): void
$session = new Session('example.myshopify.com', 'abc123');
$api->setSession($session);

$this->assertEquals($session, $api->getSession());
$this->assertSame($session, $api->getSession());
}

public function testWithSession(): void
Expand Down
8 changes: 4 additions & 4 deletions test/Clients/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testExtractLinkHeader(): void
// Run the request
$result = $api->getRestClient()->request('GET', '/admin/shop.json');

$this->assertEquals($pageInfo, $result['link']['next']);
$this->assertSame($pageInfo, $result['link']['next']);
}

public function testRequestAccess(): void
Expand Down Expand Up @@ -138,7 +138,7 @@ public function testGetAuthUrlForOffline(): void
});
$api->setSession(new Session('example.myshopify.com'));

$this->assertEquals(
$this->assertSame(
'https://example.myshopify.com/admin/oauth/authorize?client_id=123&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalapp.local%2F',
$api->getAuthUrl(['read_products', 'write_products'], 'https://localapp.local/')
);
Expand All @@ -152,7 +152,7 @@ public function testGetAuthUrlForPerUser(): void
});
$api->setSession(new Session('example.myshopify.com'));

$this->assertEquals(
$this->assertSame(
'https://example.myshopify.com/admin/oauth/authorize?client_id=123&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalapp.local%2F&grant_options%5B%5D=per-user',
$api->getAuthUrl(['read_products', 'write_products'], 'https://localapp.local/', 'per-user')
);
Expand Down Expand Up @@ -196,7 +196,7 @@ public function testRequestSuccess(): void
$this->assertInstanceOf(ResponseAccess::class, $response['body']);
$this->assertSame('limit=1&page=1', $query);
$this->assertSame('!#@', $tokenHeader);
$this->assertEquals(true, $specialHeader);
$this->assertSame('1', $specialHeader);
}

public function testRequestForceRequestType(): void
Expand Down
8 changes: 4 additions & 4 deletions test/Middleware/AuthRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testRestVersioningOfApiPath(): void
$callMw = call_user_func(
$this->buildMw($opts),
function (RequestInterface $request, array $options): void {
$this->assertEquals(
$this->assertSame(
'/admin/api/2020-01/shop.json',
(string) $request->getUri()
);
Expand All @@ -40,7 +40,7 @@ public function testGraphVersioningOfApiPath(): void
$callMw = call_user_func(
$this->buildMw($opts),
function (RequestInterface $request, array $options): void {
$this->assertEquals(
$this->assertSame(
'/admin/api/2020-01/graphql.json',
(string) $request->getUri()
);
Expand All @@ -59,7 +59,7 @@ public function testRestNotVersioningApiPath(): void
$callMw = call_user_func(
$this->buildMw($opts),
function (RequestInterface $request, array $options): void {
$this->assertEquals(
$this->assertSame(
'/admin/api/2019-04/shop.json',
(string) $request->getUri()
);
Expand All @@ -78,7 +78,7 @@ public function testGraphNotVersioningApiPath(): void
$callMw = call_user_func(
$this->buildMw($opts),
function (RequestInterface $request, array $options): void {
$this->assertEquals(
$this->assertSame(
'/admin/api/2019-04/graphql.json',
(string) $request->getUri()
);
Expand Down
2 changes: 1 addition & 1 deletion test/Middleware/UpdateRequestTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testRuns(): void
$mw = new UpdateRequestTime($api);

// Ensure its empty
$this->assertEquals(
$this->assertSame(
[],
$api->getRestClient()->getTimeStore()->get($api->getSession())
);
Expand Down
10 changes: 5 additions & 5 deletions test/ResponseAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testIteratorAndCount(): void

$i = 0;
foreach ($resp['names'] as $r) {
$this->assertEquals($names[$i], $r);
$this->assertSame($names[$i], $r);
$i += 1;
}

Expand All @@ -78,8 +78,8 @@ public function testKeysAndValues(): void
'names' => $names,
]);

$this->assertEquals(['names'], $resp->keys());
$this->assertEquals(array_values($names), $resp->names->values());
$this->assertSame(['names'], $resp->keys());
$this->assertSame(array_values($names), $resp->names->values());
}

public function testJsonSerialize(): void
Expand All @@ -93,7 +93,7 @@ public function testJsonSerialize(): void
'names' => $names,
]);

$this->assertEquals(json_encode(['names' => $names]), json_encode($resp));
$this->assertSame(json_encode(['names' => $names]), json_encode($resp));
}

public function testToArray(): void
Expand All @@ -107,6 +107,6 @@ public function testToArray(): void
];
$resp = new ResponseAccess($names);

$this->assertEquals($names, $resp->toArray());
$this->assertSame($names, $resp->toArray());
}
}
8 changes: 4 additions & 4 deletions test/Store/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ public function test(): void
$session = new Session('example.myshopify.com');

// Test all
$this->assertEquals([], $mem->all());
$this->assertSame([], $mem->all());

// Test set and get
$mem->set(['b', 'a'], $session);
$this->assertEquals(
$this->assertSame(
['b', 'a'],
$mem->get($session)
);

// Test push
$mem->push('c', $session);
$this->assertEquals(
$this->assertSame(
['c', 'b', 'a'],
$mem->get($session)
);

// Test reset
$mem->reset($session);
$this->assertEquals([], $mem->get($session));
$this->assertSame([], $mem->get($session));
}
}

0 comments on commit a626260

Please sign in to comment.