Skip to content

Commit 14cbf17

Browse files
committed
Add expects never where the methods should not be called
1 parent 76b2257 commit 14cbf17

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

tests/Unit/Cryptography/PersonalDataPayloadCryptographerTest.php

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class PersonalDataPayloadCryptographerTest extends TestCase
2727
public function testSkipEncrypt(): void
2828
{
2929
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
30-
$cipherKeyStore->method('get');
30+
$cipherKeyStore->expects($this->never())->method('get');
3131

3232
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
3333
$cipher = $this->createMock(Cipher::class);
@@ -85,10 +85,13 @@ public function testEncryptWithExistingKey(): void
8585

8686
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
8787
$cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey);
88-
$cipherKeyStore->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
88+
$cipherKeyStore
89+
->expects($this->never())
90+
->method('store')
91+
->with('foo', $this->isInstanceOf(CipherKey::class));
8992

9093
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
91-
$cipherKeyFactory->method('__invoke');
94+
$cipherKeyFactory->expects($this->never())->method('__invoke');
9295

9396
$cipher = $this->createMock(Cipher::class);
9497
$cipher->expects($this->once())->method('encrypt')->with($cipherKey, 'info@patchlevel.de')
@@ -115,10 +118,13 @@ public function testEncryptWithExistingKeyEncryptedFieldName(): void
115118

116119
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
117120
$cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey);
118-
$cipherKeyStore->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
121+
$cipherKeyStore
122+
->expects($this->never())
123+
->method('store')
124+
->with('foo', $this->isInstanceOf(CipherKey::class));
119125

120126
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
121-
$cipherKeyFactory->method('__invoke');
127+
$cipherKeyFactory->expects($this->never())->method('__invoke');
122128

123129
$cipher = $this->createMock(Cipher::class);
124130
$cipher->expects($this->once())->method('encrypt')->with($cipherKey, 'info@patchlevel.de')
@@ -139,7 +145,7 @@ public function testEncryptWithExistingKeyEncryptedFieldName(): void
139145
public function testSkipDecrypt(): void
140146
{
141147
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
142-
$cipherKeyStore->method('get');
148+
$cipherKeyStore->expects($this->never())->method('get');
143149

144150
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
145151
$cipher = $this->createMock(Cipher::class);
@@ -163,10 +169,10 @@ public function testDecryptWithMissingKey(): void
163169
$cipherKeyStore->method('get')->with('foo')->willThrowException(new CipherKeyNotExists('foo'));
164170

165171
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
166-
$cipherKeyFactory->method('__invoke');
172+
$cipherKeyFactory->expects($this->never())->method('__invoke');
167173

168174
$cipher = $this->createMock(Cipher::class);
169-
$cipher->method('decrypt');
175+
$cipher->expects($this->never())->method('decrypt');
170176

171177
$cryptographer = new PersonalDataPayloadCryptographer(
172178
$cipherKeyStore,
@@ -189,10 +195,13 @@ public function testDecryptWithInvalidKey(): void
189195

190196
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
191197
$cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey);
192-
$cipherKeyStore->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
198+
$cipherKeyStore
199+
->expects($this->never())
200+
->method('store')
201+
->with('foo', $this->isInstanceOf(CipherKey::class));
193202

194203
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
195-
$cipherKeyFactory->method('__invoke');
204+
$cipherKeyFactory->expects($this->never())->method('__invoke');
196205

197206
$cipher = $this->createMock(Cipher::class);
198207
$cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted')
@@ -219,10 +228,10 @@ public function testDecryptWithInvalidKeyWithFallbackCallback(): void
219228

220229
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
221230
$cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey);
222-
$cipherKeyStore->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
231+
$cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
223232

224233
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
225-
$cipherKeyFactory->method('__invoke');
234+
$cipherKeyFactory->expects($this->never())->method('__invoke');
226235

227236
$cipher = $this->createMock(Cipher::class);
228237
$cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted')
@@ -249,10 +258,10 @@ public function testDecryptWithValidKey(): void
249258

250259
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
251260
$cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey);
252-
$cipherKeyStore->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
261+
$cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
253262

254263
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
255-
$cipherKeyFactory->method('__invoke');
264+
$cipherKeyFactory->expects($this->never())->method('__invoke');
256265

257266
$cipher = $this->createMock(Cipher::class);
258267
$cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted')
@@ -280,10 +289,10 @@ public function testDecryptWithValidKeyAndEncryptedFieldName(): void
280289

281290
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
282291
$cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey);
283-
$cipherKeyStore->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
292+
$cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
284293

285294
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
286-
$cipherKeyFactory->method('__invoke');
295+
$cipherKeyFactory->expects($this->never())->method('__invoke');
287296

288297
$cipher = $this->createMock(Cipher::class);
289298
$cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted')
@@ -311,10 +320,10 @@ public function testDecryptWithValidKeyAndEncryptedFieldNameWithoutEncryptedData
311320

312321
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
313322
$cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey);
314-
$cipherKeyStore->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
323+
$cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
315324

316325
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
317-
$cipherKeyFactory->method('__invoke');
326+
$cipherKeyFactory->expects($this->never())->method('__invoke');
318327

319328
$cipher = $this->createMock(Cipher::class);
320329

@@ -340,10 +349,10 @@ public function testDecryptWithValidKeyAndEncryptedFieldNameAndFallbackFieldName
340349

341350
$cipherKeyStore = $this->createMock(CipherKeyStore::class);
342351
$cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey);
343-
$cipherKeyStore->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
352+
$cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class));
344353

345354
$cipherKeyFactory = $this->createMock(CipherKeyFactory::class);
346-
$cipherKeyFactory->method('__invoke');
355+
$cipherKeyFactory->expects($this->never())->method('__invoke');
347356

348357
$cipher = $this->createMock(Cipher::class);
349358
$cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted')

0 commit comments

Comments
 (0)