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


相关推荐

  • Hdu1396「建议收藏」

    Hdu1396「建议收藏」//CountingTriangles/*顶角朝上的三角形:a[i]=a[i-1]+c(i+1,2)(从底边任选两点为正三角形底边)顶角朝下的三角形:b[i]=b[i-1]+c((i+1)/2,2)+c((i+2)/2,2)(因为偶数边长的正三角形和其边长一半的反三角形存在着对应关系,所以将底边所有的点分为两类:奇数和偶数点;再在相应的奇数…

    2022年8月12日
  • springboot到底是什么_Springboot注解

    springboot到底是什么_Springboot注解SpringBoot是干哈的介绍:springboot是由Pivotal团队提供的全新框架。spring的出现是为了解决企业级开发应用的复杂性,spring的通过注册bean的方式来管理类,但是随着业务的增加,使用xml配置bean的方式也显得相当繁琐,所以springboot就是为了解决spring配置繁琐的问题而诞生的,并且近几年来非常流行开启我的第一个HelloSpringBoot!开启方式根据https://start.spring.io网址创建一个springboot项目

    2022年9月25日
  • 树莓派4B设置USB启动

    树莓派4B设置USB启动千呼万唤始出来!官方在2020-05-15发布了一个4B的beta版EEPROM固件更新,这次更新终于增加了期待已久的USB引导功能,今天这个教程就来讲一下如何使用USB而脱离SD卡启动树莓派4B。

    2022年5月18日
  • 10.20卸载tensorflow2.0,安装tensorflow1.14.0

    10.20卸载tensorflow2.0,安装tensorflow1.14.0这里写自定义目录标题卸载tensorflow2.0安装1.14.0卸载tensorflow2.0安装1.14.0已安装python版本3.8.5,最开始误按装了tensorflow2.0,发现2.0和1.0版本语句不兼容,解决办法:tensorflow版本问题(1版本和2版本语句不兼容)当我们在tensorflow2.0版本上写的语句是1.0的格式时,可能会报错。这时只修改两条语句,就可以覆盖全部语句,不需要再担心。下面展示一些内联代码片。//Acodeblockvarfoo=

    2022年6月22日
  • “请在微信客户端打开链接”解决方案[通俗易懂]

    “请在微信客户端打开链接”解决方案[通俗易懂]1、“请在微信客户端打开链接”解决方案https://blog.csdn.net/weixin_41190571/article/details/829908392、微信调试工具无法点击授权按钮https://blog.csdn.net/Call_me_small_pure/article/details/801013073、微信web开发工具https://mp.weixin.qq.c…

    2022年5月6日
  • python 面向对象(进阶篇)

    python 面向对象(进阶篇)上一篇《Python面向对象(初级篇)》文章介绍了面向对象基本知识:面向对象是一种编程方式,此编程方式的实现是基于对类和对象的使用类是一个模板,模板中包装了多个“函数”供使用(可以讲多函数

    2022年7月5日

发表回复

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

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