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

Commit 63a9152

Browse files
committed
Merge pull request #337 from alextech/feature/unit-tests
Add skeleton unit tests
2 parents a88789b + 8e563ed commit 63a9152

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ 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, need to either choose to install
35+
MVC testing support during project creation, or to add [zend-test](https://zendframework.github.io/zend-test/)
36+
as a development dependency with
37+
38+
```bash
39+
$ composer require --dev zendframework/zend-test
40+
```
41+
42+
Once installed, you can run the tests using:
43+
44+
```bash
45+
$ ./vendor/bin/phpunit
46+
```
47+
48+
If you need to make local modifications to phpunit xml configuration file,
49+
copy `phpunit.xml.dist` to `phpunit.xml`, which will take precedence by the test runner
50+
and is ignored by the repository.
51+
52+
3253
## Using Vagrant
3354

3455
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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
18+
// Many of the configurations to load the module should still be applicable for tests.
19+
// Can override them here with test case specific values, such as,
20+
// sample view templates, path stacks, module_listener_options, 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+
36+
$this->assertModuleName('application');
37+
$this->assertControllerName(IndexController::class); // as specified in router's controller name alias
38+
$this->assertControllerClass('IndexController');
39+
$this->assertMatchedRouteName('home');
40+
}
41+
42+
public function testIndexActionViewModelTemplateRenderedWithinLayout()
43+
{
44+
$this->dispatch('/', 'GET');
45+
46+
$this->assertQuery('.container .jumbotron');
47+
}
48+
49+
public function testInvalidRouteDoesNotCrash()
50+
{
51+
$this->dispatch('/invalid/route', 'GET');
52+
53+
$this->assertResponseStatusCode(404);
54+
}
55+
}

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)