Clone a mock object generating a collection populated with mocks of the same kind.

@param \PHPUnit_Framework_MockObject_MockObject $mock
@param int                                      $repeatFor

@return array
963394
protected function generateMocksCollection(\PHPUnit_Framework_MockObject_MockObject $mock, $repeatFor = 1)
    {
        $collection = [];

        for ($i = 1; $i <= $repeatFor; $i++) {
            $collection[] = clone $mock;
        }

        return $collection;
    }
1013440
function repeat ($n)
  {
    $this->setIterator ($it = new LoopIterator ($this->getIterator ()));
    $it->repeat ($n);
    return $this;
  }
1332198
public function CloneInstance()
	{
		$result = new IDFilterNodeIterator( $this->context, $this->type );
		$result->IDRef = $this->IDRef;
		$result->iterator = $this->iterator->CloneInstance();
		$result->Reset();
		return $result;
	}
130891
private static function getMethodRequiredClassesByMethod(\ReflectionMethod $rm) : array
    {
        $classes = [];
        
        $params = $rm->getParameters();
        foreach($params as $rp){
            $type = $rp->getType();
            if ($type instanceof \ReflectionType && !$type->isBuiltin()){
                $type_class = "$type";
                $classes[] = new \ReflectionClass($type_class);
            }
        }
        
        $has_return_type = $rm->hasReturnType();
        if ($has_return_type){
            $ret_type = $rm->getReturnType();
            if (!$ret_type->isBuiltin()){
                $ret_type_class = "$ret_type";
                $classes[] = new \ReflectionClass($ret_type_class);
            }
        }
        
        return array_unique($classes);
    }
1106679
public function getNewRequestMeta($clone = TRUE, $subResource = NULL) {
    if (!isset($this->newRequestMeta)) {
      $this->newRequestMeta = new RequestMeta(\Psc\Net\HTTP\Request::POST,
                                              $this->constructUrl(array($this->getEntityNamePlural()))
                                             );
    }
    if ($clone) {
      $meta = clone $this->newRequestMeta;
      if ($subResource != NULL) {
        $meta->appendUrl('/'.$subResource);
      }
      return $meta;
    }
    return $this->newRequestMeta;
  }
440167
protected function duplicateRequest(\Exception $exception, Request $request)
    {
        $attributes = [
            '_controller' => $this->controller,
            'exception'   => $exception,
            'format'      => $request->getRequestFormat()
        ];

        $request = $request->duplicate(null, null, $attributes);
        $request->setMethod('GET');

        return $request;
    }
1054796
public function replay()
    {
        $mockClassName = parent::replay();

        $mockClassReflector = new \ReflectionClass($mockClassName);
        return $mockClassReflector->newInstanceArgs($this->constructor_arguments);
    }
341452
public function create($classToMock)
    {
        $mockBuilder = new \PHPUnit_Framework_MockObject_MockBuilder(
            $this->testCase, $classToMock
        );
        $mockBuilder->disableOriginalConstructor();
        return $mockBuilder->getMock();
    }
693114
public function getStrategyForExpectation(MockConfig $expectation)
    {
        if ($expectation->getResponse()->isProxyResponse()) {
            return $this->factory->createProxyResponseStrategy();
        }
        if ($this->requestBodyOrUrlAreRegexp($expectation)) {
            return $this->factory->createRegexResponseStrategy();
        }

        return $this->factory->createHttpResponseStrategy();
    }
417124
public function CloneInstance()
	{
		return new ForIterator( $this->owner, $this->provider, $this->dataPool, $this->baseIter );
	}
464339
public function duplicateAction(Request $request)
    {
        /* @var $rep ItemRepository */
        $rep = $this->getDoctrine()->getRepository('AnimeDbCatalogBundle:Item');

        // get store item
        $item = $request->getSession()->get(self::NAME_ITEM_ADDED);
        if (!($item instanceof Item)) {
            throw $this->createNotFoundException('Not found item for confirm duplicate');
        }

        // confirm duplicate
        if ($request->isMethod('POST')) {
            $request->getSession()->remove(self::NAME_ITEM_ADDED);
            switch ($request->request->get('do')) {
                case 'add':
                    return $this->addItem($item->freez($this->getDoctrine()));
                default:
                    return $this->redirect($this->generateUrl('home'));
            }
        }

        // re searching for duplicates
        $duplicate = $rep->findDuplicate($item);
        // now there is no duplication
        if (!$duplicate) {
            return $this->addItem($item->freez($this->getDoctrine()));
        }

        return $this->render('AnimeDbCatalogBundle:Item:duplicate.html.twig', [
            'items' => $duplicate,
        ]);
    }
