-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:/PhpGt/DomTemplate
- Loading branch information
Showing
10 changed files
with
280 additions
and
0 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
18 changes: 18 additions & 0 deletions
18
test/phpunit/TestHelper/Model/IteratorAggregate/Music/Album.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,18 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test\TestHelper\Model\IteratorAggregate\Music; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
use Traversable; | ||
|
||
class Album implements IteratorAggregate { | ||
/** @param array<Track> $trackList */ | ||
public function __construct( | ||
public readonly string $name, | ||
public readonly array $trackList, | ||
) {} | ||
|
||
public function getIterator():Traversable { | ||
return new ArrayIterator($this->trackList); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
test/phpunit/TestHelper/Model/IteratorAggregate/Music/Artist.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,19 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test\TestHelper\Model\IteratorAggregate\Music; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
use Traversable; | ||
|
||
class Artist implements IteratorAggregate { | ||
/** @param array<Album> $albumList */ | ||
public function __construct( | ||
public readonly string $name, | ||
public readonly array $albumList, | ||
) { | ||
} | ||
|
||
public function getIterator():Traversable { | ||
return new ArrayIterator($this->albumList); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test/phpunit/TestHelper/Model/IteratorAggregate/Music/MusicFactory.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,28 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test\TestHelper\Model\IteratorAggregate\Music; | ||
|
||
class MusicFactory { | ||
/** | ||
* @param array<string, array<string, array<string>>> $input | ||
* @return array<Artist> | ||
*/ | ||
public function buildArtistArray(array $input):array { | ||
$artistArray = []; | ||
|
||
foreach($input as $artistName => $inputAlbums) { | ||
$albumList = []; | ||
foreach($inputAlbums as $albumName => $inputTracks) { | ||
$trackList = []; | ||
foreach($inputTracks as $trackName) { | ||
$trackList[$trackName] = new Track($trackName, rand(20, 300)); | ||
} | ||
|
||
$albumList[$albumName] = new Album($albumName, $trackList); | ||
} | ||
|
||
$artistArray[$artistName] = new Artist($artistName, $albumList); | ||
} | ||
|
||
return $artistArray; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/phpunit/TestHelper/Model/IteratorAggregate/Music/Track.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,10 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test\TestHelper\Model\IteratorAggregate\Music; | ||
|
||
class Track { | ||
public function __construct( | ||
public string $name, | ||
public ?int $durationSeconds = null, | ||
) { | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/phpunit/TestHelper/Model/IteratorAggregate/Student/Module.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,8 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test\TestHelper\Model\IteratorAggregate\Student; | ||
|
||
class Module { | ||
public function __construct( | ||
public readonly string $title, | ||
) {} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/phpunit/TestHelper/Model/IteratorAggregate/Student/Name.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,9 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test\TestHelper\Model\IteratorAggregate\Student; | ||
|
||
class Name { | ||
public function __construct( | ||
public readonly string $first, | ||
public readonly string $last, | ||
) {} | ||
} |
16 changes: 16 additions & 0 deletions
16
test/phpunit/TestHelper/Model/IteratorAggregate/Student/Student.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,16 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test\TestHelper\Model\IteratorAggregate\Student; | ||
|
||
use Traversable; | ||
|
||
class Student implements \IteratorAggregate { | ||
/** @param array<Module> $moduleList */ | ||
public function __construct( | ||
public readonly Name $name, | ||
public readonly array $moduleList, | ||
) {} | ||
|
||
public function getIterator():Traversable { | ||
return new \ArrayIterator($this->moduleList); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
test/phpunit/TestHelper/Model/IteratorAggregate/Student/StudentFactory.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,35 @@ | ||
<?php | ||
|
||
namespace Gt\DomTemplate\Test\TestHelper\Model\IteratorAggregate\Student; | ||
|
||
class StudentFactory { | ||
/** | ||
* @param array<int, array<string, string|array<string>>> $input | ||
* @return array<Student> | ||
*/ | ||
public function buildStudentArray(array $input):array { | ||
$studentArray = []; | ||
|
||
foreach($input as $inputStudent) { | ||
$moduleList = []; | ||
foreach($inputStudent["modules"] as $moduleName) { | ||
array_push( | ||
$moduleList, | ||
new Module($moduleName), | ||
); | ||
} | ||
|
||
$name = new Name($inputStudent["firstName"], $inputStudent["lastName"]); | ||
|
||
array_push( | ||
$studentArray, | ||
new Student( | ||
$name, | ||
$moduleList, | ||
), | ||
); | ||
} | ||
|
||
return $studentArray; | ||
} | ||
} |