Skip to content

Commit

Permalink
Merge pull request #49 from sebb/upgrade-php-phpunit
Browse files Browse the repository at this point in the history
Upgrade PHPUnit to 8+ and allow the package to be installed with PHP 8.0
  • Loading branch information
absolute-quantum authored Nov 20, 2021
2 parents 917f3a2 + c1d2420 commit d1d0157
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 43 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ matrix:
- php: 7.3
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"

- php: 7.4
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"

- php: 8.0
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"

# Latest commit to master
- php: 7.3
env: STABILITY="dev"
Expand Down
6 changes: 3 additions & 3 deletions Tests/Functional/AbstractFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class AbstractFunctionalTestCase extends TestCase

abstract protected function getEncryptor(): EncryptorInterface;

public function setUp()
public function setUp(): void
{
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
Expand Down Expand Up @@ -73,7 +73,7 @@ public function setUp()
error_reporting(E_ALL);
}

public function tearDown()
public function tearDown(): void
{
unlink($this->dbFile);
}
Expand Down Expand Up @@ -132,4 +132,4 @@ public function assertStringDoesNotContain($needle, $string, $ignoreCase = false

static::assertThat($string, $constraint, $message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

abstract class AbstractBasicQueryTestCase extends AbstractFunctionalTestCase
{
public function testPersistEntity()
public function testPersistEntity(): void
{
$user = new CascadeTarget();
$user->setNotSecret('My public information');
Expand All @@ -21,7 +21,7 @@ public function testPersistEntity()
$this->assertEquals(3,$this->getCurrentQueryCount());
}

public function testNoUpdateOnReadEncrypted()
public function testNoUpdateOnReadEncrypted(): void
{
$this->entityManager->beginTransaction();
$this->assertEquals(1,$this->getCurrentQueryCount());
Expand Down Expand Up @@ -57,7 +57,7 @@ public function testNoUpdateOnReadEncrypted()
$this->assertEquals(4,$this->getCurrentQueryCount());
}

public function testStoredDataIsEncrypted()
public function testStoredDataIsEncrypted(): void
{
$user = new CascadeTarget();
$user->setNotSecret('My public information');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

abstract class AbstractDoctrineEncryptSubscriberTestCase extends AbstractFunctionalTestCase
{
public function testEncryptionHappensOnOnlyAnnotatedFields()
public function testEncryptionHappensOnOnlyAnnotatedFields(): void
{
$secret = "It's a secret";
$notSecret = "You're all welcome to know this.";
Expand Down Expand Up @@ -44,7 +44,7 @@ public function testEncryptionHappensOnOnlyAnnotatedFields()
$this->assertEquals($secret, $decrypted);
}

public function testEncryptionCascades()
public function testEncryptionCascades(): void
{
$secret = "It's a secret";
$notSecret = "You're all welcome to know this.";
Expand Down Expand Up @@ -87,7 +87,7 @@ public function testEncryptionCascades()
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function testEncryptionDoesNotHappenWhenThereIsNoChange()
public function testEncryptionDoesNotHappenWhenThereIsNoChange(): void
{
$secret = "It's a secret";
$notSecret = "You're all welcome to know this.";
Expand Down Expand Up @@ -155,7 +155,7 @@ public function testEncryptionDoesNotHappenWhenThereIsNoChange()

}

public function testEncryptionDoesHappenWhenASecretIsChanged()
public function testEncryptionDoesHappenWhenASecretIsChanged(): void
{
$secret = "It's a secret";
$notSecret = "You're all welcome to know this.";
Expand Down Expand Up @@ -198,4 +198,4 @@ public function testEncryptionDoesHappenWhenASecretIsChanged()
$this->assertStringEndsWith('<ENC>', $shouldBeDifferentFromBefore); // is encrypted
$this->assertNotEquals($originalEncryption, $shouldBeDifferentFromBefore);
}
}
}
10 changes: 5 additions & 5 deletions Tests/Unit/DependencyInjection/DoctrineEncryptExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ class DoctrineEncryptExtensionTest extends TestCase
*/
private $extension;

protected function setUp()
protected function setUp(): void
{
$this->extension = new DoctrineEncryptExtension();
}

public function testConfigLoadHalite()
public function testConfigLoadHalite(): void
{
$container = $this->createContainer();
$this->extension->load([[]], $container);

$this->assertSame(HaliteEncryptor::class, $container->getParameter('ambta_doctrine_encrypt.encryptor_class_name'));
}

public function testConfigLoadDefuse()
public function testConfigLoadDefuse(): void
{
$container = $this->createContainer();

Expand All @@ -41,7 +41,7 @@ public function testConfigLoadDefuse()
$this->assertSame(DefuseEncryptor::class, $container->getParameter('ambta_doctrine_encrypt.encryptor_class_name'));
}

public function testConfigLoadCustom()
public function testConfigLoadCustom(): void
{
$container = $this->createContainer();
$config = [
Expand All @@ -54,7 +54,7 @@ public function testConfigLoadCustom()
$this->assertSame(self::class, $container->getParameter('ambta_doctrine_encrypt.encryptor_class_name'));
}

private function createContainer()
private function createContainer(): ContainerBuilder
{
$container = new ContainerBuilder(
new ParameterBag(['kernel.debug' => false])
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Encryptors/DefuseEncryptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DefuseEncryptorTest extends TestCase
{
private const DATA = 'foobar';

public function testEncrypt()
public function testEncrypt(): void
{
$keyfile = __DIR__.'/fixtures/defuse.key';
$key = file_get_contents($keyfile);
Expand All @@ -24,7 +24,7 @@ public function testEncrypt()
$this->assertSame($key, $newkey, 'The key must not be modified');
}

public function testGenerateKey()
public function testGenerateKey(): void
{
$keyfile = sys_get_temp_dir().'/defuse-'.md5(time());
if (file_exists($keyfile)) {
Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/Encryptors/HaliteEncryptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class HaliteEncryptorTest extends TestCase
{
private const DATA = 'foobar';

public function testEncryptExtension()
public function testEncryptExtension(): void
{
if (! extension_loaded('sodium')) {
$this->markTestSkipped('This test only runs when the sodium extension is enabled.');
Expand All @@ -27,7 +27,7 @@ public function testEncryptExtension()
$this->assertSame($key, $newkey, 'The key must not be modified');
}

public function testGenerateKey()
public function testGenerateKey(): void
{
if (! extension_loaded('sodium')) {
$this->markTestSkipped('This test only runs when the sodium extension is enabled.');
Expand All @@ -46,7 +46,7 @@ public function testGenerateKey()
}


public function testEncryptWithoutExtensionThrowsException()
public function testEncryptWithoutExtensionThrowsException(): void
{
if (extension_loaded('sodium')) {
$this->markTestSkipped('This only runs when the sodium extension is disabled.');
Expand Down
28 changes: 14 additions & 14 deletions Tests/Unit/Subscribers/DoctrineEncryptSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DoctrineEncryptSubscriberTest extends TestCase
*/
private $reader;

protected function setUp()
protected function setUp(): void
{
$this->encryptor = $this->createMock(EncryptorInterface::class);
$this->encryptor
Expand Down Expand Up @@ -71,7 +71,7 @@ protected function setUp()
$this->subscriber = new DoctrineEncryptSubscriber($this->reader, $this->encryptor);
}

public function testSetRestorEncryptor()
public function testSetRestorEncryptor(): void
{
$replaceEncryptor = $this->createMock(EncryptorInterface::class);

Expand All @@ -82,7 +82,7 @@ public function testSetRestorEncryptor()
$this->assertSame($this->encryptor, $this->subscriber->getEncryptor());
}

public function testProcessFieldsEncrypt()
public function testProcessFieldsEncrypt(): void
{
$user = new User('David', 'Switzerland');

Expand All @@ -92,7 +92,7 @@ public function testProcessFieldsEncrypt()
$this->assertStringStartsWith('encrypted-', $user->getAddress());
}

public function testProcessFieldsEncryptExtend()
public function testProcessFieldsEncryptExtend(): void
{
$user = new ExtendedUser('David', 'Switzerland', 'extra');

Expand All @@ -103,7 +103,7 @@ public function testProcessFieldsEncryptExtend()
$this->assertStringStartsWith('encrypted-', $user->extra);
}

public function testProcessFieldsEncryptEmbedded()
public function testProcessFieldsEncryptEmbedded(): void
{
$withUser = new WithUser('Thing', 'foo', new User('David', 'Switzerland'));

Expand All @@ -115,7 +115,7 @@ public function testProcessFieldsEncryptEmbedded()
$this->assertStringStartsWith('encrypted-', $withUser->user->getAddress());
}

public function testProcessFieldsEncryptNull()
public function testProcessFieldsEncryptNull(): void
{
$user = new User('David', null);

Expand All @@ -125,7 +125,7 @@ public function testProcessFieldsEncryptNull()
$this->assertNull($user->getAddress());
}

public function testProcessFieldsNoEncryptor()
public function testProcessFieldsNoEncryptor(): void
{
$user = new User('David', 'Switzerland');

Expand All @@ -136,7 +136,7 @@ public function testProcessFieldsNoEncryptor()
$this->assertSame('Switzerland', $user->getAddress());
}

public function testProcessFieldsDecrypt()
public function testProcessFieldsDecrypt(): void
{
$user = new User('encrypted-David<ENC>', 'encrypted-Switzerland<ENC>');

Expand All @@ -146,7 +146,7 @@ public function testProcessFieldsDecrypt()
$this->assertSame('Switzerland', $user->getAddress());
}

public function testProcessFieldsDecryptExtended()
public function testProcessFieldsDecryptExtended(): void
{
$user = new ExtendedUser('encrypted-David<ENC>', 'encrypted-Switzerland<ENC>', 'encrypted-extra<ENC>');

Expand All @@ -157,7 +157,7 @@ public function testProcessFieldsDecryptExtended()
$this->assertSame('extra', $user->extra);
}

public function testProcessFieldsDecryptEmbedded()
public function testProcessFieldsDecryptEmbedded(): void
{
$withUser = new WithUser('encrypted-Thing<ENC>', 'foo', new User('encrypted-David<ENC>', 'encrypted-Switzerland<ENC>'));

Expand All @@ -169,7 +169,7 @@ public function testProcessFieldsDecryptEmbedded()
$this->assertSame('Switzerland', $withUser->user->getAddress());
}

public function testProcessFieldsDecryptNull()
public function testProcessFieldsDecryptNull(): void
{
$user = new User('encrypted-David<ENC>', null);

Expand All @@ -179,7 +179,7 @@ public function testProcessFieldsDecryptNull()
$this->assertNull($user->getAddress());
}

public function testProcessFieldsDecryptNonEncrypted()
public function testProcessFieldsDecryptNonEncrypted(): void
{
// no trailing <ENC> but somethint that our mock decrypt would change if called
$user = new User('encrypted-David', 'encrypted-Switzerland');
Expand All @@ -193,7 +193,7 @@ public function testProcessFieldsDecryptNonEncrypted()
/**
* Test that fields are encrypted before flushing.
*/
public function testOnFlush()
public function testOnFlush(): void
{
$user = new User('David', 'Switzerland');

Expand Down Expand Up @@ -222,7 +222,7 @@ public function testOnFlush()
/**
* Test that fields are decrypted again after flushing
*/
public function testPostFlush()
public function testPostFlush(): void
{
$user = new User('encrypted-David<ENC>', 'encrypted-Switzerland<ENC>');

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"description": "Encrypted symfony entity's by verified and standardized libraries",
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"paragonie/halite": "^4.6",
"paragonie/sodium_compat": "^1.5",
"doctrine/orm": "^2.5",
Expand All @@ -16,7 +16,7 @@
"symfony/config": "^4.1|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^6.5",
"phpunit/phpunit": "^8.0|^9.0",
"defuse/php-encryption": "^2.1"
},
"suggest": {
Expand Down
11 changes: 5 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
syntaxCheck="true">
convertWarningsToExceptions="true">

<testsuites>
<testsuite name="unit">
Expand All @@ -16,15 +15,15 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory>./Command</directory>
<directory>./Configuration</directory>
<directory>./DependencyInjection</directory>
<directory>./Encryptors</directory>
<directory>./Subscribers</directory>
</whitelist>
</filter>
</include>
</coverage>

<php>
<env name="KERNEL_DIR" value="./Tests/Functional/Fixtures/app" />
Expand Down

0 comments on commit d1d0157

Please sign in to comment.