Is there a method to assert that a string has a specific length in a PHPUnit TestCase
or do I have to test it manually using strlen?
assertCount does not work because it expects a iterable.
// This is how I currently do it
$this->assertEquals(10, strlen($str));
// This is how id like to do it
$this->assertLength(10, $str);
PHPUnit doesn't have a dedicated function for this, but you can just use:
$this->assertEquals($expectedLength, strlen($string));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With