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)
上一篇 2022年7月12日 下午6:46
下一篇 2022年7月12日 下午6:46


相关推荐

  • PageRank算法详解

    PageRank算法详解PageRank 算法详解主要内容 PageRank 算法简介 PageRank 算法详解基本 PageRank 模型终止点问题陷阱问题解决终止点问题和陷阱问题 1 PageRank 算法简介 PageRank 网页排名 又称网页级别或佩奇排名 是一种根据网页间相互超链接进行网页排名的技术 以 Google 公司创办人拉里 佩奇 LarryPage 之姓来命名 Google 用它来体现网页的相关

    2026年3月17日
    2
  • 微信公众号是html页面吗,微信公众号网页开发

    微信公众号是html页面吗,微信公众号网页开发基本配置1.设置—公众号设置—功能设置—配置JS接口安全域名安全域名配置规则如下2.开发—基本配置开发者密码第一次使用需要重新设置记录开发者ID(AppID)开发者密码(AppSecret)后面会用到3.IP白名单配置推荐填写当前本地开发IP地址和服务器IP地址本地开发地址获取方式服务器IP地址(根据自己的服务器Ip地址自行填写)多个IP地址填写用回车隔开4重要的一步在:微信公众号-开发-接…

    2022年6月6日
    32
  • COFF文件的格式

    COFF文件的格式COFF 格式 nbsp nbsp nbsp nbsp nbsp COFF 通用对象文件格式 CommonObject 是一种很流行的对象文件格式 注意 这里不说它是 目标 文件 是为了和编译器产生的目标文件 o obj 相区别 因为这种格式不只用于目标文件 库文件 可执行文件也经常是这种格式 大家可能会经常使用 VC 吧 它所产生的目标文件 obj 就是这种格式 其

    2026年3月18日
    1
  • win10下使用vs2015编译支持xp系统的libcurl

    win10下使用vs2015编译支持xp系统的libcurl在我的一篇博客中写了编译libcurl的,那种方式编译的curl动态库在win7到win10上可以使用,但是在xp系统里就不能使用了,接下来讲解一种方法可以在xp系统里使用cur。1编译openssl由于在perl官网里提供的perl版本没有dmake,因此使用我提供的perl5.24带dmake的包,下载地址。安装好perl后,可以尝试使用ppminstalldmake命令来进行安装dmake模块,在我电脑里无法安装,因此直接使用dmake离线包。将dmake.exe所在目录添加到系统pat

    2022年7月12日
    19
  • 使用java随机生成验证码

    使用java随机生成验证码

    2021年7月10日
    106
  • portraiture mac智能磨皮滤镜

    portraiture mac智能磨皮滤镜portraiture3Mac版是一款MacOS平台基于原始肖像插件的核心技术和功能集的PS智能磨皮滤镜软件,portraituremac将您的皮肤修饰工作流程提升到更高的性能水平,结果质量和整体易用性。我们敢说,我们的portraiture滤镜插件将继续改变行业,实现几乎所有技能水平,在图像主题和生产挑战的范围内实现卓越的皮肤修饰,包括肖像,全身,团体拍摄,广告,时尚,美容,医疗和运动图像,没有与其他软件产品,插件或数字修饰技术相关的熟悉约束或学习曲线。portraituremac可以出色的完成磨

    2022年7月22日
    9

发表回复

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

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