Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sealed class OrderDocument #5

Merged
merged 1 commit into from
Oct 22, 2024
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
8 changes: 4 additions & 4 deletions src/OrderDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -108,7 +108,7 @@ protected function createOrderObject()
*
* @return SerializerInterface
*/
public function getSerializer()
protected function getSerializer()
{
return $this->serializer;
}
Expand All @@ -118,7 +118,7 @@ public function getSerializer()
*
* @return OrderObjectHelper
*/
public function getObjectHelper()
protected function getObjectHelper()
{
return $this->objectHelper;
}
Expand Down
17 changes: 16 additions & 1 deletion src/OrderDocumentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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);
}
}
14 changes: 14 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
3 changes: 2 additions & 1 deletion tests/testcases/OrderDocumentBuilderBasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion tests/testcases/OrderDocumentBuilderComfortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion tests/testcases/OrderDocumentBuilderExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion tests/testcases/OrderDocumentPdfReaderComfortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/testcases/OrderDocumentPdfReaderExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/testcases/OrderDocumentReaderComfortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/testcases/OrderDocumentReaderExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down