123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Bridge\PhpUnit\Legacy;
- use PHPUnit\Framework\Constraint\IsEqual;
- use PHPUnit\Framework\Constraint\LogicalNot;
- use PHPUnit\Framework\Constraint\StringContains;
- use PHPUnit\Framework\Constraint\TraversableContains;
- /**
- * This trait is @internal.
- */
- trait PolyfillAssertTrait
- {
- /**
- * @param float $delta
- * @param string $message
- *
- * @return void
- */
- public static function assertEqualsWithDelta($expected, $actual, $delta, $message = '')
- {
- $constraint = new IsEqual($expected, $delta);
- static::assertThat($actual, $constraint, $message);
- }
- /**
- * @param iterable $haystack
- * @param string $message
- *
- * @return void
- */
- public static function assertContainsEquals($needle, $haystack, $message = '')
- {
- $constraint = new TraversableContains($needle, false, false);
- static::assertThat($haystack, $constraint, $message);
- }
- /**
- * @param iterable $haystack
- * @param string $message
- *
- * @return void
- */
- public static function assertNotContainsEquals($needle, $haystack, $message = '')
- {
- $constraint = new LogicalNot(new TraversableContains($needle, false, false));
- static::assertThat($haystack, $constraint, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsArray($actual, $message = '')
- {
- static::assertInternalType('array', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsBool($actual, $message = '')
- {
- static::assertInternalType('bool', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsFloat($actual, $message = '')
- {
- static::assertInternalType('float', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsInt($actual, $message = '')
- {
- static::assertInternalType('int', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsNumeric($actual, $message = '')
- {
- static::assertInternalType('numeric', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsObject($actual, $message = '')
- {
- static::assertInternalType('object', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsResource($actual, $message = '')
- {
- static::assertInternalType('resource', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsString($actual, $message = '')
- {
- static::assertInternalType('string', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsScalar($actual, $message = '')
- {
- static::assertInternalType('scalar', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsCallable($actual, $message = '')
- {
- static::assertInternalType('callable', $actual, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertIsIterable($actual, $message = '')
- {
- static::assertInternalType('iterable', $actual, $message);
- }
- /**
- * @param string $needle
- * @param string $haystack
- * @param string $message
- *
- * @return void
- */
- public static function assertStringContainsString($needle, $haystack, $message = '')
- {
- $constraint = new StringContains($needle, false);
- static::assertThat($haystack, $constraint, $message);
- }
- /**
- * @param string $needle
- * @param string $haystack
- * @param string $message
- *
- * @return void
- */
- public static function assertStringContainsStringIgnoringCase($needle, $haystack, $message = '')
- {
- $constraint = new StringContains($needle, true);
- static::assertThat($haystack, $constraint, $message);
- }
- /**
- * @param string $needle
- * @param string $haystack
- * @param string $message
- *
- * @return void
- */
- public static function assertStringNotContainsString($needle, $haystack, $message = '')
- {
- $constraint = new LogicalNot(new StringContains($needle, false));
- static::assertThat($haystack, $constraint, $message);
- }
- /**
- * @param string $needle
- * @param string $haystack
- * @param string $message
- *
- * @return void
- */
- public static function assertStringNotContainsStringIgnoringCase($needle, $haystack, $message = '')
- {
- $constraint = new LogicalNot(new StringContains($needle, true));
- static::assertThat($haystack, $constraint, $message);
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertFinite($actual, $message = '')
- {
- static::assertInternalType('float', $actual, $message);
- static::assertTrue(is_finite($actual), $message ?: "Failed asserting that $actual is finite.");
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertInfinite($actual, $message = '')
- {
- static::assertInternalType('float', $actual, $message);
- static::assertTrue(is_infinite($actual), $message ?: "Failed asserting that $actual is infinite.");
- }
- /**
- * @param string $message
- *
- * @return void
- */
- public static function assertNan($actual, $message = '')
- {
- static::assertInternalType('float', $actual, $message);
- static::assertTrue(is_nan($actual), $message ?: "Failed asserting that $actual is nan.");
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertIsReadable($filename, $message = '')
- {
- static::assertInternalType('string', $filename, $message);
- static::assertTrue(is_readable($filename), $message ?: "Failed asserting that $filename is readable.");
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertNotIsReadable($filename, $message = '')
- {
- static::assertInternalType('string', $filename, $message);
- static::assertFalse(is_readable($filename), $message ?: "Failed asserting that $filename is not readable.");
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertIsNotReadable($filename, $message = '')
- {
- static::assertNotIsReadable($filename, $message);
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertIsWritable($filename, $message = '')
- {
- static::assertInternalType('string', $filename, $message);
- static::assertTrue(is_writable($filename), $message ?: "Failed asserting that $filename is writable.");
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertNotIsWritable($filename, $message = '')
- {
- static::assertInternalType('string', $filename, $message);
- static::assertFalse(is_writable($filename), $message ?: "Failed asserting that $filename is not writable.");
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertIsNotWritable($filename, $message = '')
- {
- static::assertNotIsWritable($filename, $message);
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryExists($directory, $message = '')
- {
- static::assertInternalType('string', $directory, $message);
- static::assertTrue(is_dir($directory), $message ?: "Failed asserting that $directory exists.");
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryNotExists($directory, $message = '')
- {
- static::assertInternalType('string', $directory, $message);
- static::assertFalse(is_dir($directory), $message ?: "Failed asserting that $directory does not exist.");
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryDoesNotExist($directory, $message = '')
- {
- static::assertDirectoryNotExists($directory, $message);
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryIsReadable($directory, $message = '')
- {
- static::assertDirectoryExists($directory, $message);
- static::assertIsReadable($directory, $message);
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryNotIsReadable($directory, $message = '')
- {
- static::assertDirectoryExists($directory, $message);
- static::assertNotIsReadable($directory, $message);
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryIsNotReadable($directory, $message = '')
- {
- static::assertDirectoryNotIsReadable($directory, $message);
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryIsWritable($directory, $message = '')
- {
- static::assertDirectoryExists($directory, $message);
- static::assertIsWritable($directory, $message);
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryNotIsWritable($directory, $message = '')
- {
- static::assertDirectoryExists($directory, $message);
- static::assertNotIsWritable($directory, $message);
- }
- /**
- * @param string $directory
- * @param string $message
- *
- * @return void
- */
- public static function assertDirectoryIsNotWritable($directory, $message = '')
- {
- static::assertDirectoryNotIsWritable($directory, $message);
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileExists($filename, $message = '')
- {
- static::assertInternalType('string', $filename, $message);
- static::assertTrue(file_exists($filename), $message ?: "Failed asserting that $filename exists.");
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileNotExists($filename, $message = '')
- {
- static::assertInternalType('string', $filename, $message);
- static::assertFalse(file_exists($filename), $message ?: "Failed asserting that $filename does not exist.");
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileDoesNotExist($filename, $message = '')
- {
- static::assertFileNotExists($filename, $message);
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileIsReadable($filename, $message = '')
- {
- static::assertFileExists($filename, $message);
- static::assertIsReadable($filename, $message);
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileNotIsReadable($filename, $message = '')
- {
- static::assertFileExists($filename, $message);
- static::assertNotIsReadable($filename, $message);
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileIsNotReadable($filename, $message = '')
- {
- static::assertFileNotIsReadable($filename, $message);
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileIsWritable($filename, $message = '')
- {
- static::assertFileExists($filename, $message);
- static::assertIsWritable($filename, $message);
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileNotIsWritable($filename, $message = '')
- {
- static::assertFileExists($filename, $message);
- static::assertNotIsWritable($filename, $message);
- }
- /**
- * @param string $filename
- * @param string $message
- *
- * @return void
- */
- public static function assertFileIsNotWritable($filename, $message = '')
- {
- static::assertFileNotIsWritable($filename, $message);
- }
- /**
- * @param string $pattern
- * @param string $string
- * @param string $message
- *
- * @return void
- */
- public static function assertMatchesRegularExpression($pattern, $string, $message = '')
- {
- static::assertRegExp($pattern, $string, $message);
- }
- /**
- * @param string $pattern
- * @param string $string
- * @param string $message
- *
- * @return void
- */
- public static function assertDoesNotMatchRegularExpression($pattern, $string, $message = '')
- {
- static::assertNotRegExp($pattern, $string, $message);
- }
- }
|