forked from biig-io/Melodiia
-
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.
Merge pull request biig-io#30 from swagindustries/feature/add-collect…
…ion-model Add collection response
- Loading branch information
Showing
8 changed files
with
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Feature: | ||
As a developer | ||
I should be able to render custom response easily with Melodiia | ||
|
||
Scenario: return array of object for a response | ||
Given there are some todos | ||
And I make a GET request on "/todos/contains/foo" | ||
Then the last response contains: | ||
""" | ||
{ | ||
"meta": { | ||
"totalPages": 1, | ||
"totalResults": 1, | ||
"currentPage": 1, | ||
"maxPerPage": 1 | ||
}, | ||
"links": { | ||
"prev": null, | ||
"next": null, | ||
"last": "http://localhost/todos/contains/foo", | ||
"first": "http://localhost/todos/contains/foo" | ||
}, | ||
"data": [ | ||
{ | ||
"id": 1, | ||
"content": "foo" | ||
} | ||
] | ||
} | ||
""" |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SwagIndustries\Melodiia\Response\Model; | ||
|
||
/** | ||
* Fix issue #12. | ||
*/ | ||
class Collection extends \ArrayIterator | ||
{ | ||
} |
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
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
26 changes: 26 additions & 0 deletions
26
tests/TestApplication/src/Controller/TodoContainsAction.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,26 @@ | ||
<?php | ||
|
||
namespace TestApplication\Controller; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use SwagIndustries\Melodiia\Response\Model\Collection; | ||
use SwagIndustries\Melodiia\Response\OkContent; | ||
use Symfony\Component\String\UnicodeString; | ||
use TestApplication\Entity\Todo; | ||
|
||
class TodoContainsAction | ||
{ | ||
/** | ||
* This is just a test. To achieve that easily you should use filters and crud controllers. | ||
*/ | ||
public function __invoke(EntityManagerInterface $manager, $word) | ||
{ | ||
$todos = array_filter($manager->getRepository(Todo::class)->findAll(), function (Todo $todo) use ($word) { | ||
$str = new UnicodeString($todo->getContent()); | ||
|
||
return $str->containsAny($word); | ||
}); | ||
|
||
return new OkContent(new Collection($todos)); | ||
} | ||
} |