untymage's avatar

Received Mockery Illuminate Encryption Encrypter::getKey(), but no expectations were specified

I want to test a redirect:

$this->disableCookieEncryption()
->withoutExceptionHandling()
->get(route('test', ['hash' => 123]))
->assertRedirect($redirect);

but i got :

Mockery\Exception\BadMethodCallException : Received Mockery_2_Illuminate_Encryption_Encrypter::getKey(), but no expectations were specified
 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:180
 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67

why the disable methods not working ?

0 likes
2 replies
kevinbui's avatar

Which dependencies are you mocking? Can you pls share the code for the full test case?

untymage's avatar

@kevinbui

Crypt::shouldReceive('getKey');
Crypt::shouldReceive('encrypt');
Crypt::shouldReceive('decrypt')->andReturn(['u' => $user->id, 'p' => $plan->id])->once();

$this->disableCookieEncryption()
->withoutExceptionHandling()
->get(route('test', ['hash' => 123]))
->assertRedirect($redirect);

When i remove the two first line i got that error, the full code does not use any crypto

Please or to participate in this conversation.