Skip to content

Commit 34a7288

Browse files
authored
Merge pull request #9 from justbetter/feature/urlencode
URL encode to support slashes in strings
2 parents 42fbfec + ad173e4 commit 34a7288

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

src/Actions/UpdateSimpleStock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function update(MagentoStock $model): void
2828
],
2929
];
3030

31-
$response = $this->magento->put("products/$model->sku", $payload);
31+
$response = $this->magento->put('products/'.urlencode($model->sku), $payload);
3232

3333
try {
3434
$response->throw();

src/Data/StockData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public static function make(
3333

3434
array $data = [],
3535
): static {
36-
return new static($sku, $quantity, $inStock, $backorders, $msiQuantity, $msiStatus, $data);
36+
return new self($sku, $quantity, $inStock, $backorders, $msiQuantity, $msiStatus, $data);
3737
}
3838

3939
public static function fromModel(MagentoStock $stock): static
4040
{
41-
return new static(
41+
return new self(
4242
$stock->sku,
4343

4444
$stock->quantity,

tests/Actions/CompareSimpleStockTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function test_quantity_equals(int $magentoQty, int $localQty, bool $shoul
3535
});
3636

3737
Http::fake([
38-
'::magento::/rest/all/V1/products/::sku::' => Http::response([
38+
'http://magento.test/rest/all/V1/products/::sku::' => Http::response([
3939
'extension_attributes' => [
4040
'stock_item' => [
4141
'qty' => $magentoQty,

tests/Actions/UpdateMsiStockTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function test_it_updates_msi_stock(): void
8080

8181
Http::assertSentInOrder([
8282
function (Request $request) {
83-
return $request->url() == '::magento::/rest/all/V1/inventory/sources?searchCriteria%5BpageSize%5D=50&searchCriteria%5BcurrentPage%5D=1';
83+
return $request->url() == 'http://magento.test/rest/all/V1/inventory/sources?searchCriteria%5BpageSize%5D=50&searchCriteria%5BcurrentPage%5D=1';
8484
},
8585
function (Request $request) use ($expectedPayload) {
8686
return $request->data() == $expectedPayload;

tests/Actions/UpdateSimpleStockTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public function test_it_updates_simple_stock(): void
1818
{
1919
Event::fake();
2020
Http::fake([
21-
'rest/all/V1/products/::sku::' => Http::response(),
21+
'http://magento.test/rest/all/V1/products/%3A%3Ask%2Fu%3A%3A' => Http::response(),
2222
]);
2323

2424
$model = MagentoStock::query()
2525
->create([
26-
'sku' => '::sku::',
26+
'sku' => '::sk/u::',
2727
'quantity' => 10,
2828
'backorders' => false,
2929
'in_stock' => true,
@@ -55,7 +55,7 @@ public function test_it_updates_simple_stock(): void
5555
public function test_it_logs_error(): void
5656
{
5757
Http::fake([
58-
'rest/all/V1/products/::sku::' => Http::response('::error::', 500),
58+
'http://magento.test/rest/all/V1/products/%3A%3Asku%3A%3A' => Http::response('::error::', 500),
5959
]);
6060

6161
$this->expectException(UpdateException::class);

tests/TestCase.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace JustBetter\MagentoStock\Tests;
44

55
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
6+
use JustBetter\MagentoClient\Client\Magento;
67
use JustBetter\MagentoStock\Calculator\SimpleStockCalculator;
78
use JustBetter\MagentoStock\Retriever\DummySkuRetriever;
89
use JustBetter\MagentoStock\Retriever\DummyStockRetriever;
@@ -16,10 +17,7 @@ abstract class TestCase extends BaseTestCase
1617

1718
protected function defineEnvironment($app): void
1819
{
19-
config()->set('magento.base_url', '::magento::');
20-
config()->set('magento.access_token', '::token::');
21-
config()->set('magento.timeout', 30);
22-
config()->set('magento.connect_timeout', 30);
20+
Magento::fake();
2321

2422
config()->set('magento-stock.retriever.sku', DummySkuRetriever::class);
2523
config()->set('magento-stock.retriever.stock', DummyStockRetriever::class);

0 commit comments

Comments
 (0)