First of all, I am very new to Zend Framework. Actually just about 1 day old in the scope. I am also absolutely dumb with PHPUnit. I don't think using Zend Framework is practical without Unit Testing and am in need of understanding how to in a short time. I would be obliged if you could help me out with this. This is what I did.
I am going through the documentation and I am finding it difficult to follow. I don't know if its just me or if it is unprocessed documentation. I feel some thing is missing.
I also installed Composer.
Here is what I did, I got PHPUnit installed after install PEAR. Now when I put phpunit
some where it gives a list of options. So I assume it is doing good.
I got the Zend Skeleton Application
from GitHub. Got the Zend Framework
through Composer
.
I went through the documentation. I feel like my head is going to blow!!! My question is with unit testing in particular. The issue is with the content at http://framework.zend.com/manual/2.1/en/user-guide/unit-testing.html.
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="Bootstrap.php">
<testsuites>
<testsuite name="zf2tutorial">
<directory>./ApplicationTest</directory>
</testsuite>
</testsuites>
</phpunit>
This file which lies in the zf2-tutorial/module/Application/test
. My question is, isn't the Bootstrap.php
a file that resides in zf2-tutorial/module/Application/test
?
The documentation says to create a Bootstrap.php but in {Application Folder}/test
. With it when I run phpunit
in zf2-tutorial/module/Application/test
it says the file zf2-tutorial/module/Application/test/Bootstrap.php
could not be opened.
Then I changed Bootstrap.php
in the XML to /../../../test/Bootstrap.php
(as adviced by the document to be created along the XML file) which resolved the error. But the test count is zero: No tests executed!
Here is the Test Class:
<?php
namespace ApplicationTest\Controller;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
//use PHPUnit_Framework_TestCase;
//I also tried PHPUnit_Framework_TestCase instead of AbstractHttpControllerTestCase
class IndexControllerTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
$this->setApplicationConfig(
//include '/path/to/application/config/test/application.config.php'
include __DIR__ . '/../../../../config/application.config.php'
);
parent::setUp();
}
/**
* @test
*/
public function testIndexActionCanBeAccessed(){
$this->dispatch('/');
$this->assertResponseStatusCode(200);
$this->assertModule('application');
$this->assertControllerName('application_index');
$this->assertControllerClass('IndexController');
$this->assertMatchedRouteName('home');
}
}
include '/path/to/application/config/test/application.config.php'
??? This fancy path I renamed to include __DIR__ . '/../../../../config/application.config.php'
.
The file is located within the test folder zf-tutorial/module/Application/test/ApplicationTest/Controller
.
At the end of ever thing, No tests executed!
is all what PHP unit has to say.
What have I done wrong? What could I do to get it right.
I would also like to have a crash-course in the subject (link to a blog or some thing like that), I understand that not even Amazon has a book for the ZF2. I would be glad if you could give me a hand. It is really urgent!
Thank you in advance!
Additions:: I missed the making of the Bootstrap.php in the test folder.
The new XML is like this
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="Bootstrap.php">
<testsuites>
<testsuite name="zf2tutorial">
<directory>./ApplicationTest</directory>
</testsuite>
</testsuites>
</phpunit>
The Bootstrap.php looks like this
<?php
chdir(dirname(__DIR__));
include __DIR__ . '/../../../init_autoloader.php';
init_autoloader.php
was modified to find the zendframework library.
But still PHPUnit says No tests executed!