Repository: symfony/symfony
File: src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php (PHP)

Code before:
    {
        if (!\array_key_exists('testPrune', $this->skippedTests) && !$this->createCachePool() instanceof PruneableInterface) {
            $this->skippedTests['testPrune'] = 'Not a pruneable cache pool.';
        }

        try {
            \assert(false === true, new \Exception());
            $this->skippedTests['testGetItemInvalidKeys'] =
            $this->skippedTests['testGetItemsInvalidKeys'] =
            $this->skippedTests['testHasItemInvalidKeys'] =
            $this->skippedTests['testDeleteItemInvalidKeys'] =
            $this->skippedTests['testDeleteItemsInvalidKeys'] = 'Keys are checked only when assert() is enabled.';
        } catch (\Exception $e) {
        }
    }

    public function testGet()
    {
        if (isset($this->skippedTests[__FUNCTION__])) {
            $this->markTestSkipped($this->skippedTests[__FUNCTION__]);
        }

        $cache = $this->createCachePool();
        $cache->clear();

        $value = random_int(0, PHP_INT_MAX);

        $this->assertSame($value, $cache->get('foo', function (CacheItem $item) use ($value) {
            $this->assertSame('foo', $item->getKey());

            return $value;
        }));

        $item = $cache->getItem('foo');
        $this->assertSame($value, $item->get());

        $isHit = true;
        $this->assertSame($value, $cache->get('foo', static function (CacheItem $item) use (&$isHit) { $isHit = false; }, 0));
        $this->assertTrue($isHit);

        $this->assertNull($cache->get('foo', function (CacheItem $item) use (&$isHit, $value) {
            $isHit = false;
            $this->assertTrue($item->isHit());
            $this->assertSame($value, $item->get());
        }, \INF));
        $this->assertFalse($isHit);

        $this->assertSame($value, $cache->get('bar', new class($value) implements CallbackInterface {
            private int $value;

            public function __construct(int $value)

Review comment (suggestion):
same below:
```suggestion
        $value = random_int(0, \PHP_INT_MAX);
```

Code after:
    {
        if (!\array_key_exists('testPrune', $this->skippedTests) && !$this->createCachePool() instanceof PruneableInterface) {
            $this->skippedTests['testPrune'] = 'Not a pruneable cache pool.';
        }

        try {
            \assert(false === true, new \Exception());
            $this->skippedTests['testGetItemInvalidKeys'] =
            $this->skippedTests['testGetItemsInvalidKeys'] =
            $this->skippedTests['testHasItemInvalidKeys'] =
            $this->skippedTests['testDeleteItemInvalidKeys'] =
            $this->skippedTests['testDeleteItemsInvalidKeys'] = 'Keys are checked only when assert() is enabled.';
        } catch (\Exception $e) {
        }
    }

    public function testGet()
    {
        if (isset($this->skippedTests[__FUNCTION__])) {
            $this->markTestSkipped($this->skippedTests[__FUNCTION__]);
        }

        $cache = $this->createCachePool();
        $cache->clear();

        $value = random_int(0, \PHP_INT_MAX);

        $this->assertSame($value, $cache->get('foo', function (CacheItem $item) use ($value) {
            $this->assertSame('foo', $item->getKey());

            return $value;
        }));

        $item = $cache->getItem('foo');
        $this->assertSame($value, $item->get());

        $isHit = true;
        $this->assertSame($value, $cache->get('foo', static function (CacheItem $item) use (&$isHit) { $isHit = false; }, 0));
        $this->assertTrue($isHit);

        $this->assertNull($cache->get('foo', function (CacheItem $item) use (&$isHit, $value) {
            $isHit = false;
            $this->assertTrue($item->isHit());
            $this->assertSame($value, $item->get());
        }, \INF));
        $this->assertFalse($isHit);

        $this->assertSame($value, $cache->get('bar', new class($value) implements CallbackInterface {
            private int $value;

            public function __construct(int $value)