Skip to content

Commit

Permalink
Merge pull request #3 from eclipxe13/revision-3.0.0-1
Browse files Browse the repository at this point in the history
Revisión antes de liberar la versión 3
  • Loading branch information
eclipxe13 authored Mar 8, 2024
2 parents c7b7ee9 + b7f249d commit 6ee35eb
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 22 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ Esta librería se mantendrá compatible con al menos la versión con
También utilizamos [Versionado Semántico 2.0.0](docs/SEMVER.md) por lo que puedes usar esta librería
sin temor a romper tu aplicación.

| Version | PHP | Notes |
|---------|----------|------------|
| 1.0.0 | 8.2, 8.3 | 2023-12-13 |
| 2.0.0 | 8.2, 8.3 | 2024-03-07 |
| Versión | PHP | Nota |
|---------|----------|-----------------------------------|
| 1.0.0 | 8.2, 8.3 | 2023-12-13 Fuera de mantenimiento |
| 2.0.0 | 8.2, 8.3 | 2024-03-07 Fuera de mantenimiento |
| 3.0.0 | 8.2, 8.3 | 2024-03-07 |

## Contribuciones

Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ versión, aunque sí su incorporación en la rama principal de trabajo. Generalm
### Versión 3.0.0 2023-03-07

- Se cambia el método `SatPysScraper::run()` para una mejor inyección de dependencias y capacidad de pruebas.
- Se introduce una excepción dedicada para los errores de procesamiento de argumentos.
- Se cambia la forma de procesar los argumentos para usar `array_shift`.

### Versión 2.0.0 2023-03-07

Expand Down
28 changes: 10 additions & 18 deletions src/App/SatPysScraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,22 @@ public function processArguments(string ...$arguments): array
$quiet = false;
$sort = 'key';

$argumentsCount = count($arguments);
for ($i = 0; $i < $argumentsCount; $i++) {
$argument = $arguments[$i];
while ([] !== $arguments) {
$argument = (string) array_shift($arguments);
if (in_array($argument, ['--xml', '-x'], true)) {
$xml = strval($arguments[++$i] ?? '');
continue;
}
if (in_array($argument, ['--json', '-j'], true)) {
$json = strval($arguments[++$i] ?? '');
continue;
}
if (in_array($argument, ['--sort', '-s'], true)) {
$sort = strval($arguments[++$i] ?? '');
$xml = (string) array_shift($arguments);
} elseif (in_array($argument, ['--json', '-j'], true)) {
$json = (string) array_shift($arguments);
} elseif (in_array($argument, ['--sort', '-s'], true)) {
$sort = (string) array_shift($arguments);
if (! in_array($sort, ['key', 'name'])) {
throw new ArgumentException(sprintf('Invalid sort "%s"', $sort));
}
continue;
}
if (in_array($argument, ['--quiet', '-q'], true)) {
} elseif (in_array($argument, ['--quiet', '-q'], true)) {
$quiet = true;
continue;
} else {
throw new ArgumentException(sprintf('Invalid argument "%s"', $argument));
}

throw new ArgumentException(sprintf('Invalid argument "%s"', $argument));
}

if ('' === $xml && '' === $json) {
Expand Down
59 changes: 59 additions & 0 deletions tests/Unit/App/PrinterGeneratorTrackerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace PhpCfdi\SatPysScraper\Tests\Unit\App;

use PhpCfdi\SatPysScraper\App\PrinterGeneratorTracker;
use PhpCfdi\SatPysScraper\Data\Classification;
use PhpCfdi\SatPysScraper\Data\Family;
use PhpCfdi\SatPysScraper\Data\Segment;
use PhpCfdi\SatPysScraper\Data\Type;
use PhpCfdi\SatPysScraper\Tests\Unit\TestCase;

final class PrinterGeneratorTrackerTest extends TestCase
{
public function testBoot(): void
{
$printer = new PrinterGeneratorTracker();

$this->expectOutputRegex('/^Obteniendo tipos/');
$printer->boot();
}

public function testType(): void
{
$printer = new PrinterGeneratorTracker();
$type = new Type('1', 'Foo');

$this->expectOutputRegex('/^Obteniendo segmentos para el tipo 1 - Foo/');
$printer->type($type);
}

public function testSegment(): void
{
$printer = new PrinterGeneratorTracker();
$segment = new Segment('99', 'Foo');

$this->expectOutputRegex('/^\tObteniendo familias para el segmento 99 - Foo/');
$printer->segment($segment);
}

public function testFamily(): void
{
$printer = new PrinterGeneratorTracker();
$family = new Family('9999', 'Foo');

$this->expectOutputRegex('/^\t\tObteniendo clases para la familia 9999 - Foo/');
$printer->family($family);
}

public function testClass(): void
{
$printer = new PrinterGeneratorTracker();
$classification = new Classification('999999', 'Foo');

$this->expectOutputString('');
$printer->class($classification);
}
}

0 comments on commit 6ee35eb

Please sign in to comment.