Skip to content

Commit

Permalink
Added moew unit tests for better test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Mar 28, 2024
1 parent 05f58ad commit a4acca4
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/ZugferdDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function getInvoiceObject()
* Create a new instance of the internal invoice object
*
* @return \horstoeko\zugferd\entities\basic\rsm\CrossIndustryInvoice|\horstoeko\zugferd\entities\basicwl\rsm\CrossIndustryInvoice|\horstoeko\zugferd\entities\en16931\rsm\CrossIndustryInvoice|\horstoeko\zugferd\entities\extended\rsm\CrossIndustryInvoice|\horstoeko\zugferd\entities\minimum\rsm\CrossIndustryInvoice
* @codeCoverageIgnore
*/
protected function createInvoiceObject()
{
Expand Down
41 changes: 41 additions & 0 deletions tests/testcases/BuilderEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ public function testDocumentProfile(): void
$this->assertNotEquals(ZugferdProfiles::PROFILE_EXTENDED, self::$document->getProfileId());
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getInvoiceObject
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getSerializer
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getObjectHelper
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getProfileDefinitionParameter
*/
public function testDocumentGetters(): void
{
$this->assertNotNull(self::$document->getInvoiceObject());
$this->assertNotNull(self::$document->getSerializer());
$this->assertNotNull(self::$document->getObjectHelper());
$this->assertEquals('en16931', self::$document->getProfileDefinitionParameter('name'));
$this->assertEquals('EN 16931 (COMFORT)', self::$document->getProfileDefinitionParameter('altname'));
$this->assertEquals('urn:cen.eu:en16931:2017', self::$document->getProfileDefinitionParameter('contextparameter'));
$this->assertEquals('factur-x.xml', self::$document->getProfileDefinitionParameter('attachmentfilename'));
$this->assertEquals('EN 16931', self::$document->getProfileDefinitionParameter('xmpname'));
$this->expectNoticeOrWarningExt(
function () {
self::$document->getProfileDefinitionParameter('unknownparameter');
}
);
}

public function testXmlGenerals(): void
{
$xml = $this->getXml();
Expand Down Expand Up @@ -2279,4 +2302,22 @@ public function testToString(): void
$this->assertIsString($xmlContent);
$this->assertStringStartsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rsm:CrossIndustryInvoice", $xmlContent);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getContentAsDomDocument
*/
public function testGetContentAsDomDocument(): void
{
$domDocument = self::$document->getContentAsDomDocument();
$this->assertInstanceOf(\DOMDocument::class, $domDocument);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getContentAsDomXPath
*/
public function testGetContentAsDomXPath(): void
{
$domXPath = self::$document->getContentAsDomXPath();
$this->assertInstanceOf(\DOMXpath::class, $domXPath);
}
}
41 changes: 41 additions & 0 deletions tests/testcases/BuilderExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ public function testDocumentProfile(): void
$this->assertEquals(ZugferdProfiles::PROFILE_EXTENDED, self::$document->getProfileId());
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getInvoiceObject
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getSerializer
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getObjectHelper
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getProfileDefinitionParameter
*/
public function testDocumentGetters(): void
{
$this->assertNotNull(self::$document->getInvoiceObject());
$this->assertNotNull(self::$document->getSerializer());
$this->assertNotNull(self::$document->getObjectHelper());
$this->assertEquals('extended', self::$document->getProfileDefinitionParameter('name'));
$this->assertEquals('EXTENDED', self::$document->getProfileDefinitionParameter('altname'));
$this->assertEquals('urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended', self::$document->getProfileDefinitionParameter('contextparameter'));
$this->assertEquals('factur-x.xml', self::$document->getProfileDefinitionParameter('attachmentfilename'));
$this->assertEquals('EXTENDED', self::$document->getProfileDefinitionParameter('xmpname'));
$this->expectNoticeOrWarningExt(
function () {
self::$document->getProfileDefinitionParameter('unknownparameter');
}
);
}

public function testXmlGenerals(): void
{
$xml = $this->getXml();
Expand Down Expand Up @@ -2134,4 +2157,22 @@ public function testToString(): void
$this->assertIsString($xmlContent);
$this->assertStringStartsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rsm:CrossIndustryInvoice", $xmlContent);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getContentAsDomDocument
*/
public function testGetContentAsDomDocument(): void
{
$domDocument = self::$document->getContentAsDomDocument();
$this->assertInstanceOf(\DOMDocument::class, $domDocument);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getContentAsDomXPath
*/
public function testGetContentAsDomXPath(): void
{
$domXPath = self::$document->getContentAsDomXPath();
$this->assertInstanceOf(\DOMXpath::class, $domXPath);
}
}
41 changes: 41 additions & 0 deletions tests/testcases/BuilderMinimumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ public function testDocumentProfile(): void
$this->assertNotEquals(ZugferdProfiles::PROFILE_EN16931, self::$document->getProfileId());
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getInvoiceObject
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getSerializer
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getObjectHelper
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getProfileDefinitionParameter
*/
public function testDocumentGetters(): void
{
$this->assertNotNull(self::$document->getInvoiceObject());
$this->assertNotNull(self::$document->getSerializer());
$this->assertNotNull(self::$document->getObjectHelper());
$this->assertEquals('minimum', self::$document->getProfileDefinitionParameter('name'));
$this->assertEquals('MINIMUM', self::$document->getProfileDefinitionParameter('altname'));
$this->assertEquals('urn:factur-x.eu:1p0:minimum', self::$document->getProfileDefinitionParameter('contextparameter'));
$this->assertEquals('factur-x.xml', self::$document->getProfileDefinitionParameter('attachmentfilename'));
$this->assertEquals('MINIMUM', self::$document->getProfileDefinitionParameter('xmpname'));
$this->expectNoticeOrWarningExt(
function () {
self::$document->getProfileDefinitionParameter('unknownparameter');
}
);
}

public function testXmlGenerals(): void
{
$xml = $this->getXml();
Expand Down Expand Up @@ -2133,4 +2156,22 @@ public function testToString(): void
$this->assertIsString($xmlContent);
$this->assertStringStartsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rsm:CrossIndustryInvoice", $xmlContent);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getContentAsDomDocument
*/
public function testGetContentAsDomDocument(): void
{
$domDocument = self::$document->getContentAsDomDocument();
$this->assertInstanceOf(\DOMDocument::class, $domDocument);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentBuilder::getContentAsDomXPath
*/
public function testGetContentAsDomXPath(): void
{
$domXPath = self::$document->getContentAsDomXPath();
$this->assertInstanceOf(\DOMXpath::class, $domXPath);
}
}
13 changes: 13 additions & 0 deletions tests/testcases/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ public function testDocumentInternals(): void
$this->assertNotNull($property->getValue($doc));
}

/**
* @covers \horstoeko\zugferd\ZugferdDocument::getInvoiceObject
* @covers \horstoeko\zugferd\ZugferdDocument::getSerializer
* @covers \horstoeko\zugferd\ZugferdDocument::getObjectHelper
*/
public function testDocumentGetters(): void
{
$doc = ZugferdDocumentBuilder::createNew(ZugferdProfiles::PROFILE_EXTENDED);
$this->assertNotNull($doc->getInvoiceObject());
$this->assertNotNull($doc->getSerializer());
$this->assertNotNull($doc->getObjectHelper());
}

/**
* Access to private properties
*
Expand Down
22 changes: 22 additions & 0 deletions tests/testcases/ObjectHelperEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ public static function setUpBeforeClass(): void
self::$objectHelper = new ZugferdObjectHelper(ZugferdProfiles::PROFILE_EN16931);
}

/**
* @covers \horstoeko\zugferd\ZugferdObjectHelper::getDocumentCodeType
*/
public function testGetDocumentCodeTypeEmpty(): void
{
$codeType = self::$objectHelper->getDocumentCodeType();
$this->assertNull($codeType);
}

/**
* @covers \horstoeko\zugferd\ZugferdObjectHelper::getDocumentCodeType
*/
public function testGetDocumentCodeTypeNotEmpty(): void
{
/**
* @var \horstoeko\zugferd\entities\en16931\qdt\DocumentCodeType
*/
$codeType = self::$objectHelper->getDocumentCodeType("380");
$this->assertNotNull($codeType);
$this->assertEquals("380", $codeType->value());
}

/**
* @covers \horstoeko\zugferd\ZugferdObjectHelper::getIdType
*/
Expand Down
22 changes: 22 additions & 0 deletions tests/testcases/ObjectHelperExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ public static function setUpBeforeClass(): void
self::$objectHelper = new ZugferdObjectHelper(ZugferdProfiles::PROFILE_EXTENDED);
}

/**
* @covers \horstoeko\zugferd\ZugferdObjectHelper::getDocumentCodeType
*/
public function testGetDocumentCodeTypeEmpty(): void
{
$codeType = self::$objectHelper->getDocumentCodeType();
$this->assertNull($codeType);
}

/**
* @covers \horstoeko\zugferd\ZugferdObjectHelper::getDocumentCodeType
*/
public function testGetDocumentCodeTypeNotEmpty(): void
{
/**
* @var \horstoeko\zugferd\entities\extended\qdt\DocumentCodeType
*/
$codeType = self::$objectHelper->getDocumentCodeType("380");
$this->assertNotNull($codeType);
$this->assertEquals("380", $codeType->value());
}

/**
* @covers \horstoeko\zugferd\ZugferdObjectHelper::getIdType
*/
Expand Down
24 changes: 23 additions & 1 deletion tests/testcases/ReaderBasicSimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ public function testDocumentProfile(): void
$this->assertNotEquals(ZugferdProfiles::PROFILE_EXTENDED, self::$document->getProfileId());
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getInvoiceObject
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getSerializer
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getObjectHelper
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getProfileDefinitionParameter
*/
public function testDocumentGetters(): void
{
$this->assertNotNull(self::$document->getInvoiceObject());
$this->assertNotNull(self::$document->getSerializer());
$this->assertNotNull(self::$document->getObjectHelper());
$this->assertEquals('basic', self::$document->getProfileDefinitionParameter('name'));
$this->assertEquals('BASIC', self::$document->getProfileDefinitionParameter('altname'));
$this->assertEquals('urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic', self::$document->getProfileDefinitionParameter('contextparameter'));
$this->assertEquals('factur-x.xml', self::$document->getProfileDefinitionParameter('attachmentfilename'));
$this->assertEquals('BASIC', self::$document->getProfileDefinitionParameter('xmpname'));
$this->expectNoticeOrWarningExt(
function () {
self::$document->getProfileDefinitionParameter('unknownparameter');
}
);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getDocumentInformation
*/
Expand All @@ -42,7 +65,6 @@ public function testDocumentGenerals(): void
$this->assertEquals("", $documentname);
$this->assertEquals("", $documentlanguage);
$this->assertNull($effectiveSpecifiedPeriod);
$this->assertNotNull(self::$document->getInvoiceObject());
}

/**
Expand Down
24 changes: 23 additions & 1 deletion tests/testcases/ReaderEn16931AllowanceChargeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ public function testDocumentProfile(): void
$this->assertNotEquals(ZugferdProfiles::PROFILE_EXTENDED, self::$document->getProfileId());
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getInvoiceObject
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getSerializer
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getObjectHelper
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getProfileDefinitionParameter
*/
public function testDocumentGetters(): void
{
$this->assertNotNull(self::$document->getInvoiceObject());
$this->assertNotNull(self::$document->getSerializer());
$this->assertNotNull(self::$document->getObjectHelper());
$this->assertEquals('en16931', self::$document->getProfileDefinitionParameter('name'));
$this->assertEquals('EN 16931 (COMFORT)', self::$document->getProfileDefinitionParameter('altname'));
$this->assertEquals('urn:cen.eu:en16931:2017', self::$document->getProfileDefinitionParameter('contextparameter'));
$this->assertEquals('factur-x.xml', self::$document->getProfileDefinitionParameter('attachmentfilename'));
$this->assertEquals('EN 16931', self::$document->getProfileDefinitionParameter('xmpname'));
$this->expectNoticeOrWarningExt(
function () {
self::$document->getProfileDefinitionParameter('unknownparameter');
}
);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getDocumentInformation
*/
Expand All @@ -42,7 +65,6 @@ public function testDocumentGenerals(): void
$this->assertEquals("", $documentname);
$this->assertEquals("", $documentlanguage);
$this->assertNull($effectiveSpecifiedPeriod);
$this->assertNotNull(self::$document->getInvoiceObject());
}

/**
Expand Down
24 changes: 23 additions & 1 deletion tests/testcases/ReaderEn16931Bank1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ public function testDocumentProfile(): void
$this->assertNotEquals(ZugferdProfiles::PROFILE_EXTENDED, self::$document->getProfileId());
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getInvoiceObject
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getSerializer
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getObjectHelper
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getProfileDefinitionParameter
*/
public function testDocumentGetters(): void
{
$this->assertNotNull(self::$document->getInvoiceObject());
$this->assertNotNull(self::$document->getSerializer());
$this->assertNotNull(self::$document->getObjectHelper());
$this->assertEquals('en16931', self::$document->getProfileDefinitionParameter('name'));
$this->assertEquals('EN 16931 (COMFORT)', self::$document->getProfileDefinitionParameter('altname'));
$this->assertEquals('urn:cen.eu:en16931:2017', self::$document->getProfileDefinitionParameter('contextparameter'));
$this->assertEquals('factur-x.xml', self::$document->getProfileDefinitionParameter('attachmentfilename'));
$this->assertEquals('EN 16931', self::$document->getProfileDefinitionParameter('xmpname'));
$this->expectNoticeOrWarningExt(
function () {
self::$document->getProfileDefinitionParameter('unknownparameter');
}
);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getDocumentInformation
*/
Expand All @@ -43,7 +66,6 @@ public function testDocumentGenerals(): void
$this->assertEquals("", $documentname);
$this->assertEquals("", $documentlanguage);
$this->assertNull($effectiveSpecifiedPeriod);
$this->assertNotNull(self::$document->getInvoiceObject());
}

/**
Expand Down
24 changes: 23 additions & 1 deletion tests/testcases/ReaderEn16931SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ public function testDocumentProfile(): void
$this->assertNotEquals(ZugferdProfiles::PROFILE_EXTENDED, self::$document->getProfileId());
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getInvoiceObject
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getSerializer
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getObjectHelper
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getProfileDefinitionParameter
*/
public function testDocumentGetters(): void
{
$this->assertNotNull(self::$document->getInvoiceObject());
$this->assertNotNull(self::$document->getSerializer());
$this->assertNotNull(self::$document->getObjectHelper());
$this->assertEquals('en16931', self::$document->getProfileDefinitionParameter('name'));
$this->assertEquals('EN 16931 (COMFORT)', self::$document->getProfileDefinitionParameter('altname'));
$this->assertEquals('urn:cen.eu:en16931:2017', self::$document->getProfileDefinitionParameter('contextparameter'));
$this->assertEquals('factur-x.xml', self::$document->getProfileDefinitionParameter('attachmentfilename'));
$this->assertEquals('EN 16931', self::$document->getProfileDefinitionParameter('xmpname'));
$this->expectNoticeOrWarningExt(
function () {
self::$document->getProfileDefinitionParameter('unknownparameter');
}
);
}

/**
* @covers \horstoeko\zugferd\ZugferdDocumentReader::getDocumentInformation
*/
Expand All @@ -42,7 +65,6 @@ public function testDocumentGenerals(): void
$this->assertEquals("", $documentname);
$this->assertEquals("", $documentlanguage);
$this->assertNull($effectiveSpecifiedPeriod);
$this->assertNotNull(self::$document->getInvoiceObject());
}

/**
Expand Down
Loading

0 comments on commit a4acca4

Please sign in to comment.