Skip to content

Commit

Permalink
✨ Finished adding collection attributes to carrier.
Browse files Browse the repository at this point in the history
  • Loading branch information
NickVries committed Feb 16, 2024
1 parent ef1218d commit f4e1295
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Resources/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,17 @@ public function getVoidsRegisteredCollections(): bool
return $this->attributes[self::ATTRIBUTE_VOIDS_REGISTERED_COLLECTIONS];
}

public function setAllowsAddingRegisteredShipmentsToCollection(bool $allowsAddingRegisteredShipments,
public function setAllowsAddingRegisteredShipmentsToCollection(
bool $allowsAddingRegisteredShipments
): self {
$this->attributes[self::ATTRIBUTE_VOIDS_REGISTERED_COLLECTIONS] = $allowsAddingRegisteredShipments;
$this->attributes[self::ATTRIBUTE_ALLOWS_ADDING_REGISTERED_SHIPMENTS_TO_COLLECTION] = $allowsAddingRegisteredShipments;

return $this;
}

public function getAllowsAddingRegisteredShipmentsToCollection(): bool
{
return $this->attributes[self::ATTRIBUTE_VOIDS_REGISTERED_COLLECTIONS];
return $this->attributes[self::ATTRIBUTE_ALLOWS_ADDING_REGISTERED_SHIPMENTS_TO_COLLECTION];
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Resources/ResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function __construct()
$fileFactory = [$this, 'fileFactory'];
$shipmentItemFactory = [$this, 'shipmentItemFactory'];
$customsFactory = [$this, 'customsFactory'];
$carrierFactory = [$this, 'carrierFactory'];

$this->setFactoryForType(ResourceInterface::TYPE_SHIPMENT, $shipmentFactory);
$this->setFactoryForType(ShipmentInterface::class, $shipmentFactory);
Expand All @@ -137,6 +138,8 @@ public function __construct()
$this->setFactoryForType(ShipmentItemInterface::class, $shipmentItemFactory);

$this->setFactoryForType(CustomsInterface::class, $customsFactory);

$this->setFactoryForType(ResourceInterface::TYPE_CARRIER, $carrierFactory);
}

/**
Expand Down Expand Up @@ -365,6 +368,21 @@ protected function customsFactory(array &$attributes): Customs
return $customs;
}

protected function carrierFactory(array &$attributes): Carrier
{
$carrier = new Carrier();

if (isset($attributes['attributes']['collections'])) {
$carrier->setOffersCollections($attributes['attributes']['collections']['offers_collections']);
$carrier->setVoidsRegisteredCollections($attributes['attributes']['collections']['voids_registered_collections']);
$carrier->setAllowsAddingRegisteredShipmentsToCollection($attributes['attributes']['collections']['allows_adding_registered_shipments_to_collection']);

unset($attributes['attributes']['collections']);
}

return $carrier;
}

public function create(string $type, array $properties = []): ResourceInterface|JsonSerializable
{
$resource = $this->createResource($type, $properties);
Expand Down
18 changes: 18 additions & 0 deletions tests/Feature/Proxy/CarrierProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public function testAccessors()
{
$this->assertEquals('Carrier Name', $this->carrierProxy->setName('Carrier Name')->getName());
$this->assertEquals('an-id-for-a-carrier', $this->carrierProxy->setId('an-id-for-a-carrier')->getId());
$this->assertFalse(
$this->carrierProxy
->setOffersCollections(false)
->getOffersCollections()
);
$this->assertFalse(
$this->carrierProxy
->setAllowsAddingRegisteredShipmentsToCollection(false)
->getAllowsAddingRegisteredShipmentsToCollection()
);
$this->assertTrue(
$this->carrierProxy
->setVoidsRegisteredCollections(true)
->getVoidsRegisteredCollections()
);
}

/** @test */
Expand All @@ -54,6 +69,9 @@ public function testAttributes()
$this->assertEquals('eef00b32-177e-43d3-9b26-715365e4ce46', $this->carrierProxy->getId());
$this->assertEquals(ResourceInterface::TYPE_CARRIER, $this->carrierProxy->getType());
$this->assertEquals('Test Carrier', $this->carrierProxy->getName());
$this->assertTrue($this->carrierProxy->getOffersCollections());
$this->assertTrue($this->carrierProxy->getVoidsRegisteredCollections());
$this->assertFalse($this->carrierProxy->getAllowsAddingRegisteredShipmentsToCollection());
}

/** @test */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
}
}
},
"collections": {
"offers_collections": true,
"voids_registered_collections": true,
"allows_adding_registered_shipments_to_collection": false
},
"label_mime_types": [
"application/pdf"
]
Expand Down

0 comments on commit f4e1295

Please sign in to comment.