Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves file upload testing documentation #1862

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/file-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,13 @@ class MediaObjectTest extends ApiTestCase
$file = new UploadedFile('fixtures/files/image.png', 'image.png');
$client = self::createClient();

// Do not pass extra form fields through the "body" option as it won't work
$client->request('POST', '/media_objects', [
'headers' => ['Content-Type' => 'multipart/form-data'],
'extra' => [
// If you have additional fields in your MediaObject entity, use the parameters.
'parameters' => [
'title' => 'My file uploaded',
'title' => 'My file uploaded', // These parameters will be available in the application through $request->request
],
'files' => [
'file' => $file,
Expand All @@ -329,6 +330,8 @@ class MediaObjectTest extends ApiTestCase
}
```

**Important:** Using Symfony's `FormDataPart` Class will not work with the ApiTestCase Client.

## Uploading to an Existing Resource with its Fields

In this example, the file will be included in an existing resource (in our case: `Book`).
Expand Down
7 changes: 7 additions & 0 deletions core/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,10 @@ class BooksTest extends ApiTestCase
```

[Check out the dedicated Symfony documentation entry](https://symfony.com/doc/current/testing/functional_tests_assertions.html).


## Testing File Uploads and multipart/form-data Requests

It is also possible to test file uploads and `multipart/form-data` requests with the API Platform test client.

[Check out the dedicated File Upload Testing documentation entry](https://api-platform.com/docs/core/file-upload/#testing).
2 changes: 1 addition & 1 deletion extra/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For example:

3 versions are maintained at the same time:

* **stable** (currently the **3.1** branch): regular bugfixes are integrated in this version
* **stable** (currently the **3.2** branch): regular bugfixes are integrated in this version
* **old-stable** (are the last 2 minor branches: currently **3.0** and **3.1** branches): [security fixes](security.md) are integrated in this version, regular bugfixes are **not** backported in it
* **development** (**main** branch): new features target this branch

Expand Down