1058270
private function createReferenceManyWithRepositoryMethodIterator(PersistentCollectionInterface $collection)
    {
        $mapping          = $collection->getMapping();
        $repositoryMethod = $mapping->repositoryMethod;
        $repository       = $this->dm->getRepository($mapping->targetDocument);
        $iterator         = $repository->$repositoryMethod($collection->getOwner());

        if (!$iterator instanceof Iterator) {
            throw new \BadMethodCallException(sprintf('Expected repository method %s to return an iterable object', $repositoryMethod));
        }

        if (!empty($mapping->prime)) {
            $referencePrimer = new ReferencePrimer($this->dm, $this->dm->getUnitOfWork());
            $primers         = array_combine($mapping->prime, array_fill(0, count($mapping->prime), true));
            $class           = $this->dm->getClassMetadata($mapping['targetDocument']);

            $iterator = new PrimingIterator(
                $iterator,
                $class,
                $referencePrimer,
                $primers,
                $collection->isReadOnly()
            );
        }

        return $iterator;
    }
1182170
function clone(obj) {
    if (typeof obj !== 'object') {
        return obj;
    }
    var ret;
    if (util.isArray(obj)) {
        ret = [];
        obj.forEach(function (val) {
            ret.push(clone(val));
        });
        return ret;
    }
    ret = {};
    Object.keys(obj).forEach(function (key) {
        ret[key] = clone(obj[key]);
    });
    return ret;
}
469844
public function retry(RetrySchedulerInterface $retryScheduler): array
    {
        if (!$this->isRetryable()) {
            throw new class('This job cannot be retried anymore.') extends \BadMethodCallException implements ExceptionInterface {};
        }

        $cloned = clone $this;
        $cloned->retries++;

        return [$cloned, $retryScheduler->scheduleNextRetry($cloned, $cloned->retries)];
    }
1118904
public function update(RepeatingFieldCollection $collection)
    {
        $updated = [];
        // First give priority to already existing entities
        foreach ($collection->flatten() as $entity) {
            $master = $this->getOriginal($entity);
            $master->setValue($entity->getValue());
            $master->setFieldtype($entity->getFieldtype());
            $master->handleStorage($this->getFieldType($entity->getFieldname(), $entity->getBlock()));

            $updated[] = $master;
        }

        $deleted = [];
        foreach ($this->flatten() as $old) {
            if (!in_array($old, $updated)) {
                $deleted[] = $old;
            }
        }

        // Clear the collection so that we re-add only the updated elements
        $this->clear();
        foreach ($updated as $new) {
            $this->add($new);
        }

        return $deleted;
    }
214199
function clone(candidate)
{
  var copy;

  if (typeOf(candidate) == 'array')
  {
    copy = [].concat(candidate);
  }
  else if (typeOf(candidate) == 'object')
  {
    copy = extend(candidate);
  }
  else
  {
    copy = candidate;
  }

  return copy;
}
1165114
private function getMockByCalls($class, array $calls = []): MockObject
    {
        $mock = $this->prepareMock($class);

        $mockName = (new \ReflectionObject($mock))->getShortName();

        $className = $this->getMockClassAsString($class);

        $options = JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;

        $callIndex = -1;

        $mock->expects(self::exactly(count($calls)))->method(self::anything())->willReturnCallback(
            function () use ($className, $mock, $mockName, &$callIndex, &$calls, $options) {
                ++$callIndex;

                $call = array_shift($calls);

                $method = $call->getMethod();
                $mocketMethod = $this->getMockedMethod($mockName);

                if ($mocketMethod !== $method) {
                    self::fail(
                        sprintf(
                            'Call at index %d on class "%s" expected method "%s", "%s" given',
                            $callIndex,
                            $className,
                            $method,
                            $mocketMethod
                        )
                        .PHP_EOL
                        .json_encode($this->getStackTrace($mock), $options)
                    );
                }

                return $this->getMockCallback($className, $callIndex, $call, $mock)(...func_get_args());
            }
        );

        return $mock;
    }