Creates simple PHPUnit Mock Object with disabled original constructor
@param string $classToMock
@return \PHPUnit_Framework_MockObject_MockObject
341452
public function create($classToMock)
    {
        $mockBuilder = new \PHPUnit_Framework_MockObject_MockBuilder(
            $this->testCase, $classToMock
        );
        $mockBuilder->disableOriginalConstructor();
        return $mockBuilder->getMock();
    }
282574
public static function create($class)
    {
        try {
            $reflection = new \ReflectionClass($class);
        } catch (\ReflectionException $e) {
            return false;
        }

        $constructor = $reflection->getConstructor();

        // If there are no parameters, just return a new object.
        if (null === $constructor) {
            return new $class;
        }

        $newInstanceArgs = self::getMethodArgs($constructor);

        // Create a callable for the dataStorage
        return $reflection->newInstanceArgs($newInstanceArgs);
    }
898183
def CreateMock(self, class_to_mock):
    

    new_mock = MockObject(class_to_mock)
    self._mock_objects.append(new_mock)
    return new_mock
479701
public function setClass($clazz)
    {
        if($clazz instanceof ClassMetadata)
        {
            $classMetadata = $clazz;
            $classname = $clazz->getReflectionClass()->getName();
        }
        else if (class_exists($clazz))
        {
            $classname = $clazz;
            $classMetadata = $this->getEntityManager()->getClassMetadata($clazz);
        } else
        {
            $parts = explode(':', $clazz);
            $alias = array_shift($parts);
            $rest = implode('\\', $parts);

            try
            {
                $namespace = $this->getEntityManager()->getConfiguration()->getEntityNamespace($alias);
            }
            catch (\Doctrine\ORM\ORMException $e) {
                throw new \InvalidArgumentException("Can't find class: $clazz'");
            }

            $classname = $namespace.'\\'.$rest;
            $classMetadata = $this->getEntityManager()->getClassMetadata($classname);
        }

        $reflectionClass = $classMetadata->getReflectionClass();
        if(!$reflectionClass->implementsInterface('Haven\CoreBundle\Lib\NestedSet\Node'))
        {
            throw new \InvalidArgumentException('Class must implement Node interface: ' . $classname);
        }

        $this->hasManyRoots = $reflectionClass->implementsInterface('Haven\CoreBundle\Lib\NestedSet\MultipleRootNode');
        $this->classMetadata = $classMetadata;
        $this->classname = $classname;

        return $this;
    }
174242
protected function matchObjectWithClass(
        /*# string */ $classOrInterface,
        $objectToMatch
    )/*# : bool */ {
        if (is_object($objectToMatch) &&
            is_a($objectToMatch, $classOrInterface)) {
            return true;
        }
        return false;
    }
476070
public function newInstance(ClassMetadata $class)
    {
        $entity = $this->instantiator->instantiate($class->getClassName());

        if ($entity instanceof EntityManagerAware) {
            $entity->injectEntityManager($this->em, $class);
        }

        return $entity;
    }
632225
protected static function createFreshMockInstance($name)
    {
        static::$instance[$name] = $mock = static::createMockByName($name);

        if (isset(static::$container)) {
            static::$container->instance($name, $mock);
        }

        return $mock;
    }
405292
public static function reflectionClassFromObjectOrClass($object_or_class)
    {
        $reflection = null;

        if (is_object($object_or_class)) {
            $reflection = new ReflectionObject($object_or_class);
        } elseif (class_exists($object_or_class)) {
            $reflection = new ReflectionClass($object_or_class);
        }

        return $reflection;
    }
232834
protected function initializeClassBuilder()
    {
        // build the mock class
        $builder = new ClassBuilder();
        if (class_exists($this->className)) {
            $builder->setExtends($this->className);
        } elseif (interface_exists($this->className)) {
            $builder->addInterface($this->className);
        } else {
            throw new \InvalidArgumentException("Class or interface " . $this->className . " does not exist");
        }

        // every mocked method goes through this invocation, which delegates
        // the retrieval of the correct Spec to this Instance's Ordering constraint.
        $resolveCall = function (Invocation $inv) {
            $spec = $this->ordering->nextSpec($inv->getMethodName());
            return $spec->doInvocation($inv);
        };

        return $this->addMethodsToBuilder($builder, $resolveCall);
    }
