您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertStringMatchesFormat
发布时间:2021-10-05 16:57:30编辑:雪饮阅读()
%e
:表示目录分隔符,例如在 Linux 系统中是/
。%s
:一个或多个除了换行符以外的任意字符(非空白字符或者空白字符)。%S
:零个或多个除了换行符以外的任意字符(非空白字符或者空白字符)。%a
:一个或多个包括换行符在内的任意字符(非空白字符或者空白字符)。%A
:零个或多个包括换行符在内的任意字符(非空白字符或者空白字符)。%w
:零个或多个空白字符。%i
:带符号整数值,例如+3142
、-3142
。%d
:无符号整数值,例如123456
。%x
:一个或多个十六进制字符。所谓十六进制字符,指的是在以下范围内的字符:0-9
、a-f
、A-F
。%f
:浮点数,例如3.142
、-3.142
、3.142E-10
、3.142e+10
。%c
:单个任意字符。%%
:原本的百分比字符:%
。
assertStringMatchesFormat断言主要是用format字符串格式化表达式例如%i则匹配一个数字即int型的值。
StringMatchesFormatTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class StringMatchesFormatTest extends TestCase
{
public function testFailure(): void
{
$this->assertStringMatchesFormat('%i', 'foo');
}
public function testTwo(): void
{
$this->assertStringMatchesFormat('%i', '1');
}
}
use PHPUnit\Framework\TestCase;
final class StringMatchesFormatTest extends TestCase
{
public function testFailure(): void
{
$this->assertStringMatchesFormat('%i', 'foo');
}
public function testTwo(): void
{
$this->assertStringMatchesFormat('%i', '1');
}
}
运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit -c C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\StringMatchesFormatTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 00:00.009, Memory: 6.00 MB
There was 1 failure:
1) StringMatchesFormatTest::testFailure
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
-%i
+foo
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\StringMatchesFormatTest.php:8
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
补充:
关于更多的占位符:
格式定义字符串中可以使用如下占位符:
关键字词:phpunit,assertStringMatchesFormat
相关文章
- phpunit断言-assertMatchesRegularExpression
- phpunit断言-assertObjectHasAttribute
- phpunit断言-assertNull
- phpunit断言-assertNan
- phpunit断言-assertLessThanOrEqual
- phpunit断言-assertLessThan
- phpunit断言-assertJsonStringEqualsJsonString
- phpunit断言-assertJsonStringEqualsJsonFile
- phpunit断言-assertJsonFileEqualsJsonFile
- phpunit断言-assertIsWritable