Skip to content

Commit

Permalink
feat: add cadomaestro package
Browse files Browse the repository at this point in the history
  • Loading branch information
rem42 committed Jun 5, 2024
1 parent 39bf129 commit e1f4f97
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Entity/CadoMaestro/PrestashopPackage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

namespace Scraper\ScraperPrestashop\Entity\CadoMaestro;

use Scraper\ScraperPrestashop\Entity\PrestashopItem;

class PrestashopPackage
{
public ?int $id = null;
public ?string $idPackageType = null;
/** @var array<int, PrestashopItem> */
public array $name = [];
/** @var array<int, PrestashopItem> */
public array $picto = [];
public ?string $default = null;
public ?string $actif = null;
public ?string $dateAdd = null;
public ?string $dateUpd = null;

public function addName(PrestashopItem $name): self
{
$this->name[] = $name;
return $this;
}

public function addPicto(PrestashopItem $picto): self
{
$this->picto[] = $picto;
return $this;
}
}
13 changes: 13 additions & 0 deletions src/Entity/CadoMaestro/PrestashopPackageType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace Scraper\ScraperPrestashop\Entity\CadoMaestro;

class PrestashopPackageType
{
public ?int $id = null;
public ?string $name = null;
public ?string $sentence = null;
public ?string $price = null;
public ?string $idProduct = null;
public ?string $actif = null;
}
15 changes: 15 additions & 0 deletions src/Entity/CadoMaestro/PrestashopPackageTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace Scraper\ScraperPrestashop\Entity\CadoMaestro;

class PrestashopPackageTypes
{
/** @var array<int, PrestashopPackageType> */
public array $packageTypes = [];

public function addPackageType(PrestashopPackageType $packageType): self
{
$this->packageTypes[] = $packageType;
return $this;
}
}
15 changes: 15 additions & 0 deletions src/Entity/CadoMaestro/PrestashopPackages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace Scraper\ScraperPrestashop\Entity\CadoMaestro;

class PrestashopPackages
{
/** @var array<int, PrestashopPackage> */
public array $packages = [];

public function addPackage(PrestashopPackage $package): self
{
$this->packages[] = $package;
return $this;
}
}
14 changes: 14 additions & 0 deletions src/Tools/ResourceMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Scraper\ScraperPrestashop\Tools;

use Scraper\ScraperPrestashop\Entity\CadoMaestro\PrestashopPackage;
use Scraper\ScraperPrestashop\Entity\CadoMaestro\PrestashopPackages;
use Scraper\ScraperPrestashop\Entity\CadoMaestro\PrestashopPackageType;
use Scraper\ScraperPrestashop\Entity\CadoMaestro\PrestashopPackageTypes;
use Scraper\ScraperPrestashop\Entity\PrestashopAddress;
use Scraper\ScraperPrestashop\Entity\PrestashopAddresses;
use Scraper\ScraperPrestashop\Entity\PrestashopCarrier;
Expand Down Expand Up @@ -430,6 +434,16 @@ class ResourceMapping
'rem42_webservices/orders/invoices' => [
'isFile' => true,
],
'package_types' => [
'list' => PrestashopPackageTypes::class,
'one' => PrestashopPackageType::class,
'singular' => 'package_type',
],
'packages' => [
'list' => PrestashopPackages::class,
'one' => PrestashopPackage::class,
'singular' => 'package',
],
];

public static function find(PrestashopRequest $prestashopRequest): string
Expand Down
44 changes: 44 additions & 0 deletions tests/Api/PrestashopPackageApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

namespace Scraper\ScraperPrestashop\Tests\Api;

use Scraper\ScraperPrestashop\Entity\CadoMaestro\PrestashopPackage;
use Scraper\ScraperPrestashop\Entity\CadoMaestro\PrestashopPackages;
use Scraper\ScraperPrestashop\Entity\PrestashopStockAvailable;
use Scraper\ScraperPrestashop\Entity\PrestashopStockAvailables;

/**
* @internal
*/
class PrestashopPackageApiTest extends AbstractPrestashopApiTestCase
{
public function testOne(): void
{
/** @var PrestashopStockAvailable $result */
$result = $this->executeGetApi(
'packages',
1,
200,
'package.json'
);

$this->assertInstanceOf(PrestashopPackage::class, $result);

$this->assertEquals(1, $result->id);
}

public function testList(): void
{
/** @var PrestashopStockAvailables $result */
$result = $this->executeGetApi(
'packages',
null,
200,
'packages.json'
);

$this->assertInstanceOf(PrestashopPackages::class, $result);
$this->assertCount(2, $result->packages);
$this->assertInstanceOf(PrestashopPackage::class, $result->packages[0]);
}
}
44 changes: 44 additions & 0 deletions tests/Api/PrestashopPackageTypeApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

namespace Scraper\ScraperPrestashop\Tests\Api;

use Scraper\ScraperPrestashop\Entity\CadoMaestro\PrestashopPackageType;
use Scraper\ScraperPrestashop\Entity\CadoMaestro\PrestashopPackageTypes;
use Scraper\ScraperPrestashop\Entity\PrestashopStockAvailable;
use Scraper\ScraperPrestashop\Entity\PrestashopStockAvailables;

/**
* @internal
*/
class PrestashopPackageTypeApiTest extends AbstractPrestashopApiTestCase
{
public function testOne(): void
{
/** @var PrestashopStockAvailable $result */
$result = $this->executeGetApi(
'package_types',
1,
200,
'package_type.json'
);

$this->assertInstanceOf(PrestashopPackageType::class, $result);

$this->assertEquals(1, $result->id);
}

public function testList(): void
{
/** @var PrestashopStockAvailables $result */
$result = $this->executeGetApi(
'package_types',
null,
200,
'package_types.json'
);

$this->assertInstanceOf(PrestashopPackageTypes::class, $result);
$this->assertCount(2, $result->packageTypes);
$this->assertInstanceOf(PrestashopPackageType::class, $result->packageTypes[0]);
}
}
30 changes: 30 additions & 0 deletions tests/fixtures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"package": {
"id": 1,
"id_package_type": "1",
"name": [
{
"id": "1",
"value": "Papier ananas jaune"
},
{
"id": "8",
"value": "Ananas - Ananas"
}
],
"picto": [
{
"id": "1",
"value": "/img/nq_packaging/pictos/package1-ananas.jpg"
},
{
"id": "8",
"value": "/img/nq_packaging/pictos/package1-Ananas.jpg"
}
],
"default": "0",
"actif": "1",
"date_add": "2019-11-13 14:52:10",
"date_upd": "2023-05-04 10:49:36"
}
}
10 changes: 10 additions & 0 deletions tests/fixtures/package_type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"package_type": {
"id": 1,
"name": "Papier cadeau",
"sentence": "Choisissez votre papier cadeau",
"price": "3.950000",
"id_product": "11587",
"actif": "0"
}
}
10 changes: 10 additions & 0 deletions tests/fixtures/package_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"package_types": [
{
"id": 1
},
{
"id": 2
}
]
}
10 changes: 10 additions & 0 deletions tests/fixtures/packages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"packages": [
{
"id": 1
},
{
"id": 2
}
]
}

0 comments on commit e1f4f97

Please sign in to comment.