Skip to content

Commit

Permalink
refactor: enable phpunit code quality set for rector (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 4, 2025
1 parent 57b6691 commit 31533bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public function testKey(): void
'key' => 'abc'
]);

$this->assertSame('abc', $config->getKey());
self::assertSame('abc', $config->getKey());
}
}
25 changes: 8 additions & 17 deletions tests/EncrypterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ public function testInjection(): void
new EncrypterConfig(['key' => $key])
);

$this->assertInstanceOf(
EncrypterInterface::class,
$container->get(EncrypterInterface::class)
);
self::assertInstanceOf(EncrypterInterface::class, $container->get(EncrypterInterface::class));

$this->assertInstanceOf(Encrypter::class, $container->get(EncrypterInterface::class));
self::assertInstanceOf(Encrypter::class, $container->get(EncrypterInterface::class));

$encrypter = $container->get(EncrypterInterface::class);
$this->assertSame($key, $encrypter->getKey());
self::assertSame($key, $encrypter->getKey());
}

public function testGetEncrypter(): void
Expand All @@ -55,19 +52,13 @@ public function testGetEncrypter(): void
new EncrypterConfig(['key' => $key])
);

$this->assertInstanceOf(
EncryptionInterface::class,
$container->get(EncryptionInterface::class)
);
self::assertInstanceOf(EncryptionInterface::class, $container->get(EncryptionInterface::class));

$this->assertInstanceOf(
EncrypterFactory::class,
$container->get(EncryptionInterface::class)
);
self::assertInstanceOf(EncrypterFactory::class, $container->get(EncryptionInterface::class));

$encrypter = $container->get(EncryptionInterface::class)->getEncrypter();
$this->assertSame($key, $encrypter->getKey());
$this->assertSame($key, $container->get(EncryptionInterface::class)->getKey());
self::assertSame($key, $encrypter->getKey());
self::assertSame($key, $container->get(EncryptionInterface::class)->getKey());
}

public function testExceptionKey(): void
Expand All @@ -88,6 +79,6 @@ public function testGenerateKey(): void
'key' => $key,
]));

$this->assertNotSame($key, $manager->generateKey());
self::assertNotSame($key, $manager->generateKey());
}
}
22 changes: 11 additions & 11 deletions tests/EncrypterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ public function testImmutable(): void
$encrypter = new Encrypter($keyA = Key::CreateNewRandomKey()->saveToAsciiSafeString());
$new = $encrypter->withKey($keyB = Key::CreateNewRandomKey()->saveToAsciiSafeString());

$this->assertNotSame($encrypter, $new);
self::assertNotSame($encrypter, $new);

$this->assertEquals($keyA, $encrypter->getKey());
$this->assertEquals($keyB, $new->getKey());
self::assertEquals($keyA, $encrypter->getKey());
self::assertEquals($keyB, $new->getKey());
}

public function testEncryption(): void
{
$encrypter = new Encrypter(Key::CreateNewRandomKey()->saveToAsciiSafeString());

$encrypted = $encrypter->encrypt('test string');
$this->assertNotEquals('test string', $encrypted);
$this->assertEquals('test string', $encrypter->decrypt($encrypted));
self::assertNotSame('test string', $encrypted);
self::assertEquals('test string', $encrypter->decrypt($encrypted));

$encrypter = $encrypter->withKey(Key::CreateNewRandomKey()->saveToAsciiSafeString());

$encrypted = $encrypter->encrypt('test string');
$this->assertNotEquals('test string', $encrypted);
$this->assertEquals('test string', $encrypter->decrypt($encrypted));
self::assertNotSame('test string', $encrypted);
self::assertEquals('test string', $encrypter->decrypt($encrypted));

$encrypted = $encrypter->encrypt('test string');
$this->assertNotEquals('test string', $encrypted);
$this->assertEquals('test string', $encrypter->decrypt($encrypted));
self::assertNotSame('test string', $encrypted);
self::assertEquals('test string', $encrypter->decrypt($encrypted));
}

public function testBadData(): void
Expand All @@ -50,8 +50,8 @@ public function testBadData(): void
$encrypter = new Encrypter(Key::CreateNewRandomKey()->saveToAsciiSafeString());

$encrypted = $encrypter->encrypt('test string');
$this->assertNotEquals('test string', $encrypted);
$this->assertEquals('test string', $encrypter->decrypt($encrypted));
self::assertNotSame('test string', $encrypted);
self::assertEquals('test string', $encrypter->decrypt($encrypted));

$encrypter->decrypt('badData.' . $encrypted);
}
Expand Down

0 comments on commit 31533bc

Please sign in to comment.