0

Does anyone know of a basic unit testing framework for PHP that does not require Composer in order to use it? The project's testing requirements are simple, and I expect any framework would be fine. I'd be very happy with PHPUnit if there's a way of using that without Composer, though I don't think that's possible. The alternative is to roll my own, but I'd rather not do that unless it's necessary.

I know Composer is a perfectly good system, and if the decision were mine, we'd be using it. But it's not my decision, and it has been made clear that the project leader would rather not have any unit testing if the alternative is to use Composer. That's wholly irrational, I know, but it's not a battle I have time to fight.

1 Answer 1

1

Actually, if you look at the installation docs, composer is not even stated as the preferred way to install PHPUnit.

The Phar version of PHPUnit can be used instead. It's easy to install and does not require composer.

To execute the tests, instead of a composer script, simply create a bash script (or cmd/powershell if you are on Windows). Although, depending on the configuration you use, it might also be as efficient to directly execute the phar.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm sorry, but I feel like I'm being really dense here. The installation docs you link to don't tell you how to install PHPUnit from a phar file – they tell you how to fetch it and verify its signature, but then what? The instructions for running the tests assume you have a phpunit CLI test runner, but unless I'm missing something, nothing on the installation instructions page creates this.
I'm assuming you are on a UNIX based OS for the following, but if you're on windows you can simply download the file and execute it in the same way. First you get the PHPUnit phar with curl -LO https://phar.phpunit.de/phpunit-9.5.phar and then you can run it using php phpunit-9.5.phar --version. Alternatively (and that will only work on UNIX) you can make it executable chmod +x phpunit-9.5.phar and run it like that ./phpunit-9.5.phar --version.
Oh, I see. So when the documentation says run (say) phpunit ArrayTest, what it actually means is run php phpunit-9.5.phar ArrayTest, or write a wrapper script that does that. Thanks for helping me out with that. PS, yes, I am using a Unix-based OS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.