I try to make some tests for my project but I have issue.
When I launch Unit tests with PHPUnit it's works perfectly but when I try to do functional tests (with extends WebTestCase), there is an error.
I run phpunit -c app/ src/path/to/my/fileTest.php:
PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'src/Eat/MainBundle/Tests/Controller/PaiementControllerTest' could not be found in '/Applications/MAMP/htdocs/PopLink/Symfony/src/Eat/MainBundle/Tests/Controller/PaiementControllerTest.php'. in phar:///usr/local/bin/phpunit/phpunit/Runner/StandardTestSuiteLoader.php:101
Stack trace:
#0 phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php(130): PHPUnit\Runner\StandardTestSuiteLoader->load('src/Eat/MainBun...', '/Applications/M...')
#1 phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php(73): PHPUnit\Runner\BaseTestRunner->loadSuiteClass('src/Eat/MainBun...', '/Applications/M...')
#2 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(162): PHPUnit\Runner\BaseTestRunner->getTest('src/Eat/MainBun...', '/Applications/M...', Array)
#3 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(141): PHPUnit\TextUI\Command->run(Array, true)
#4 /usr/local/bin/phpunit(546): PHPUnit\TextUI\Command::main()
#5 {main}
thrown in phar:///usr/local/bin/phpunit/phpunit/Runner/StandardTestSuiteLoader.php on line 101
I have read some topics about this error but I still don't understand.
Can you help me ?
Thanks.
Related
I've been stuck trying to figure out why I get this every time I try to run php artisan key:generate (or any other php artisan command).
PHP Fatal error: Uncaught ReflectionException: Class log does not exist in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php:734
Stack trace:
#0 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(734): ReflectionClass->__construct('log')
#1 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Container\Container->build('log', Array)
#2 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(697): Illuminate\Container\Container->make('log', Array)
#3 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(849): Illuminate\Foundation\Application->make('log')
#4 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(804): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 C:\Users\Sam\P in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 734
Fatal error: Uncaught ReflectionException: Class log does not exist in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php:734
Stack trace:
#0 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(734): ReflectionClass->__construct('log')
#1 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Container\Container->build('log', Array)
#2 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(697): Illuminate\Container\Container->make('log', Array)
#3 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(849): Illuminate\Foundation\Application->make('log')
#4 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(804): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 C:\Users\Sam\P in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 734
Some suggested putting this at the top of vendor\laravel\framework\src\Illuminate\Container\Container.php because it would reveal the underlying error:
namespace {
use Monolog\Logger as Monolog;
class log extends Illuminate\Log\Writer {
function __construct()
{
$this->monolog = new Monolog("local");
}
}
}
But instead I started getting:
PHP Fatal error: Uncaught ReflectionException: Class env does not exist in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\
framework\src\Illuminate\Container\Container.php:744
with a similar stacktrace to the initial error. I've been researching online what could be causing it. Someone suggested running 'phpunit', so I did and I got the error:
Dotenv\Exception\InvalidFileException: Dotenv values containing spaces must be surrounded by quotes.
I thought this was interesting because people had suggested that .env values containing spaces could have caused the initial problem, but I have thoroughly and repeatedly checked my .env file for spaces and there are none where there shouldn't be. I even tried wrapping literally every single .env value in quotes. On top of all this my IDE (Phpstorm) tells me that there are no errors in any of the files in my config folder.
What could be causing this issue?
STEP 1
Make sure you have installed all packages properly composer install.
STEP 2
Run composer dump-autoload to generate class references again.
I have a laravel project I installed the composer
and run
composer install
After that I executed the update command
composer update
on the project's root directory, and during the execution on the command
php artisan optimize
I got the error shown in the attached image.
When I try to execute any php artisan command I got the same error too.
Error lines
PHP Fatal error: Uncaught Error: Call to undefined method Illuminate\Support\Facades\Auth::check() in C:\xampp\htdocs\projectx\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:221
Stack trace:
#0 C:\xampp\htdocs\projectx\app\Exceptions\Handler.php(39): Illuminate\Support\Facades\Facade::__callStatic('check', Array)
#1 C:\xampp\htdocs\projectx\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(81): App\Exceptions\Handler->report(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#3 {main}
thrown in C:\xampp\htdocs\projectx\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 221
PHP Fatal error: Uncaught Error: Call to undefined method Illuminate\Support\Facades\Auth::check() in C:\xampp\htdocs\projectx\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:221
Stack trace:
#0 C:\xampp\htdocs\projectx\app\Exceptions\Handler.php(39): Illuminate\Support\Facades\Facade::__callStatic('check', Array)
#1 C:\xampp\htdocs\projectx\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(81): App\Exceptions\Handler->report(Object(Symfony\Component\Debug\Exception\FatalErrorException))
#2 C:\xampp\htdocs\projectx\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(123): Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalErrorException))
#3 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
#4 {main}
thrown in C:\xampp\htdocs\projectx\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 221
You could try to use the append_config() helper method in your environment app configuration file:
'providers' => append_config(array(
'LocalOnlyServiceProvider',
))
The command php artisan optimize has been remove in laravel 5.6
see more: https://laravel.com/docs/5.6/upgrade
I need to make unit tests for my laravel app. So far I have started to code the test, but when i ran it it returned not what i expected, so far i have not seen this anywhere on the internet. So I must be doing somethng stupid or missing something, right?
my testing class in tests/tests.php
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class Tests extends TestCase
{
public function testLoad(){
$this->call('GET', '/');
$this->assertResponseOk();
$response = $this->action('GET', 'mainController#load');
$this->visit('/')
->see('Todo seznam');
$this->assertViewHas('tasks');
}
public function dbTest(){
$this->call('GET', '/delete');
$this->assertHasOldInput();
}
}
so I presumed i have to install phpunit (I'm on ubuntu 16.04) and then I ran it in root of my project with "phpunit" like everyone else who succeded but got this result:
..............................................................................
Time: 70 ms, Memory: 4.00MB
PHP Fatal error: Uncaught Error: Call to undefined method PHPUnit_Framework_TestResult::warningCount() in /usr/share/php/PHPUnit/TextUI/ResultPrinter.php:185
Stack trace:
#0 /home/matic/Documents/todo-app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(446): PHPUnit_TextUI_ResultPrinter->printResult(Object(PHPUnit_Framework_TestResult))
#1 /usr/share/php/PHPUnit/TextUI/Command.php(155): PHPUnit_TextUI_TestRunner->doRun(Array)
#2 /usr/share/php/PHPUnit/TextUI/Command.php(106): PHPUnit_TextUI_Command->run(Array, true)
#3 /usr/bin/phpunit(29): PHPUnit_TextUI_Command::main()
#4 {main}
thrown in /usr/share/php/PHPUnit/TextUI/ResultPrinter.php on line 185
..............................................................................
a bunch of files i have done no changes to whasoever.
Then i figured i would just make a new project and phpunit there but the result was the same, but even more errors.
............................................................................
Time: 107 ms, Memory: 10.00MB
PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php:748
Stack trace:
#0 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 [internal function]: Illuminate\Foundation\Bootstrap\HandleE in /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 748
PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php:748
Stack trace:
#0 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /home/matic/Documents/unit/vendor/laravel/framework/src/Illu in /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 748
...........................................................................
Am I wrong for thinking there is something fishy here?
How should i go about fixing this?
Is it normal?
Thanks for any help you give me I will be so greatfull.
I'm a bit sad nobody helped might have saved me some time. but here goes. Idk what the problem was, but i deleted the vendor folder and ran composer install, which repalced it and now it works
I want to play around with changing PHPUnit's source, but first I'd like to be able to run its tests to make sure I don't break anything.
I used git to get version 4.7.7 out into a directory. In that directory, I then ran composer install.
Then I cd into tests and run:
phpunit --bootstrap ./bootstrap.php ./
(The version of PHPUnit I'm using to run the tests is also 4.7.7.)
but I get this:
PHP Fatal error: Uncaught exception 'Exception' with message 'PHPUnit suppresses exceptions thrown outside of test case function' in C:\Users\jodes\Documents\NetBeansProjects\PHPUnit\phpunit\tests\Regression\GitHub\873\Issue873Test.php:7
Stack trace:
#0 phar://C:/phpbin/phpunit.phar/phpunit/Util/Fileloader.php(52): include_once()
#1 phar://C:/phpbin/phpunit.phar/phpunit/Util/Fileloader.php(36): PHPUnit_Util_Fileloader::load('C:\Users\jody\D...')
#2 phar://C:/phpbin/phpunit.phar/phpunit/Framework/TestSuite.php(334): PHPUnit_Util_Fileloader::checkAndLoad('C:\Users\jody\D...')
#3 phar://C:/phpbin/phpunit.phar/phpunit/Framework/TestSuite.php(406): PHPUnit_Framework_TestSuite->addTestFile('C:\Users\jody\D...')
#4 phar://C:/phpbin/phpunit.phar/phpunit/Runner/BaseTestRunner.php(57): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#5 phar://C:/phpbin/phpunit.phar/phpunit/TextUI/Command.php(121): PHPUnit_Runner_BaseTestRunner->getTest('.\tests\', '', Array)
#6 phar://C:/phpbin/phpunit.phar/phpunit/TextUI/Command.php(99): PHPUnit_TextU in C:\Users\jody\Documents\NetBeansProjects\PHPUnit\phpunit\tests\Regression\GitHub\873\Issue873Test.php on line 7
Fatal error: Uncaught exception 'Exception' with message 'PHPUnit suppresses exceptions thrown outside of test case function' in C:\Users\jodes\Documents\NetBeansProjects\PHPUnit\phpunit\tests\Regression\GitHub\873\Issue873Test.php:7
Stack trace:
#0 phar://C:/phpbin/phpunit.phar/phpunit/Util/Fileloader.php(52): include_once()
#1 phar://C:/phpbin/phpunit.phar/phpunit/Util/Fileloader.php(36): PHPUnit_Util_Fileloader::load('C:\Users\jody\D...')
#2 phar://C:/phpbin/phpunit.phar/phpunit/Framework/TestSuite.php(334): PHPUnit_Util_Fileloader::checkAndLoad('C:\Users\jody\D...')
#3 phar://C:/phpbin/phpunit.phar/phpunit/Framework/TestSuite.php(406): PHPUnit_Framework_TestSuite->addTestFile('C:\Users\jody\D...')
#4 phar://C:/phpbin/phpunit.phar/phpunit/Runner/BaseTestRunner.php(57): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#5 phar://C:/phpbin/phpunit.phar/phpunit/TextUI/Command.php(121): PHPUnit_Runner_BaseTestRunner->getTest('.\tests\', '', Array)
#6 phar://C:/phpbin/phpunit.phar/phpunit/TextUI/Command.php(99): PHPUnit_TextU in C:\Users\jody\Documents\NetBeansProjects\PHPUnit\phpunit\tests\Regression\GitHub\873\Issue873Test.php on line 7
What am I doing wrong? Thanks
If your class "Success" have a namespace, you better use your autoloader with phpunit's --bootstrap parameter
if this situation is related with autoloading, you maybe want to read http://jes.st/2011/phpunit-bootstrap-and-autoloading-classes/ (an old one, but a clear one)
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.