S
S
Sergey Beloventsev2020-08-21 21:27:44
Laravel
Sergey Beloventsev, 2020-08-21 21:27:44

Why don't unit tests pass?

Actually, the User class has such a method

public static function register(RegisterRequest $request):self
   
{
         return static::create([
             'name'=>$request->name,
             'email'=>$request->email,
             'password'=>bcrypt($request->password),
             'verify_token' => Str::random(),
             'status' => self::STATUS_WAIT,
         ]);
    }

this is how i try to test it

public function create():void
    {
        $user=User::register($this->request);
        self::assertNotEmpty($user);
        self::assertEquals($this->name,$user->name);
        self::assertEquals($this->email,$user->email);
        self::assertNotEmpty($user->password);
        self::assertEquals($this->password,$user->password);
        self::assertTrue($user->isWait());
        self::assertFalse($user->isActive());
    }


this is how I create RegisterRequest
public function setUp(): void
    {
        parent::setUp();
        $this->request= $this->createMock(RegisterRequest::class);
        $this->request->name=$this->name;
        $this->request->email=$this->email;
        $this->request->password=$this->password;
    }


I get such an error

Caused by
ReflectionException: Class hash does not exist

/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:809
/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:691
/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:796
/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:637
/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:781
/www/app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:119
/www/app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:205
/www/app/app/Entity/User.php:81
/www/app/tests/Unit/RegisterTest.php:69

actually swears on this line

'password'=>bcrypt($request->password),
in a method register Why such can be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-sem, 2020-08-21
@Sergalas

Why are you hashing this way, and not as in the documentation?
https://laravel.com/docs/7.x/hashing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question