Fatal error: Cannot redeclare route() when running PHPUnit - php

I got a specific problem with PHPUnit.
I had to write our own route() helper, which I require at the very start of the boot process. It all works fine, because Laravel actually asks if a similar named function already exists whenever generating a helper.
When I try to run tests, I get:
Fatal error: Cannot redeclare route() (previously declared in
E:\laragon\www\fksp\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php:754)
in E:\laragon\www\fksp\app\Http\helpers.php on line 30
And I don't know why. Why does PHPUnit think that the Laravel helper is declared before ours?
I could wrap our function into
if (! function_exists('route')) {}
and it works, but then most likely I will run into problems in the long run with every test that uses the route function?
Any idea or insights how PHPUnit works?

Related

include a class from a different website in laravel new project

I am working on a backend api using laravel 5.6
Already have a website with tons of code - all the answers I found point at create a new folder and adding my classes there that is not an option.
I would like to include the class from the main site (same server) and use the methods within laravel to generate the data from the api.
Route::get('api/author/full/', array('uses' => 'AuthorController#getAuthor'));
I am using this line to include my class:
require_once('/var/www/html/modules/author/models/Author.class.php');
laravel is located in a subfolder at /var/www/html/api/
this is the error I get when i try to require that file from within the AuthorController :
Fatal error: Call to undefined method ErrorException::getStatusCode() in /html/api/app/Exceptions/Handler.php on line 61
Fatal error: Call to undefined method Symfony\Component\Debug\Exception\FatalErrorException::getStatusCode() in /html/api/app/Exceptions/Handler.php on line 61
really tried everything here,included it in public/index.php and in other places and none of these things worked.

PHP Fatal error: Uncaught Error: Class when using exec();

I'm writing a web app, and I created a scraper to get data from my own site.
I have a few dependencies, so they're being extended, but now that I'm trying to run this php script from exec, and it doesn't work, I get the error:
PHP Fatal error: Uncaught Error: Class 'App\Helpers\ScraperHelper' not found in /home/username/public_html/App/Libraries/Scraper/execute.php:6.
Begin.php
This is how I'm calling my script:
exec('/usr/bin/php/ home/username/public_htm/App/Libraries/Scraper/execute.php');
Execute.php
namespace App\Libraries\Scraper;
use \App\Helpers\ScraperHelper;
$recipe = new ScraperHelper();
$recipe->fromFeed();
fromFeed() runs the script that's included in the ScraperHelper class, scrape the information from the site and inserts it into the database.
I've tried removing all the namespaces, and using require with full server path, but there are a 4 other dependencies that doesn't allow me to access them.
require_once '/home/username/public_html/App/Helpers/ScraperHelper.php';
require_once '/home/username/public_html/App/Models/Food.php';
require_once '/home/username/public_html/Core/Model.php';
Composer is autoloading two folders. Core and App, but I figure that the exec function ignores it which is why I keep getting Uncaught Error.
I believe exec isn't being able to process the namespaces and use calls, I included all the files with require_once and it worked, but It's not what I need still, I really need to know how to make exec process namespaces, use calls.

Laravel 5.3 unauthorized() AuthenticationException fatal error

I've followed Laravel 5.3 upgrade guide, which says to add an unauthenticated method in App\Exceptions\Handler.
However, I get the following error when it gets called by the Auth system:
FatalThrowableError in Handler.php line 59:
Type error: Argument 2 passed to App\Exceptions\Handler::unauthenticated() must be an instance of App\Exceptions\AuthenticationException, instance of Illuminate\Auth\AuthenticationException given, called in /Users/Username/Development/ProjectName/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 135
I've been searching for the last half hour and couldn't find a solution.
Any help?
Check how your Handler.php file compares to the 5.3 branch version here: https://github.com/laravel/laravel/blob/5.3/app/Exceptions/Handler.php
Note the unauthenticated() method in Handler.php expects an instance of \Illuminate\Auth\AuthenticationException. Make sure use Illuminate\Auth\AuthenticationException; is included at the top of the file.
In my case, i just deleted whoops... or restore the default Handler.php
I had this Error 500 inexplicable issue while upgrading from Laravel 5.2 to 5.3. No laravel error logs in storage/logs, no Apache error logs. no issue with .env, debug was turned on, no broken .htaccess directives, plus php artisan could not run. Tried everything until I looked in the PHP error logs and found:
PHP Fatal error: Uncaught Error: Undefined constant 'Illuminate\Auth\AuthenticationException' in C:\code\laravel-project\vendor\laravel\framework\src\Illuminate\Container\Container.php:79
So I did what #jon suggested and compared my Handler.php file with the fresh laravel one and found this:
In your App/Exceptions/Handler.php make sure that the classes in the $dontreport array are referenced as either strings in quotes:
'\Illuminate\Auth\AuthenticationException',
'\Illuminate\Auth\Access\AuthorizationException',
'\Symfony\Component\HttpKernel\Exception\HttpException',
'\Illuminate\Database\Eloquent\ModelNotFoundException',
'\Illuminate\Session\TokenMismatchException',
'\Illuminate\Validation\ValidationException',
or this way:
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
For some reason I found mine to not have the quotes and fixing that got rid of the Error 500.

How to detect which file error in Lavel 5

I'm learing laravel 5. A day, when I run php artisan command I got this error
Catchable fatal error: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in C:\xampp\htdocs\premiumlens\vendor\laravel\framework\src\Illuminate\Routing\RoutingServiceProvider.php on line 62 and defined in C:\xampp\htdocs\premiumlens\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php on line 102
Almost application functions work perfect. But may not all. I'm sure the error is not caused by UrlGenerator.php
Now I cant use any artisan functions. How can I detect which file cause this issue.
Thank you !
I think you used url() helper in your config file, find where you put url() helper in your config file and remove it. your problem will be solved. i had this same problem and solved by removing url() form config file..
url('bassets/plugins/highcharts/highcharts.css'),

fatal Error when using pear pager !

i used PEAR Pager in my Projects . it's works fine in my local server but when i upload it to hosing server it's gaves me fatal error :
Fatal error: Cannot redeclare class PEAR_Common in /usr/lib/php/PEAR/Common.php on line 1123
i don't know what's the problem , how can i solve that ?!
The error message says it all. It seems like the class PEAR_Common is loaded twice. Check your code for includes/requires of this class.
If you are using other pear packages that might load (include) this class before you include your Pear_Pager class then this might be the problem.
Regards,

Categories