Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3eeb3bb

Browse files
committed
[VarDumper] Code review changes
- rename and made static methods private - add hard coded expectations to test non default options
1 parent 95e83a9 commit 3eeb3bb

File tree

2 files changed

+18
-76
lines changed

2 files changed

+18
-76
lines changed

src/Symfony/Component/VarDumper/Caster/MemcachedCaster.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
*/
1919
class MemcachedCaster
2020
{
21-
public static $optionConstants;
22-
public static $defaultOptions;
21+
private static $optionConstants;
22+
private static $defaultOptions;
2323

2424
public static function castMemcached(\Memcached $c, array $a, Stub $stub, $isNested)
2525
{
2626
$a += array(
2727
Caster::PREFIX_VIRTUAL.'servers' => $c->getServerList(),
2828
Caster::PREFIX_VIRTUAL.'options' => new EnumStub(
29-
self::getMemcachedNonDefaultValueOptions($c)
29+
self::getNonDefaultOptions($c)
3030
),
3131
);
3232

3333
return $a;
3434
}
3535

36-
public static function getMemcachedNonDefaultValueOptions(\Memcached $c)
36+
private static function getNonDefaultOptions(\Memcached $c)
3737
{
38-
self::$defaultOptions = self::$defaultOptions ?? self::discoverDefaultMemcachedOptions();
39-
self::$optionConstants = self::$optionConstants ?? self::getMemcachedOptionConstants();
38+
self::$defaultOptions = self::$defaultOptions ?? self::discoverDefaultOptions();
39+
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
4040

4141
$nonDefaultOptions = array();
4242
foreach (self::$optionConstants as $constantKey => $value) {
@@ -48,13 +48,13 @@ public static function getMemcachedNonDefaultValueOptions(\Memcached $c)
4848
return $nonDefaultOptions;
4949
}
5050

51-
public static function discoverDefaultMemcachedOptions()
51+
private static function discoverDefaultOptions()
5252
{
5353
$defaultMemcached = new \Memcached();
5454
$defaultMemcached->addServer('127.0.0.1', 11211);
5555

5656
$defaultOptions = array();
57-
self::$optionConstants = self::$optionConstants ?? self::getMemcachedOptionConstants();
57+
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
5858

5959
foreach (self::$optionConstants as $constantKey => $value) {
6060
$defaultOptions[$constantKey] = $defaultMemcached->getOption($value);
@@ -63,7 +63,7 @@ public static function discoverDefaultMemcachedOptions()
6363
return $defaultOptions;
6464
}
6565

66-
public static function getMemcachedOptionConstants()
66+
private static function getOptionConstants()
6767
{
6868
$reflectedMemcached = new \ReflectionClass(\Memcached::class);
6969

src/Symfony/Component/VarDumper/Tests/Caster/MemcachedCasterTest.php

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ public function testCastMemcachedWithCustomOptions()
6161
$var = new \Memcached();
6262
$var->addServer('127.0.0.1', 11211);
6363
$var->addServer('127.0.0.2', 11212);
64-
$var->setOptions($this->getCustomOptions());
64+
65+
// set a subset of non default options to test boolean, string and integer output
66+
$var->setOption(\Memcached::OPT_COMPRESSION, false);
67+
$var->setOption(\Memcached::OPT_PREFIX_KEY, 'pre');
68+
$var->setOption(\Memcached::OPT_DISTRIBUTION, \Memcached::DISTRIBUTION_CONSISTENT);
6569

6670
$expected = <<<'EOTXT'
6771
Memcached {
@@ -78,75 +82,13 @@ public function testCastMemcachedWithCustomOptions()
7882
]
7983
]
8084
options: {
81-
OPT_COMPRESSION: %s
82-
OPT_PREFIX_KEY: "%s"
83-
OPT_USER_FLAGS: %i
84-
OPT_STORE_RETRY_COUNT: %i
85-
OPT_HASH: %i
86-
OPT_DISTRIBUTION: %i
87-
OPT_LIBKETAMA_COMPATIBLE: %i
88-
OPT_LIBKETAMA_HASH: %i
89-
OPT_TCP_KEEPALIVE: %i
90-
OPT_BINARY_PROTOCOL: %i
91-
OPT_NO_BLOCK: %i
92-
OPT_TCP_NODELAY: %i
93-
OPT_SOCKET_SEND_SIZE: %i
94-
OPT_SOCKET_RECV_SIZE: %i
95-
OPT_CONNECT_TIMEOUT: %i
96-
OPT_RETRY_TIMEOUT: %i
97-
OPT_DEAD_TIMEOUT: %i
98-
OPT_SEND_TIMEOUT: %i
99-
OPT_RECV_TIMEOUT: %i
100-
OPT_POLL_TIMEOUT: %i
101-
OPT_SERVER_FAILURE_LIMIT: %i
102-
OPT_AUTO_EJECT_HOSTS: %i
103-
OPT_HASH_WITH_PREFIX_KEY: %i
104-
OPT_NOREPLY: %i
105-
OPT_SORT_HOSTS: %i
106-
OPT_USE_UDP: %i
107-
OPT_NUMBER_OF_REPLICAS: %i
108-
OPT_RANDOMIZE_REPLICA_READ: %i
109-
OPT_REMOVE_FAILED_SERVERS: %i
110-
OPT_SERVER_TIMEOUT_LIMIT: %i
85+
OPT_COMPRESSION: false
86+
OPT_PREFIX_KEY: "pre"
87+
OPT_DISTRIBUTION: 1
11188
}
11289
}
11390
EOTXT;
11491

115-
$this->assertDumpMatchesFormat($expected, $var);
116-
}
117-
118-
private function getCustomOptions()
119-
{
120-
$optionsToIgnore = array(
121-
\Memcached::OPT_SERIALIZER, // trying to set this option to something else then default throws Memcached::setOptions(): invalid serializer provided
122-
\Memcached::OPT_CACHE_LOOKUPS, // option is deprecated
123-
\Memcached::OPT_VERIFY_KEY, // trying to set this option throws Memcached::setOption(): error setting memcached option: INVALID ARGUMENTS
124-
);
125-
126-
$optionConstants = MemcachedCaster::getMemcachedOptionConstants();
127-
$defaultOptions = MemcachedCaster::discoverDefaultMemcachedOptions();
128-
$customOptions = array();
129-
130-
foreach ($optionConstants as $optionConstantKey => $optionConstantValue) {
131-
if (\in_array($optionConstantValue, $optionsToIgnore, true)) {
132-
continue;
133-
}
134-
135-
$defaultOptionValue = $defaultOptions[$optionConstantKey];
136-
137-
if (\is_bool($defaultOptionValue)) {
138-
$customOptions[$optionConstants[$optionConstantKey]] = !$defaultOptionValue;
139-
}
140-
141-
if (\is_string($defaultOptionValue)) {
142-
$customOptions[$optionConstants[$optionConstantKey]] = 'custom';
143-
}
144-
145-
if (\is_int($defaultOptionValue)) {
146-
$customOptions[$optionConstants[$optionConstantKey]] = $defaultOptionValue + 1;
147-
}
148-
}
149-
150-
return $customOptions;
92+
$this->assertDumpEquals($expected, $var);
15193
}
15294
}

0 commit comments

Comments
 (0)