diff --git a/lib/Doctrine/Common/Cache/PhpFileCache.php b/lib/Doctrine/Common/Cache/PhpFileCache.php index 02ceba7e..3678bf47 100644 --- a/lib/Doctrine/Common/Cache/PhpFileCache.php +++ b/lib/Doctrine/Common/Cache/PhpFileCache.php @@ -78,14 +78,6 @@ protected function doSave($id, $data, $lifeTime = 0) $lifeTime = time() + $lifeTime; } - if (is_object($data) && ! method_exists($data, '__set_state')) { - throw new \InvalidArgumentException( - "Invalid argument given, PhpFileCache only allows objects that implement __set_state() " . - "and fully support var_export(). You can use the FilesystemCache to save arbitrary object " . - "graphs using serialize()/deserialize()." - ); - } - $filename = $this->getFilename($id); $value = [ @@ -93,8 +85,13 @@ protected function doSave($id, $data, $lifeTime = 0) 'data' => $data ]; - $value = var_export($value, true); - $code = sprintf('writeFile($filename, $code); } diff --git a/tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php b/tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php index 6608d6f8..26fc8725 100644 --- a/tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/PhpFileCacheTest.php @@ -45,12 +45,27 @@ public function testImplementsSetState() $this->assertTrue($cache->contains('test_set_state')); } + /** + * @group 154 + */ public function testNotImplementsSetState() { $cache = $this->_getCacheDriver(); - $this->setExpectedException('InvalidArgumentException'); - $cache->save('test_not_set_state', new NotSetStateClass([1,2,3])); + $cache->save('test_not_set_state', new NotSetStateClass([5,6,7])); + $this->assertEquals(new NotSetStateClass([5,6,7]), $cache->fetch('test_not_set_state')); + } + + /** + * @group 154 + */ + public function testNotImplementsSetStateInArray() + { + $cache = $this->_getCacheDriver(); + + $cache->save('test_not_set_state_in_array', [new NotSetStateClass([4,3,2])]); + $this->assertEquals([new NotSetStateClass([4,3,2])], $cache->fetch('test_not_set_state_in_array')); + $this->assertTrue($cache->contains('test_not_set_state_in_array')); } public function testGetStats()