Skip to content

Commit 33d2da7

Browse files
committed
Added behat test
1 parent 9ce38f3 commit 33d2da7

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

features/bootstrap/DoctrineContext.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoCustom;
9191
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoNoInput;
9292
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoNoOutput;
93+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoOutputSameClass;
9394
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyFriend;
9495
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyGroup;
9596
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyImmutableDate;
@@ -1379,6 +1380,19 @@ public function thereAreNbDummyDtoCustom($nb)
13791380
$this->manager->clear();
13801381
}
13811382

1383+
/**
1384+
* @Given there is a DummyDtoOutputSameClass
1385+
*/
1386+
public function thereIsADummyDtoOutputSameClass()
1387+
{
1388+
$dto = new DummyDtoOutputSameClass();
1389+
$dto->lorem = 'test';
1390+
$dto->ipsum = '1';
1391+
$this->manager->persist($dto);
1392+
$this->manager->flush();
1393+
$this->manager->clear();
1394+
}
1395+
13821396
/**
13831397
* @Given there is an order with same customer and recipient
13841398
*/

features/jsonld/input_output.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ Feature: JSON-LD DTO input and output
8383
}
8484
"""
8585

86+
@createSchema
87+
Scenario: Get an item with same class as custom output
88+
Given there is a DummyDtoOutputSameClass
89+
When I send a "GET" request to "/dummy_dto_output_same_classes/1"
90+
Then the response status code should be 200
91+
And the response should be in JSON
92+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
93+
And the JSON should be equal to:
94+
"""
95+
{
96+
"@context": "/contexts/DummyDtoOutputSameClass",
97+
"@id": "/dummy_dto_output_same_classes/1",
98+
"@type": "DummyDtoOutputSameClass",
99+
"lorem": "test",
100+
"ipsum": "1",
101+
"id": 1
102+
}
103+
"""
104+
86105
@createSchema
87106
Scenario: Create a DummyDtoCustom object without output
88107
When I send a "POST" request to "/dummy_dto_custom_post_without_output" with body:
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity;
15+
16+
use ApiPlatform\Core\Annotation\ApiResource;
17+
use Doctrine\ORM\Mapping as ORM;
18+
19+
/**
20+
* Dummy InputOutput.
21+
*
22+
* @author Kévin Dunglas <[email protected]>
23+
*
24+
* @ApiResource(attributes={"output"=DummyDtoOutputSameClass::class})
25+
* @ORM\Entity
26+
*/
27+
class DummyDtoOutputSameClass
28+
{
29+
/**
30+
* @var int The id
31+
*
32+
* @ORM\Column(type="integer")
33+
* @ORM\Id
34+
* @ORM\GeneratedValue(strategy="AUTO")
35+
*/
36+
private $id;
37+
38+
/**
39+
* @var string
40+
*
41+
* @ORM\Column
42+
*/
43+
public $lorem;
44+
45+
/**
46+
* @var string
47+
*
48+
* @ORM\Column
49+
*/
50+
public $ipsum;
51+
52+
public function getId()
53+
{
54+
return $this->id;
55+
}
56+
}

0 commit comments

Comments
 (0)