diff --git a/src/OrderDocument.php b/src/OrderDocument.php index 923cf45..c68aa0b 100644 --- a/src/OrderDocument.php +++ b/src/OrderDocument.php @@ -57,7 +57,7 @@ class OrderDocument /** * @internal - * @return \horstoeko\orderx\entities\basic\rsm\SCRDMCCBDACIOMessageStructure|\horstoeko\orderx\entities\comfort\rsm\SCRDMCCBDACIOMessageStructure|\horstoeko\orderx\entities\extended\rsm\SCRDMCCBDACIOMessageStructure + * @return \horstoeko\orderx\entities\basic\rsm\SCRDMCCBDACIOMessageStructure|\horstoeko\orderx\entities\comfort\rsm\SCRDMCCBDACIOMessageStructure|\horstoeko\orderx\entities\extended\rsm\SCRDMCCBDACIOMessageStructure */ private $orderObject = null; @@ -86,7 +86,7 @@ final protected function __construct(int $profile) * * @return \horstoeko\orderx\entities\basic\rsm\SCRDMCCBDACIOMessageStructure|\horstoeko\orderx\entities\comfort\rsm\SCRDMCCBDACIOMessageStructure|\horstoeko\orderx\entities\extended\rsm\SCRDMCCBDACIOMessageStructure */ - public function getOrderObject() + protected function getOrderObject() { return $this->orderObject; } @@ -108,7 +108,7 @@ protected function createOrderObject() * * @return SerializerInterface */ - public function getSerializer() + protected function getSerializer() { return $this->serializer; } @@ -118,7 +118,7 @@ public function getSerializer() * * @return OrderObjectHelper */ - public function getObjectHelper() + protected function getObjectHelper() { return $this->objectHelper; } diff --git a/src/OrderDocumentValidator.php b/src/OrderDocumentValidator.php index e8f80f8..2945597 100644 --- a/src/OrderDocumentValidator.php +++ b/src/OrderDocumentValidator.php @@ -57,7 +57,7 @@ public function __construct(OrderDocument $document) */ public function validateDocument(): ConstraintViolationListInterface { - return $this->validator->validate($this->document->getOrderObject(), null, ['xsd_rules']); + return $this->validator->validate($this->getDocumentOrderObject(), null, ['xsd_rules']); } /** @@ -103,4 +103,19 @@ private function globRecursive(string $pattern, int $flags = 0): array return $files; } + + /** + * Returns the internal invoice object from the document + * + * @return object + */ + private function getDocumentOrderObject() + { + $reflector = new \ReflectionClass($this->document); + + $method = $reflector->getMethod('getOrderObject'); + $method->setAccessible(true); + + return $method->invoke($this->document); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 266e7eb..64ffa48 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -190,6 +190,20 @@ public function getPrivateMethodFromObject(object $object, string $methodName): return $method; } + /** + * Access to private method and invoke it + * + * @param object $object + * @param string $methodName + * @param array $args + * @return mixed + */ + public function invokePivateMethodFromObject($object, string $methodName, ...$args) + { + $method = $this->getPrivateMethodFromObject($object, $methodName); + return $method->invoke($object, ...$args); + } + /** * Create a dummy DateTime instance * diff --git a/tests/testcases/OrderDocumentBuilderBasicTest.php b/tests/testcases/OrderDocumentBuilderBasicTest.php index da1e2cd..477fa0f 100644 --- a/tests/testcases/OrderDocumentBuilderBasicTest.php +++ b/tests/testcases/OrderDocumentBuilderBasicTest.php @@ -26,7 +26,8 @@ public function testDocumentProperties(): void { (self::$document)->initNewDocument(); - $this->assertNotNull(self::$document->getOrderObject()); + $this->assertNotNull($this->invokePivateMethodFromObject(self::$document, 'getOrderObject')); + $this->assertEquals('horstoeko\orderx\entities\basic\rsm\SCRDMCCBDACIOMessageStructure', get_class($this->invokePivateMethodFromObject(self::$document, 'getOrderObject'))); $property = $this->getPrivatePropertyFromObject(self::$document, 'headerTradeAgreement'); $this->assertNotNull($property->getValue(self::$document)); $property = $this->getPrivatePropertyFromObject(self::$document, 'headerTradeDelivery'); diff --git a/tests/testcases/OrderDocumentBuilderComfortTest.php b/tests/testcases/OrderDocumentBuilderComfortTest.php index 3fd9478..f72d63a 100644 --- a/tests/testcases/OrderDocumentBuilderComfortTest.php +++ b/tests/testcases/OrderDocumentBuilderComfortTest.php @@ -26,7 +26,8 @@ public function testDocumentProperties(): void { (self::$document)->initNewDocument(); - $this->assertNotNull(self::$document->getOrderObject()); + $this->assertNotNull($this->invokePivateMethodFromObject(self::$document, 'getOrderObject')); + $this->assertEquals('horstoeko\orderx\entities\comfort\rsm\SCRDMCCBDACIOMessageStructure', get_class($this->invokePivateMethodFromObject(self::$document, 'getOrderObject'))); $property = $this->getPrivatePropertyFromObject(self::$document, 'headerTradeAgreement'); $this->assertNotNull($property->getValue(self::$document)); $property = $this->getPrivatePropertyFromObject(self::$document, 'headerTradeDelivery'); diff --git a/tests/testcases/OrderDocumentBuilderExtendedTest.php b/tests/testcases/OrderDocumentBuilderExtendedTest.php index 18a342d..7479ef4 100644 --- a/tests/testcases/OrderDocumentBuilderExtendedTest.php +++ b/tests/testcases/OrderDocumentBuilderExtendedTest.php @@ -26,7 +26,8 @@ public function testDocumentProperties(): void { (self::$document)->initNewDocument(); - $this->assertNotNull(self::$document->getOrderObject()); + $this->assertNotNull($this->invokePivateMethodFromObject(self::$document, 'getOrderObject')); + $this->assertEquals('horstoeko\orderx\entities\extended\rsm\SCRDMCCBDACIOMessageStructure', get_class($this->invokePivateMethodFromObject(self::$document, 'getOrderObject'))); $property = $this->getPrivatePropertyFromObject(self::$document, 'headerTradeAgreement'); $this->assertNotNull($property->getValue(self::$document)); $property = $this->getPrivatePropertyFromObject(self::$document, 'headerTradeDelivery'); diff --git a/tests/testcases/OrderDocumentPdfReaderComfortTest.php b/tests/testcases/OrderDocumentPdfReaderComfortTest.php index 9b8bfca..d37e3fa 100644 --- a/tests/testcases/OrderDocumentPdfReaderComfortTest.php +++ b/tests/testcases/OrderDocumentPdfReaderComfortTest.php @@ -35,7 +35,8 @@ public function testPdfRead(): void public function testDocumentProperties(): void { - $this->assertNotNull(self::$document->getOrderObject()); + $this->assertNotNull($this->invokePivateMethodFromObject(self::$document, 'getOrderObject')); + $this->assertEquals('horstoeko\orderx\entities\comfort\rsm\SCRDMCCBDACIOMessageStructure', get_class($this->invokePivateMethodFromObject(self::$document, 'getOrderObject'))); } public function testDocumentProfile(): void diff --git a/tests/testcases/OrderDocumentPdfReaderExtendedTest.php b/tests/testcases/OrderDocumentPdfReaderExtendedTest.php index 8668c55..aaa09ee 100644 --- a/tests/testcases/OrderDocumentPdfReaderExtendedTest.php +++ b/tests/testcases/OrderDocumentPdfReaderExtendedTest.php @@ -35,7 +35,8 @@ public function testPdfRead(): void public function testDocumentProperties(): void { - $this->assertNotNull(self::$document->getOrderObject()); + $this->assertNotNull($this->invokePivateMethodFromObject(self::$document, 'getOrderObject')); + $this->assertEquals('horstoeko\orderx\entities\extended\rsm\SCRDMCCBDACIOMessageStructure', get_class($this->invokePivateMethodFromObject(self::$document, 'getOrderObject'))); } public function testDocumentProfile(): void diff --git a/tests/testcases/OrderDocumentReaderComfortTest.php b/tests/testcases/OrderDocumentReaderComfortTest.php index 3376c30..4376159 100644 --- a/tests/testcases/OrderDocumentReaderComfortTest.php +++ b/tests/testcases/OrderDocumentReaderComfortTest.php @@ -26,7 +26,8 @@ public static function setUpBeforeClass(): void public function testDocumentProperties(): void { - $this->assertNotNull(self::$document->getOrderObject()); + $this->assertNotNull($this->invokePivateMethodFromObject(self::$document, 'getOrderObject')); + $this->assertEquals('horstoeko\orderx\entities\comfort\rsm\SCRDMCCBDACIOMessageStructure', get_class($this->invokePivateMethodFromObject(self::$document, 'getOrderObject'))); } public function testDocumentProfile(): void diff --git a/tests/testcases/OrderDocumentReaderExtendedTest.php b/tests/testcases/OrderDocumentReaderExtendedTest.php index 32ab51c..c0cd1d2 100644 --- a/tests/testcases/OrderDocumentReaderExtendedTest.php +++ b/tests/testcases/OrderDocumentReaderExtendedTest.php @@ -26,7 +26,8 @@ public static function setUpBeforeClass(): void public function testDocumentProperties(): void { - $this->assertNotNull(self::$document->getOrderObject()); + $this->assertNotNull($this->invokePivateMethodFromObject(self::$document, 'getOrderObject')); + $this->assertEquals('horstoeko\orderx\entities\extended\rsm\SCRDMCCBDACIOMessageStructure', get_class($this->invokePivateMethodFromObject(self::$document, 'getOrderObject'))); } public function testDocumentProfile(): void