Skip to content

Commit

Permalink
Merge pull request #5 from horstoeko/seal
Browse files Browse the repository at this point in the history
Sealed class OrderDocument
  • Loading branch information
horstoeko authored Oct 22, 2024
2 parents 07bdd70 + f5335cf commit bdd2533
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 12 deletions.
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

0 comments on commit bdd2533

Please sign in to comment.