@mallory_cormier
PHPUnit has a wide range of built-in assertions for strings. Here are some of the commonly used ones:
- assertEquals($expected, $actual): Asserts that two strings are equal.
Example: $this->assertEquals("Hello", $result);
- assertNotEquals($expected, $actual): Asserts that two strings are not equal.
Example: $this->assertNotEquals("Hello", $result);
- assertStringContainsString($needle, $haystack): Asserts that a string contains another substring.
Example: $this->assertStringContainsString("substring", $string);
- assertStringNotContainsString($needle, $haystack): Asserts that a string does not contain another substring.
Example: $this->assertStringNotContainsString("substring", $string);
- assertStringMatchesFormat($format, $string): Asserts that a string matches a given format (using sprintf syntax).
Example: $this->assertStringMatchesFormat("Hello, %s!", $string);
- assertStringStartsWith($prefix, $string): Asserts that a string starts with a given prefix.
Example: $this->assertStringStartsWith("Hello", $string);
- assertStringEndsWith($suffix, $string): Asserts that a string ends with a given suffix.
Example: $this->assertStringEndsWith("World", $string);
- assertRegExp($pattern, $string): Asserts that a string matches a regular expression.
Example: $this->assertRegExp("/d{4}-d{2}-d{2}/", $dateString);
These are just a few of the many assertions available for strings in PHPUnit.