`
shangjava
  • 浏览: 1233096 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

PHPUnit袖珍指南-第一章 简介

阅读更多

第一章 简介

很长时间里,我对“你什么时候会为PHPUnit写一个文档”这个问题的回答是:“你不需要PHPUnit文档,去读读JUnit文档或买一本Junit的书,试一试用PHPPHPUnit来重写JavaJunit的例子”。当我和O’Reilly德国办公室的Barbara WeissAlexandra Follenius这样说的时候,他们鼓励我想想是不是可以写一本书来作为PHPUnit的文档。

1.1 基本要求

本书的主题是PHPUnit,这是一个支持用PHP进行测试驱动开发的开放源代码框架。本书覆盖了PHPUnit 2.3,需要PHP5.1支持。当然,大部分例子在PHPUnit 2.02.2PHP5.0也都可以运行。本书的后半部分,“在PHP4中使用PHPUnit”一章中,覆盖了老式的,不再进一步积极发展的在PHP4中运行的PHPUnit

本书的读者需要对使用PHP5进行面向对象编程要很好的理解。建议德文读者读读我写的Professionelle Softwareentwicklung mit PHP 5一书,这是对使用PHP5进行面向对象编程的介绍。英文读者可以参考Andi Gutmans, Stig BakkenDerick Rethans合著的PHP 5 Power Programming

1.2 本书是自由发布的

本书可以在Creative Commons license版权公约下自由获得。访问http://www.phpunit.de/pocket_guide/你可以总是发现本书的最新版本。你根据自己的需要修改和重新发布。当然,相比你发布你自己的版本,我更推荐你发送反馈和更新给sb@sebastian-bergmann.de

1.3 本书的约定

下面是本书的一些书写约定:

斜体

表示新名词,URL,邮件地址,文件名,文件扩展名,路径名,目录和Unix应用程序

固定宽度字体

表示命令,选项,开关语句,变量,函数,类,名字空间,方法,模块,参数,值,对象,文件内容或命令输出。

固定宽度加重字体

表示需要读者逐字逐句输入的命令或文本内容。

固定宽度斜体

表示需要用读者自己的值替代的文本。

辅助信息

这是一个辅助信息,是建议或者普通注释。它包含了关于相关主题有用的辅助内容。

警告

这是一个提醒注意的警告或注释

1.4 如何联系我们

我们已经尽力测试和验证过本书的内容,但是你还是可能发现特性改变了,甚至有错误!

作为本书的读者,你可以通过发送反馈给我来帮助我们改进未来的版本。请告诉我们任何书中的错误,不精确,臭虫,误导、混淆语句或输入错误。

也请你让我们知道如果能让本书更有用。我们会慎重对待你的来信,并尽力在未来版本加以改进。你可以发信到如下地址:

O'Reilly Media, Inc.

<street w:st="on"><address w:st="on"><span lang="EN-US">1005 Gravenstein Highway North</span></address></street>

<place w:st="on"><city w:st="on"><span lang="EN-US">Sebastopol</span></city><span lang="EN-US">, <state w:st="on">CA</state><postalcode w:st="on">95472</postalcode></span></place>

(800) 998-9938 (in the <country-region w:st="on">U.S.</country-region> or <country-region w:st="on"><place w:st="on">Canada</place></country-region>)

(707) 829-0515 (international/local)

(707) 829-0104 (fax)

如果想问技术问题,或对本书发表评论,可以发送到bookquestions@oreilly.com

PHPUnit口袋书指南的网站列出了例子,勘误表和未来的版本计划。你可以在如下网址找到它们:

http://www.oreilly.com/catalog/phpunitpg

想要更多本书或其他书籍更多信息,请访问O’Reilly的网站:

http://www.oreilly.com

1.5 鸣谢

我要感谢Kent BeckErich Gamma发明了Junit给了我发明PHPUnit的灵感,我更要谢谢Kent Beck写了Junit口袋书一书,这使我有了写本书的冲动。同时我要感Allison Randal, Alexandra FolleniusBarbara Weiss,是他们在O’Reilly负责本书。

我要感谢Andi Gutmans, Zeev SuraskiMarcus Börger,是他们开发了PHP5的核心Zend Engine 2。我还有谢谢Derick Rethans,他开发了PHP扩展功能Xdebug,使得PHPUnit的代码覆盖率功能成为可能。最后,我还有谢谢Michiel Rook,他写了PhingPHPUnit任务。

--------------------------------------------------------------------------------------------------------------

原文:

Chapter 1. Introduction

For a very long time, my answer to the question, "When will you write documentation for PHPUnit?" has been, "You do not need documentation for PHPUnit. Just read the documentation for JUnit or buy a book on JUnit and adapt the code examples from Java™ and JUnit to PHP and PHPUnit." When I mentioned this to Barbara Weiss and Alexandra Follenius from the O'Reilly Germany office, they encouraged me to think it over and write a book that would serve as the documentation for PHPUnit.

1.1. Requirements

The topic of this book is PHPUnit, an open source framework for test-driven development with the PHP programming language. This book covers Version 2.3 of PHPUnit, which requires PHP 5.1. However, most of the examples should work with PHPUnit Versions 2.02.2, as well as PHP 5.0. The "PHPUnit for PHP 4" section, later in this book, covers the older, no longer actively developed version of PHPUnit for PHP 4.

The reader should have a good understanding of object-oriented programming with PHP 5. To German readers, I recommend my book Professionelle Softwareentwicklung mit PHP 5 as an introduction to object-oriented programming with PHP 5. A good English book on the subject is PHP 5 Power Programming by Andi Gutmans, Stig Bakken, and Derick Rethans (Prentice Hall PTR).

1.2. This Book Is Free

This book is available under the Creative Commons license. You will always find the latest version of this book at its web site: http://www.phpunit.de/pocket_guide/. You may distribute and make changes to this book however you wish. Of course, rather than distribute your own private version of the book, I would prefer you send feedback and patches to sb@sebastian-bergmann.de.

1.3. Conventions Used in This Book

The following is a list of the typographical conventions used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilities.

Constant width

Indicates commands, options, switches, variables, functions, classes, namespaces, methods, modules, parameters, values, objects, the contents of files, or the output from commands.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values.

You should pay special attention to notes set apart from the text with the following styles:

TIP

This is a tip, suggestion, or general note. It contains useful supplementary information about the topic at hand.

WARNING

This is a warning or note of caution.

1.4. How to Contact Us

We have tested and verified the information in this book to the best of our ability, but you may find that features have changed (or even that we have made mistakes!).

As a reader of this book, you can help us to improve future editions by sending us your feedback. Please let us know about any errors, inaccuracies, bugs, misleading or confusing statements, and typos that you find anywhere in this book.

Please also let us know what we can do to make this book more useful to you. We take your comments seriously and will try to incorporate reasonable suggestions into future editions. You can write to us at:

O'Reilly Media, Inc.

<street w:st="on"><address w:st="on"><span lang="EN-US"><font face="Times New Roman" size="3">1005 Gravenstein Highway North</font></span></address></street>

<place w:st="on"><font size="3"><font face="Times New Roman"><city w:st="on"><span lang="EN-US">Sebastopol</span></city><span lang="EN-US">, <state w:st="on">CA</state><postalcode w:st="on">95472</postalcode></span></font></font></place>

(800) 998-9938 (in the <country-region w:st="on">U.S.</country-region> or <country-region w:st="on"><place w:st="on">Canada</place></country-region>)

(707) 829-0515 (international/local)

(707) 829-0104 (fax)

To ask technical questions or to comment on the book, send email to:

bookquestions@oreilly.com

The web site for PHPUnit Pocket Guide lists examples, errata, and plans for future editions. You can find this page at:

http://www.oreilly.com/catalog/phpunitpg

For more information about this book and others, see the O'Reilly web site:

http://www.oreilly.com

1.5. Acknowledgments

I would like to thank Kent Beck and Erich Gamma for JUnit and for the inspiration to write PHPUnit. I would also like to thank Kent Beck for his JUnit Pocket Guide, which sparked the idea for this book. I would like to thank Allison Randal, Alexandra Follenius, and Barbara Weiss for sponsoring this book at O'Reilly.

I would like to thank Andi Gutmans, Zeev Suraski, and Marcus Börger for their work on the Zend Engine 2, the core of PHP 5. I would like to thank Derick Rethans for Xdebug, the PHP extension that makes PHPUnit's code-coverage functionality possible. Finally, I would like to thank Michiel Rook, who wrote the PHPUnit tasks for Phing.

分享到:
评论

相关推荐

    PHPUnit袖珍指南.doc

    PHPUnit袖珍指南.doc PHPUnit 单元测试 从环境配置到 段元详细介绍

    phpunit-clever-and-smart, 更智能的runner 测试.zip

    phpunit-clever-and-smart, 更智能的runner 测试 PHPUnit的智能测试 runner 任务通过在数据库中存储测试用例并按以下顺序在连续运行中重新排序测试来启用快速反馈周期:失败和错误迄今为止未记录的测试按执行时间( ...

    phpunit-mock-objects, PHPUnit的模拟对象库.zip

    phpunit-mock-objects, PHPUnit的模拟对象库 PHPUnit_MockObjectPHPUnit_MockObject 是PHPUnit默认的模拟对象库。要求PHP 5.6是必需的,但使用最新版本的PHP非常安装你可以使用 Composer 将这里库作为

    PHPUnit中文手册-PDF-5.1

    网上找到的文档都是比较老旧的了,在官网上找到了最新版的中文手册,觉得还不错,分享给大家。 附上来源地址:https://phpunit.de/documentation.html PHPUnit中文站:...PHPUnit官方站:https://phpunit.de/

    phpunit-pretty-result-printer:PHPUnit漂亮结果打印机-使您PHPUnit测试看起来漂亮!

    如果要从以前的版本升级,并且已在本地发布phpunit-printer.yml ,请确保将以下内容添加到选项部分 ... cd-printer-dont-format-classname : false ... 执行初始化脚本(可选) 以下步骤是可选的,但将为实现...

    Etsy的PHPUnit扩展phpunit-extensions.zip

    phpunit-extensions 是 Etsy 的 PHPUnit 扩展。 标签:phpunit

    ci-phpunit-test, 一种简单的使用 PHPUnit 3.x 语言的方法.zip

    ci-phpunit-test, 一种简单的使用 PHPUnit 3.x 语言的方法 ci-phpunit-test用于 CodeIgniter 3 。x 在 CodeIgniter 3. x. 中使用PHPUnit的简便方法你根本不需要修改CodeIgniter核心文件。你可以轻松编

    PHPUnit袖珍指南之PHPUnit的目的

    首先,让我们看一个具体的例子(例5),展示如何使用PHPUnit对数组操作进行测试。在这个例子中,我们创建了一个名为`ArrayTest`的类,它继承自`PHPUnit\Framework\TestCase`。这个基类提供了测试所需的基础设施。...

    PHPUnit袖珍指南之自动测试

    **PHPUnit自动测试详解** 在软件开发中,错误是难以避免的。优秀程序员的标志在于他们能够通过测试有效地发现和修复这些问题。尽早发现错误意味着更低的修复成本,这也是为什么仅在软件发布前进行测试往往会导致...

    phpunit-coverage-check:检查phpunit代码覆盖率的工具

    PHPUnit覆盖率检查工具安装composer require --dev iro88/phpunit-coverage-check用法示例根据文本输出检查 # using streamset -o pipefail && phpunit | phpunit-coverage-check --format=text 85.00# ...with ...

    PHPUnit袖珍指南之装置器

    本文主要关注的是PHPUnit中的装置器(Fixture)概念,它是测试中一个至关重要的部分。 装置器在测试中扮演着初始化和清理环境的角色,确保每次测试都在一个已知的、一致的状态下开始和结束。这种状态通常涉及到创建...

    phpunit-json-assertions:PHPUnit的JSON断言(包括JSON模式)

    phpunit-json-assertions PHPUnit的JSON断言包含特征/方法,以帮助通过各种方法验证JSON数据。 特征 通过JSON模式验证JSON数据 描述您现有的数据格式 清晰的,人为和机器可读的文档 完整的结构验证,对 自动化测试 ...

    Laravel开发-phpunit-selenium-webdriver

    Laravel提供了一个名为`Laravel\Dusk`的组件,它整合了PHPUnit和Selenium WebDriver,让浏览器自动化测试变得更为便捷。Dusk提供了一套Fluent API,使测试代码更易于理解和编写。 在Laravel项目中配置Selenium ...

    phpunit-github-actions-printer

    phpunit-github-actions-printer 在有一种零配置方式来实现这一这是一台PHPUnit打印机,使用GitHub Actions的::error和::warning功能为失败的测试运行添加注释。 与上述内容的主要区别在于,它支持添加除错误之外的...

    phpunit-pretty-print::white_heavy_check_mark:使您PHPUnit输出漂亮

    phpunit-pretty-print :white_heavy_check_mark: 使您PHPUnit输出漂亮 安装 composer require sempro/phpunit-pretty-print --dev 该软件包需要&gt;=7.0.0PHPUnit。 如果您在6.x运行,请使用1.0.3版。 如果您在9.x...

    phpunit-runner-teamcity:TeamCity 的 PHPUnit 运行程序

    `phpunit-runner-teamcity` 是一个专门为 TeamCity 设计的扩展工具,用于更好地集成和报告 PHPUnit 单元测试的结果。这个库的主要目的是在执行 PHP 的单元测试时,能够与 JetBrains 的持续集成和部署服务器 TeamCity...

    phpunit-json-assert:JSON文档PHPUnit断言

    $ composer require --dev helmich/phpunit-json-assert 兼容性 该库有多个发行分支,每个分支都与PHPUnit和PHP的不同发行版兼容。 下表应该提供简单的概述: “ JSON断言”版本 PHPUnit 4 PHPUnit 5 PHPUnit 6 ...

    phpunit-snapshot-assertions:一种无需编写实际测试用例即可进行测试的方法

    用PHPUnit进行快照测试 快照测试是一种无需编写实际测试用例即可进行测试的方法use Spatie \ Snapshots \ MatchesSnapshots ;class OrderTest{ use MatchesSnapshots ; public function test_it_casts_to_json () { ...

    phpunit-arraysubset-asserts:提供assertArraySubset以在PHPunit中使用

    composer require --dev dms/phpunit-arraysubset-asserts :light_bulb: 在PHP 5.4上,可以安全地要求该软件包与PHPUnit 4.8.36 / 5.7.21一起使用。 当PHPUnit assertArraySubset()方法本身可用时(PHPUnit 4.x-8....

Global site tag (gtag.js) - Google Analytics