【发布时间】:2021-10-10 15:13:01
【问题描述】:
我有一个绑定在服务提供者中的类
这个类使用我的门面,它扩展了 laravel 的门面,但是
当我尝试模拟班级时,它说的是Cannot redeclare Mockery_1_App_Classes_Dashboard_class::shouldReceive()。
我的测试方法:
public function test_method()
{
class::shouldReceive('method')->once()->andReturns(true);
$response = $this->another_class->method();
dd($response);
}
我的门面:
<?php
namespace App\Facades\Dashboard;
use Illuminate\Support\Facades\Facade;
class class extends Facade
{
protected static function getFacadeAccessor()
{
return 'class';
}
}
应用服务提供者:
<?php
namespace App\Providers;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use App\Classes\Dashboard\class;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('class', function($app) {
return new class;
});
}
public function boot()
{
Schema::defaultStringLength(191);
}
}
我在网上搜索过,很遗憾没有找到任何东西。
【问题讨论】:
标签: php laravel unit-testing mocking facade