1

I need to make an auto-test for a function, which grabs request body with

file_get_contents('php://input')

So, I run my test in command-line, and want to put something in "request body", like

file_put_contents('php://input', 'kek')

But this straightforward approach is not working.

How can I achieve that?

nikserg
  • 382
  • 1
  • 11
  • You didn't tell us the environment, how do you make a manual-test? – shingo May 23 '22 at 10:29
  • php://input is a read-only stream that allows you to read raw data from the request body. php://input is not available with enctype="multipart/form-data". – Ajit Agarwal May 23 '22 at 10:35
  • @shingo I've mentioned: it runs from command line. It's functional test with Codeception. Creating application class, simulating web server behaviour. – nikserg May 23 '22 at 10:35
  • You can only read from this stream. php://input contains the HTTP request data, try doing that. – Ajit Agarwal May 23 '22 at 10:36
  • 1
    Does this help perhaps? https://stackoverflow.com/questions/38197116/how-do-i-simulate-php-input-in-php – CBroe May 23 '22 at 11:12
  • Apparently it's time to refactor this code and decouple the business logic from the input device ;) – Honk der Hase May 23 '22 at 13:17

0 Answers0