PHP code example of webgriffe / esb
1. Go to this page and download the library: Download webgriffe/esb library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webgriffe / esb example snippets
public function testShouldProduceMultipleJobsWithMultipleEntriesFile()
{
filesystem(new BlockingDriver());
vfsStream::setup();
$this->importFile = vfsStream::url('root/stock.xml');
$this->producer = new Stock($this->importFile);
copy(__DIR__ . '/StockTestFixtures/multiple_entries.xml', $this->importFile);
$this->jobs = [];
Loop::run(
function () use ($data) {
$iterator = $this->producer->produce($data);
while (yield $iterator->advance()) {
$this->jobs[] = $iterator->getCurrent();
}
}
);
$this->assertCount(52, $this->jobs);
$this->assertEquals(new Job(['sku' => 'SKU-1', 'qty' => 9519.000]), $this->jobs[0]);
$this->assertEquals(new Job(['sku' => 'SKU-23', 'qty' => 299.000]), $this->jobs[12]);
$this->assertEquals(new Job(['sku' => 'SKU-50', 'qty' => 2017.000]), $this->jobs[21]);
}
public function testWorksSimpleJob()
{
$this->sessionId = random_int(1, 1000);
$this->client = $this->prophesize(Client::class);
$this->clientFactory = $this->prophesize(Factory::class);
$this->clientFactory->create()->willReturn(new Success($this->client->reveal()));
$this->worker = new Stock($this->clientFactory->reveal());
$sku = 'SKU-1';
$qty = 10;
$this->client
->login()
->shouldBeCalled()
->willReturn(new Success($this->sessionId))
;
$this->client
->call('cataloginventory_stock_item.update', [$sku, ['qty' => $qty, 'is_in_stock' => true]])
->shouldBeCalled()
->willReturn(new Success(true))
;
$this->client->endSession()->shouldBeCalled()->willReturn(new Success());
$job = new QueuedJob(1, ['sku' => $sku, 'qty' => $qty]);
Loop::run(function () use ($job) {
yield $this->worker->init();
yield $this->worker->work($job);
});
}
bash
docker-compose run php composer tests
bash
docker-compose run php vendor/bin/phpunit