Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pôle IS
Bundles Symfony 2
ng-model-generator-bundle
Commits
3c01ecff
Commit
3c01ecff
authored
Nov 13, 2019
by
Guillaume Perréal
Browse files
Sépare les tests des DTO et des méthodes customs.
parent
7a97df07
Changes
5
Hide whitespace changes
Inline
Side-by-side
tests/Fixtures/Controller/CustomController.php
View file @
3c01ecff
...
...
@@ -21,8 +21,7 @@
namespace
Irstea\NgModelGeneratorBundle\Tests\Fixtures\Controller
;
use
Irstea\NgModelGeneratorBundle\Tests\Fixtures\ValueObject\InputDTO
;
use
Irstea\NgModelGeneratorBundle\Tests\Fixtures\ValueObject\OutputDTO
;
use
Irstea\NgModelGeneratorBundle\Tests\Fixtures\Entity\EntityWithCustomMethods
;
/**
* Class CustomController.
...
...
@@ -30,19 +29,19 @@ use Irstea\NgModelGeneratorBundle\Tests\Fixtures\ValueObject\OutputDTO;
final
class
CustomController
{
/**
* @param
InputDTO
$input
* @param
EntityWithCustomMethods
$input
*
* @return
OutputDTO
* @return
EntityWithCustomMethods
*/
public
function
customItem
(
InputDTO
$input
):
OutputDTO
public
function
customItem
(
EntityWithCustomMethods
$input
):
EntityWithCustomMethods
{
return
new
OutputDTO
();
return
new
EntityWithCustomMethods
();
}
/**
* @param
InputDTO
[] $inputs
* @param
EntityWithCustomMethods
[] $inputs
*
* @return
OutputDTO
[]
* @return
EntityWithCustomMethods
[]
*/
public
function
customCollection
(
array
$inputs
):
array
{
...
...
tests/Fixtures/Entity/EntityWithCustomMethods.php
View file @
3c01ecff
...
...
@@ -22,8 +22,6 @@
namespace
Irstea\NgModelGeneratorBundle\Tests\Fixtures\Entity
;
use
ApiPlatform\Core\Annotation
as
API
;
use
Irstea\NgModelGeneratorBundle\Tests\Fixtures\ValueObject\InputDTO
;
use
Irstea\NgModelGeneratorBundle\Tests\Fixtures\ValueObject\OutputDTO
;
use
Ramsey\Uuid\Uuid
;
use
Ramsey\Uuid\UuidInterface
;
...
...
@@ -33,18 +31,18 @@ use Ramsey\Uuid\UuidInterface;
* @API\ApiResource(
* itemOperations={
* "get",
* "put",
* "delete",
* "custom": {
* "method": "PUT",
* "input": InputDTO::class,
* "output": OutputDTO::class,
* "controller": "Irstea\NgModelGeneratorBundle\Tests\Fixtures\Controller\CustomController::customItem",
* }
* },
* collectionOperations={
* "get",
* "post",
* "custom": {
* "method": "POST",
* "input": InputDTO::class,
* "output": OutputDTO::class,
* "controller": "Irstea\NgModelGeneratorBundle\Tests\Fixtures\Controller\CustomController::customCollection",
* }
* }
...
...
tests/Fixtures/Entity/EntityWithDTO.php
0 → 100644
View file @
3c01ecff
<?php
declare
(
strict_types
=
1
);
/*
* This file is part of "irstea/ng-model-generator-bundle".
*
* "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata.
* Copyright (C) 2018-2019 IRSTEA
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace
Irstea\NgModelGeneratorBundle\Tests\Fixtures\Entity
;
use
ApiPlatform\Core\Annotation
as
API
;
use
Irstea\NgModelGeneratorBundle\Tests\Fixtures\ValueObject\InputDTO
;
use
Irstea\NgModelGeneratorBundle\Tests\Fixtures\ValueObject\OutputDTO
;
use
Ramsey\Uuid\Uuid
;
use
Ramsey\Uuid\UuidInterface
;
/**
* Class EntityWithCustomMethods.
*
* @API\ApiResource(
* itemOperations={
* "put": {
* "method": "PUT",
* "input": InputDTO::class,
* "output": OutputDTO::class,
* }
* },
* collectionOperations={
* "post": {
* "method": "POST",
* "input": InputDTO::class,
* "output": OutputDTO::class,
* }
* }
* )
*/
class
EntityWithDTO
{
/**
* @var UuidInterface
* @API\ApiProperty(identifier=true)
*/
private
$id
;
public
function
__construct
()
{
$this
->
id
=
Uuid
::
uuid4
();
}
/**
* Get id.
*
* @return UuidInterface
*/
public
function
getId
():
UuidInterface
{
return
$this
->
id
;
}
}
tests/Functional/CustomMethodTest.php
View file @
3c01ecff
...
...
@@ -44,23 +44,8 @@ final class CustomMethodTest extends GenerationTestCase
public
function
listExpectedSnippets
():
array
{
return
[
'CustomInputDTO'
=>
[
<<<'TYPESCRIPT'
export interface CustomInputDTO {
values: Array<number>;
}
TYPESCRIPT
],
'OutputDTO'
=>
[
<<<'TYPESCRIPT'
export interface OutputDTO {
results: Array<string>;
success: boolean;
}
TYPESCRIPT
],
'CustomItemMethod'
=>
[
'public custom(iri: IRI<EntityWithCustomMethods>, body: CustomInputDTO, options: RequestOptions = {}): Observable<OutputDTO> {'
],
'CustomCollectionMethod'
=>
[
'public customs(body: Array<CustomInputDTO>, options: RequestOptions = {}): Observable<Collection<OutputDTO>> {'
],
'CustomItemMethod'
=>
[
'public custom(iri: IRI<EntityWithCustomMethods>, body: CustomEntityWithCustomMethods, options: RequestOptions = {}): Observable<EntityWithCustomMethods> {'
],
'CustomCollectionMethod'
=>
[
'public customs(body: Array<CustomEntityWithCustomMethods>, options: RequestOptions = {}): Observable<Collection<EntityWithCustomMethods>> {'
],
];
}
}
tests/Functional/DTOTest.php
0 → 100644
View file @
3c01ecff
<?php
declare
(
strict_types
=
1
);
/*
* This file is part of "irstea/ng-model-generator-bundle".
*
* "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata.
* Copyright (C) 2018-2019 IRSTEA
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace
Irstea\NgModelGeneratorBundle\Tests\Functional
;
/**
* Class CustomMethodTest.
*/
final
class
DTOTest
extends
GenerationTestCase
{
/**
* @param string $snippet
* @param string $code
*
* @test
* @dataProvider listExpectedSnippets
*/
public
function
checkCodeSnippet
(
string
$snippet
):
void
{
self
::
assertCodeContains
(
$snippet
,
self
::
generateTypescript
());
}
/**
* @return array
*/
public
function
listExpectedSnippets
():
array
{
return
[
'PutInputDTO'
=>
[
<<<'TYPESCRIPT'
export interface PutInputDTO {
values?: Array<number>;
}
TYPESCRIPT
],
'PostInputDTO'
=>
[
<<<'TYPESCRIPT'
export interface PostInputDTO {
values: Array<number>;
}
TYPESCRIPT
],
'OutputDTO'
=>
[
<<<'TYPESCRIPT'
export interface OutputDTO {
results: Array<string>;
success: boolean;
}
TYPESCRIPT
],
'PutItemMethod'
=>
[
'public put(id: UUID, body: PutInputDTO, options: RequestOptions = {}): Observable<OutputDTO> {'
],
'PostCollectionMethod'
=>
[
'public post(body: PostInputDTO, options: RequestOptions = {}): Observable<OutputDTO> {'
],
];
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment