From b8b0d5b283af0e117e7ef6141b5b7e5efb20b247 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Jan 2024 14:51:25 +0100 Subject: [PATCH 1/2] Apply php-cs-fixer fix --rules nullable_type_declaration_for_default_null_value --- Lock.php | 4 ++-- LockInterface.php | 2 +- NoLock.php | 2 +- Store/FlockStore.php | 2 +- Tests/Store/DoctrineDbalStoreTest.php | 2 +- Tests/Store/PdoDbalStoreTest.php | 2 +- Tests/Store/PdoStoreTest.php | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lock.php b/Lock.php index 154f92e..ef9871c 100644 --- a/Lock.php +++ b/Lock.php @@ -39,7 +39,7 @@ final class Lock implements SharedLockInterface, LoggerAwareInterface * @param float|null $ttl Maximum expected lock duration in seconds * @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed */ - public function __construct(Key $key, PersistingStoreInterface $store, float $ttl = null, bool $autoRelease = true) + public function __construct(Key $key, PersistingStoreInterface $store, ?float $ttl = null, bool $autoRelease = true) { $this->store = $store; $this->key = $key; @@ -191,7 +191,7 @@ public function acquireRead(bool $blocking = false): bool /** * {@inheritdoc} */ - public function refresh(float $ttl = null) + public function refresh(?float $ttl = null) { if (null === $ttl) { $ttl = $this->ttl; diff --git a/LockInterface.php b/LockInterface.php index 31c77ab..f03b796 100644 --- a/LockInterface.php +++ b/LockInterface.php @@ -41,7 +41,7 @@ public function acquire(bool $blocking = false); * @throws LockConflictedException If the lock is acquired by someone else * @throws LockAcquiringException If the lock cannot be refreshed */ - public function refresh(float $ttl = null); + public function refresh(?float $ttl = null); /** * Returns whether or not the lock is acquired. diff --git a/NoLock.php b/NoLock.php index 074c6c3..d6f325e 100644 --- a/NoLock.php +++ b/NoLock.php @@ -26,7 +26,7 @@ public function acquire(bool $blocking = false): bool return true; } - public function refresh(float $ttl = null) + public function refresh(?float $ttl = null) { } diff --git a/Store/FlockStore.php b/Store/FlockStore.php index c476fd3..0d4f681 100644 --- a/Store/FlockStore.php +++ b/Store/FlockStore.php @@ -37,7 +37,7 @@ class FlockStore implements BlockingStoreInterface, SharedLockStoreInterface * * @throws LockStorageException If the lock directory doesn’t exist or is not writable */ - public function __construct(string $lockPath = null) + public function __construct(?string $lockPath = null) { if (null === $lockPath) { $lockPath = sys_get_temp_dir(); diff --git a/Tests/Store/DoctrineDbalStoreTest.php b/Tests/Store/DoctrineDbalStoreTest.php index e037341..5545a99 100644 --- a/Tests/Store/DoctrineDbalStoreTest.php +++ b/Tests/Store/DoctrineDbalStoreTest.php @@ -81,7 +81,7 @@ public function testAbortAfterExpiration() /** * @dataProvider provideDsnWithSQLite */ - public function testDsnWithSQLite(string $dsn, string $file = null) + public function testDsnWithSQLite(string $dsn, ?string $file = null) { $key = new Key(uniqid(__METHOD__, true)); diff --git a/Tests/Store/PdoDbalStoreTest.php b/Tests/Store/PdoDbalStoreTest.php index ee34366..5d8cdd0 100644 --- a/Tests/Store/PdoDbalStoreTest.php +++ b/Tests/Store/PdoDbalStoreTest.php @@ -94,7 +94,7 @@ public function testConfigureSchema() /** * @dataProvider provideDsn */ - public function testDsn(string $dsn, string $file = null) + public function testDsn(string $dsn, ?string $file = null) { $this->expectDeprecation('Since symfony/lock 5.4: Usage of a DBAL Connection with "Symfony\Component\Lock\Store\PdoStore" is deprecated and will be removed in symfony 6.0. Use "Symfony\Component\Lock\Store\DoctrineDbalStore" instead.'); $key = new Key(uniqid(__METHOD__, true)); diff --git a/Tests/Store/PdoStoreTest.php b/Tests/Store/PdoStoreTest.php index d2960d0..e6683b3 100644 --- a/Tests/Store/PdoStoreTest.php +++ b/Tests/Store/PdoStoreTest.php @@ -78,7 +78,7 @@ public function testInvalidTtlConstruct() /** * @dataProvider provideDsnWithSQLite */ - public function testDsnWithSQLite(string $dsn, string $file = null) + public function testDsnWithSQLite(string $dsn, ?string $file = null) { $key = new Key(uniqid(__METHOD__, true)); From 2de81b4883eb80622a79462ff38ecfd73a93c2e1 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Jan 2024 15:42:10 +0100 Subject: [PATCH 2/2] Fix bad merge --- Tests/Store/PdoDbalStoreTest.php | 122 ------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 Tests/Store/PdoDbalStoreTest.php diff --git a/Tests/Store/PdoDbalStoreTest.php b/Tests/Store/PdoDbalStoreTest.php deleted file mode 100644 index 5d8cdd0..0000000 --- a/Tests/Store/PdoDbalStoreTest.php +++ /dev/null @@ -1,122 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Lock\Tests\Store; - -use Doctrine\DBAL\Configuration; -use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DriverManager; -use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory; -use Doctrine\DBAL\Schema\Schema; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; -use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\PersistingStoreInterface; -use Symfony\Component\Lock\Store\PdoStore; - -/** - * @author Jérémy Derussé - * - * @requires extension pdo_sqlite - * - * @group legacy - */ -class PdoDbalStoreTest extends AbstractStoreTestCase -{ - use ExpectDeprecationTrait; - use ExpiringStoreTestTrait; - - protected static $dbFile; - - public static function setUpBeforeClass(): void - { - self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_lock'); - - $config = new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } - - $store = new PdoStore(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $config)); - $store->createTable(); - } - - public static function tearDownAfterClass(): void - { - @unlink(self::$dbFile); - } - - /** - * {@inheritdoc} - */ - protected function getClockDelay() - { - return 1500000; - } - - /** - * {@inheritdoc} - */ - public function getStore(): PersistingStoreInterface - { - $this->expectDeprecation('Since symfony/lock 5.4: Usage of a DBAL Connection with "Symfony\Component\Lock\Store\PdoStore" is deprecated and will be removed in symfony 6.0. Use "Symfony\Component\Lock\Store\DoctrineDbalStore" instead.'); - - $config = new Configuration(); - if (class_exists(DefaultSchemaManagerFactory::class)) { - $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); - } - - return new PdoStore(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile], $config)); - } - - public function testAbortAfterExpiration() - { - $this->markTestSkipped('Pdo expects a TTL greater than 1 sec. Simulating a slow network is too hard'); - } - - public function testConfigureSchema() - { - $this->expectDeprecation('Since symfony/lock 5.4: Usage of a DBAL Connection with "Symfony\Component\Lock\Store\PdoStore" is deprecated and will be removed in symfony 6.0. Use "Symfony\Component\Lock\Store\DoctrineDbalStore" instead.'); - - $store = new PdoStore($this->createMock(Connection::class), ['db_table' => 'lock_table']); - $schema = new Schema(); - $store->configureSchema($schema); - $this->assertTrue($schema->hasTable('lock_table')); - } - - /** - * @dataProvider provideDsn - */ - public function testDsn(string $dsn, ?string $file = null) - { - $this->expectDeprecation('Since symfony/lock 5.4: Usage of a DBAL Connection with "Symfony\Component\Lock\Store\PdoStore" is deprecated and will be removed in symfony 6.0. Use "Symfony\Component\Lock\Store\DoctrineDbalStore" instead.'); - $key = new Key(uniqid(__METHOD__, true)); - - try { - $store = new PdoStore($dsn); - $store->createTable(); - - $store->save($key); - $this->assertTrue($store->exists($key)); - } finally { - if (null !== $file) { - @unlink($file); - } - } - } - - public static function provideDsn() - { - $dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache'); - yield ['sqlite://localhost/'.$dbFile.'1', $dbFile.'1']; - yield ['sqlite3:///'.$dbFile.'3', $dbFile.'3']; - yield ['sqlite://localhost/:memory:']; - } -}