Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 2f7e0e5

Browse files
baijunyaoWynnChen
authored andcommitted
Update writing-tests-for-phpunit.rst
1 parent a12e250 commit 2f7e0e5

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Composer
216216
217217
.. code-block:: bash
218218
219-
composer require --dev phpunit/phpunit ^6.5
219+
composer require --dev phpunit/phpunit ^|version|
220220
221221
.. _installation.optional-packages:
222222

src/writing-tests-for-phpunit.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
编写 PHPUnit 测试
77
=============
88

9-
:numref:`writing-tests-for-phpunit.examples.StackTest.php`展示了如何用 PHPUnit 编写测试来对 PHP 数组操作进行测试。本例介绍了用 PHPUnit 编写测试的基本惯例与步骤:
9+
:numref:`writing-tests-for-phpunit.examples.StackTest.php` 展示了如何用 PHPUnit 编写测试来对 PHP 数组操作进行测试。本例介绍了用 PHPUnit 编写测试的基本惯例与步骤:
1010

1111
#.
1212

@@ -24,7 +24,7 @@
2424

2525
#.
2626

27-
在测试方法内,类似于 ``assertEquals()``参见 :ref:`appendixes.assertions`这样的断言方法用来对实际值与预期值的匹配做出断言。
27+
在测试方法内,类似于 ``assertSame()`` (参见 :ref:`appendixes.assertions`) 这样的断言方法用来对实际值与预期值的匹配做出断言。
2828

2929
.. code-block:: php
3030
:caption: 用 PHPUnit 测试数组操作
@@ -73,7 +73,7 @@ PHPUnit支持对测试方法之间的显式依赖关系进行声明。这种依
7373

7474
消费者(consumer),是依赖于一个或多个生产者及其返回值的测试方法。
7575

76-
:numref:`writing-tests-for-phpunit.examples.StackTest2.php`展示了如何用 ``@depends`` 标注来表达测试方法之间的依赖关系。
76+
:numref:`writing-tests-for-phpunit.examples.StackTest2.php` 展示了如何用 ``@depends`` 标注来表达测试方法之间的依赖关系。
7777

7878
.. code-block:: php
7979
:caption: 用 ``@depends`` 标注来表达依赖关系
@@ -121,7 +121,7 @@ PHPUnit支持对测试方法之间的显式依赖关系进行声明。这种依
121121

122122
默认情况下,生产者所产生的返回值将“原样”传递给相应的消费者。这意味着,如果生产者返回的是一个对象,那么传递给消费者的将是一个指向此对象的引用。如果需要传递对象的副本而非引用,则应当用 @depends clone 替代 @depends。
123123

124-
为了快速定位缺陷,我们希望把注意力集中于相关的失败测试上。这就是为什么当某个测试所依赖的测试失败时,PHPUnit 会跳过这个测试。通过利用测试之间的依赖关系,缺陷定位得到了改进,如:numref:`writing-tests-for-phpunit.examples.DependencyFailureTest.php`中所示。
124+
为了快速定位缺陷,我们希望把注意力集中于相关的失败测试上。这就是为什么当某个测试所依赖的测试失败时,PHPUnit 会跳过这个测试。通过利用测试之间的依赖关系,缺陷定位得到了改进,如 :numref:`writing-tests-for-phpunit.examples.DependencyFailureTest.php` 中所示。
125125

126126
.. code-block:: php
127127
:caption: 利用测试之间的依赖关系
@@ -172,7 +172,7 @@ PHPUnit支持对测试方法之间的显式依赖关系进行声明。这种依
172172
173173
测试可以使用多个 ``@depends`` 标注。PHPUnit 不会更改测试的运行顺序,因此你需要自行保证某个测试所依赖的所有测试均出现于这个测试之前。
174174

175-
拥有多个 ``@depends`` 标注的测试,其第一个参数是第一个生产者提供的基境,第二个参数是第二个生产者提供的基境,以此类推。参见:numref:`writing-tests-for-phpunit.examples.MultipleDependencies.php`
175+
拥有多个 ``@depends`` 标注的测试,其第一个参数是第一个生产者提供的基境,第二个参数是第二个生产者提供的基境,以此类推。参见 :numref:`writing-tests-for-phpunit.examples.MultipleDependencies.php`
176176

177177
.. code-block:: php
178178
:caption: 有多重依赖的测试
@@ -225,7 +225,7 @@ PHPUnit支持对测试方法之间的显式依赖关系进行声明。这种依
225225
数据供给器
226226
#####
227227

228-
测试方法可以接受任意参数。这些参数由数据供给器方法(在 :numref:`writing-tests-for-phpunit.data-providers.examples.DataTest.php`中,是 ``additionProvider()`` 方法)提供。用 ``@dataProvider`` 标注来指定使用哪个数据供给器方法。
228+
测试方法可以接受任意参数。这些参数由数据供给器方法(在 :numref:`writing-tests-for-phpunit.data-providers.examples.DataTest.php` 中,是 ``additionProvider()`` 方法)提供。用 ``@dataProvider`` 标注来指定使用哪个数据供给器方法。
229229

230230
数据供给器方法必须声明为 ``public``,其返回值要么是一个数组,其每个元素也是数组;要么是一个实现了 ``Iterator`` 接口的对象,在对它进行迭代时每步产生一个数组。每个数组都是测试数据集的一部分,将以它的内容作为参数来调用测试方法。
231231

@@ -670,7 +670,7 @@ PHPUnit支持对测试方法之间的显式依赖关系进行声明。这种依
670670

671671
有时候,想要断言(比如说)某方法的运行过程中生成了预期的输出(例如,通过 ``echo`` 或 ``print``)。``PHPUnit\Framework\TestCase`` 类使用 PHP 的 `输出缓冲 <http://www.php.net/manual/en/ref.outcontrol.php>`_ 特性来为此提供必要的功能支持。
672672

673-
:numref:`writing-tests-for-phpunit.output.examples.OutputTest.php`展示了如何用 ``expectOutputString()`` 方法来设定所预期的输出。如果没有产生预期的输出,测试将计为失败。
673+
:numref:`writing-tests-for-phpunit.output.examples.OutputTest.php` 展示了如何用 ``expectOutputString()`` 方法来设定所预期的输出。如果没有产生预期的输出,测试将计为失败。
674674

675675
.. code-block:: php
676676
:caption: 对函数或方法的输出进行测试
@@ -717,7 +717,7 @@ PHPUnit支持对测试方法之间的显式依赖关系进行声明。这种依
717717
FAILURES!
718718
Tests: 2, Assertions: 2, Failures: 1.
719719
720-
:numref:`writing-tests-for-phpunit.output.tables.api`中列举了用于对输出进行测试的各种方法。
720+
:numref:`writing-tests-for-phpunit.output.tables.api` 中列举了用于对输出进行测试的各种方法。
721721

722722
.. rst-class:: table
723723
.. list-table:: 用于对输出进行测试的方法

0 commit comments

Comments
 (0)