Skip to content

feat: Support file uploads in feature tests - #10574

Open
wakqasahmed wants to merge 3 commits into
codeigniter4:4.8from
wakqasahmed:feature/issue-7987-test-file-uploads
Open

wakqasahmed wants to merge 3 commits into
codeigniter4:4.8from
wakqasahmed:feature/issue-7987-test-file-uploads

Conversation

@wakqasahmed

Copy link
Copy Markdown
Contributor

Description

I added withFiles() so a feature test can attach MockUploadedFile objects to its next request. The request exposes them through getFile() and file validation, sets a multipart content type, and clears the files before the following request. The mock uses a local file for move() and store() while normal uploads still use PHP's move_uploaded_file().

The route-level test covers file access, uploaded validation, form fields, the content type, and moving the file. A second request confirms that the attached file does not carry over. The existing upload move tests also pass.

Fixes #7987.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage (focused tests pass; coverage was not measured locally)
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the 4.8 PRs that target the `4.8` branch. label Sep 19, 2026
wakqasahmed

This comment was marked as outdated.

Comment thread system/Test/FeatureTestTrait.php Outdated
*
* @return $this
*/
public function withFiles(array $files)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a static return type for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, added the static return type in 1e0104d.

@paulbalandan paulbalandan changed the title feat: Support file uploads in feature tests (#7987) feat: Support file uploads in feature tests Sep 25, 2026
@paulbalandan paulbalandan added the enhancement PRs that improve existing functionalities label Sep 25, 2026
@carson-codeigniter4 carson-codeigniter4 Bot removed the enhancement PRs that improve existing functionalities label Sep 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants