-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from eclipxe13/version-0.5.4
Corrección de paquetes truncados al descargar y mantenimiento (v0.5.4)
- Loading branch information
Showing
16 changed files
with
228 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phive xmlns="https://phar.io/phive"> | ||
<phar name="php-cs-fixer" version="^3.37.1" installed="3.37.1" location="./tools/php-cs-fixer" copy="false"/> | ||
<phar name="phpcs" version="^3.7.2" installed="3.7.2" location="./tools/phpcs" copy="false"/> | ||
<phar name="phpcbf" version="^3.7.2" installed="3.7.2" location="./tools/phpcbf" copy="false"/> | ||
<phar name="phpstan" version="^1.10.40" installed="1.10.40" location="./tools/phpstan" copy="false"/> | ||
<phar name="php-cs-fixer" version="^3.54.0" installed="3.54.0" location="./tools/php-cs-fixer" copy="false"/> | ||
<phar name="phpcs" version="^3.9.1" installed="3.9.1" location="./tools/phpcs" copy="false"/> | ||
<phar name="phpcbf" version="^3.9.1" installed="3.9.1" location="./tools/phpcbf" copy="false"/> | ||
<phar name="phpstan" version="^1.10.67" installed="1.10.67" location="./tools/phpstan" copy="false"/> | ||
</phive> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/Unit/Services/Download/DownloadTranslatorContentsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\SatWsDescargaMasiva\Tests\Unit\Services\Download; | ||
|
||
use LogicException; | ||
use PhpCfdi\SatWsDescargaMasiva\Services\Download\DownloadTranslator; | ||
use PhpCfdi\SatWsDescargaMasiva\Tests\TestCase; | ||
use ZipArchive; | ||
|
||
final class DownloadTranslatorContentsTest extends TestCase | ||
{ | ||
private const FILE_SIZE_LIMIT = 10 * 1024 * 1024; // 10 MiB | ||
|
||
/** @var string */ | ||
private $hugeZipFile; | ||
|
||
/** @var string */ | ||
private $hugeResponse; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$hugeZipFile = tempnam('', ''); | ||
if (false === $hugeZipFile) { | ||
throw new LogicException('Unable to create a temporary file'); | ||
} | ||
|
||
$this->hugeZipFile = $hugeZipFile; | ||
$this->createHugeZipFile($this->hugeZipFile); | ||
$this->hugeResponse = $this->createHugeResponse($this->hugeZipFile); | ||
if (strlen($this->hugeResponse) < self::FILE_SIZE_LIMIT) { | ||
throw new LogicException( | ||
sprintf('Unable to create a response with size bigger than %s bytes', self::FILE_SIZE_LIMIT) | ||
); | ||
} | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
unlink($this->hugeZipFile); | ||
parent::tearDown(); | ||
} | ||
|
||
private function createHugeZipFile(string $destination): void | ||
{ | ||
$chunkSize = 2 * 1024 * 1024; // 1MB | ||
$limitSize = self::FILE_SIZE_LIMIT; // 10MB | ||
$fileCount = intval($limitSize / $chunkSize) + 1; | ||
$archive = new ZipArchive(); | ||
$archive->open($destination, ZipArchive::OVERWRITE); | ||
for ($i = 1; $i < $fileCount; $i++) { | ||
/** @noinspection PhpUnhandledExceptionInspection */ | ||
$archive->addFromString(sprintf('%d.txt', $i), random_bytes($chunkSize)); | ||
} | ||
$archive->close(); | ||
} | ||
|
||
private function createHugeResponse(string $contentFile): string | ||
{ | ||
$template = $this->fileContents('download/response-with-package-template.xml'); | ||
$template = (string) preg_replace('/>\s+</', '><', $template); | ||
$template = str_replace('?>', "?>\n", $template); | ||
$search = '<Paquete />'; | ||
$strpos = (int) strpos($template, $search); | ||
/** @noinspection PhpUnnecessaryLocalVariableInspection */ | ||
$template = substr($template, 0, $strpos) | ||
. '<Paquete>' . base64_encode((string) file_get_contents($contentFile)) . '</Paquete>' | ||
. substr($template, $strpos + strlen($search)); | ||
// file_put_contents('/tmp/sample-response.xml', $template); | ||
return $template; | ||
} | ||
|
||
public function testCreateDownloadResultFromHugeResponse(): void | ||
{ | ||
$translator = new DownloadTranslator(); | ||
|
||
$result = $translator->createDownloadResultFromSoapResponse($this->hugeResponse); | ||
|
||
$this->assertSame( | ||
sha1_file($this->hugeZipFile), | ||
sha1($result->getPackageContent()), | ||
'Extracted package contents for huge file are not the expected', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.