-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
getMusicFolders
method
- Loading branch information
Showing
13 changed files
with
295 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
src/FeatureSet/V1161/Contract/MusicFolderListDataProviderInterface.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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Usox\HyperSonic\FeatureSet\V1161\Contract; | ||
|
||
use Traversable; | ||
|
||
interface MusicFolderListDataProviderInterface | ||
{ | ||
/** | ||
* @return Traversable<array{name: string, id: string}> | ||
*/ | ||
public function getMusicFolders(): Traversable; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Usox\HyperSonic\FeatureSet\V1161\Method; | ||
|
||
use Usox\HyperSonic\Exception\SubSonicApiException; | ||
use Usox\HyperSonic\FeatureSet\V1161\Contract\MusicFolderListDataProviderInterface; | ||
use Usox\HyperSonic\FeatureSet\V1161\Responder\ResponderFactoryInterface; | ||
use Usox\HyperSonic\Response\ResponderInterface; | ||
|
||
/** | ||
* Retrieves the list of available music folders | ||
* | ||
* This class covers the `getMusicFolders.view` method | ||
*/ | ||
final class GetMusicFoldersMethod implements V1161MethodInterface | ||
{ | ||
public function __construct( | ||
private readonly ResponderFactoryInterface $responderFactory, | ||
) { | ||
} | ||
|
||
/** | ||
* @param array<string, scalar> $queryParams | ||
* @param array<string, scalar> $args | ||
* | ||
* @throws SubSonicApiException | ||
*/ | ||
public function __invoke( | ||
MusicFolderListDataProviderInterface $dataProvider, | ||
array $queryParams, | ||
array $args | ||
): ResponderInterface { | ||
return $this->responderFactory->createMusicFoldersResponder( | ||
$dataProvider->getMusicFolders() | ||
); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Usox\HyperSonic\FeatureSet\V1161\Responder; | ||
|
||
use AaronDDM\XMLBuilder\XMLArray; | ||
use Traversable; | ||
use Usox\HyperSonic\Response\FormattedResponderInterface; | ||
|
||
final class MusicFoldersResponder implements FormattedResponderInterface | ||
{ | ||
/** | ||
* @param Traversable<array{ | ||
* name: string, | ||
* id: string | ||
* }> $musicFolders | ||
*/ | ||
public function __construct( | ||
private readonly Traversable $musicFolders | ||
) { | ||
} | ||
|
||
public function writeXml(XMLArray $XMLArray): void | ||
{ | ||
$XMLArray->startLoop( | ||
'musicFolders', | ||
[], | ||
function (XMLArray $XMLArray): void { | ||
foreach ($this->musicFolders as $musicFolder) { | ||
$XMLArray->add( | ||
'musicFolder', | ||
'', | ||
[ | ||
'name' => htmlspecialchars($musicFolder['name']), | ||
'id' => $musicFolder['id'], | ||
] | ||
); | ||
} | ||
} | ||
); | ||
} | ||
|
||
public function writeJson(array &$root): void | ||
{ | ||
$root['musicFolders'] = ['musicFolder' => iterator_to_array($this->musicFolders)]; | ||
} | ||
|
||
public function isBinaryResponder(): bool | ||
{ | ||
return false; | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
tests/FeatureSet/V1161/Method/GetMusicFoldersMethodTest.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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Usox\HyperSonic\FeatureSet\V1161\Method; | ||
|
||
use ArrayIterator; | ||
use Mockery; | ||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
use Mockery\MockInterface; | ||
use Usox\HyperSonic\FeatureSet\V1161\Contract\MusicFolderListDataProviderInterface; | ||
use Usox\HyperSonic\FeatureSet\V1161\Responder\ResponderFactoryInterface; | ||
use Usox\HyperSonic\Response\ResponderInterface; | ||
|
||
class GetMusicFoldersMethodTest extends MockeryTestCase | ||
{ | ||
private MockInterface $responder_factory; | ||
|
||
private GetMusicFoldersMethod $subject; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->responder_factory = Mockery::mock(ResponderFactoryInterface::class); | ||
|
||
$this->subject = new GetMusicFoldersMethod( | ||
$this->responder_factory, | ||
); | ||
} | ||
|
||
public function testInvokeReturnsResponder(): void | ||
{ | ||
$dataProvider = Mockery::mock(MusicFolderListDataProviderInterface::class); | ||
$responder = Mockery::mock(ResponderInterface::class); | ||
|
||
$value = new ArrayIterator([666]); | ||
|
||
$dataProvider->shouldReceive('getMusicFolders') | ||
->withNoArgs() | ||
->once() | ||
->andReturn($value); | ||
|
||
$this->responder_factory->shouldReceive('createMusicFoldersResponder') | ||
->with($value) | ||
->once() | ||
->andReturn($responder); | ||
|
||
$this->assertSame( | ||
$responder, | ||
call_user_func($this->subject, $dataProvider, [], []) | ||
); | ||
} | ||
} |
Oops, something went wrong.