Configure boostrap file for PHPUnit in Yii - php

If I'm using this YiiPimple for dependency injection, then how to configure bootstrap file for phpunit?
Below given bootstrap file content:
$yiit=dirname(__FILE__).'/../../../../../yii-assets/framework/yiit.php';
$config=dirname(__FILE__).'/../config/test.php';
require_once($yiit);
require_once(dirname(__FILE__).'/WebTestCase.php');
require_once(dirname(__FILE__).'/../../../components/WebApplication.php');
Yii::createApplication('WebApplication', $config)->run();
But when I run this phpunit following error occurs:
Fatal error: Uncaught exception 'CHttpException' with message 'Unable to resolve
the request "site".' in D:\xampp\htdocs\yii-assets\framework\web\CWebApplicatio
n.php:286
Stack trace:
#0 D:\xampp\htdocs\yii-assets\framework\web\CWebApplication.php(141): CWebApplic
ation->runController('')
#1 D:\xampp\htdocs\yii-assets\framework\base\CApplication.php(180): CWebApplicat
ion->processRequest()
#2 D:\xampp\htdocs\AdlugeCore\protected\modules\lead\tests\bootstrap.php(11): CA
pplication->run()
#3 D:\xampp\php\pear\PHPUnit\Util\Fileloader.php(92): include_once('D:\xampp\htd
ocs...')
#4 D:\xampp\php\pear\PHPUnit\Util\Fileloader.php(76): PHPUnit_Util_Fileloader::l
oad('D:\xampp\htdocs...')
#5 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(778): PHPUnit_Util_Fileloader::c
heckAndLoad('D:\xampp\htdocs...')
#6 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(606): PHPUnit_TextUI_Command->ha
ndleBootstrap('D:\xampp\htdocs...')
#7 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(138): PHPUnit_TextUI_Command->ha
ndleArguments(Array)
#8 D:\xampp\php\pear\PH in D:\xampp\htdocs\yii-assets\framework\web\CWebApplicat
ion.php on line 286

You shouldn't run the application in the phpunit bootstrap file.
Try changing
Yii::createApplication('WebApplication', $config)->run();
To
Yii::createApplication('WebApplication', $config);

Related

Uncaught Error: Class "Test\TestCase" not found running test with PHPStorm

I'm using PHPUNIT 9.5 and I'm running tests with PHPStorm like I show in the following image
The test that I want to run is:
<?php
namespace test\ccs\repository;
 
use test\UnitTestCase;
 
class SignInRepositoryTest extends UnitTestCase
 {
...
...
}
Composer.json has:
"autoload": {
"classmap": [
"app/controllers",
"app/models",
"app/views"
],
"psr-4": {
"ccs\\": "library/ccs/",
"test\\": "tests/test/"
}
},
When I run the test I got the error:
PHP Fatal error: Uncaught Error: Class "test\UnitTestCase" not found
in
C:\inetpub\PublicPortal\application\ccsignin\tests\test\ccs\repository\SignInRepositoryTest.php:4
Stack trace:
#0 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Util\FileLoader.php(66):
include_once()
#1 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Util\FileLoader.php(49):
PHPUnit\Util\FileLoader::load()
#2 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Framework\TestSuite.php(397):
PHPUnit\Util\FileLoader::checkAndLoad()
#3 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Framework\TestSuite.php(527):
PHPUnit\Framework\TestSuite->addTestFile()
#4 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\Runner\BaseTestRunner.php(98):
PHPUnit\Framework\TestSuite->addTestFiles()
#5 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php(121):
PHPUnit\Runner\BaseTestRunner->getTest()
#6 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php(97):
PHPUnit\TextUI\Command->run()
#7 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\phpunit(98): PHPUnit\TextUI\Command::main()
#8 {main}
Next PHPUnit\TextUI\RuntimeException: Class "test\UnitTestCase" not
found in
C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php:99
Stack trace:
#0 C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\phpunit(98): PHPUnit\TextUI\Command::main()
#1 {main} thrown in C:\inetpub\PublicPortal\vendors\PHPUnit\phpunit\src\TextUI\Command.php
on line 99

Laravel error tries to use log before autoload

I have a project with Laravel 4.
I use an helper in config/database.php
I get this error:
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class log does not exist' in /var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php:741
Stack trace:
#0 /var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(741): ReflectionClass->__construct('log')
#1 /var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('log', Array)
#2 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('log', Array)
#3 /var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(842): Illuminate\Foundation\Application->make('Psr\\Log\\LoggerI...')
#4 /var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(805): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 /var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(776): Illuminate\Container\C in /var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 741
I checked and the class name thats passed to make on /var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php(842)
is Psr\Log\LoggerInterface.
I assume the log class gets called before it is loaded and thats why it breaks.
If I remove the use of the helper in config/database.php all works, even if I simulate errors.
Is there a way to resolve it?
I need the Helper there.

CakePHP and Memcached error - php5.6

