Skip to content

Commit

Permalink
Merge branch 'review-1.0.0-3'
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 committed Dec 19, 2023
2 parents e0e8ec0 + 7048642 commit 06a6342
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/Example.php

This file was deleted.

5 changes: 5 additions & 0 deletions src/NullGeneratorTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ class NullGeneratorTracker implements GeneratorTrackerInterface
{
public function boot(): void
{
// Null Object
}

public function type(Data\Type $type): void
{
// Null Object
}

public function segment(Data\Segment $segment): void
{
// Null Object
}

public function family(Data\Family $family): void
{
// Null Object
}

public function class(Data\Classification $class): void
{
// Null Object
}
}
52 changes: 52 additions & 0 deletions tests/Unit/Data/FamilyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace PhpCfdi\SatPysScraper\Tests\Unit\Data;

use PhpCfdi\SatPysScraper\Data\Classification;
use PhpCfdi\SatPysScraper\Data\Family;
use PhpCfdi\SatPysScraper\Tests\Unit\TestCase;

final class FamilyTest extends TestCase
{
/** @return array<int|string, Classification> */
private function createUnsortedChildren(): array
{
$children = [
new Classification(11, 'One'),
new Classification(22, 'Two'),
new Classification(33, 'Three'),
new Classification(44, 'Four'),
];
shuffle($children);
return array_combine(array_column($children, 'id'), $children);
}

public function testProperties(): void
{
$id = 1;
$name = 'foo';
$children = $this->createUnsortedChildren();
$parent = new Family($id, $name, $children);
$this->assertSame($id, $parent->id);
$this->assertSame($name, $parent->name);
$this->assertSame($children, iterator_to_array($parent));
}

public function testSortByKey(): void
{
$children = $this->createUnsortedChildren();
$parent = new Family(1, 'foo', $children);
$parent->sortByKey();
$this->assertSame([11, 22, 33, 44], array_column(iterator_to_array($parent), 'id'));
}

public function testSortByName(): void
{
$children = $this->createUnsortedChildren();
$parent = new Family(1, 'foo', $children);
$parent->sortByName();
$this->assertSame(['Four', 'One', 'Three', 'Two'], array_column(iterator_to_array($parent), 'name'));
}
}
52 changes: 52 additions & 0 deletions tests/Unit/Data/SegmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace PhpCfdi\SatPysScraper\Tests\Unit\Data;

use PhpCfdi\SatPysScraper\Data\Family;
use PhpCfdi\SatPysScraper\Data\Segment;
use PhpCfdi\SatPysScraper\Tests\Unit\TestCase;

final class SegmentTest extends TestCase
{
/** @return array<int|string, Family> */
private function createUnsortedChildren(): array
{
$children = [
new Family(11, 'One'),
new Family(22, 'Two'),
new Family(33, 'Three'),
new Family(44, 'Four'),
];
shuffle($children);
return array_combine(array_column($children, 'id'), $children);
}

public function testProperties(): void
{
$id = 1;
$name = 'foo';
$children = $this->createUnsortedChildren();
$parent = new Segment($id, $name, $children);
$this->assertSame($id, $parent->id);
$this->assertSame($name, $parent->name);
$this->assertSame($children, iterator_to_array($parent));
}

public function testSortByKey(): void
{
$children = $this->createUnsortedChildren();
$parent = new Segment(1, 'foo', $children);
$parent->sortByKey();
$this->assertSame([11, 22, 33, 44], array_column(iterator_to_array($parent), 'id'));
}

public function testSortByName(): void
{
$children = $this->createUnsortedChildren();
$parent = new Segment(1, 'foo', $children);
$parent->sortByName();
$this->assertSame(['Four', 'One', 'Three', 'Two'], array_column(iterator_to_array($parent), 'name'));
}
}
52 changes: 52 additions & 0 deletions tests/Unit/Data/TypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace PhpCfdi\SatPysScraper\Tests\Unit\Data;

use PhpCfdi\SatPysScraper\Data\Segment;
use PhpCfdi\SatPysScraper\Data\Type;
use PhpCfdi\SatPysScraper\Tests\Unit\TestCase;

final class TypeTest extends TestCase
{
/** @return array<int|string, Segment> */
private function createUnsortedChildren(): array
{
$children = [
new Segment(11, 'One'),
new Segment(22, 'Two'),
new Segment(33, 'Three'),
new Segment(44, 'Four'),
];
shuffle($children);
return array_combine(array_column($children, 'id'), $children);
}

public function testProperties(): void
{
$id = 1;
$name = 'foo';
$children = $this->createUnsortedChildren();
$parent = new Type($id, $name, $children);
$this->assertSame($id, $parent->id);
$this->assertSame($name, $parent->name);
$this->assertSame($children, iterator_to_array($parent));
}

public function testSortByKey(): void
{
$children = $this->createUnsortedChildren();
$parent = new Type(1, 'foo', $children);
$parent->sortByKey();
$this->assertSame([11, 22, 33, 44], array_column(iterator_to_array($parent), 'id'));
}

public function testSortByName(): void
{
$children = $this->createUnsortedChildren();
$parent = new Type(1, 'foo', $children);
$parent->sortByName();
$this->assertSame(['Four', 'One', 'Three', 'Two'], array_column(iterator_to_array($parent), 'name'));
}
}
48 changes: 48 additions & 0 deletions tests/Unit/Data/TypesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace PhpCfdi\SatPysScraper\Tests\Unit\Data;

use PhpCfdi\SatPysScraper\Data\Type;
use PhpCfdi\SatPysScraper\Data\Types;
use PhpCfdi\SatPysScraper\Tests\Unit\TestCase;

final class TypesTest extends TestCase
{
/** @return array<int|string, Type> */
private function createUnsortedChildren(): array
{
$children = [
new Type(11, 'One'),
new Type(22, 'Two'),
new Type(33, 'Three'),
new Type(44, 'Four'),
];
shuffle($children);
return array_combine(array_column($children, 'id'), $children);
}

public function testProperties(): void
{
$children = $this->createUnsortedChildren();
$parent = new Types($children);
$this->assertSame($children, iterator_to_array($parent));
}

public function testSortByKey(): void
{
$children = $this->createUnsortedChildren();
$parent = new Types($children);
$parent->sortByKey();
$this->assertSame([11, 22, 33, 44], array_column(iterator_to_array($parent), 'id'));
}

public function testSortByName(): void
{
$children = $this->createUnsortedChildren();
$parent = new Types($children);
$parent->sortByName();
$this->assertSame(['Four', 'One', 'Three', 'Two'], array_column(iterator_to_array($parent), 'name'));
}
}

0 comments on commit 06a6342

Please sign in to comment.