diff --git a/src/PackageReader/Internal/FilteredPackageReader.php b/src/PackageReader/Internal/FilteredPackageReader.php index 548674a..a1613a1 100644 --- a/src/PackageReader/Internal/FilteredPackageReader.php +++ b/src/PackageReader/Internal/FilteredPackageReader.php @@ -57,18 +57,19 @@ public static function createFromFile(string $filename): self return new self($filename, $archive); } - /** @inheritDoc */ + /** + * @inheritDoc + * @codeCoverageIgnore Unable to produce code coverage for error handling + */ public static function createFromContents(string $content): self { // create temp file try { $tmpfile = tempnam(sys_get_temp_dir(), ''); } catch (Throwable $exception) { - /** @codeCoverageIgnore */ throw CreateTemporaryZipFileException::create('Cannot create a temporary file', $exception); } if (false === $tmpfile) { - /** @codeCoverageIgnore */ throw CreateTemporaryZipFileException::create('Cannot not create a temporary file'); } @@ -76,11 +77,9 @@ public static function createFromContents(string $content): self try { $write = file_put_contents($tmpfile, $content); } catch (Throwable $exception) { - /** @codeCoverageIgnore */ throw CreateTemporaryZipFileException::create('Cannot store contents on temporary file', $exception); } if (false === $write) { - /** @codeCoverageIgnore */ throw CreateTemporaryZipFileException::create('Cannot store contents on temporary file'); } diff --git a/tests/Unit/PackageReader/Internal/ThirdPartiesExtractorTest.php b/tests/Unit/PackageReader/Internal/ThirdPartiesExtractorTest.php new file mode 100644 index 0000000..847d99e --- /dev/null +++ b/tests/Unit/PackageReader/Internal/ThirdPartiesExtractorTest.php @@ -0,0 +1,77 @@ + [ + 'RfcACuentaTerceros' => 'AAAA010101AAA', + 'NombreACuentaTerceros' => 'Registro de ejemplo 1', + ], + '00000000-AAAA-BBBB-1111-000000000002' => [ + 'RfcACuentaTerceros' => 'AAAA010102AAA', + 'NombreACuentaTerceros' => 'Registro de ejemplo 2', + ], + '00000000-AAAA-BBBB-1111-000000000003' => [ + 'RfcACuentaTerceros' => 'AAAA010103AAA', + 'NombreACuentaTerceros' => 'Registro de ejemplo 3', + ], + ]; + $extractor = new ThirdPartiesExtractor(new CsvReader(new ArrayIterator($source))); + $this->assertSame($expected, iterator_to_array($extractor->eachRecord())); + } + + public function testEmptyUuidIsIgnored(): void + { + $source = [ + ['Uuid', 'RfcACuentaTerceros', 'NombreACuentaTerceros'], + ['', 'AAAA010101AAA', 'Registro de ejemplo 1'], + ]; + $expected = []; + $extractor = new ThirdPartiesExtractor(new CsvReader(new ArrayIterator($source))); + $this->assertSame($expected, iterator_to_array($extractor->eachRecord())); + } + + public function testCreateFromPackageReaderNotFilteredPackageReader(): void + { + $packageReader = $this->createMock(PackageReaderInterface::class); + $this->expectException(LogicException::class); + $this->expectExceptionMessage('PackageReader parameter must be a FilteredPackageReader'); + ThirdPartiesExtractor::createFromPackageReader($packageReader); + } + + public function testCreateFromPackageReaderRestoreFilter(): void + { + $packageReader = FilteredPackageReader::createFromFile($this->filePath('zip/metadata.zip')); + $filter = new NullFileFilter(); + $packageReader->setFilter($filter); + + ThirdPartiesExtractor::createFromPackageReader($packageReader); + + $this->assertSame( + $filter, + $packageReader->getFilter(), + 'FilteredPackageReader filter must not change after call createFromPackageReader' + ); + } +} diff --git a/tests/Unit/RequestBuilder/FielRequestBuilder/FielTest.php b/tests/Unit/RequestBuilder/FielRequestBuilder/FielTest.php index 1bf9e0e..7b0efc4 100644 --- a/tests/Unit/RequestBuilder/FielRequestBuilder/FielTest.php +++ b/tests/Unit/RequestBuilder/FielRequestBuilder/FielTest.php @@ -5,6 +5,10 @@ namespace PhpCfdi\SatWsDescargaMasiva\Tests\Unit\RequestBuilder\FielRequestBuilder; use Exception; +use PhpCfdi\Credentials\Certificate; +use PhpCfdi\Credentials\Credential; +use PhpCfdi\Credentials\Internal\SatTypeEnum; +use PhpCfdi\Credentials\PrivateKey; use PhpCfdi\SatWsDescargaMasiva\RequestBuilder\FielRequestBuilder\Fiel; use PhpCfdi\SatWsDescargaMasiva\Tests\TestCase; @@ -51,4 +55,16 @@ public function testIsNotValidUsingCsd(): void ); $this->assertFalse($fiel->isValid()); } + + public function testIsNotValidExpiredCertificate(): void + { + $certificate = $this->createMock(Certificate::class); + $certificate->method('satType')->willReturn(SatTypeEnum::fiel()); + $certificate->method('validOn')->willReturn(false); + $privateKey = $this->createMock(PrivateKey::class); + $privateKey->method('belongsTo')->willReturn(true); + $credential = new Credential($certificate, $privateKey); + $fiel = new Fiel($credential); + $this->assertFalse($fiel->isValid()); + } }