Skip to content

Commit fe30fe2

Browse files
committed
docs: small improvements
1 parent 75d4ed4 commit fe30fe2

6 files changed

Lines changed: 27 additions & 14 deletions

File tree

user_guide_src/source/testing/overview.rst

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Testing
33
#######
44

55
CodeIgniter has been built to make testing both the framework and your application as simple as possible.
6-
Support for ``PHPUnit`` is built in, and the framework provides a number of convenient
6+
Support for `PHPUnit <https://phpunit.de/>`__ is built in, and the framework provides a number of convenient
77
helper methods to make testing every aspect of your application as painless as possible.
88

99
.. contents::
1010
:local:
11-
:depth: 2
11+
:depth: 3
1212

1313
*************
1414
System Set Up
@@ -35,7 +35,11 @@ application and system directories) type the following from the command line::
3535
This will install the correct version for your current PHP version. Once that is done, you can run all of the
3636
tests for this project by typing::
3737

38-
> ./vendor/bin/phpunit
38+
> vendor/bin/phpunit
39+
40+
If you are using Windows, use the following command::
41+
42+
> vendor\bin\phpunit
3943

4044
Phar
4145
----
@@ -144,8 +148,8 @@ Ensure that a header or cookie was actually emitted:
144148

145149
.. literalinclude:: overview/009.php
146150

147-
Note: the test case with this should be `run as a separate process
148-
in PHPunit <https://phpunit.readthedocs.io/en/9.5/annotations.html#runinseparateprocess>`_.
151+
.. note:: the test case with this should be `run as a separate process
152+
in PHPunit <https://phpunit.readthedocs.io/en/9.5/annotations.html#runinseparateprocess>`_.
149153

150154
assertHeaderNotEmitted($header, $ignoreCase = false)
151155
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -154,8 +158,8 @@ Ensure that a header or cookie was not emitted:
154158

155159
.. literalinclude:: overview/010.php
156160

157-
Note: the test case with this should be `run as a separate process
158-
in PHPunit <https://phpunit.readthedocs.io/en/9.5/annotations.html#runinseparateprocess>`_.
161+
.. note:: the test case with this should be `run as a separate process
162+
in PHPunit <https://phpunit.readthedocs.io/en/9.5/annotations.html#runinseparateprocess>`_.
159163

160164
assertCloseEnough($expected, $actual, $message = '', $tolerance = 1)
161165
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -215,8 +219,8 @@ your tests to only the code in question, while simulating various responses from
215219
true when testing controllers and other integration testing. The **Services** class provides the following methods
216220
to simplify this.
217221

218-
injectMock()
219-
------------
222+
Services::injectMock()
223+
----------------------
220224

221225
This method allows you to define the exact instance that will be returned by the Services class. You can use this to
222226
set properties of a service so that it behaves in a certain way, or replace a service with a mocked class.
@@ -226,13 +230,15 @@ set properties of a service so that it behaves in a certain way, or replace a se
226230
The first parameter is the service that you are replacing. The name must match the function name in the Services
227231
class exactly. The second parameter is the instance to replace it with.
228232

229-
reset()
230-
-------
233+
Services::reset()
234+
-----------------
231235

232236
Removes all mocked classes from the Services class, bringing it back to its original state.
233237

234-
resetSingle(string $name)
235-
-------------------------
238+
You can also use the ``$this->resetServices()`` method that ``CIUnitTestCase`` provides.
239+
240+
Services::resetSingle(string $name)
241+
-----------------------------------
236242

237243
Removes any mock and shared instances for a single service, by its name.
238244

@@ -242,7 +248,7 @@ Mocking Factory Instances
242248
=========================
243249

244250
Similar to Services, you may find yourself needing to supply a pre-configured class instance
245-
during testing that will be used with ``Factories``. Use the same ``injectMock()`` and ``reset()``
251+
during testing that will be used with ``Factories``. Use the same ``Factories::injectMock()`` and ``Factories::reset()``
246252
static methods like **Services**, but they take an additional preceding parameter for the
247253
component name:
248254

user_guide_src/source/testing/overview/003.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ final class OneOfMyModelsTest extends CIUnitTestCase
99
protected function setUp(): void
1010
{
1111
parent::setUp();
12+
1213
helper('text');
1314
}
1415
}

user_guide_src/source/testing/overview/004.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ final class OneOfMyModelsTest extends CIUnitTestCase
1010
'mockEmail',
1111
'mockSession',
1212
];
13+
1314
protected $tearDownMethods = [];
1415
}

user_guide_src/source/testing/overview/016.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use CodeIgniter\Test\CIUnitTestCase;
4+
use Config\Services;
45

56
final class SomeTest extends CIUnitTestCase
67
{

user_guide_src/source/testing/overview/017.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use CodeIgniter\Config\Factories;
34
use CodeIgniter\Test\CIUnitTestCase;
45

56
final class SomeTest extends CIUnitTestCase

user_guide_src/source/testing/overview/018.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3+
use CodeIgniter\CLI\CLI;
34
use CodeIgniter\Test\CIUnitTestCase;
5+
use CodeIgniter\Test\Filters\CITestStreamFilter;
46

57
final class SomeTest extends CIUnitTestCase
68
{
@@ -18,6 +20,7 @@ protected function tearDown(): void
1820
public function testSomeOutput(): void
1921
{
2022
CLI::write('first.');
23+
2124
$expected = "first.\n";
2225
$this->assertSame($expected, CITestStreamFilter::$buffer);
2326
}

0 commit comments

Comments
 (0)