@@ -183,6 +183,32 @@ public function testDeleteUserIdUnknown()
183183 $ keyEditor ->edit ('second-keypair@example.com ' , 'test2 ' )->deleteUserId ($ user )->save ();
184184 }
185185
186+ /**
187+ * Test `expire` command
188+ */
189+ public function testExpire ()
190+ {
191+ $ keyEditor = $ this ->gpg ->getKeyEditor ();
192+
193+ // Test setting an expiration date (one year from today)
194+ $ keyEditor ->edit ('second-keypair@example.com ' , 'test2 ' )->expire ('1y ' )->save ();
195+
196+ $ keys = $ this ->gpg ->getKeys ('second-keypair@example.com ' );
197+ $ primary = $ keys [0 ]->getPrimaryKey ();
198+ $ this ->assertSame ((date ('Y ' ) + 1 ) . date ('-m-d ' ), $ primary ->getExpirationDateTime ()->format ('Y-m-d ' ));
199+
200+ // Test unsetting an expiration date
201+ $ keyEditor ->edit ('second-keypair@example.com ' , 'test2 ' )->expire (0 )->save ();
202+
203+ $ keys = $ this ->gpg ->getKeys ('second-keypair@example.com ' );
204+ $ primary = $ keys [0 ]->getPrimaryKey ();
205+ $ this ->assertNull ($ primary ->getExpirationDateTime ());
206+
207+ // Test invalid period
208+ $ this ->expectException ('Crypt_GPG_Exception ' );
209+ $ keyEditor ->edit ('second-keypair@example.com ' , 'test2 ' )->expire ('-1 ' )->save ();
210+ }
211+
186212 /**
187213 * Test `passwd` command
188214 */
@@ -218,8 +244,9 @@ public function testRevokeUserId()
218244 $ keys = $ this ->gpg ->getKeys ('second-keypair@example.com ' );
219245 $ userIds = $ keys [0 ]->getUserIds ();
220246 $ this ->assertCount (2 , $ userIds );
221- $ userIds = array_filter ($ userIds , function ($ id ) use ($ user1 ) { return $ id ->getEmail () == $ user1 ->getEmail (); });
247+ $ userIds = array_values ( array_filter ($ userIds , function ($ id ) use ($ user1 ) { return $ id ->getEmail () == $ user1 ->getEmail (); }) );
222248 $ this ->assertCount (1 , $ userIds );
249+ $ this ->assertTrue ($ userIds [0 ]->isRevoked ());
223250
224251 // Test revoking the last user
225252 $ user = new Crypt_GPG_UserId ('Second Keypair Test Key (do not encrypt important data with this key) <second-keypair@example.com> ' );
0 commit comments