我用我自己的ModuleServiceProvider和Module类为我的系统使用了一个转换过的Spatie/laravel-package-skeleton。
我没有在网上找到足够的资源来制作我的模块系统,所以可能有一个实现的问题。
通常(我认为),当你开发一个像这样抽象的包时,你的包是独立的,可以安装在各种Stack上。但是我的包需要直接链接到我的应用程序类,因为我有一个src文件夹和很多类直接链接到它。
我使用Pest和Orchestra/test-bench来运行我的测试
我需要在包编写器中添加一些依赖项。Json和处理psr-4自动加载,所以我的作曲家。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 TestsArchTest > 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 10PHP 8.2Laravel帆当我尝试运行测试时,我要去vendor/alexisvs/multipass-testing-module,我安装依赖并运行composer run test
如果有人知道…
我甚至不知道我能做些什么来调试更多./vendor/vin/pest -vvv
是相当有限的:)
它实际上是我在myPackage/tests/TestCase.php中的数据库配置
我用
解决了这个问题public function getEnvironmentSetUp($app)
{
config()->set('database.default', 'testing');
}