Skip to content

Commit e764e4e

Browse files
authored
Merge branch 'sebastianbergmann:master' into master
2 parents 85e74aa + 6f504c7 commit e764e4e

6 files changed

+58
-21
lines changed

src/annotations.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ The ``@testdox`` annotation can be applied to both test classes and test methods
684684
of the ``@test`` annotation.
685685

686686
When using the ``@testdox`` annotation at method level with a ``@dataProvider`` you may use the method parameters as placeholders in your alternative description.
687+
``$_dataName`` is available in addition to use the actual name of the current data. That would be ``data set 1`` up to 4 in below example.
687688

688689
.. code-block:: php
689690
@@ -699,10 +700,10 @@ When using the ``@testdox`` annotation at method level with a ``@dataProvider``
699700
public function additionProvider()
700701
{
701702
return [
702-
[0, 0, 0],
703-
[0, 1, 1],
704-
[1, 0, 1],
705-
[1, 1, 3]
703+
'data set 1' => [0, 0, 0],
704+
'data set 2' => [0, 1, 1],
705+
'data set 3' => [1, 0, 1],
706+
'data set 4' => [1, 1, 3]
706707
];
707708
}
708709

src/code-coverage-analysis.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,20 @@ This can either be done using the ``--coverage-filter``
100100
:ref:`command line <textui.clioptions>` option or via the
101101
configuration file (see :ref:`appendixes.configuration.coverage.include`).
102102

103-
The ``includeUncoveredFilesInCodeCoverageReport`` and ``processUncoveredFilesForCodeCoverageReport`` configuration settings are available to configure how the filter is used:
103+
The ``includeUncoveredFiles`` and ``processUncoveredFiles`` configuration settings are available to configure how the filter is used:
104104

105-
- ``includeUncoveredFilesInCodeCoverageReport="false"`` means that only files that have at least one line of executed code are included in the code coverage report
105+
- ``includeUncoveredFiles="false"`` means that only files that have at least one line of executed code are included in the code coverage report
106106

107-
- ``includeUncoveredFilesInCodeCoverageReport="true"`` (default) means that all files are included in the code coverage report even if not a single line of code of such a file is executed
107+
- ``includeUncoveredFiles="true"`` (default) means that all files are included in the code coverage report even if not a single line of code of such a file is executed
108108

109-
- ``processUncoveredFilesForCodeCoverageReport="false"`` (default) means that a file that has no executed lines of code will be added to the code coverage report (if ``includeUncoveredFilesInCodeCoverageReport="true"`` is set) but it will not be loaded by PHPUnit and it will therefore not be analysed for correct executable lines of code information
109+
- ``processUncoveredFiles="false"`` (default) means that a file that has no executed lines of code will be added to the code coverage report (if ``includeUncoveredFiles="true"`` is set) but it will not be loaded by PHPUnit and it will therefore not be analysed for correct executable lines of code information
110110

111-
- ``processUncoveredFilesForCodeCoverageReport="true"`` means that a file that has no executed lines of code will be loaded by PHPUnit so that it can be analysed for correct executable lines of code information
111+
- ``processUncoveredFiles="true"`` means that a file that has no executed lines of code will be loaded by PHPUnit so that it can be analysed for correct executable lines of code information
112112

113113
.. admonition:: Note
114114

115115
Please note that the loading of sourcecode files that is performed when
116-
``processUncoveredFilesForCodeCoverageReport="true"`` is set can
116+
``processUncoveredFiles="true"`` is set can
117117
cause problems when a sourcecode file contains code outside the scope of
118118
a class or function, for instance.
119119

src/extending-phpunit.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ definition to the extension class:
174174
175175
protected $config_value_2 = 0;
176176
177-
public function __construct(string $value1 = '', int $value2 = 0)
177+
public function __construct(string $config_value_1 = '', int $config_value_2 = 0)
178178
{
179-
$this->config_value_1 = $config_1;
180-
$this->config_value_2 = $config_2;
179+
$this->config_value_1 = $config_value_1;
180+
$this->config_value_2 = $config_value_2;
181181
}
182182
183183
public function executeBeforeFirstTest(): void

