【问题标题】:InvalidArgumentException: Unable to locate factory with name [default] [App\Routedata]InvalidArgumentException:无法找到名称为 [default] [App\Routedata] 的工厂
【发布时间】:2017-09-20 19:04:36
【问题描述】:

这是我的功能

public function create($alias, $profileId)
    {
        $this->setClientAndClientProfile($alias, $profileId);

        return view('client.data.map')->with('client', $this->client)->with('clientProfile', $this->clientProfile);
    }

这是我写的测试

public function createTest()
    {
        $this->Data = factory(App\Data::class)->create([
            'id' => '1',
            'client' => 'first',
            ' name' => 'name1',
            'Status' => ''

        ]);
       $this->be($this->$RouteForecast);
       $this->visit('/backend/data')

        ->seePageIs('/backend/data');

    }

当我运行时出现此错误

InvalidArgumentException: Unable to locate factory with name [default] [App\Data].

我该如何解决这个问题?

【问题讨论】:

  • 您在database/factories/ModelFactory.php 文件中是否有带有App\Data::class 的条目?
  • 这是我的模式工厂 $factory->define(App\User::class, function (Faker\Generator $faker) { return [ 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10), ]; });
  • 这就是你的错误。你应该有另一个代码块,比如$factory->define(App\Data::class, function(Faker\Generator $faker) {...})

标签: php laravel unit-testing laravel-5 laravel-5.1


【解决方案1】:

在我的情况下是:

phpunit --version PHPUnit 3.7.21 by Sebastian Bergmann.

我在 laravel 5.5 中遇到了这个问题。但在我的 composer.json 中是 6.4。这意味着我有另一个旧版本的 phpunit 路径。它在 Xampp/php/phpunit 文件中。 Laravel 的 phpunit 是 'vendor/bin/phpunit'。所以我尝试了这个:

C:\xampp\htdocs\www\blog\vendor\bin\phpunit --version
PHPUnit 6.4.3 by Sebastian Bergmann and contributors.

瞧!

【讨论】:

    猜你喜欢
    • 2017-03-13
    • 2017-04-20
    • 2020-02-26
    • 2019-05-26
    • 2019-03-19
    • 2016-04-06
    • 1970-01-01
    • 2020-04-05
    • 2021-01-29
    相关资源
    最近更新 更多