【问题标题】:redeclaring method when i try to mock it当我尝试模拟它时重新声明方法
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多