mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Note traiting in UG
This commit is contained in:
parent
7b7d26a737
commit
fad21d9642
@ -103,7 +103,7 @@ have the correct namespace relative to ``App``.
|
||||
|
||||
.. note:: Namespaces are not strictly required for test classes, but they are helpful to ensure no class names collide.
|
||||
|
||||
When testing database results, you must use the `CIDatabaseTestClass <database.html>`_ class.
|
||||
When testing database results, you must use the `DatabaseTestTrait <database.html>`_ in your class.
|
||||
|
||||
Staging
|
||||
-------
|
||||
@ -150,6 +150,32 @@ that or provide their own::
|
||||
$this->model->purgeDeleted()
|
||||
}
|
||||
|
||||
Traits
|
||||
------
|
||||
|
||||
A common way to enhance your tests is by using traits to consolidate staging across different
|
||||
test cases. ``CIUintTestCase`` will detect any class traits and look for staging methods to
|
||||
to run named for the trait itself. The framework's own ``DatabaseTestTrait`` implements this
|
||||
with methods ``setUpDatabaseTestTrait()`` and ``tearDownDatabaseTestTrait()``.
|
||||
|
||||
For example, if you needed to add authentication to some of your test cases you could create
|
||||
an authentication trait with a set up method to fake a logged in user::
|
||||
|
||||
trait AuthTrait
|
||||
{
|
||||
protected setUpAuthTrait()
|
||||
{
|
||||
$user = $this->createFakeUser();
|
||||
$this->logInUser($user);
|
||||
}
|
||||
...
|
||||
|
||||
class AuthenticationFeatureTest
|
||||
{
|
||||
use AuthTrait;
|
||||
...
|
||||
|
||||
|
||||
Additional Assertions
|
||||
---------------------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user