您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertSame-对象断言
发布时间:2021-10-05 20:25:32编辑:雪饮阅读()
对于assertSame断言上篇了解了,其是对值及其值的数据类型进行断言,有点相当于全等的概念。
那么它对于一个对象的断言则是断言对象的堆地址。不同地址,则是断言不成功的。
SameTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class SameTest extends TestCase
{
public function testFailure(): void
{
$this->assertSame(new stdClass, new stdClass);
}
public function testSuccess(): void
{
$a=new stdClass;
$b=$a;
$this->assertSame($a, $b);
}
}
use PHPUnit\Framework\TestCase;
final class SameTest extends TestCase
{
public function testFailure(): void
{
$this->assertSame(new stdClass, new stdClass);
}
public function testSuccess(): void
{
$a=new stdClass;
$b=$a;
$this->assertSame($a, $b);
}
}
运行结果:
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\SameTest.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) SameTest::testFailure
Failed asserting that two variables reference the same object.
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\SameTest.php:8
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
关键字词:phpunit,assertSame
相关文章
- phpunit断言-assertSame
- phpunit断言-assertStringMatchesFormatFile
- phpunit断言-assertStringMatchesFormat
- phpunit断言-assertMatchesRegularExpression
- phpunit断言-assertObjectHasAttribute
- phpunit断言-assertNull
- phpunit断言-assertNan
- phpunit断言-assertLessThanOrEqual
- phpunit断言-assertLessThan
- phpunit断言-assertJsonStringEqualsJsonString