r/PHPhelp • u/Spiritual_Cycle_3263 • Jun 16 '26
Writing tests with PHPUnit 12+
I'm struggling to figure out when to write tests, what to test, and also how and when to do integration tests.
Let's say I have a class that returns a hard-coded string. Is this something you would test, why or why not?
<?php
declare(strict_types=1);
class Foo
{
public function name(): string
{
return 'Reddit';
}
}Let's say your class essentially wraps a third party library, would this be mainly integration testing? And do you use the same class name for Integration as you do with Unit tests, just in different folders?, ie /tests/Integration/S3StorageTest.php?
<?php
declare(strict_types=1);
use Aws\S3\S3Client;
class S3Storage
{
public function put(string $key, mixed $content): void
{
$this->s3->putObject([]);
}
public function delete(string $key): void
{
$this->s3->deleteObject([]);
}
}
0
Upvotes
View all comments
Show parent comment
1
u/Spiritual_Cycle_3263 Jun 18 '26
In the case of Foo class, if you use typed return, testing for a string value seems redundant to me, but if someone drops the return type, then it loses the safety of what a test would catch. So is it more important that to test that it returns a string type than the value, ie 'Reddit'?