Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions Tests/Cipher/CryptoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
use Defuse\Crypto\Key as DefuseKey;
use Joomla\Crypt\Cipher\Crypto as CryptoCipher;
use Joomla\Crypt\Key;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\Polyfill\Util\Binary;

/**
* Test class for \Joomla\Crypt\Cipher\Crypto.
*/
#[CoversClass(CryptoCipher::class)]
#[UsesClass(Key::class)]
class CryptoTest extends TestCase
{
/**
Expand Down Expand Up @@ -52,14 +57,10 @@ public static function dataStrings(): array
}

/**
* @testdox Validates data is encrypted and decrypted correctly
*
* @param string $data The decrypted data to validate
*
* @covers \Joomla\Crypt\Cipher\Crypto
* @uses \Joomla\Crypt\Key
*/
#[DataProvider('dataStrings')]
#[TestDox('Validates data is encrypted and decrypted correctly')]
public function testDataEncryptionAndDecryption($data)
{
$cipher = new CryptoCipher();
Expand All @@ -76,12 +77,7 @@ public function testDataEncryptionAndDecryption($data)
$this->assertSame($data, $decrypted);
}

/**
* @testdox Validates keys are correctly generated
*
* @covers \Joomla\Crypt\Cipher\Crypto
* @uses \Joomla\Crypt\Key
*/
#[TestDox('Validates keys are correctly generated')]
public function testGenerateKey()
{
$cipher = new CryptoCipher();
Expand Down
18 changes: 7 additions & 11 deletions Tests/Cipher/OpenSSLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@

use Joomla\Crypt\Cipher\OpenSSL;
use Joomla\Crypt\Key;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Crypt\Cipher\OpenSSL.
*/
#[CoversClass(OpenSSL::class)]
#[UsesClass(Key::class)]
class OpenSSLTest extends TestCase
{
/**
Expand Down Expand Up @@ -50,14 +55,10 @@ public static function dataStrings(): array
}

/**
* @testdox Validates data is encrypted and decrypted correctly
*
* @param string $data The decrypted data to validate
*
* @covers \Joomla\Crypt\Cipher\OpenSSL
* @uses \Joomla\Crypt\Key
*/
#[DataProvider('dataStrings')]
#[TestDox('Validates data is encrypted and decrypted correctly')]
public function testDataEncryptionAndDecryption($data)
{
$cipher = new OpenSSL('1234567890123456', 'aes-128-cbc');
Expand All @@ -74,12 +75,7 @@ public function testDataEncryptionAndDecryption($data)
$this->assertSame($data, $decrypted);
}

/**
* @testdox Validates keys are correctly generated
*
* @covers \Joomla\Crypt\Cipher\OpenSSL
* @uses \Joomla\Crypt\Key
*/
#[TestDox('Validates keys are correctly generated')]
public function testGenerateKey()
{
$passphraseFile = __DIR__ . '/stubs/openssl-passphrase.dat';
Expand Down
18 changes: 7 additions & 11 deletions Tests/Cipher/SodiumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
use Joomla\Crypt\Cipher\Sodium;
use Joomla\Crypt\Key;
use ParagonIE\Sodium\Compat;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\Polyfill\Util\Binary;

/**
* Test class for \Joomla\Crypt\Cipher\Sodium.
*/
#[CoversClass(Sodium::class)]
#[UsesClass(Key::class)]
class SodiumTest extends TestCase
{
/**
Expand Down Expand Up @@ -52,14 +57,10 @@ public static function dataStrings(): array
}

/**
* @testdox Validates data is encrypted and decrypted correctly
*
* @param string $data The decrypted data to validate
*
* @covers \Joomla\Crypt\Cipher\Sodium
* @uses \Joomla\Crypt\Key
*/
#[DataProvider('dataStrings')]
#[TestDox('Validates data is encrypted and decrypted correctly')]
public function testDataEncryptionAndDecryption($data)
{
$cipher = new Sodium();
Expand All @@ -78,12 +79,7 @@ public function testDataEncryptionAndDecryption($data)
$this->assertSame($data, $decrypted);
}

/**
* @testdox Validates keys are correctly generated
*
* @covers \Joomla\Crypt\Cipher\Sodium
* @uses \Joomla\Crypt\Key
*/
#[TestDox('Validates keys are correctly generated')]
public function testGenerateKey()
{
$cipher = new Sodium();
Expand Down
39 changes: 15 additions & 24 deletions Tests/CryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
use Joomla\Crypt\CipherInterface;
use Joomla\Crypt\Crypt;
use Joomla\Crypt\Key;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Crypt\Crypt.
*/
#[CoversClass(Crypt::class)]
#[UsesClass(Key::class)]
class CryptTest extends TestCase
{
/**
Expand Down Expand Up @@ -51,16 +57,12 @@ protected function setUp(): void
parent::setUp();

$this->cipher = $this->createMock(CipherInterface::class);
$this->key = $this->createMock(Key::class);
$this->key = $this->createStub(Key::class);

$this->object = new Crypt($this->cipher, $this->key);
}

/**
* @testdox Validates data is encrypted and decrypted correctly
*
* @covers \Joomla\Crypt\Crypt
*/
#[TestDox('Validates data is encrypted and decrypted correctly')]
public function testDataEncryptionAndDecryption()
{
$decrypted = 'decrypt';
Expand All @@ -80,30 +82,21 @@ public function testDataEncryptionAndDecryption()
$this->object->decrypt($encrypted);
}

/**
* @testdox Validates keys are correctly generated
*
* @covers \Joomla\Crypt\Crypt
* @uses \Joomla\Crypt\Key
*/
#[TestDox('Validates keys are correctly generated')]
public function testGenerateKey()
{
$this->cipher->expects($this->once())
->method('generateKey')
->willReturn($this->createMock(Key::class));
->willReturn($this->createStub(Key::class));

$this->object->generateKey();
}

/**
* @testdox Validates a new key can be set
*
* @covers \Joomla\Crypt\Crypt
* @uses \Joomla\Crypt\Key
*/
#[AllowMockObjectsWithoutExpectations]
#[TestDox('Validates a new key can be set')]
public function testSetKey()
{
$key = $this->createMock(Key::class);
$key = $this->createStub(Key::class);

$this->object->setKey($key);

Expand All @@ -130,13 +123,11 @@ public static function dataRandomByteLength(): array
}

/**
* @testdox Validates a string of random bytes of the requested size is returned
*
* @param integer $length The length of the random string to generate
*
* @covers \Joomla\Crypt\Crypt
*/
#[AllowMockObjectsWithoutExpectations]
#[DataProvider('dataRandomByteLength')]
#[TestDox('Validates a string of random bytes of the requested size is returned')]
public function testGenRandomBytes($length)
{
$this->assertSame(
Expand Down
21 changes: 6 additions & 15 deletions Tests/KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
namespace Joomla\Crypt\Tests;

use Joomla\Crypt\Key;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Joomla\Crypt\Key.
*/
#[CoversClass(Key::class)]
class KeyTest extends TestCase
{
/**
Expand Down Expand Up @@ -60,31 +63,19 @@ protected function setUp(): void
$this->object = new Key($this->type, $this->private, $this->public);
}

/**
* @testdox Validates the private key is returned
*
* @covers Joomla\Crypt\Key
*/
#[TestDox('Validates the private key is returned')]
public function testGetPrivate()
{
$this->assertSame($this->private, $this->object->getPrivate());
}

/**
* @testdox Validates the public key is returned
*
* @covers Joomla\Crypt\Key
*/
#[TestDox('Validates the public key is returned')]
public function testGetPublic()
{
$this->assertSame($this->public, $this->object->getPublic());
}

/**
* @testdox Validates the key type is returned
*
* @covers Joomla\Crypt\Key
*/
#[TestDox('Validates the key type is returned')]
public function testGetKeyType()
{
$this->assertSame($this->type, $this->object->getType());
Expand Down
7 changes: 0 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@
<directory>Tests</directory>
</testsuite>
</testsuites>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
Loading