0

i'm trying to use phpunit with zendframework and i'm follwing the tutorial in

https://media.readthedocs.org/pdf/zf2/latest/zf2.pdfhere is my

bootstrap.php

<?php
chdir(dirname(__DIR__));
include __DIR__ . '/../init_autoloader.php';

here is my IndexControllerTest.php

<?php

namespace ApplicationTest\Controller;

use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;

class IndexControllerTest extends AbstractHttpControllerTestCase
{
public function setUp()
{
$this->setApplicationConfig(
include '/C:/wamp/www/zf2/config/application.config.php'
);
    parent::setUp();
}

public function testIndexActionCanBeAccessed()
{
    $this->dispatch('/'); // this is line 20
    $this->assertResponseStatusCode(200);

    $this->assertModule('application');
    $this->assertControllerName('application_index');
    $this->assertControllerClass('IndexController');
    $this->assertMatchedRouteName('home');
}
}

and i'm getting the follwing errors

Warning: include(C:\wamp\www\zf2\module\Application\test/../init_autoloader.php)
: failed to open stream: No such file or directory in C:\wamp\www\zf2\module\App
lication\test\Bootstrap.php on line 4


Fatal error: Class 'Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase'
not found in C:\wamp\www\zf2\module\Application\test\ApplicationTest\Controller
\IndexControllerTest.php on line 8

i think that's a path probleme (auloading)but i don't know how to fix

any one can help me please ?

2 Answers 2

1
Warning: include(C:\wamp\www\zf2\module\Application\test/../init_autoloader.php)
: failed to open stream: No such file or directory in C:\wamp\www\zf2\module\App
lication\test\Bootstrap.php on line 4

This warning is telling you that it can't find the location of your init_autoloader.php file. Assuming that file is located in the root of your ZF2 project (so C:\wamp\www\zf2) as is convention, you need to change:

include __DIR__ . '/../init_autoloader.php';

to

include __DIR__ . '/../../../init_autoloader.php';

EDIT Continued...

PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to 
load ZF2. Run php composer.phar install or define a ZF2_PATH environment 
variable.' in C:\wamp\www\zf2\init_autoloader.php:48

Your init_autloader.php file is having trouble finding your ZF2 library autoloader. As you're using composer. Add

"zendframework/zendframework": "2.1.*",

to your "require" section in composer.json if its not already there. Run composer and update your vendor libraries with

php composer.phar update

Try run the application again and see if it works. It may do depending what is included in your init_autoload.php file. If you're still having problems add the following to init_autoloader.php

if(file_exists('vendor/autoload.php'))
{
    $loader = require 'vendor/autoload.php';
}
Sign up to request clarification or add additional context in comments.

5 Comments

thanks for your help , i dit as you told me and it seems that there is a problem with loading my module zf2 PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. Run php composer.phar install or define a ZF2_PATH environment variable.' in C:\wamp\www\zf2\init_autoloader.php:48 have any idea where this is comming from ? my all others model are running fine with auloader
This fatal error shows it is having trouble finding your ZF2 library autoloader. Where is ZF2 located in your environment? Do you have a vendor folder? Are you using composer?
yes i'm using composer( i edited composer.json to install phpunit) , phpunit is installed in : C:\wamp\www\zf2\vendor zf2 is located in : C:\wamp\www PS: originally zf2 was named zend skeleton application (that you can download from zend website,then i named it to zf2 ) also i have composer folder located in C:\wamp\www\zf2\vendor , witch contains autoload_classmap.php , autoload_namespaces.php , autoload_real.php, ClassLoader.php, include_paths.php and installed.json . thanks for your time i hope that we find a solution to this issue because i really tried my best without result :(
i did us you exactly tell me and still got the same error , i even reinstall zf2 and phpunit and wamp and every tool i used for my project . i'm running out of solutions :((( any ideas ?
That exception is being thrown in your init_autloader.php file. Make sure that file looks like raw.github.com/akrabat/zf2-tutorial/master/init_autoloader.php. If you're still getting that error you need to check the path to your ZF2 library (not your ZF2 project). Do you have a vendor/zendframework folder? Can you find and give me the path to the /Zend/Loader/AutoloaderFactory.php file. It should be in your ZF2 library folder.
0

Here's the Fix for the fatal error.

You must be missing the 'zend-test' package in your application.

$ composer require zendframework/zend-test

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.