laravel错误调用未定义的方法Illuminate \ Hashing \ BcryptHasher :: driver()

时间:2018-03-06 08:31:43

标签: laravel phpunit

我正在尝试测试我的laravel应用程序,运行phpunit,但收到错误:

Error: Call to undefined method Illuminate\Hashing\BcryptHasher::driver()

laravel 5.5,PHPUnit 7.0

我的用户测试:

namespace Tests\Feature;

use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class UserTest extends TestCase
{
   use RefreshDatabase;

   /** @test */
   function name_should_not_be_too_long()
   {
      $response = $this->post('/users', [
          'name' => str_repeat('a', 51),
          'email' => $this->user->email,
          'password' => 'secret',
      ]);

      $response->assertStatus(302);
      $response->assertSessionHasErrors([
          'name' => 'The name may not be greater than 50 characters.'
      ]);
  }

}

1 个答案:

答案 0 :(得分:5)

在CreatesApplication类中更改以下行:

Hash::driver('bcrypt')->setRounds(4); 

对此:

Hash::setRounds(4); 

之后,执行composer dumpautoload

如果仍然没有运气,请降级到phpunit 6.0。