Skip to content

Commit b451206

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents eafb769 + c36c1c5 commit b451206

File tree

13 files changed

+43
-26
lines changed

13 files changed

+43
-26
lines changed

user_guide_src/source/testing/controllers/001.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
namespace CodeIgniter;
3+
namespace App\Controllers;
44

55
use CodeIgniter\Test\CIUnitTestCase;
66
use CodeIgniter\Test\ControllerTestTrait;
77
use CodeIgniter\Test\DatabaseTestTrait;
88

9-
class TestControllerA extends CIUnitTestCase
9+
class FooControllerTest extends CIUnitTestCase
1010
{
1111
use ControllerTestTrait;
1212
use DatabaseTestTrait;

user_guide_src/source/testing/controllers/002.php

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

3-
namespace CodeIgniter;
3+
namespace App\Controllers;
44

55
use CodeIgniter\Test\CIUnitTestCase;
66
use CodeIgniter\Test\ControllerTestTrait;
77
use CodeIgniter\Test\DatabaseTestTrait;
88

9-
class TestControllerA extends CIUnitTestCase
9+
class ForumControllerTest extends CIUnitTestCase
1010
{
1111
use ControllerTestTrait;
1212
use DatabaseTestTrait;
1313

1414
public function testShowCategories()
1515
{
1616
$result = $this->withURI('http://example.com/categories')
17-
->controller(\App\Controllers\ForumController::class)
17+
->controller(ForumController::class)
1818
->execute('showCategories');
1919

2020
$this->assertTrue($result->isOK());
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace CodeIgniter;
3+
namespace App\Filters;
44

55
use CodeIgniter\Test\CIUnitTestCase;
66
use CodeIgniter\Test\FilterTestTrait;
77

8-
class FilterTestCase extends CIUnitTestCase
8+
class FooFilterTest extends CIUnitTestCase
99
{
1010
use FilterTestTrait;
1111
}

user_guide_src/source/testing/controllers/012.php

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

3-
namespace CodeIgniter;
3+
namespace App\Filters;
44

55
use CodeIgniter\Test\CIUnitTestCase;
66
use CodeIgniter\Test\FilterTestTrait;
77

8-
final class FilterTestCase extends CIUnitTestCase
8+
final class FooFilterTest extends CIUnitTestCase
99
{
1010
use FilterTestTrait;
1111

user_guide_src/source/testing/controllers/014.php

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

3-
namespace CodeIgniter;
3+
namespace App\Filters;
44

55
use CodeIgniter\Test\CIUnitTestCase;
66
use CodeIgniter\Test\FilterTestTrait;
77

8-
final class FilterTestCase extends CIUnitTestCase
8+
final class FooFilterTest extends CIUnitTestCase
99
{
1010
use FilterTestTrait;
1111

user_guide_src/source/testing/overview.rst

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,31 @@ Testing Your Application
6060
PHPUnit Configuration
6161
=====================
6262

63-
The framework has a ``phpunit.xml.dist`` file in the project root. This controls unit
64-
testing of the framework itself. If you provide your own ``phpunit.xml``, it will
65-
over-ride this.
63+
In your CodeIgniter project root, there is the ``phpunit.xml.dist`` file. This
64+
controls unit testing of your application. If you provide your own ``phpunit.xml``,
65+
it will over-ride this.
6666

67-
Your ``phpunit.xml`` should exclude the ``system`` folder, as well as any ``vendor`` or
68-
``ThirdParty`` folders, if you are unit testing your application.
67+
By default, test files are placed under the **tests** directory in the project root.
6968

7069
The Test Class
7170
==============
7271

73-
In order to take advantage of the additional tools provided, your tests must extend ``CIUnitTestCase``. All tests
74-
are expected to be located in the **tests/app** directory by default.
72+
In order to take advantage of the additional tools provided, your tests must extend
73+
``CodeIgniter\Test\CIUnitTestCase``.
7574

76-
To test a new library, **Foo**, you would create a new file at **tests/app/Libraries/FooTest.php**:
75+
There are no rules for how test files must be placed. However, we recommend that
76+
you establish placement rules in advance so that you can quickly understand where
77+
the test files are located.
78+
79+
In this document, we will place the test files corresponding to the classes in
80+
the **app** directory in the **tests/app** directory. To test a new library,
81+
**app/Libraries/Foo.php**, you would create a new file at
82+
**tests/app/Libraries/FooTest.php**:
7783

7884
.. literalinclude:: overview/001.php
7985

80-
To test one of your models, you might end up with something like this in **tests/app/Models/OneOfMyModelsTest.php**:
86+
To test one of your models, **app/Models/UserMode.php**, you might end up with
87+
something like this in **tests/app/Models/UserModelTest.php**:
8188

8289
.. literalinclude:: overview/002.php
8390

@@ -104,7 +111,7 @@ to help with staging and clean up::
104111
The static methods ``setUpBeforeClass()`` and ``tearDownAfterClass()`` run before and after the entire test case, whereas the protected methods ``setUp()`` and ``tearDown()`` run
105112
between each test.
106113

107-
If you implement any of these special functions make sure you run their
114+
If you implement any of these special functions, make sure you run their
108115
parent as well so extended test cases do not interfere with staging:
109116

110117
.. literalinclude:: overview/003.php

user_guide_src/source/testing/overview/002.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use CodeIgniter\Test\CIUnitTestCase;
66

7-
class OneOfMyModelsTest extends CIUnitTestCase
7+
class UserModelTest extends CIUnitTestCase
88
{
99
public function testFooNotBar()
1010
{

user_guide_src/source/testing/overview/003.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use CodeIgniter\Test\CIUnitTestCase;
66

7-
final class OneOfMyModelsTest extends CIUnitTestCase
7+
final class UserModelTest extends CIUnitTestCase
88
{
99
protected function setUp(): void
1010
{

user_guide_src/source/testing/overview/016.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
22

3+
namespace Tests;
4+
5+
use CodeIgniter\HTTP\CURLRequest;
36
use CodeIgniter\Test\CIUnitTestCase;
47
use Config\Services;
58

69
final class SomeTest extends CIUnitTestCase
710
{
811
public function testSomething()
912
{
10-
$curlrequest = $this->getMockBuilder('CodeIgniter\HTTP\CURLRequest')
11-
->setMethods(['request'])
13+
$curlrequest = $this->getMockBuilder(CURLRequest::class)
14+
->onlyMethods(['request'])
1215
->getMock();
1316
Services::injectMock('curlrequest', $curlrequest);
1417

user_guide_src/source/testing/overview/017.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tests;
44

5+
use App\Models\UserModel;
56
use CodeIgniter\Config\Factories;
67
use CodeIgniter\Test\CIUnitTestCase;
78
use Tests\Support\Mock\MockUserModel;
@@ -13,6 +14,6 @@ protected function setUp(): void
1314
parent::setUp();
1415

1516
$model = new MockUserModel();
16-
Factories::injectMock('models', 'App\Models\UserModel', $model);
17+
Factories::injectMock('models', UserModel::class, $model);
1718
}
1819
}

user_guide_src/source/testing/overview/018.php

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

3+
namespace Tests;
4+
35
use CodeIgniter\CLI\CLI;
46
use CodeIgniter\Test\CIUnitTestCase;
57
use CodeIgniter\Test\StreamFilterTrait;

user_guide_src/source/testing/overview/019.php

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

3+
namespace Tests;
4+
35
use CodeIgniter\CLI\CLI;
46
use CodeIgniter\Test\CIUnitTestCase;
57
use CodeIgniter\Test\PhpStreamWrapper;

user_guide_src/source/testing/overview/020.php

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

3+
namespace Tests;
4+
35
use CodeIgniter\CLI\CLI;
46
use CodeIgniter\Test\CIUnitTestCase;
57
use CodeIgniter\Test\Filters\CITestStreamFilter;

0 commit comments

Comments
 (0)