Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 88 additions & 16 deletions src/GraphQL/Models/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,43 +57,115 @@ public function setIsbn(?string $isbn): void
$this->setData('isbn', $isbn);
}

public function getWidth(): ?float
public function getWidthMm(): ?float
{
return $this->getData('width');
return $this->getData('widthMm');
}

public function setWidth(?float $width): void
public function setWidthMm(?float $widthMm, bool $convert = false): void
{
$this->setData('width', $width);
$this->setData('widthMm', $widthMm);

if ($convert) {
$this->setData('widthIn', $widthMm ? round($widthMm / 25.4, 2) : null);
}
}

public function getWidthIn(): ?float
{
return $this->getData('widthIn');
}

public function setWidthIn(?float $widthIn, bool $convert = false): void
{
$this->setData('widthIn', $widthIn);

if ($convert) {
$this->setData('widthMm', $widthIn ? round($widthIn * 25.4, 2) : null);
}
}

public function getHeightMm(): ?float
{
return $this->getData('heightMm');
}

public function setHeightMm(?float $heightMm, bool $convert = false): void
{
$this->setData('heightMm', $heightMm);

if ($convert) {
$this->setData('heightIn', $heightMm ? round($heightMm / 25.4, 2) : null);
}
}

public function getHeightIn(): ?float
{
return $this->getData('heightIn');
}

public function setHeightIn(?float $heightIn, bool $convert = false): void
{
$this->setData('heightIn', $heightIn);

if ($convert) {
$this->setData('heightMm', $heightIn ? round($heightIn * 25.4, 2) : null);
}
}

public function getDepthMm(): ?float
{
return $this->getData('depthMm');
}

public function setDepthMm(?float $depthMm, bool $convert = false): void
{
$this->setData('depthMm', $depthMm);

if ($convert) {
$this->setData('depthIn', $depthMm ? round($depthMm / 25.4, 2) : null);
}
}

public function getHeight(): ?float
public function getDepthIn(): ?float
{
return $this->getData('height');
return $this->getData('depthIn');
}

public function setHeight(?float $height): void
public function setDepthIn(?float $depthIn, bool $convert = false): void
{
$this->setData('height', $height);
$this->setData('depthIn', $depthIn);

if ($convert) {
$this->setData('depthMm', $depthIn ? round($depthIn * 25.4, 2) : null);
}
}

public function getDepth(): ?float
public function getWeightG(): ?float
{
return $this->getData('depth');
return $this->getData('weightG');
}

public function setDepth(?float $depth): void
public function setWeightG(?float $weightG, bool $convert = false): void
{
$this->setData('depth', $depth);
$this->setData('weightG', $weightG);

if ($convert) {
$this->setData('weightOz', $weightG ? round($weightG / 28.349523125, 4) : null);
}
}

public function getWeight(): ?float
public function getWeightOz(): ?float
{
return $this->getData('weight');
return $this->getData('weightOz');
}

public function setWeight(?float $weight): void
public function setWeightOz(?float $weightOz, bool $convert = false): void
{
$this->setData('weight', $weight);
$this->setData('weightOz', $weightOz);

if ($convert) {
$this->setData('weightG', $weightOz ? round($weightOz * 28.349523125, 4) : null);
}
}
}
38 changes: 26 additions & 12 deletions tests/GraphQL/Models/PublicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,42 @@ public function testGettersAndSetters(): void
$workId = 'ad904728-2f96-4cbb-973f-70b4414cf27e';
$publicationType = Publication::PUBLICATION_TYPE_PAPERBACK;
$isbn = '987-6-54321-234-5';
$width = 156.0;
$height = 234.0;
$depth = 25.0;
$weight = 206.0;
$widthMm = 156.0;
$heightMm = 234.0;
$depthMm = 25.0;
$weightG = 206.0;

$publication = new Publication();
$publication->setPublicationId($publicationId);
$publication->setWorkId($workId);
$publication->setPublicationType($publicationType);
$publication->setIsbn($isbn);
$publication->setWidth($width);
$publication->setHeight($height);
$publication->setDepth($depth);
$publication->setWeight($weight);
$publication->setWidthMm($widthMm);
$publication->setHeightMm($heightMm);
$publication->setDepthMm($depthMm);
$publication->setWeightG($weightG);

$this->assertSame($publicationId, $publication->getPublicationId());
$this->assertSame($workId, $publication->getWorkId());
$this->assertSame($publicationType, $publication->getPublicationType());
$this->assertSame($isbn, $publication->getIsbn());
$this->assertSame($width, $publication->getWidth());
$this->assertSame($height, $publication->getHeight());
$this->assertSame($depth, $publication->getDepth());
$this->assertSame($weight, $publication->getWeight());
$this->assertSame($widthMm, $publication->getWidthMm());
$this->assertSame($heightMm, $publication->getHeightMm());
$this->assertSame($depthMm, $publication->getDepthMm());
$this->assertSame($weightG, $publication->getWeightG());
}

public function testGettersAndSettersWithConvention(): void
{
$publication = new Publication();
$publication->setWidthMm(156, true);
$publication->setHeightMm(234, true);
$publication->setDepthMm(5, true);
$publication->setWeightG(206, true);

$this->assertSame(6.14, $publication->getWidthIn());
$this->assertSame(9.21, $publication->getHeightIn());
$this->assertSame(0.2, $publication->getDepthIn());
$this->assertSame(7.2664, $publication->getWeightOz());
}
}