I'm trying to migrate our company application from php 5.3 to php 5.6. This app uses cakephp 2.4.3 and memcached, but when I try to execute ./cake bake command, the next error comes up:
Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /cluster/data/deploy/clickdelivery/current/lib/Cake/Cache/Cache.php:181
Stack trace:
#0 /cluster/data/deploy/clickdelivery/current/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_')
#1 /cluster/data/deploy/clickdelivery/current/app/Config/core.php(381): Cache::config('_cake_core_', Array)
#2 /cluster/data/deploy/clickdelivery/current/lib/Cake/Core/Configure.php(72): include('/cluster/data/d...')
#3 /cluster/data/deploy/clickdelivery/current/lib/Cake/bootstrap.php(177): Configure::bootstrap(true)
#4 /cluster/data/deploy/clickdelivery/current/lib/Cake/Console/ShellDispatcher.php(136): require('/cluster/data/d...')
#5 /cluster/data/deploy/clickdelivery/current/lib/Cake/Console/ShellDispatcher.php(98): ShellDispatcher->_bootstrap()
#6 /cluster/data/deploy/clickdelivery/current/lib/Cake/Console/ShellDispatcher.php(54): ShellDispatcher->_initEnvironment()
#7 /cluster/data/deploy/clickdelivery/cu in /cluster/data/deploy/clickdelivery/current/lib/Cake/Cache/Cache.php on line 181
Persistent and models directory are created with +W.
Thanks in advance.

How to run php unit tests in Yii 1.1

Please help. I've been at this for days.
PHPUnit version: 4.4.0
Whenever I try to run a unit test, I get this error:
PHP Fatal error: Uncaught exception 'CException' with message 'CHttpRequest is unable to determine the request URI.' in /var/www/framework/web/CHttpRequest.php:519
My bootstrap file:
// change the following paths if necessary
set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/protected/config/vendor/phpunit/phpunit-selenium');
$yiit=dirname(__FILE__).'/../../framework/yiit.php';
$config=dirname(__FILE__).'/../config/test.php';
require_once($yiit);
require_once(dirname(__FILE__).'/WebTestCase.php');
Yii::createWebApplication($config);
The error Stack trace:
#0 /vagrant/black-box/framework/web/CHttpRequest.php(431): CHttpRequest->getRequestUri()
#1 /vagrant/black-box/framework/web/CUrlManager.php(364): CHttpRequest->getPathInfo()
#2 /vagrant/black-box/protected/extensions/yii-debug-toolbar/YiiDebugToolbarRoute.php(113): CUrlManager->parseUrl(Object(CHttpRequest))
#3 /vagrant/black-box/framework/logging/CLogRouter.php(66): YiiDebugToolbarRoute->init()
#4 /vagrant/black-box/framework/base/CModule.php(387): CLogRouter->init()
#5 /vagrant/black-box/framework/base/CModule.php(523): CModule->getComponent('log')
#6 /vagrant/black-box/framework/base/CApplication.php(164): CModule->preloadComponents()
#7 /vagrant/black-box/framework/YiiBase.php(125): CApplication->__construct('/vagrant/black-...')
#8 /vagrant/black-box/framework/YiiBase.php(98): YiiBase::createApplication('CWebApplication', '/vagrant/blac in /vagrant/black-box/framework/web/CHttpRequest.php on line 519
Looks like you have configured the YiiDebugToolbarRoute in your configuration.
This is only useful in web environment and causes problems here.
Remove the configuration for logging from your application config in test ENV.

PHPExcel not working on windows but works on Linux

I am using a extension of import/export products in OpenCart but there is an error when i used it on window.
Fatal error: Uncaught exception 'Exception' with message 'Could not
open C:\Windows\Temp\php479C.tmp for reading! File does not exist.' in
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\system\PHPExcel\Classes\PHPExcel\Reader\Excel2007.php:168
Stack trace: #0
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\system\PHPExcel\Classes\PHPExcel\IOFactory.php(269):
PHPExcel_Reader_Excel2007->canRead('C:\Windows\Temp...') #1
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\system\PHPExcel\Classes\PHPExcel\IOFactory.php(207):
PHPExcel_IOFactory::createReaderForFile('C:\Windows\Temp...') #2
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\admin\model\catalog\productimportexport.php(1208):
PHPExcel_IOFactory::identify('C:\Windows\Temp...') #3
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\admin\controller\catalog\productimportexport.php(352):
ModelCatalogProductImportExport->upload('C:\Windows\Temp...', '1') #4
[internal function]: ControllerCatalogProductImportExport->bulk() #5
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\vqmod\ in
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\system\PHPExcel\Classes\PHPExcel\Reader\Excel2007.php
on line 168 Fatal Error: Uncaught exception 'Exception' with message
'Could not open C:\Windows\Temp\php479C.tmp for reading! File does not
exist.' in
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\system\PHPExcel\Classes\PHPExcel\Reader\Excel2007.php:168
Stack trace: #0
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\system\PHPExcel\Classes\PHPExcel\IOFactory.php(269):
PHPExcel_Reader_Excel2007->canRead('C:\Windows\Temp...') #1
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\system\PHPExcel\Classes\PHPExcel\IOFactory.php(207):
PHPExcel_IOFactory::createReaderForFile('C:\Windows\Temp...') #2
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\admin\model\catalog\productimportexport.php(1208):
PHPExcel_IOFactory::identify('C:\Windows\Temp...') #3
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\admin\controller\catalog\productimportexport.php(352):
ModelCatalogProductImportExport->upload('C:\Windows\Temp...', '1') #4
[internal function]: ControllerCatalogProductImportExport->bulk() #5
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\vqmod\ in
C:\Inetpub\vhosts\webwhisperer.com.au\watermark\system\PHPExcel\Classes\PHPExcel\Reader\Excel2007.php
on line 168
Does anyone know what's the Problem here ..thanks in advance
The top of the stack trace tells you the answer:
Could not open C:\Windows\Temp\php479C.tmp for reading! File does not exist.
The PHPExcel class is unable to open that file as it does not exist. Looking at the stack trace, this is being uploaded by the 'upload' method of the ModelCatalogProductImportExport object. I would ensure that this function is correctly importing the file, and saving it to the correct directory before running the PHPExcel class functions over the file.

Categories