From b37f259148b2f111b9f799e3ecf755d133dc0feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 5 Jan 2025 16:45:11 +0100 Subject: [PATCH] add device properties --- src/Device/Device.php | 20 ++++++- src/Device/DeviceInterface.php | 8 ++- tests/Device/DeviceTest.php | 101 +++++++++++++++++++++++---------- 3 files changed, 97 insertions(+), 32 deletions(-) diff --git a/src/Device/Device.php b/src/Device/Device.php index b389f1c..dfcf554 100644 --- a/src/Device/Device.php +++ b/src/Device/Device.php @@ -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 } @@ -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 */ @@ -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, ]; } } diff --git a/src/Device/DeviceInterface.php b/src/Device/DeviceInterface.php index 431d169..c579be9 100644 --- a/src/Device/DeviceInterface.php +++ b/src/Device/DeviceInterface.php @@ -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 */ diff --git a/tests/Device/DeviceTest.php b/tests/Device/DeviceTest.php index 90e898f..8002d6a 100644 --- a/tests/Device/DeviceTest.php +++ b/tests/Device/DeviceTest.php @@ -27,18 +27,29 @@ 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()); @@ -46,34 +57,32 @@ public function testSetterGetter(): void 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); @@ -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(); @@ -103,23 +121,41 @@ 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); @@ -127,5 +163,10 @@ public function testClone(): void 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()); } }