<commit_before><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\VarDumper\Tests\Caster;

use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

/**
 * @author <NAME> <<EMAIL>>
 * @requires extension redis
 * @group integration
 */
class RedisCasterTest extends TestCase
{
    use VarDumperTestTrait;

    public function testNotConnected()
    {
        $redis = new \Redis();

        $xCast = <<<'EODUMP'
Redis {
  isConnected: false
}
EODUMP;

        $this->assertDumpMatchesFormat($xCast, $redis);
    }

    public function testConnected()
    {
        $redisHost = getenv('REDIS_HOST');
        $redis = new \Redis();
        try {
            $redis->connect($redisHost);
        } catch (\Exception $e) {
            self::markTestSkipped($e->getMessage());
        }

        $xCast = <<<EODUMP
Redis {%A
  isConnected: true
  host: "$redisHost"
  port: 6379
  auth: null
  mode: ATOMIC
  dbNum: 0
  timeout: 0.0
  lastError: null
  persistentId: null<commit_msg>[Cache] Fix connecting to Redis via a socket file<commit_after><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\VarDumper\Tests\Caster;

use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

/**
 * @author <NAME> <<EMAIL>>
 * @requires extension redis
 * @group integration
 */
class RedisCasterTest extends TestCase
{
    use VarDumperTestTrait;

    public function testNotConnected()
    {
        $redis = new \Redis();

        $xCast = <<<'EODUMP'
Redis {
  isConnected: false
}
EODUMP;

        $this->assertDumpMatchesFormat($xCast, $redis);
    }

    public function testConnected()
    {
        $redisHost = explode(':', getenv('REDIS_HOST')) + [1 => 6379];
        $redis = new \Redis();
        try {
            $redis->connect(...$redisHost);
        } catch (\Exception $e) {
            self::markTestSkipped($e->getMessage());
        }

        $xCast = <<<EODUMP
Redis {%A
  isConnected: true
  host: "{$redisHost[0]}"
  port: {$redisHost[1]}
  auth: null
  mode: ATOMIC
  dbNum: 0
  timeout: 0.0
  lastError: null
  persistentId: null
{'fraction_non_alphanumeric': 0.12956277577216205, 'fraction_numerical': 0.00681909346169274, 'mean_word_length': 2.9029733959311423, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5754644', 'n_tokens_mistral': 850, 'n_tokens_neox': 828, 'n_words': 212}