A flip/flop unit test to give you a sample:
<?php
use PHPUnit\Framework\TestCase;
class SodiumTest extends TestCase
{
public function testSodium()
{
$key = sodium_crypto_aead_xchacha20poly1305_ietf_keygen();
$nonce = random_bytes(SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES);
$flip = 'Hello, world!';
$ciphertext = sodium_crypto_aead_chacha20poly1305_encrypt($flip, $nonce, $nonce, $key);
$flop = sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, $nonce, $nonce, $key);
$this->assertEquals($flip, $flop);
}
}
?>
Side note: the nonce is used twice in this test, but you can use a username, an identifier or whatever you like in `$additional_data`