Skip to content
This repository was archived by the owner on Jan 1, 2020. It is now read-only.

Commit 70b2ab6

Browse files
committed
Merge branch 'feature/337' into develop
Close #337
2 parents a88789b + 4c68863 commit 70b2ab6

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ nbproject
99
.settings
1010
vendor
1111
composer.phar
12+
phpunit.xml

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ interfaces.
2929

3030
**Note:** The built-in CLI server is *for development only*.
3131

32+
## Running Unit Tests
33+
34+
To run the supplied skeleton unit tests, you need to do one of the following:
35+
36+
- During initial project creation, select to install the MVC testing support.
37+
- After initial project creation, install [zend-test](https://zendframework.github.io/zend-test/):
38+
39+
```bash
40+
$ composer require --dev zendframework/zend-test
41+
```
42+
43+
Once testing support is present, you can run the tests using:
44+
45+
```bash
46+
$ ./vendor/bin/phpunit
47+
```
48+
49+
If you need to make local modifications for the PHPUnit test setup, copy
50+
`phpunit.xml.dist` to `phpunit.xml` and edit the new file; the latter has
51+
precedence over the former when running tests, and is ignored by version
52+
control. (If you want to make the modifications permanent, edit the
53+
`phpunit.xml.dist` file.)
54+
3255
## Using Vagrant
3356

3457
This skeleton includes a `Vagrantfile` based on ubuntu 14.04, and using the

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
"Application\\": "module/Application/src/"
2323
}
2424
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"ApplicationTest\\": "module/Application/test/"
28+
}
29+
},
2530
"extra": {
2631
"zend-skeleton-installer": [
2732
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace ApplicationTest\Controller;
9+
10+
use Application\Controller\IndexController;
11+
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
12+
13+
class IndexControllerTest extends AbstractHttpControllerTestCase
14+
{
15+
public function setUp()
16+
{
17+
// The module configuration should still be applicable for tests.
18+
// You can override configuration here with test case specific values,
19+
// such as sample view templates, path stacks, module_listener_options,
20+
// etc.
21+
$configOverrides = [];
22+
23+
$this->setApplicationConfig(array_merge(
24+
include __DIR__ . '/../../../../config/application.config.php',
25+
$configOverrides
26+
));
27+
28+
parent::setUp();
29+
}
30+
31+
public function testIndexActionCanBeAccessed()
32+
{
33+
$this->dispatch('/', 'GET');
34+
$this->assertResponseStatusCode(200);
35+
$this->assertModuleName('application');
36+
$this->assertControllerName(IndexController::class); // as specified in router's controller name alias
37+
$this->assertControllerClass('IndexController');
38+
$this->assertMatchedRouteName('home');
39+
}
40+
41+
public function testIndexActionViewModelTemplateRenderedWithinLayout()
42+
{
43+
$this->dispatch('/', 'GET');
44+
$this->assertQuery('.container .jumbotron');
45+
}
46+
47+
public function testInvalidRouteDoesNotCrash()
48+
{
49+
$this->dispatch('/invalid/route', 'GET');
50+
$this->assertResponseStatusCode(404);
51+
}
52+
}

phpunit.xml.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<phpunit colors="true">
2+
<testsuites>
3+
<testsuite name="ZendSkeletonApplication Test Suite">
4+
<directory>./module/Application/test</directory>
5+
</testsuite>
6+
</testsuites>
7+
</phpunit>

0 commit comments

Comments
 (0)