assertequals() php,assertEquals()

assertequals() php,assertEquals()assertEquals()assertEquals(mixed$expected,mixed$actual[,string$message=”])当两个变量$expected和$actual不相等时报告错误,错误讯息由$message指定。assertNotEquals()是与之相反的断言,接受相同的参数。assertAttributeEquals()和asser…

大家好,又见面了,我是你们的朋友全栈君。

assertEquals()

assertEquals(mixed $expected, mixed $actual[, string $message = ”])

当两个变量 $expected 和 $actual 不相等时报告错误,错误讯息由 $message 指定。

assertNotEquals() 是与之相反的断言,接受相同的参数。

assertAttributeEquals() 和 assertAttributeNotEquals() 是便捷包装(convenience wrapper),以某个类或对象的某个 public、protected 或 private 属性作为实际值来进行比较。

Example A.13. assertEquals() 的用法

<?php class EqualsTest extends PHPUnit_Framework_TestCase { public function testFailure() { $this->assertEquals(1, 0); } public function testFailure2() { $this->assertEquals(‘bar’, ‘baz’); } public function testFailure3() { $this->assertEquals(“foonbarnbazn”, “foonbahnbazn”); } } ?>

phpunit EqualsTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. FFF Time: 0 seconds, Memory: 5.25Mb There were 3 failures: 1) EqualsTest::testFailure Failed asserting that 0 matches expected 1. /home/sb/EqualsTest.php:6 2) EqualsTest::testFailure2 Failed asserting that two strings are equal. — Expected +++ Actual @@ @@ -‘bar’ +’baz’ /home/sb/EqualsTest.php:11 3) EqualsTest::testFailure3 Failed asserting that two strings are equal. — Expected +++ Actual @@ @@ ‘foo -bar +bah baz ‘ /home/sb/EqualsTest.php:16 FAILURES! Tests: 3, Assertions: 3, Failures: 3.

如果 $expected 和 $actual 是某些特定的类型,将使用更加专门的比较方式,参阅下文。

assertEquals(float $expected, float $actual[, string $message = ”, float $delta = 0])

当两个浮点数 $expected 和 $actual 之间的差值(的绝对值)大于 $delta 时报告错误,错误讯息由 $message 指定。

关于为什么 $delta 参数是必须的,请阅读《关于浮点运算,每一位计算机科学从业人员都应该知道的事实》。

Example A.14. 将assertEquals()用于浮点数时的用法

<?php class EqualsTest extends PHPUnit_Framework_TestCase { public function testSuccess() { $this->assertEquals(1.0, 1.1, ”, 0.2); } public function testFailure() { $this->assertEquals(1.0, 1.1); } } ?>

phpunit EqualsTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. .F Time: 0 seconds, Memory: 5.75Mb There was 1 failure: 1) EqualsTest::testFailure Failed asserting that 1.1 matches expected 1.0. /home/sb/EqualsTest.php:11 FAILURES! Tests: 2, Assertions: 2, Failures: 1.

assertEquals(DOMDocument $expected, DOMDocument $actual[, string $message = ”])

当 $expected 和 $actual 这两个 DOMDocument 对象所表示的 XML 文档对应的无注释规范形式不相同时报告错误,错误讯息由 $message 指定。

Example A.15. assertEquals()应用于 DOMDocument 对象时的用法

<?php class EqualsTest extends PHPUnit_Framework_TestCase { public function testFailure() { $expected = new DOMDocument; $expected->loadXML(”); $actual = new DOMDocument; $actual->loadXML(”); $this->assertEquals($expected, $actual); } } ?>

phpunit EqualsTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. F Time: 0 seconds, Memory: 5.00Mb There was 1 failure: 1) EqualsTest::testFailure Failed asserting that two DOM documents are equal. — Expected +++ Actual @@ @@ <?xml version=”1.0″?> – – – + + + /home/sb/EqualsTest.php:12 FAILURES! Tests: 1, Assertions: 1, Failures: 1.

assertEquals(object $expected, object $actual[, string $message = ”])

当 $expected 和 $actual 这两个对象的属性值不相等时报告错误,错误讯息由 $message 指定。

Example A.16. assertEquals()应用于对象时的用法

<?php class EqualsTest extends PHPUnit_Framework_TestCase { public function testFailure() { $expected = new stdClass; $expected->foo = ‘foo’; $expected->bar = ‘bar’; $actual = new stdClass; $actual->foo = ‘bar’; $actual->baz = ‘bar’; $this->assertEquals($expected, $actual); } } ?>

