在Laravel包上运行测试的问题

wkftcu5l  于 2023-03-31  发布在  其他
关注(0)|答案(1)|浏览(118)

我使用了一个经过转换的Spatie/laravel-package-skeleton,并为我的系统使用了我自己的ModuleServiceProvider和Module类。
我没有在网上找到足够的资源来制作我的模块系统,所以可能有一个实现的问题。
通常(我认为),当你开发一个包时,你希望像这样抽象,你的包是独立的,可以安装在各种Stack上。但是我的包需要直接链接到我的应用程序类,因为我有一个src文件夹和很多直接链接到它的类。
我使用Pest和Orchestra/test-bench运行我的测试
我需要在我的包composer.json中添加一些依赖项并处理psr-4自动加载,所以我的composer.json自动加载部分看起来像这样:

"autoload": {
        "psr-4": {
            "App\\": "../../../app/",
            "Src\\": "../../../src/",
            "Src\\core\\": "../../../src/core/",
            "Src\\core\\database\\": "../../../src/core/database/",
            "Src\\core\\database\\factories\\": "../../../src/core/database/factories/",
            "Src\\core\\database\\migrations\\": "../../../src/core/database/migrations/",
            "Src\\core\\action\\": "../../../src/core/action/",
            "Src\\core\\component\\": "../../../src/core/component/",
            "Src\\core\\hook\\": "../../../src/core/hook/",
            "Src\\core\\module\\": "../../../src/core/module/",
            "AlexisVS\\MultipassTestingModule\\": "src/",
            "AlexisVS\\MultipassTestingModule\\Database\\Factories\\": "database/factories/",
            "AlexisVS\\MultipassTestingModule\\Database\\Migrations\\": "database/migrations/",
            "AlexisVS\\MultipassTestingModule\\Tests\\": "tests/"
        }
    },

我觉得很奇怪,但它加载他们,所以我留在这样
现在我犯了这个错误:

FAILED  Tests\ArchTest > it will not use debugging functions                  TypeError   
  str_ends_with(): Argument #1 ($haystack) must be of type string, array given

  at vendor/laravel/framework/src/Illuminate/Support/Str.php:301
    297▕             $needles = (array) $needles;
    298▕         }
    299▕
    300▕         foreach ($needles as $needle) {
  ➜ 301▕             if ((string) $needle !== '' && str_ends_with($haystack, $needle)) {     
    302▕                 return true;
    303▕             }
    304▕         }
    305▕

  1   vendor/laravel/framework/src/Illuminate/Support/Str.php:301
  2   vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:124
  3   vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:92
  4   vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1820
  5   vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1786
  6   vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1578
  7   vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1497
  8   vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1533
  9   vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1486
  10  vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2335
  11  vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2347
  12  /var/www/html/src/core/module/AbstractModuleClass.php:67
  13  /var/www/html/src/core/module/ModuleServiceProvider.php:42
  14  vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
  15  vendor/laravel/framework/src/Illuminate/Container/Util.php:41
  16  vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
  17  vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35
  18  vendor/laravel/framework/src/Illuminate/Container/Container.php:661
  19  vendor/laravel/framework/src/Illuminate/Foundation/Application.php:1006
  20  vendor/laravel/framework/src/Illuminate/Foundation/Application.php:789
  21  vendor/laravel/framework/src/Illuminate/Foundation/Application.php:898
  22  vendor/laravel/framework/src/Illuminate/Foundation/Application.php:878
  23  vendor/laravel/framework/src/Illuminate/Foundation/Application.php:854
  24  vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:431
  25  vendor/orchestra/testbench-core/src/Concerns/CreatesApplication.php:369
  26  vendor/orchestra/testbench-core/src/Concerns/CreatesApplication.php:230
  27  vendor/orchestra/testbench-core/src/TestCase.php:85
  28  vendor/orchestra/testbench-core/src/Concerns/Testing.php:88
  29  vendor/orchestra/testbench-core/src/TestCase.php:52
  30  tests/TestCase.php:32
  31  vendor/pestphp/pest/src/Concerns/Testable.php:182
  32  vendor/pestphp/pest/src/Kernel.php:86
  33  vendor/pestphp/pest/bin/pest:91
  34  vendor/pestphp/pest/bin/pest:99

但问题(我认为)不在这里。
为了更好的上下文,我用途:Laravel 10 PHP 8.2 Laravel
当我尝试运行测试时,我将转到vendor/alexisvs/multipass-testing-module,安装依赖项并运行composer run test
如果有人知道...
我甚至不知道我还能做些什么来调试
./vendor/vin/pest -vvv是一个相当有限的:)

z9smfwbn

z9smfwbn1#

它实际上是我在myPackage/tests/TestCase.php中的数据库配置
我已经解决了这个问题

public function getEnvironmentSetUp($app)
{
    config()->set('database.default', 'testing');
}

相关问题