*/ private array $options = []; protected function setUp(): void { parent::setUp(); $this->options = []; Functions\when('get_option')->alias( fn (string $name, mixed $default = false): mixed => $this->options[$name] ?? $default ); Functions\when('update_option')->alias(function (string $name, mixed $value, mixed $autoload = null): bool { $this->options[$name] = $value; self::assertFalse($autoload, 'releases are read only by the gate – no autoload'); return true; }); } public function testAddsFindsAndWithdrawsPerDiviAndPluginVersion(): void { $store = new ReleaseStore(); $store->add('5.3.0', '0.6.0', 1, 'r1'); $store->add('5.3.0', '0.6.0', 2, 'r2'); self::assertCount(1, $store->entries(), 'one entry per version pair'); self::assertSame(2, $store->find('5.3.0', '0.6.0')['user_id'] ?? null); self::assertNull($store->find('5.3.0', '0.7.0'), 'another plugin version needs its own check'); self::assertTrue($store->withdraw('5.3.0', '0.6.0')); self::assertFalse($store->withdraw('5.3.0', '0.6.0')); self::assertSame([], $store->entries()); } public function testIgnoresBrokenRows(): void { $this->options[ReleaseStore::OPTION] = ['x', ['divi_version' => '5.3.0'], [ 'divi_version' => '5.2.2', 'plugin_version' => '0.6.0', 'user_id' => 3, 'released_at' => 'd', 'report_id' => 'r', ]]; self::assertSame(['5.2.2'], array_column((new ReleaseStore())->entries(), 'divi_version')); } }