phpunit EqualsTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. F Time: 0 seconds, Memory: 5.25Mb There was 1 failure: 1) EqualsTest::testFailure Failed asserting that two objects are equal. — Expected +++ Actual @@ @@ stdClass Object ( – ‘foo’ => ‘foo’ – ‘bar’ => ‘bar’ + ‘foo’ => ‘bar’ + ‘baz’ => ‘bar’ ) /home/sb/EqualsTest.php:14 FAILURES! Tests: 1, Assertions: 1, Failures: 1.

assertEquals(array $expected, array $actual[, string $message = ”])

当 $expected 和 $actual 这两个数组不相等时报告错误,错误讯息由 $message 指定。

Example A.17. assertEquals() 应用于数组时的用法

<?php class EqualsTest extends PHPUnit_Framework_TestCase { public function testFailure() { $this->assertEquals(array(‘a’, ‘b’, ‘c’), array(‘a’, ‘c’, ‘d’)); } } ?>

phpunit EqualsTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. F Time: 0 seconds, Memory: 5.25Mb There was 1 failure: 1) EqualsTest::testFailure Failed asserting that two arrays are equal. — Expected +++ Actual @@ @@ Array ( 0 => ‘a’ – 1 => ‘b’ – 2 => ‘c’ + 1 => ‘c’ + 2 => ‘d’ ) /home/sb/EqualsTest.php:6 FAILURES! Tests: 1, Assertions: 1, Failures: 1.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/157874.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 内核态与用户态_linux内核态和用户态通信

    内核态与用户态_linux内核态和用户态通信1、高位地址:栈(存放着局部变量和函数参数等数据),向下生长   (可读可写可执行)2、           堆(给动态分配内存是使用),向上生长             (可读可写可执行)3、           数据段(保存全局数据和静态数据)                    (可读可写不可执行)4、低位地址:代码段(保存代码)

    2022年9月17日
    13
  • 牛逼plus的springboot+maven车牌识别开源系统

    牛逼plus的springboot+maven车牌识别开源系统

    2020年11月13日
    201
  • nonblock recvfrom

    nonblock recvfromif(-1==fcntl(iSocketfd,F_SETFL,O_NONBLOCK)){ printf(“fcntlsocketerror!\n”); return-1;}intiSocketLen=sizeof(structsockaddr_in);/*setrecvfromfromservertimeout*/structti

    2022年7月23日
    7
  • pycharm是java开发的吗_pycharmjupyter

    pycharm是java开发的吗_pycharmjupyterPycharm—编译器使用:虚拟环境与系统环境:就是包的区别。虚拟环境需要重新下包,但包不互相影响系统环境就是有下载过的所有包—通过切换本地—虚拟编译器即可切换环境本地:即python所在目录的python.exe程序–python最主要就是lib(第三方库群),python.exe编译器,pythonshell自带的IDLE,再加上个集成开发环境(pycharm)就齐了虚拟:v…

    2022年8月27日
    5
  • DDR中的ODT功能详解及波形对比[通俗易懂]

    DDR中的ODT功能详解及波形对比[通俗易懂]ODT(ondietermination)即为片内端接,就是将端接电阻放在了芯片内部,这个功能只有在DDR2以上的数据信号才有。而有了ODT功能,原本需要在PCB板上加串联电阻的数据信号就不需要再额外添加端接了,只需要芯片内部打开ODT的端接功能,且这个端接可调。以下就是ODT的端接情况,如图所示:当数据读操作的时候,主控芯片(CPU)读取内存颗粒的数据,此时主控为接收端,可根据需要选择是否打开ODT功能;当数据写操作的时候,主控芯片(CPU)将数据写入内存颗粒,此时颗粒为接收端,也可以根据需要

    2025年10月10日
    4
  • java老版手机游戏合集激活成功教程

    java老版手机游戏合集激活成功教程一、前言最近刚读完一本书:《Netty、Zookeeper、Redis并发实战》,个人觉得Netty部分是写得很不错的,读完之后又对Netty进行了一波很好的复习(之前用springboot+netty+zookeeper模仿dubbo做rpc框架,那时候是刚学netty后自己造的小轮子)。虽然对于Netty的使用已经比较熟悉了,而且还知道它的底层是基于JavaNIO做进一步的封装,使得并发性能和开发效率得到大大的提升。但是,对于同步阻塞、同步非阻塞、异步这

    2022年7月7日
    27

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号