Skip to content

Commit

Permalink
Imporve explanation for $this->request()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jan 28, 2016
1 parent 84ae946 commit 80009c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
26 changes: 14 additions & 12 deletions docs/FunctionAndClassReference.md
@@ -1,6 +1,6 @@
# CI PHPUnit Test for CodeIgniter 3.0

version: **v0.11.0** |
version: **v0.11.1** |
[v0.10.1](https://github.com/kenjis/ci-phpunit-test/blob/v0.10.1/docs/FunctionAndClassReference.md) |
[v0.9.1](https://github.com/kenjis/ci-phpunit-test/blob/v0.9.1/docs/FunctionAndClassReference.md) |
[v0.8.2](https://github.com/kenjis/ci-phpunit-test/blob/v0.8.2/docs/FunctionAndClassReference.md) |
Expand Down Expand Up @@ -139,35 +139,37 @@ In contrast, if you use `$this->resetInstance()`, it resets CodeIgniter instance

`returns` (string) output strings (view)

Runs a controller method or make a request to URI string after `reset_instance()`.
Runs a controller method or make a request to URI string, after `reset_instance()`.

If you want to specify controller and method name directly:
If you want to invoke routing, specify URI string:

~~~php
$output = $this->request('GET', ['Form', 'index']);
$output = $this->request('GET', 'products/shoes/show/123');
~~~

You could add query string in URI string:

~~~php
$output = $this->request('GET', 'users/detail?name=John+O%27Reilly');
~~~

If you want to make POST request:

~~~php
$output = $this->request(
'POST',
['Form', 'index'],
['form/index'],
['name' => 'John Smith', 'email' => 'john@example.com']
);
~~~

If you want to specify URI string:
If you want to call a controller method directly:

~~~php
$output = $this->request('GET', 'products/shoes/show/123');
$output = $this->request('GET', ['Form', 'index']);
~~~

You could add query string in URI string:

~~~php
$output = $this->request('GET', 'users/detail?name=John+O%27Reilly');
~~~
**Note:** If you pass an array to the 2nd argument, it does not invoke routing, `_remap()` and `_output()` methods.

##### `request->setHeader()`

Expand Down
31 changes: 17 additions & 14 deletions docs/HowToWriteTests.md
@@ -1,6 +1,6 @@
# CI PHPUnit Test for CodeIgniter 3.0

version: **v0.11.0** |
version: **v0.11.1** |
[v0.10.1](https://github.com/kenjis/ci-phpunit-test/blob/v0.10.1/docs/HowToWriteTests.md) |
[v0.9.1](https://github.com/kenjis/ci-phpunit-test/blob/v0.9.1/docs/HowToWriteTests.md) |
[v0.8.2](https://github.com/kenjis/ci-phpunit-test/blob/v0.8.2/docs/HowToWriteTests.md) |
Expand Down Expand Up @@ -30,7 +30,6 @@ version: **v0.11.0** |
- [Libraries](#libraries)
- [Controllers](#controllers)
- [Request to Controller](#request-to-controller)
- [Request to URI string](#request-to-uri-string)
- [REST Request](#rest-request)
- [Ajax Request](#ajax-request)
- [Request and Use Mocks](#request-and-use-mocks)
Expand Down Expand Up @@ -369,6 +368,20 @@ In this case, *CI PHPUnit Test* autoloads your libraries in `application/librari

You can use [$this->request()](FunctionAndClassReference.md#testcaserequestmethod-argv-params--) method in *CI PHPUnit Test*.

~~~php
public function test_uri_sub_sub_index()
{
$output = $this->request('GET', 'sub/sub/index');
$this->assertContains('<title>Page Title</title>', $output);
}
~~~

**Note:** If you pass URI string to the 2nd argument of `$this->request()`, it invokes the routing. If the resolved controller has `_remap()` and/or `_output()` methods, they will be invoked, too.

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.11.0/application/tests/controllers/sub/Sub_test.php).

If you want to call a controller method directly, you can pass an array to the 2nd argument of `$this->request()`.

*tests/controllers/Welcome_test.php*
~~~php
<?php
Expand All @@ -383,19 +396,9 @@ class Welcome_test extends TestCase
}
~~~

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.11.0/application/tests/controllers/Welcome_test.php).

#### Request to URI string

~~~php
public function test_uri_sub_sub_index()
{
$output = $this->request('GET', 'sub/sub/index');
$this->assertContains('<title>Page Title</title>', $output);
}
~~~
**Note:** If you pass an array to the 2nd argument of `$this->request()`, it does not invokes the routing. The `_remap()` and/or `_output()` methods in a controller are not invoked, too.

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.11.0/application/tests/controllers/sub/Sub_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.11.0/application/tests/controllers/Welcome_test.php).

#### REST Request

Expand Down

1 comment on commit 80009c8

@esetnik
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that looks great.

Please sign in to comment.