I updated my project from laravel 8 to laravel 9 then I tried to make a test case generated by artisan.
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class SimpleTest extends TestCase
{
/**
* A basic feature test example.
*
* #return void
*/
public function test_example()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
But when I run phpunit I always get this error
PHP Fatal error: Uncaught Error: Class "Tests\TestCase" not found in path/to/SimpleTest.php:9
How can I fix this?
I created fresh Laravel 9 app to investigate this case.
Apparently the content of TestCase.php in my app was different from the one in fresh app. So I replace TestCase.php file with the one from fresh app and it works now.
Related
Hey guys I have integrated Google sheets using revolution/laravel-google-sheets following this blog https://drivemarketing.ca/en/blog/connecting-laravel-to-a-google-sheet/
Everything works well on my development environment so I have pushed my code to my staging server to test. After pushing my code to the staging server, I ran the following commands composer update, php artisan config:cache and composer dump-autoload in that order. When I test the flow, I get an exception error
ERROR: Class 'Sheets' not found {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0):
Below is a snippet of the controller code
<?php
namespace App\Http\Controllers\API;
use Sheets;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class MainController extends Controller
{
/**
* Write user details to google sheet
*
* #param $user
*/
public function writeUserToSheets($user)
{
Sheets::spreadsheet('google sheet id')->sheet('users')
->append([
[$user->id, $user->email, $user->first_name, $user->last_name, $user->created_at->toDateTimeString()]
]);
}
}
Am I missing anything? How do I get my code to work on my staging server?
I have following lines of code in my controller.
<?php
namespace App\Controller;
use App\Repository\TaskListRepository;
use FOS\RestBundle\Controller\AbstractFOSRestController;
class ListController extends AbstractFOSRestController
{
/**
* #var TaskListRepository
*/
private $taskListRepository;
public function __construct(TaskListRepository $taskListRepository)
{
$this->taskListRepository = $taskListRepository;
}
/**
* #Route("/lists", name="lists")
*/
public function getListsAction()
{
return $this->taskListRepository->findAll();
}
}
When I try to debug route, I am getting following error:
[info] User Deprecated: Using the WebserverBundle is deprecated since
Symfony 4.4. The new Symfony local server has more features, you can
use it instead. 2019-12-16T04:37:53+01:00 [info] User Deprecated:
Loading the file "../../src/Controller/" from the global resource
directory "D:\xampp\htdocs\symfony_rest\src" is depre cated since
Symfony 4.4 and will be removed in 5.0.
How can I fix this issue?
The deprecation message that you get has nothing to do with your controller and is just a warning, not an error.
You have included the WebserverBundle bundle in your project, but this bundle will be deprecated past Symfony 4.4. The bundle itself is fine and you can still use it, but it simply means that you won't be able to use it anymore once you move to Symfony 5.
If you don't use the bundle and want to get rid of the deprecation message, simply run the following command:
composer remove symfony/web-server-bundle
Im getting this exception when running phpunit. I'm running the latest Laravel 5.4 with PHPUnit 5.7.23
ReflectionException: Class config does not exist
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Container/Container.php:729
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Container/Container.php:608
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Container/Container.php:575
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:728
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Container/Container.php:1172
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:57
/home/vagrant/Code/ProcessingHub-App/vendor/myvendor/core/src/app/Providers/CoreServiceProvider.php:50
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:574
/home/vagrant/Code/ProcessingHub-App/tests/CreatesApplication.php:18
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:89
/home/vagrant/Code/ProcessingHub-App/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:66
/home/vagrant/Code/ProcessingHub-App/tests/TestCase.php:27
/home/vagrant/Code/ProcessingHub-App/tests/Unit/PassportTest.php:30
As you can see the exception comes from CoreServiceProvider this is one of my own ServiceProviders Nothing to weird happening there as you can see here
/**
* Register any package services.
*
* #return void
*/
public function register()
{
$this->registerEloquentFactoriesFrom(__DIR__.'/../../database/factories');
$this->mergeConfigFrom(
__DIR__.'/../../config/fields.php', 'fields'
);
}
contents of fields.php:
return [];
If i outcommend $this->mergeConfigFrom() it works like a charm, but the weird thing is i do this in multiple ServiceProviders and in these Classes it is not an issue.
I literally tried everything.
Running: composer dump-autoload
Running: php artisan optimize
Removing vendor and reinstalling everything
Debugging everywhere but no usefull info
Replacing test with basic testExample from laravel didn't work either
I already replaced my .env with an new simple .env didn't help.
My question is:
Does annyone know how i could fix this.
After I looked more into the \tests directory with a fresh Laravel installation i saw the thing i was staring at for like hours and hours.
The application was trying to register the ServiceProvider before the app was bootstraped. Sorry for the troubles (It was not my code).
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
trait CreatesApplication
{
/**
* Creates the application.
*
* #return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$app->register(\StepOrange\Core\Providers\CoreServiceProvider::class);
return $app;
}
}
Problem I'm currently facing to has been posted here already, yet none of them could solve my one.
I'm talking about database seeder located under url like http://HOSTNAME/laravelfiles/database/seeds/UsersTableSeeder.php. Its content is as follows:
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
// What should be being done, it is being done here :)
}
}
Having opened this file directly (by url given above the code), following error is printed:
Fatal error: Class 'Illuminate\Database\Seeder' not found in /var/www/laravelfiles/database/seeds/UsersTableSeeder.php on line 6
I found possible solution. Doesn't work for me:
composer dump-autoload
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
}
NOTE: Even the code above produces the same error.
You must run seeder class via command line, not browser.
you should open your command line and change directory to laravel root folder.
then you need to run command:
php artisan db:seed
and check your database.
for more info please check laravel documentation(Laravel Database Seeding)
I'm trying to follow some examples of using KernetTestCase for a Symfony 2 test that touches the DB.
I get this error:
Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Test\KernelTestCase' not found in...
In my test files I have:
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
and
class AcmeContestTest extends KernelTestCase
However I still get the error above when running tests...
I figured out that Symfony version 2.3 which I'm using doesn't have KernelTestCase extracted out of WebTestCase as Symfony version 2.5 has...
for reference check out: https://github.com/symfony/symfony/tree/master/src/Symfony/Bundle/FrameworkBundle/Test