1132738
protected function bindExpectedToObject()
    {
        $accessor = PropertyAccess::createPropertyAccessor();

        $values = array_merge($this->expectedValues, $this->expectedMocks, $this->expectedMocksCollections);

        foreach ($values as $property => $value) {
            if (is_array($value)) {
                $addMethod = 'add'.ucfirst($property);
                foreach ($value as $mock) {
                    $this->getObjectToTest()->$addMethod($mock);
                }
            } else {
                if ($accessor->isWritable($this->getObjectToTest(), $property)) {
                    // Use direct access to property to avoid "only variables should be passed by reference"
                    $accessor->setValue($this->objectToTest, $property, $value);
                }
            }
        }

        // Tear down
        unset($values);
        unset($accessor);

        return $this;
    }
1230228
public function getOrCreate($className, $params = array())
    {
        $key = $className . join('-', $params);

        if (isset($this->mapping[$key])) {
            return $this->mapping[$key];
        }

        if (method_exists($this, $this->getMethodName($className))) {
            $callback = array($this, $this->getMethodName($className));
            $instance =  call_user_func_array($callback, $params);
        } else {
            $instance = new $className;
        }

        return $this->mapping[$key] = $instance;
    }
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;
    }
1213032
protected function doGet($mock)
    {
        try {
            return $mock->reveal();
        } catch (ObjectProphecyException $exception) {
            throw new MockNotCreatedException(
                sprintf(
                    'Cannot create mock object: %s',
                    $exception->getMessage()
                )
            );
        }
    }
316643
protected function createClient($class)
    {
        try {
            $reflection = new \ReflectionClass($class);
        } catch (\ReflectionException $e) {
            throw new ModelException(sprintf(
                "Could not instantiate Model class '%s'. (Reason: '%s').",
                $class,
                $e->getMessage()
            ));
        }

        if (!$reflection->implementsInterface('\PommProject\Foundation\Client\ClientInterface')) {
            throw new ModelException(sprintf("'%s' class does not implement the ClientInterface interface.", $class));
        }

        if (!$reflection->isSubclassOf('\PommProject\ModelManager\Model\Model')) {
            throw new ModelException(sprintf("'%s' class does not extend \PommProject\ModelManager\Model.", $class));
        }

        return new $class();
    }
423517
public static function createFromStdClass(stdClass $class)
	{
		$hash = isset($class->hash) ? $class->hash : null;
		$scope = isset($class->scope) ? $class->scope : null;
		$action = isset($class->action) ? $class->action : null;
		$data = isset($class->data) ? $class->data : null;
		$state = isset($class->state) ? $class->state : null;
		$ip = isset($class->ip) ? $class->ip : null;
		$useragent = isset($class->useragent) ? $class->useragent : null;
		$createdAt = isset($class->created_at) ? $class->created_at : null;

		return new Action($hash, $scope, $action, $data, $state, $ip, $useragent, $createdAt);
	}
735082
public function fetchFirstObj(string $class = null)
    {
        if (!$this->wasExecuted()) {
            $this->exec();
        }

        $data = $this->fetchFirst();

        if ($data === null) {
            return null;
        }

        if ($class == null) {
            $obj = new \stdClass();

            foreach ($data as $field => $value) {
                $obj->$field = $value;
            }

            return $obj;
        } else {
            return new $class($data);
        }
    }
1338014
public function deserialize($serializedObject, $objectClass)
    {
        return $this->serializer->deserialize(
            $serializedObject,
            $objectClass,
            'json',
            DeserializationContext::create()->setSerializeNull(true)->setGroups(['preview'])
        );
    }