首页 > 解决方案 > 当我尝试模拟它时重新声明方法

问题描述

我有一个绑定在服务提供者中的类,
这个类使用我的门面,它扩展了 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);
    }
}

我搜索了网络,不幸的是没有找到任何东西。

标签: phplaravelunit-testingmockingfacade

解决方案


终于发现问题了。
我不小心在我的类继承中扩展了 laravel 的外观。


推荐阅读