-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
209 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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')); | ||
} | ||
} |
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,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')); | ||
} | ||
} |
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,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')); | ||
} | ||
} |
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,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')); | ||
} | ||
} |