src/test-doubles.rst

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,32 @@ the same best practice defaults used by ``createStub()``.
182182
}
183183
184184
In the examples so far we have been returning simple values using
185-
``willReturn($value)``. This short syntax is the same as
186-
``will($this->returnValue($value))``. We can use variations
187-
on this longer syntax to achieve more complex stubbing behaviour.
185+
``willReturn($value)`` – a short syntax for convenience. :numref:`test-doubles.stubs.shorthands` shows the
186+
available stubbing short hands alongside their longer counterparts.
187+
188+
.. rst-class:: table
189+
.. list-table:: Stubbing short hands
190+
:name: test-doubles.stubs.shorthands
191+
:header-rows: 1
192+
193+
* - short hand
194+
- longer syntax
195+
* - ``willReturn($value)``
196+
- ``will($this->returnValue($value))``
197+
* - ``willReturnArgument($argumentIndex)``
198+
- ``will($this->returnArgument($argumentIndex))``
199+
* - ``willReturnCallback($callback)``
200+
- ``will($this->returnCallback($callback))``
201+
* - ``willReturnMap($valueMap)``
202+
- ``will($this->returnValueMap($valueMap))``
203+
* - ``willReturnOnConsecutiveCalls($value1, $value2)``
204+
- ``will($this->onConsecutiveCalls($value1, $value2))``
205+
* - ``willReturnSelf()``
206+
- ``will($this->returnSelf())``
207+
* - ``willThrowException($exception)``
208+
- ``will($this->throwException($exception))``
209+
210+
We can use variations on this longer syntax to achieve more complex stubbing behaviour.
188211

189212
Sometimes you want to return one of the arguments of a method call
190213
(unchanged) as the result of a stubbed method call.
@@ -587,7 +610,7 @@ method being mocked, like in ``with()``.
587610
public function testFunctionCalledTwoTimesWithSpecificArguments(): void
588611
{
589612
$mock = $this->getMockBuilder(stdClass::class)
590-
->setMethods(['set'])
613+
->addMethods(['set'])
591614
->getMock();
592615
593616
$mock->expects($this->exactly(2))
@@ -658,7 +681,7 @@ argument passes verification and ``false`` otherwise.
658681
$expectedObject = new stdClass;
659682
660683
$mock = $this->getMockBuilder(stdClass::class)
661-
->setMethods(['foo'])
684+
->addMethods(['foo'])
662685
->getMock();
663686
664687
$mock->expects($this->once())
@@ -733,11 +756,15 @@ Here is a list of methods provided by the Mock Builder:
733756

734757
-
735758

736-
``setMethods(array $methods)`` can be called on the Mock Builder object to specify the methods that are to be replaced with a configurable test double. The behavior of the other methods is not changed. If you call ``setMethods(null)``, then no methods will be replaced.
759+
``onlyMethods(array $methods)`` can be called on the Mock Builder object to specify the methods that are to be replaced with a configurable test double. The behavior of the other methods is not changed. Each method must exist in the given mock class.
760+
761+
-
762+
763+
``addMethods(array $methods)`` can be called on the Mock Builder object to specify the methods that don't exist (yet) in the given mock class. The behavior of the other methods remains the same.
737764

738765
-
739766

740-
``setMethodsExcept(array $methods)`` can be called on the Mock Builder object to specify the methods that will not be replaced with a configurable test double while replacing all other public methods. This works inverse to ``setMethods()``.
767+
``setMethodsExcept(array $methods)`` can be called on the Mock Builder object to specify the methods that will not be replaced with a configurable test double while replacing all other public methods. This works inverse to ``onlyMethods()``.
741768

742769
-
743770

src/textui.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ the following code:
303303
--filter 'TestNamespace\\TestCaseClass::testMethod'
304304
--filter 'TestNamespace\\TestCaseClass'
305305
--filter TestNamespace
306-
--filter TestCaseClase
306+
--filter TestCaseClass
307307
--filter testMethod
308308
--filter '/::testMethod .*"my named data"/'
309309
--filter '/::testMethod .*#5$/'

src/writing-tests-for-phpunit.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ Output will be more verbose as it'll contain that name of a dataset that breaks
438438
rewind($this->file);
439439
440440
$this->current = fgetcsv($this->file);
441+
442+
if (is_array($row)) {
443+
$row = array_map('intval', $row);
444+
}
445+
441446
$this->key = 0;
442447
}
443448
@@ -460,6 +465,10 @@ Output will be more verbose as it'll contain that name of a dataset that breaks
460465
{
461466
$this->current = fgetcsv($this->file);
462467
468+
if (is_array($row)) {
469+
$row = array_map('intval', $row);
470+
}
471+
463472
$this->key++;
464473
}
465474
}

0 commit comments

Comments
 (0)