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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • js操作DropDownList大全

    js操作DropDownList大全一:js设置DropDownList选中某项 1.根据Value值设置选中某项   例子如下: HTML代码: 选项0选项1  JS代码:document.getElementById(“ddlFolder”).value=”0″;//0为你要选中的项的value  2.根据Text值设置选中某项

    2022年10月16日
    3
  • 手机的屏幕分辨率_手机屏幕分辨率尺寸

    手机的屏幕分辨率_手机屏幕分辨率尺寸  什么是分辨率?说白了,分辫率高,屏幕显示就更清晰、更细腻。分辨率不高,屏幕显示就会有颗粒感,粗糙感。一句话:分辨率是屏幕显示清晰度的一个指标。现在手机常用的分辫率有:128*160、176*220、240*320。128*160多用在低档的手机。中档的手机一般分辨率为176*220。中高档手机分辨率多为:240*320。夏普现在有一款手机分辨率达到了480*640。比电脑显示屏还清晰

    2022年8月13日
    12
  • Unity3D中Isometric Tilemap功能实践「建议收藏」

    Unity3D中Isometric Tilemap功能实践「建议收藏」前言最近出于兴趣想自己做一个2D的游戏,因为有着C的基础,所以决定使用Unity3D来做。之前对于Unity3D其实了解不多,不过看了一些Unity3D的视频和官方文档后,暂时做起来也没遇到什么

    2022年8月6日
    5
  • idea2022激活码-激活码分享

    (idea2022激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.htmlS32PGH0SQB-eyJsaWNlbnNlSW…

    2022年3月22日
    292
  • Clip Converter – 视频在线下载方法

    Clip Converter – 视频在线下载方法ClipConverter-视频在线下载方法YTtoMP4&MP3Converter!1.VideoURLtoDownloadhttps://www.clipconverter.cc/2.Continue3.Start

    2022年7月14日
    44
  • python画等边三角形_四边形的画法

    python画等边三角形_四边形的画法python是编程语言,学习它只是因为要搞深度学习,其实语言类只要精通一种即可,但一定是精通,像我就是啥都知道,啥都不精,到最终一事无成。在学Python的时候,无意间看到网上有小游戏开发,于是乎就想自己调试下。第一个接触的例程是画国旗的。画国旗必然要画框,画框也就是画四边形,要画五角星,而五角星就是也是由三角形组成的,因此画一面很完美的五星红旗,则基础需要画四边形和三角形。OK,让我们一起来玩

    2026年1月29日
    5

发表回复

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

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