Assertions for CLI commands
Write assertions for your CLI scripts.
A few weeks ago, we introduced assertions for HTTP requests. HTTP Assertions are a great way to set up your own expectations about code performance but PHP is not limited to only serve HTTP requests anymore. Nowadays, most projects also use PHP for scripts that need to be run on the command line. That’s why we are happy to announce that CLI Assertions are also supported.
CLI Assertions work the same way as their HTTP counterparts, the only difference being how Blackfire decides which assertions to run for the current script. For HTTP requests, assertions are run when the URL matches the path
regex; for CLI scripts, Blackfire uses the command
regex:
tests: "The cleanup task should run fast enough": command: "cleanup.php" assertions: - "main.wall_time < 400ms" - "main.memory < 50M" "HTTP requests should not do too many SQL queries": path: "/.*" assertions: - "metrics.sql.queries.count <= 5"
Now, whenever you profile the cleanup.php script (via blackfire run php cleanup.php for instance), the first test will run. CLI assertions can use all features available for HTTP assertions, the same variables are available and you even define assertions for profile comparisons. Read more about this feature on the official documentation.
Happy profiling!