-
-
Notifications
You must be signed in to change notification settings - Fork 969
Open
Labels
Description
I have a Product entity (that implements an interface I made - AuthoredUsedEntity), related to another User entity with a relation manyToOne. AuthoredUsedEntity is used to populate the user field in Product with the current logged in User.
when I make an api call to /api/products (I use postman) passing a json like this:
{
"name": "my product",
"price": 10
}
this works and a new record is created with the correct userID. The problem is with unit tests. I make a call like this:
$headers = [
'HTTP_AUTHORIZATION' => 'Bearer ' . $token,
'CONTENT_TYPE' => 'application/ld+json',
'HTTP_ACCEPT' => 'application/ld+json'
];
$postData = [
'name' => 'my product',
'price' => 10
];
$client = $this->makeClient();
$client->request('POST', '/api/products', [], [], $headers, json_encode($postData));
and I get this error: Invalid value provided (invalid IRI?)
am I doing anything wrong? For tests I am using phpunit and Liip.
thanks
M
silviodeligios
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
msechi commentedon Apr 12, 2019
any idea anyone?
Arkowsky commentedon Apr 15, 2019
Try use just application/json as CONTENT_TYPE and HTTP_ACCEPT in your tests in this case.
msechi commentedon Apr 15, 2019
@Arkowsky yes I tried already, same result.
thanks
Arkowsky commentedon Apr 16, 2019
I think you have to setId after you create object and this is the issue. Your identifier is empty and after create is called normalizer to show your results so you need to have id set.
msechi commentedon Apr 16, 2019
@Arkowsky as mentioned it works using POSTMAN. The issue must be something different given that it is failing when testing only, and only with POST/PUT calls.
coolfarmer commentedon Jan 2, 2020
Same problem here, have you found a solution?
jonytrifulca commentedon May 13, 2020
Take a look on this line
$client->request('POST', '/api/products', [], [], $headers, json_encode($postData));
try to don´t make a json_encode() , only pass the $postData like an array.
$response = $client->request( 'POST', $url, [ 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json' ], 'json' => $postData ]);
silviodeligios commentedon Apr 28, 2022
I have the same problem :(