Comment on page
Testing your frameworks
SVRUnit can also be used to test your framework.
Let's imagine you are building a PHP framework, that is published as a composer dependency, as well as a PHAR binary.
You would usually start it with one of these 2 commands:
# composer dependency
php vendor/bin/myapp xyz
# phar file
php myapp.phar xyz
SVRUnit helps you with 2 things.
- 1.You can create your custom "E2E" setups where you start your framework and verify the expected output using SVRUnit
Let's get started.
Because SVRUnit allows you to install it with Composer, it is recommended to install it directly as dependency. You can of course also use the PHAR file for this.
composer require svrunit/svrunit
Now create a XML configuration file that specifies 2 test suites.
Both test suites use the same test directory, but use different executable placeholders. With this approach, we can then use a placeholder inside the real tests later, so that we either use the script version of our file, or the PHAR binary, when running the tests.
Please keep in mind, this is totally optional...you don't need to use placeholders.
<testsuite name="bin" executable="php bin/myapp">
<testsuite name="phar" executable="php myapp.phar">
Last but not least, we need the specification of our tests in the YAML file.
If you use placeholders for your executable, just use (($EXEC)) instead of the real path to your executable. If not, just use your real path.
- name: "Test validate command"
command: "(($EXEC)) validate"
expected: "All translations are valid"
You can now manually run your tests, or even use your CI/CD pipeline for this.
php vendor/bin/svrunit --configuration=myconfig.xml