writing.exchange is one of the many independent Mastodon servers you can use to participate in the fediverse.
A small, intentional community for poets, authors, and every kind of writer.

Administered by:

Server stats:

330
active users

#phpunit

0 posts0 participants0 posts today

Managed to get unit tests working in a pre-commit hook today - no more commits unless they pass the tests! Although every developer has to setup the hook manually because you can't easily put hooks into Git itself (there are hacky ways around this, e.g. by using post-install-cmd in Composer).

Nearly everything I work on is bespoke and legacy, so getting tests setup is a lot harder than with a new or modern project based on a framework.

A couple of years ago I wrote a #php script that mucks around with some system files. Because I didn't want to break my system while testing the code, I wrote some relatively tedious tests in #phpunit with mock objects, validating the parameters that were passed down to the filesystem.

It was a real pain in the butt, but I got the thing debugged without making a mess of my working environment.

Today I decided to add a new feature, and there's no way to express how much time having all that stuff set up saved. I copied a similar test, adapted it to the new feature, got it to pass tests, and deployed it without issue.

Coding a good test suite pays back over, and over, and over again.

I just found out that I can run `tidy -xml -indent --indent-attributes yes -m phpunit.xml.dist` to format a #phpunit configuration file. I love how PHPUnit can migrate its configuration files after a new release, but the new file has all attributes in one line, making them hard to read. Manually indenting files in 15+ repos after an update was a pain. Now, thanks to a 22-year old tool I can have automatic and consistent formatting.

Looking for #phpunit code coverage dark-themes, are you using it?

Did not find any native support from PHPunit's tools, just some drop-in custom.css files.

Found so far just 2 of them:
1. github.com/chriswpage/phpunit- (updated 2024)

2. github.com/Porthorian/phpunit- (updated 2022)

From my preliminary research: the coverage tool is using bootstrap v4, while a dark-mode was only introduced in v5.3.

I should not dig into that migration path, or should I? 😅

GitHubGitHub - chriswpage/phpunit-coverage-theme: Drop in css file for a dark phpunit coverage themeDrop in css file for a dark phpunit coverage theme - chriswpage/phpunit-coverage-theme
Replied in thread

#PHPUnit is developed with a focus on development environments and the command-line.

No specific testing or hardening with regard to using PHPUnit in an HTTP or web context or with untrusted input data is performed.

PHPUnit might also contain functionality that intentionally exposes internal application data for debugging purposes.

Replied in thread

#PHPUnit is a framework for writing as well as a command-line tool for running tests.

Writing and running tests is a development-time activity. There is no reason why PHPUnit should be installed on a webserver and/or in a production environment.

Replied in thread

The vendor directory managed by #Composer must not be publicly accessible. It must therefore be located outside the so-called document root. Should that not be possible then public access to that directory must be prohibited using the web server's configuration.

A dependency such as #PHPUnit, which is only required for working on the software but not for its operation, must not be present on a production system.