简体   繁体   English

Laravel 5.8 目标 [Illuminate\Contracts\Debug\ExceptionHandler] 不可实例化

[英]Laravel 5.8 Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable

I am working through upgrading my PHP 5.4, Laravel 4.2 application to PHP 7.4, Laravel 5.8. I am working through upgrading my PHP 5.4, Laravel 4.2 application to PHP 7.4, Laravel 5.8.

In some of my tests, on tearDownAfterClass, I will do some DB cleanup.在我的一些测试中,在 tearDownAfterClass 上,我会做一些数据库清理。 With Laravel 5.8, these don't work and I can't figure out why.使用 Laravel 5.8,这些都不起作用,我不知道为什么。

The following test using Laravel 5.4, works.以下使用 Laravel 5.4 的测试有效。 With 5.8, does not work.用5.8,不行。

I have updated my 5.8 configs from the defaults, they are proper.我已经从默认值更新了我的 5.8 配置,它们是正确的。 My database connection works, the tests all pass with DB activity.我的数据库连接有效,测试全部通过数据库活动。

The error only fails in the static tearDownAfterClass, I added the same \DB::table(static::$audittable)->truncate();该错误仅在 static tearDownAfterClass 中失败,我添加了相同的\DB::table(static::$audittable)->truncate(); to one of my tests, it works without error.对于我的一项测试,它可以正常工作。

How do I fix the exception below?如何解决以下异常?

Using PHP 7.4.6, Laravel 5.8:使用 PHP 7.4.6、Laravel 5.8:

class ModelAuditQueriesTest extends TestCase
{
  static $audittable = 'contactnotesaudit';

  public static function tearDownAfterClass()
  {
    \DB::table(static::$audittable)->truncate(); **// <-- this fails, error below; line 11**
    parent::tearDownAfterClass();
  }

  public function testInsertSingle()
  {
    \DB::table(static::$audittable)->truncate(); **// <-- this works, no errors**
    /**
     * testing stuff with models that insert and select with database, successfully
     */
  }
}

With PHPUNIT.XML, processIsolation = false使用 PHPUNIT.XML,processIsolation = false

PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php:960
Stack trace:
#0 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(794): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(767): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(170): Illuminate\Foundation\Application->make('Illuminate\\ in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 960
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php:960
Stack trace:
#0 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(794): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(767): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(170): Illuminate\Foundation\Application->make('Illuminate\\ in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 960

With PHPUNIT.XML, processIsolation = true使用 PHPUNIT.XML,processIsolation = true

PHP Fatal error:  Uncaught Error: Class 'DB' not found in C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php:11
Stack trace:
#0 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\Framework\TestSuite.php(760): Tests\commonmodelaudit\ModelAuditQueriesTest::tearDownAfterClass()
#1 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(545): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#2 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\Command.php(195): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#3 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#4 C:\CODE\IDWEB5\vendor\phpunit\phpunit\phpunit(53): PHPUnit\TextUI\Command::main()
#5 {main}
  thrown in C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php on line 11

Error : Cannot use object of type Illuminate\Support\Facades\Config as array
 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:270
 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:101
 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:77
 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:349
 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:239
 C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php:11

I have run the following to make sure all is clean:我运行了以下命令以确保一切都是干净的:

composer dump-autoload
php artisan clear-compiled
php artisan optimize
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

I think the application has already shut-down at the tearDownAfterClass part of the code.我认为应用程序已经在代码的tearDownAfterClass部分关闭。

Since you are trying to truncate a table, I think you might find it easier to instead use the trat DatabaseTransactions eg由于您正在尝试截断表,我认为您可能会发现使用 trat DatabaseTransactions更容易,例如

class ModelAuditQueriesTest extends TestCase
{
  use DatabaseTransactions;
}

this will make any changes you make in the database during this test to not be rolled back since they are all done within a transaction which is never commited.这将使您在此测试期间在数据库中所做的任何更改都不会回滚,因为它们都是在从未提交的事务中完成的。

Another hacky way to do what you want is to "restart" the application.做你想做的另一种hacky方法是“重新启动”应用程序。

The TestCase that comes in the boilerplate has a trait CreatesApplication .样板中的TestCase有一个特性CreatesApplication This unfortunately is not static but you can just copy paste it and "restart" the application:不幸的是,这不是 static 但您可以复制粘贴它并“重新启动”应用程序:

class ModelAuditQueriesTest extends TestCase
{
  static $audittable = 'contactnotesaudit';

  public static function tearDownAfterClass()
  {
    $app = require __DIR__.'/../bootstrap/app.php'; //You might need to adjust the path
    $app->make(Kernel::class)->bootstrap();
    \DB::table(static::$audittable)->truncate();
    parent::tearDownAfterClass();
  }
}

Now unfortunately the error you are seeing is that the error handler could not be instantiated which means once you do this you will see the actual reason that the error handler was being instantiated which is probably going to be another exception.现在不幸的是,您看到的错误是无法实例化错误处理程序,这意味着一旦您这样做,您将看到错误处理程序被实例化的实际原因,这可能是另一个异常。 However at least that might be more informative.但是,至少这可能会提供更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 目标 [Illuminate\\Contracts\\Debug\\ExceptionHandler] 不可实例化 - Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable Laravel “目标 [Illuminate\\Contracts\\Bus\\Dispatcher] 不可实例化。” - Laravel "Target [Illuminate\Contracts\Bus\Dispatcher] is not instantiable." 目标 [Illuminate\Contracts\Broadcasting\Factory] 不可实例化 - Target [Illuminate\Contracts\Broadcasting\Factory] is not instantiable Laravel 5.1:Auth::logout() 不起作用并且目标 [Illuminate\\Contracts\\Auth\\Registrar] 不是可实例化的错误 - Laravel 5.1: Auth::logout() is not working and Target [Illuminate\Contracts\Auth\Registrar] is not instantiable error 目标 [Laravel\Fortify\Contracts\RegisterViewResponse] 不可实例化 - target [Laravel\Fortify\Contracts\RegisterViewResponse] is not instantiable PHPUnit 给出错误:目标 [Illuminate\Contracts\View\Factory] 不可实例化 - PHPUnit gives error: Target [Illuminate\Contracts\View\Factory] is not instantiable Illuminate\\Contracts\\Filesystem\\Factory 不可实例化 - Illuminate\Contracts\Filesystem\Factory is not instantiable Laravel错误:无法实例化目标[Illuminate \\ View \\ Engines \\ EngineInterface] - Laravel error: Target [Illuminate\View\Engines\EngineInterface] is not instantiable Laravel 6 错误 - Illuminate\Contracts\Container\BindingResolutionException 目标 class 不存在 - Laravel 6 Error - Illuminate\Contracts\Container\BindingResolutionException Target class does not exist Laravel 5目标不可实例化 - Laravel 5 target is not instantiable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM