Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ixudra's avatar

How to test my package?

I maintain several packages that are available for download via composer. To my shame, most of these do not have tests, despite me using them extensively in my day to day activities. Reason is simple: I don't know how to make them work properly.

For example: my most used package is ixudra/curl, a package for easily sending cURL requests through a fluent query builder. Ideally, I'd want to set up tests that cover all different methods and options, such as GET requests, POST requests, file upload, various header types, ... but I have no idea how to do this. I can't just use random websites, I'll be fixing my tests all the time if they change their interface. I could set up a website myself and provide all the required routes but that just seems silly

How could I best tackle this issue? How can I write reliable tests without external dependencies?

Thx

0 likes
4 replies
topvillas's avatar

I'm not a testing guru but I think you need to mock responses and assert the package api returns what you're expecting.

ixudra's avatar

@topvillas That is the general idea, yes, but I have no idea how to accomplish it. cURL is a PHP extension, you can't just mock that. Additionally, the package is platform independent so I don't have a IOC container or facade I can rely on

topvillas's avatar

No, but you can mock the CurlService class in the xudra/curl package.

Like I said, I'm not an expert on testing and I might be way off the mark. But that sounds feasible to me.

ixudra's avatar

@topvillas Mocking the CurlService doesn't solve anything. That class is just an intermediary, only 2 lines of code in there. The real complexity is in the Builder class, that's the one I need to test. And I don't need the CurlService at all to do that

That said, I did consider partial mocking for the Builder class. I could help to get me some coverage at least, but not nearly the level I'm aiming towards

Please or to participate in this conversation.