Skip to content

Commit 1772b21

Browse files
committed
Add pemAsOneLine (utility for CFDI & XML-SEC)
1 parent 73a32c9 commit 1772b21

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Certificate.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public function pem(): string
6868
return $this->pem;
6969
}
7070

71+
public function pemAsOneLine(): string
72+
{
73+
return implode('', preg_grep('/^((?!-).)*$/', explode(PHP_EOL, $this->pem())));
74+
}
75+
7176
public function parsed(): array
7277
{
7378
return $this->dataArray;

tests/Unit/CertificateTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ protected function createCertificateSello(): Certificate
2525
return new Certificate($this->fileContents('CSD01_AAA010101AAA/certificate.cer'));
2626
}
2727

28+
public function testPemContents(): void
29+
{
30+
$certificate = $this->createCertificateSello();
31+
$expected = trim($this->fileContents('CSD01_AAA010101AAA/certificate.cer.pem'));
32+
$this->assertSame($expected, trim($certificate->pem()));
33+
}
34+
35+
public function testPemContentsAsOneLine(): void
36+
{
37+
$certificate = $this->createCertificateSello();
38+
$expected = base64_encode($this->fileContents('CSD01_AAA010101AAA/certificate.cer'));
39+
$this->assertSame($expected, trim($certificate->pemAsOneLine()));
40+
}
41+
2842
public function testSerialNumber(): void
2943
{
3044
$certificate = $this->createCertificate();

0 commit comments

Comments
 (0)