Skip to content

feat(file-upload): Support saving multiple files at once.#1139

Merged
rthideaway merged 13 commits intodrupal-graphql:8.x-4.xfrom
rthideaway:feature/multiple-file-upload
Dec 21, 2020
Merged

feat(file-upload): Support saving multiple files at once.#1139
rthideaway merged 13 commits intodrupal-graphql:8.x-4.xfrom
rthideaway:feature/multiple-file-upload

Conversation

@rthideaway
Copy link
Copy Markdown
Contributor

No description provided.

@rthideaway rthideaway self-assigned this Dec 21, 2020
@rthideaway rthideaway requested a review from klausi December 21, 2020 08:32
Copy link
Copy Markdown
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! Can you also add a success and a fail test case?

* @return \Drupal\file\FileInterface[]
* File entities.
*/
public function getFileEntities(): ?array {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type can be just array, this will never be NULL.

Comment thread src/GraphQL/Utility/FileUpload.php Outdated
}

/**
* Validates an uploaded files, saves them and returns a file upload response.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "an"

Comment thread src/GraphQL/Utility/FileUpload.php Outdated
* @return \Drupal\graphql\GraphQL\Response\FileUploadResponse
* The file upload response containing file entities or list of violations.
*/
public function saveMultipleFileUploads(array $uploaded_files, array $settings): ResponseInterface {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type should be FileUploadResponse so that callers see the correct methods.

@rthideaway rthideaway requested a review from klausi December 21, 2020 16:52
Copy link
Copy Markdown
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super, thanks! I just see 2 minor issues and then this can be merged.

PHPStan fail: you probably want assertSame()?

$file_entities = $file_upload_response->getFileEntities();
$this->assertEqual(count($file_entities), 3);
foreach ($file_entities as $file_entity) {
$this->assertInstanceOf('\Drupal\file\Entity\File', $file_entity);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use File::class syntax to avoid strings.

$this->assertEqual(count($file_entities), 3);
foreach ($file_entities as $file_entity) {
$this->assertInstanceOf('\Drupal\file\Entity\File', $file_entity);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should assert here that the 3 files exist at the target location, see for example testSuccess().

// There must be three file entities.
$file_entities = $file_upload_response->getFileEntities();
$this->assertEqual(count($file_entities), 3);
$this->assertEquals(count($file_entities), 3);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be assertCount()

@rthideaway rthideaway merged commit bb9741a into drupal-graphql:8.x-4.x Dec 21, 2020
@rthideaway rthideaway deleted the feature/multiple-file-upload branch December 21, 2020 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants