Hello.
I'm trying to test a ZF2 application, but I get this error.
PHPUnit 3.7.15 by Sebastian Bergmann. Configuration read from /home/egidio/NetBeansProjects/school_gear/module/Guest/test/phpunit.xml E Time: 0 seconds, Memory: 4.75Mb There was 1 error: 1) GuestTest\Controller\LoginControllerTest::testGuestCanAccessLoginPage Invalid argument supplied for foreach() /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/ModuleManager/Listener/ConfigListener.php:354 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/ModuleManager/Listener/ConfigListener.php:147 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/EventManager/EventManager.php:460 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/EventManager/EventManager.php:204 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/ModuleManager/ModuleManager.php:100 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/Mvc/Application.php:239 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:146 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:173 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:193 /home/egidio/NetBeansProjects/school_gear/vendor/ZF2/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:236 /home/egidio/NetBeansProjects/school_gear/module/Guest/test/GuestTest/Controller/LoginControllerTest.php:15 FAILURES! Tests: 1, Assertions: 0, Errors: 1.
This is the phpunit.xml file.
<?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="Bootstrap.php" colors="true"> <testsuites> <testsuite name="school_gear"> <directory>./GuestTest</directory> </testsuite> </testsuites> </phpunit>
This is the Bootstrap.php file.
<?php namespace GuestTest; error_reporting(E_ALL); chdir(_DIR_); define('ZF2_PATH', '/home/egidio/NetBeansProjects/school_gear/vendor/ZF2'); class Bootstrap { protected static $serviceManager; public static function init() { $zf2ModulePaths = array(dirname(dirname(_DIR_))); if (($path = static::findParentPath('vendor'))) { $zf2ModulePaths[] = $path; } if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0]) { $zf2ModulePaths[] = $path; } } static::initAutoloader(); // use ModuleManager to load this module and it's dependencies $config = array( 'module_listener_options' => array( 'module_paths' => $zf2ModulePaths, ), 'modules' => array('Application','Guest') ); $serviceManager = new \Zend\ServiceManager\ServiceManager( new \Zend\Mvc\Service\ServiceManagerConfig()); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); static::$serviceManager = $serviceManager; } public static function getServiceManager() { return static::$serviceManager; } protected static function initAutoloader() { $vendorPath = static::findParentPath('vendor'); $zf2Path = getenv('ZF2_PATH'); if (!$zf2Path) { if (defined('ZF2_PATH')) { $zf2Path = ZF2_PATH; } else { if (is_dir($vendorPath . '/ZF2/library')) { $zf2Path = $vendorPath . '/ZF2/library'; } } } if (!$zf2Path) { throw new \RuntimeException('Unable to load ZF2.'); } include $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; \Zend\Loader\AutoloaderFactory::factory(array( 'Zend\Loader\StandardAutoloader' => array( 'autoregister_zf' => true, 'namespaces' => array( _NAMESPACE_ => _DIR_ . '/' . _NAMESPACE_, ), ), )); } protected static function findParentPath($path) { $dir = _DIR_; $previousDir = '.'; while (!is_dir($dir . '/' . $path)) { $dir = dirname($dir); if ($previousDir === $dir) return false; $previousDir = $dir; } return $dir . '/' . $path; } } Bootstrap::init();
This is the LoginControllerTest.php file.
<?php namespace GuestTest\Controller; class LoginControllerTest extends \Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase { protected $traceError = true; public function setUp() { $config = include '/home/egidio/NetBeansProjects/school_gear/config/' . 'application.config.php'; $this->setApplicationConfig($config); parent::setUp(); } public function testGuestCanAccessLoginPage() { $this->dispatch('/login'); $this->assertResponseStatusCode(200); } }
Log in to post a comment.
Hello.
I'm trying to test a ZF2 application, but I get this error.
This is the phpunit.xml file.
This is the Bootstrap.php file.
This is the LoginControllerTest.php file.