Skip to content

Commit 8f0a2ad

Browse files
committed
docs: add note about $setUpMethods
1 parent 8e89736 commit 8f0a2ad

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

user_guide_src/source/testing/overview.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ parent as well so extended test cases do not interfere with staging:
101101

102102
.. literalinclude:: overview/003.php
103103

104-
In addition to these methods, ``CIUnitTestCase`` also comes with a convenience property for
105-
parameter-free methods you want run during set up and tear down:
104+
In addition to these methods, ``CIUnitTestCase`` also comes with a convenience property
105+
``$setUpMethods`` and ``$tearDownMethods`` for
106+
parameter-free methods you want to run during set up and tear down:
106107

107108
.. literalinclude:: overview/004.php
108109

@@ -111,12 +112,25 @@ that or provide their own:
111112

112113
.. literalinclude:: overview/005.php
113114

115+
.. note:: When you override ``$setUpMethods`` properties, do not remove the following items that are set in the parent class by default unless you know they are truly unnecessary.
116+
117+
.. code-block:: php
118+
119+
protected $setUpMethods = [
120+
'resetFactories',
121+
'mockCache',
122+
'mockEmail',
123+
'mockSession',
124+
];
125+
114126
Traits
115127
------
116128

117129
A common way to enhance your tests is by using traits to consolidate staging across different
118130
test cases. ``CIUnitTestCase`` will detect any class traits and look for staging methods
119-
to run named for the trait itself. For example, if you needed to add authentication to some
131+
to run named for the trait itself.
132+
133+
For example, if you needed to add authentication to some
120134
of your test cases you could create an authentication trait with a set up method to fake a
121135
logged in user:
122136

user_guide_src/source/testing/overview/004.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
final class OneOfMyModelsTest extends CIUnitTestCase
88
{
99
protected $setUpMethods = [
10+
'resetFactories',
11+
'mockCache',
1012
'mockEmail',
1113
'mockSession',
1214
];

0 commit comments

Comments
 (0)