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
Related
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
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 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.
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.
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)