-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from kinimodmeyer/several-warehouses
Work in Progress - #13
- Loading branch information
Showing
5 changed files
with
171 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tradebyte\Stock\Model; | ||
|
||
class StockUpdate | ||
{ | ||
private ?string $articleNumber = null; | ||
|
||
private ?int $stock = null; | ||
|
||
private array $stockForWarehouses = []; | ||
|
||
public function getArticleNumber(): ?string | ||
{ | ||
return $this->articleNumber; | ||
} | ||
|
||
public function setArticleNumber(string $articleNumber): StockUpdate | ||
{ | ||
$this->articleNumber = $articleNumber; | ||
return $this; | ||
} | ||
|
||
public function getStock(): ?int | ||
{ | ||
return $this->stock; | ||
} | ||
|
||
public function setStock(int $stock): StockUpdate | ||
{ | ||
$this->stock = $stock; | ||
return $this; | ||
} | ||
|
||
public function getStockForWarehouses(): array | ||
{ | ||
return $this->stockForWarehouses; | ||
} | ||
|
||
public function addStockForWarehouse(string $warehouseKey, int $stock): StockUpdate | ||
{ | ||
$this->stockForWarehouses[] = [ | ||
'identifier' => 'key', | ||
'key' => $warehouseKey, | ||
'stock' => $stock, | ||
]; | ||
return $this; | ||
} | ||
|
||
public function getRawData(): array | ||
{ | ||
return [ | ||
'article_number' => $this->getArticleNumber(), | ||
'stock' => $this->getStock(), | ||
'stockForWarehouses' => $this->getStockForWarehouses(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tradebyte\Stock; | ||
|
||
use Tradebyte\Base; | ||
use Tradebyte\Client; | ||
use Tradebyte\Stock\Model\StockUpdate; | ||
|
||
class StockUpdateTest extends Base | ||
{ | ||
public function testUpdateStock(): void | ||
{ | ||
$expectedXML = '<TBCATALOG><ARTICLEDATA><ARTICLE><A_NR>1234</A_NR><A_STOCK>5</A_STOCK>' | ||
. '<A_STOCK identifier="key" key="test">6</A_STOCK>' | ||
. '<A_STOCK identifier="key" key="test2">7</A_STOCK></ARTICLE></ARTICLEDATA></TBCATALOG>'; | ||
$mockRestClient = $this->getMockBuilder(Client\Rest::class) | ||
->disableOriginalConstructor() | ||
->onlyMethods(['postXML']) | ||
->getMock(); | ||
$mockRestClient->expects($this->once()) | ||
->method('postXML') | ||
->with('articles/stock', $expectedXML); | ||
$mockClient = $this->getMockBuilder(Client::class) | ||
->disableOriginalConstructor() | ||
->onlyMethods(['getRestClient']) | ||
->getMock(); | ||
$mockClient->expects($this->any()) | ||
->method('getRestClient') | ||
->willReturn($mockRestClient); | ||
$stockHandler = $mockClient->getStockHandler(); | ||
$stockHandler->updateStock( | ||
[ | ||
(new StockUpdate()) | ||
->setArticleNumber('1234') | ||
->setStock(5) | ||
->addStockForWarehouse('test', 6) | ||
->addStockForWarehouse('test2', 7) | ||
] | ||
); | ||
} | ||
|
||
public function testStockObjectGetRawData(): void | ||
{ | ||
$stock = new StockUpdate(); | ||
$stock->setStock(20); | ||
$stock->addStockForWarehouse('warehouse', 20); | ||
$stock->addStockForWarehouse('warehouse2', 40); | ||
$stock->setArticleNumber('123456'); | ||
$this->assertSame([ | ||
'article_number' => '123456', | ||
'stock' => 20, | ||
'stockForWarehouses' => [ | ||
0 => [ | ||
'identifier' => 'key', | ||
'key' => 'warehouse', | ||
'stock' => 20 | ||
], | ||
1 => [ | ||
|
||
'identifier' => 'key', | ||
'key' => 'warehouse2', | ||
'stock' => 40 | ||
] | ||
] | ||
], $stock->getRawData()); | ||
} | ||
} |