/** * @expectedException \TreeHouse\Swift\Exception\SwiftException * @expectedExceptionMessage Destination is same as source */ public function testCopyObjectCircularReference() { $container = new Container('foo'); $object = new SwiftObject($container, 'baz'); $this->driver->expects($this->never())->method('copyObject'); $this->store->copyObject($object, $container); }
/** * @param SwiftObject $object * @param Container $destination * @param string $name * * @throws SwiftException * * @return SwiftObject * * @see DriverInterface::copyObject() */ public function copyObject(SwiftObject $object, Container $destination, $name = null) { if (is_null($name)) { $name = $object->getName(); } // detect circular reference if ($object->getContainer() === $destination && $object->getName() === $name) { throw new SwiftException('Destination is same as source'); } return $this->driver->copyObject($object, $destination, $name); }