File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed
Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 11language : php
2- dist : trusty
2+ dist : xenial
33sudo : true
44php :
55 - ' 7.1'
Original file line number Diff line number Diff line change 1616
1717namespace Lablnet ;
1818
19+ use InvalidArgumentException ;
20+
1921class Encryption
2022{
2123 /**
@@ -86,6 +88,10 @@ public function setAdapter($adapter)
8688 */
8789 public function setKey ($ key )
8890 {
91+ if ($ key === '' ) {
92+ throw new InvalidArgumentException ('The key should not be empty string. ' );
93+ }
94+
8995 $ this ->key = $ key ;
9096
9197 return $ this ;
Original file line number Diff line number Diff line change 1616
1717namespace Lablnet \Tests ;
1818
19+ use InvalidArgumentException ;
1920use Lablnet \Encryption ;
2021use PHPUnit \Framework \TestCase ;
2122
@@ -42,4 +43,11 @@ public function testEncryptAndDecryptWithSodium()
4243 $ this ->assertSame (112 , strlen ($ encryptedString ));
4344 $ this ->assertSame ('plain-text ' , $ decryptedString );
4445 }
46+
47+ public function testEncryptOnEmptyStringKey ()
48+ {
49+ $ this ->expectException (InvalidArgumentException::class);
50+
51+ new Encryption ('' , 'sodium ' );
52+ }
4553}
You can’t perform that action at this time.
0 commit comments