Skip to content

Commit

Permalink
Merge pull request #381 from mimmi20/updates
Browse files Browse the repository at this point in the history
add device properties
  • Loading branch information
mimmi20 authored Jan 5, 2025
2 parents 6fb9287 + b37f259 commit 0900c47
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 32 deletions.
20 changes: 19 additions & 1 deletion src/Device/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct(
private CompanyInterface $brand,
private TypeInterface $type,
private DisplayInterface $display,
private readonly bool | null $dualOrientation,
private readonly int | null $simCount,
) {
// nothing to do
}
Expand Down Expand Up @@ -88,8 +90,22 @@ public function getType(): TypeInterface
return $this->type;
}

/** @throws void */
#[Override]
public function getDualOrientation(): bool | null
{
return $this->dualOrientation;
}

/** @throws void */
#[Override]
public function getSimCount(): int | null
{
return $this->simCount;
}

/**
* @return array{deviceName: string|null, marketingName: string|null, manufacturer: string, brand: string, type: string, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}}
* @return array{deviceName: string|null, marketingName: string|null, manufacturer: string, brand: string, type: string, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}, dualOrientation: bool|null, simCount: int|null}
*
* @throws void
*/
Expand All @@ -103,6 +119,8 @@ public function toArray(): array
'brand' => $this->brand->getType(),
'display' => $this->display->toArray(),
'type' => $this->type->getType(),
'dualOrientation' => $this->dualOrientation,
'simCount' => $this->simCount,
];
}
}
8 changes: 7 additions & 1 deletion src/Device/DeviceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ public function getDisplay(): DisplayInterface | null;
/** @throws void */
public function getType(): TypeInterface;

/** @throws void */
public function getDualOrientation(): bool | null;

/** @throws void */
public function getSimCount(): int | null;

/**
* @return array{deviceName: string|null, marketingName: string|null, manufacturer: string, brand: string, type: string, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}}
* @return array{deviceName: string|null, marketingName: string|null, manufacturer: string, brand: string, type: string, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}, dualOrientation: bool|null, simCount: int|null}
*
* @throws void
*/
Expand Down
101 changes: 71 additions & 30 deletions tests/Device/DeviceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,62 @@ final class DeviceTest extends TestCase
/** @throws Exception */
public function testSetterGetter(): void
{
$deviceName = 'TestDevicename';
$marketingName = 'TestMarketingname';
$manufacturer = $this->createMock(CompanyInterface::class);
$brand = $this->createMock(CompanyInterface::class);
$type = $this->createMock(TypeInterface::class);
$display = $this->createMock(DisplayInterface::class);
$deviceName = 'TestDevicename';
$marketingName = 'TestMarketingname';
$manufacturer = $this->createMock(CompanyInterface::class);
$brand = $this->createMock(CompanyInterface::class);
$type = $this->createMock(TypeInterface::class);
$display = $this->createMock(DisplayInterface::class);
$dualOrientation = true;
$simCount = 2;

assert($manufacturer instanceof CompanyInterface);
assert($brand instanceof CompanyInterface);
assert($type instanceof TypeInterface);
assert($display instanceof DisplayInterface);
$object = new Device($deviceName, $marketingName, $manufacturer, $brand, $type, $display);
$object = new Device(
$deviceName,
$marketingName,
$manufacturer,
$brand,
$type,
$display,
$dualOrientation,
$simCount,
);

self::assertSame($deviceName, $object->getDeviceName());
self::assertSame($marketingName, $object->getMarketingName());
self::assertSame($manufacturer, $object->getManufacturer());
self::assertSame($brand, $object->getBrand());
self::assertSame($type, $object->getType());
self::assertSame($display, $object->getDisplay());
self::assertTrue($object->getDualOrientation());
self::assertSame($simCount, $object->getSimCount());
}

/** @throws Exception */
public function testToarray(): void
{
$deviceName = 'TestDevicename';
$marketingName = 'TestMarketingname';
$typeString = 'xyz';
$manuString = 'abc';
$brandString = 'def';

$manufacturer = $this->getMockBuilder(CompanyInterface::class)
->disableOriginalConstructor()
->getMock();
$deviceName = 'TestDevicename';
$marketingName = 'TestMarketingname';
$typeString = 'xyz';
$manuString = 'abc';
$brandString = 'def';
$dualOrientation = true;
$simCount = 2;

$manufacturer = $this->createMock(CompanyInterface::class);
$manufacturer->expects(self::once())
->method('getType')
->willReturn($manuString);

$brand = $this->getMockBuilder(CompanyInterface::class)
->disableOriginalConstructor()
->getMock();
$brand = $this->createMock(CompanyInterface::class);
$brand->expects(self::once())
->method('getType')
->willReturn($brandString);

$type = $this->getMockBuilder(TypeInterface::class)
->disableOriginalConstructor()
->getMock();
$type = $this->createMock(TypeInterface::class);
$type->expects(self::once())
->method('getType')
->willReturn($typeString);
Expand All @@ -84,7 +93,16 @@ public function testToarray(): void
assert($brand instanceof CompanyInterface);
assert($type instanceof TypeInterface);
assert($display instanceof DisplayInterface);
$original = new Device($deviceName, $marketingName, $manufacturer, $brand, $type, $display);
$original = new Device(
$deviceName,
$marketingName,
$manufacturer,
$brand,
$type,
$display,
$dualOrientation,
$simCount,
);

$array = $original->toArray();

Expand All @@ -103,29 +121,52 @@ public function testToarray(): void
self::assertSame($typeString, $array['type']);
self::assertArrayHasKey('display', $array);
self::assertIsArray($array['display']);
self::assertArrayHasKey('dualOrientation', $array);
self::assertArrayHasKey('simCount', $array);

self::assertSame($deviceName, $array['deviceName']);
self::assertSame($marketingName, $array['marketingName']);
self::assertTrue($array['dualOrientation']);
self::assertSame($simCount, $array['simCount']);
}

/** @throws Exception */
public function testClone(): void
{
$deviceName = 'TestDevicename';
$marketingName = 'TestMarketingname';
$manufacturer = $this->createMock(CompanyInterface::class);
$brand = $this->createMock(CompanyInterface::class);
$type = $this->createMock(TypeInterface::class);
$display = $this->createMock(DisplayInterface::class);
$deviceName = 'TestDevicename';
$marketingName = 'TestMarketingname';
$manufacturer = $this->createMock(CompanyInterface::class);
$brand = $this->createMock(CompanyInterface::class);
$type = $this->createMock(TypeInterface::class);
$display = $this->createMock(DisplayInterface::class);
$dualOrientation = true;
$simCount = 2;

assert($manufacturer instanceof CompanyInterface);
assert($brand instanceof CompanyInterface);
assert($type instanceof TypeInterface);
assert($display instanceof DisplayInterface);
$original = new Device($deviceName, $marketingName, $manufacturer, $brand, $type, $display);
$original = new Device(
$deviceName,
$marketingName,
$manufacturer,
$brand,
$type,
$display,
$dualOrientation,
$simCount,
);
$cloned = clone $original;

self::assertNotSame($original, $cloned);
self::assertNotSame($manufacturer, $cloned->getManufacturer());
self::assertNotSame($brand, $cloned->getBrand());
self::assertNotSame($type, $cloned->getType());
self::assertNotSame($display, $cloned->getDisplay());

self::assertSame($deviceName, $cloned->getDeviceName());
self::assertSame($marketingName, $cloned->getMarketingName());
self::assertTrue($cloned->getDualOrientation());
self::assertSame($simCount, $cloned->getSimCount());
}
}

0 comments on commit 0900c47

Please sign in to comment.