@@ -34,6 +34,34 @@ public function testLongKey()
34
34
$ cache ->hasItem (str_repeat ('- ' , 39 ));
35
35
}
36
36
37
+ public function testLongKeyVersioning ()
38
+ {
39
+ $ cache = $ this ->getMockBuilder (MaxIdLengthAdapter::class)
40
+ ->setConstructorArgs (array (str_repeat ('- ' , 26 )))
41
+ ->getMock ();
42
+
43
+ $ reflectionClass = new \ReflectionClass (AbstractAdapter::class);
44
+
45
+ $ reflectionMethod = $ reflectionClass ->getMethod ('getId ' );
46
+ $ reflectionMethod ->setAccessible (true );
47
+
48
+ // No versioning enabled
49
+ $ this ->assertEquals ('--------------------------:------------ ' , $ reflectionMethod ->invokeArgs ($ cache , array (str_repeat ('- ' , 12 ))));
50
+ $ this ->assertLessThanOrEqual (50 , strlen ($ reflectionMethod ->invokeArgs ($ cache , array (str_repeat ('- ' , 12 )))));
51
+ $ this ->assertLessThanOrEqual (50 , strlen ($ reflectionMethod ->invokeArgs ($ cache , array (str_repeat ('- ' , 23 )))));
52
+ $ this ->assertLessThanOrEqual (50 , strlen ($ reflectionMethod ->invokeArgs ($ cache , array (str_repeat ('- ' , 40 )))));
53
+
54
+ $ reflectionProperty = $ reflectionClass ->getProperty ('versioningIsEnabled ' );
55
+ $ reflectionProperty ->setAccessible (true );
56
+ $ reflectionProperty ->setValue ($ cache , true );
57
+
58
+ // Versioning enabled
59
+ $ this ->assertEquals ('--------------------------:1:------------ ' , $ reflectionMethod ->invokeArgs ($ cache , array (str_repeat ('- ' , 12 ))));
60
+ $ this ->assertLessThanOrEqual (50 , strlen ($ reflectionMethod ->invokeArgs ($ cache , array (str_repeat ('- ' , 12 )))));
61
+ $ this ->assertLessThanOrEqual (50 , strlen ($ reflectionMethod ->invokeArgs ($ cache , array (str_repeat ('- ' , 23 )))));
62
+ $ this ->assertLessThanOrEqual (50 , strlen ($ reflectionMethod ->invokeArgs ($ cache , array (str_repeat ('- ' , 40 )))));
63
+ }
64
+
37
65
/**
38
66
* @expectedException \Symfony\Component\Cache\Exception\InvalidArgumentException
39
67
* @expectedExceptionMessage Namespace must be 26 chars max, 40 given ("----------------------------------------")
0 commit comments