donatj / mock-webserver

Simple mock web server in PHP for unit testing.
MIT License
131 stars 21 forks source link

Base path for routes #32

Open barchard opened 3 years ago

barchard commented 3 years ago

Is it possible to support a base path for routes? This can then be mapped to a base file path for wild card routes

thanks

donatj commented 3 years ago

Can you explain what you mean exactly?

barchard commented 3 years ago

Sure, I want to map /folder to a /path/to/folder/on/disk so that /folder/sub-folder/file.txt automatically routes to /path/to/folder/on/disk/sub-folder/file.txt

donatj commented 2 years ago

So you're just wanting a file server essentially.

Interesting. I suspect I could lean on the built in PHP server's fileserver functionality. I'll need to investigate.

donatj commented 3 months ago

@ellipsis-dev

ellipsis-dev[bot] commented 3 months ago

I was able to create an implementation plan for the requested feature, but I didn't have time to finish. The plan includes modifying the setResponseOfPath method in src/MockWebServer.php to map a URL path to a file path on the server, and updating the tests to cover this new functionality. I would appreciate any feedback or suggestions for improving the plan. Thank you.

Implementation proposal (work in progress)

Step 1: Modify the setResponseOfPath method in src/MockWebServer.php

Modify the setResponseOfPath method to map a URL path to a file path on the server. This involves changing how the method stores the response for a given path. Instead of storing a response object, it should store a file path. When the server receives a request for a path, it should read the file at the corresponding file path and return its contents as the response. Make sure to handle different types of files correctly: if the file is a PHP script, execute it and return the output; if it's a non-PHP file, return the file directly. Also implement error handling for cases when the file doesn't exist or the server fails to read the file.

Step 2: Update tests to cover new functionality in src/MockWebServer.php

Update the existing tests to cover the changes made to the setResponseOfPath method. This includes tests that verify that a URL path is correctly mapped to a file path on the server and that the server returns the correct response when a request is made to the mapped URL path. Also add tests to cover error and edge cases, such as when the requested file doesn't exist or the server fails to read the file. Make sure to run the entire test suite after making these changes to ensure that the changes do not break existing functionality.


For more information about Ellipsis, check the documentation.

donatj commented 3 months ago

@ellipsis-dev give it a shot

ellipsis-dev[bot] commented 3 months ago

I was able to create a partial implementation plan for the requested feature, but I didn't have time to finish. The plan includes modifying the setResponseOfPath method in src/MockWebServer.php to map a URL path to a file path on the server, and updating the tests to cover this new functionality. I would appreciate any feedback or suggestions for improving the plan. Thank you.

[No tentative implementation steps.]


For more information about Ellipsis, check the documentation.