How to use useStrictTypes method of generator class

Best Atoum code snippet using generator.useStrictTypes

generator.php

Source:generator.php Github

copy

Full Screen

...14 protected $allowUndefinedMethodsUsage = true;15 protected $allIsInterface = false;16 protected $testedClass = '';17 protected $eachInstanceIsUnique = false;18 protected $useStrictTypes = false;19 private $defaultNamespace = null;20 public function __construct()21 {22 $this23 ->setAdapter()24 ->setReflectionClassFactory()25 ;26 }27 public function callsToParentClassAreShunted()28 {29 return $this->shuntParentClassCalls;30 }31 public function setAdapter(atoum\adapter $adapter = null)32 {33 $this->adapter = $adapter ?: new atoum\adapter();34 return $this;35 }36 public function getAdapter()37 {38 return $this->adapter;39 }40 public function setReflectionClassFactory(\closure $factory = null)41 {42 $this->reflectionClassFactory = $factory ?: function ($class) {43 return new \reflectionClass($class);44 };45 return $this;46 }47 public function getReflectionClassFactory()48 {49 return $this->reflectionClassFactory;50 }51 public function setDefaultNamespace($namespace)52 {53 $this->defaultNamespace = trim($namespace, '\\');54 return $this;55 }56 public function getDefaultNamespace()57 {58 return ($this->defaultNamespace === null ? self::defaultNamespace : $this->defaultNamespace);59 }60 public function overload(php\method $method)61 {62 $this->overloadedMethods[strtolower($method->getName())] = $method;63 return $this;64 }65 public function isOverloaded($method)66 {67 return ($this->getOverload($method) !== null);68 }69 public function getOverload($method)70 {71 return (isset($this->overloadedMethods[$method = strtolower($method)]) === false ? null : $this->overloadedMethods[$method]);72 }73 public function shunt($method)74 {75 if ($this->isShunted($method) === false) {76 $this->shuntedMethods[] = strtolower($method);77 }78 return $this;79 }80 public function isShunted($method)81 {82 return (in_array(strtolower($method), $this->shuntedMethods) === true);83 }84 public function shuntParentClassCalls()85 {86 $this->shuntParentClassCalls = true;87 return $this;88 }89 public function unshuntParentClassCalls()90 {91 $this->shuntParentClassCalls = false;92 return $this;93 }94 public function orphanize($method)95 {96 if ($this->isOrphanized($method) === false) {97 $this->orphanizedMethods[] = strtolower($method);98 }99 return $this->shunt($method);100 }101 public function isOrphanized($method)102 {103 return (in_array($method, $this->orphanizedMethods) === true);104 }105 public function allIsInterface()106 {107 $this->allIsInterface = true;108 return $this;109 }110 public function eachInstanceIsUnique()111 {112 $this->eachInstanceIsUnique = true;113 return $this;114 }115 public function useStrictTypes()116 {117 $this->useStrictTypes = true;118 return $this;119 }120 public function testedClassIs($testedClass)121 {122 $this->testedClass = strtolower($testedClass);123 return $this;124 }125 public function getMockedClassCode($class, $mockNamespace = null, $mockClass = null)126 {127 if (trim($class, '\\') == '' || rtrim($class, '\\') != $class) {128 throw new exceptions\runtime('Class name \'' . $class . '\' is invalid');129 }130 if ($mockNamespace === null) {131 $mockNamespace = $this->getNamespace($class);132 }133 $class = '\\' . ltrim($class, '\\');134 if ($mockClass === null) {135 $mockClass = self::getClassName($class);136 }137 if ($this->adapter->class_exists($mockNamespace . '\\' . $mockClass, false) === true || $this->adapter->interface_exists($mockNamespace . '\\' . $mockClass, false) === true) {138 throw new exceptions\logic('Class \'' . $mockNamespace . '\\' . $mockClass . '\' already exists');139 }140 if ($this->adapter->class_exists($class, true) === false && $this->adapter->interface_exists($class, true) === false) {141 $code = self::generateUnknownClassCode($mockNamespace, $mockClass, $this->eachInstanceIsUnique);142 } else {143 $reflectionClass = call_user_func($this->reflectionClassFactory, $class);144 if ($reflectionClass->isFinal() === true) {145 throw new exceptions\logic('Class \'' . $class . '\' is final, unable to mock it');146 }147 $code = $reflectionClass->isInterface() === false ? $this->generateClassCode($reflectionClass, $mockNamespace, $mockClass) : $this->generateInterfaceCode($reflectionClass, $mockNamespace, $mockClass);148 }149 $this->shuntedMethods = $this->overloadedMethods = $this->orphanizedMethods = [];150 $this->unshuntParentClassCalls();151 return $code;152 }153 public function generate($class, $mockNamespace = null, $mockClass = null)154 {155 eval($this->getMockedClassCode($class, $mockNamespace, $mockClass));156 return $this;157 }158 public function methodIsMockable(\reflectionMethod $method)159 {160 switch (true) {161 case $method->isFinal():162 case $method->isStatic():163 case static::methodNameIsReservedWord($method):164 return false;165 case $method->isPrivate():166 case $method->isProtected() && $method->isAbstract() === false:167 return $this->isOverloaded($method->getName());168 default:169 return true;170 }171 }172 public function disallowUndefinedMethodInInterface()173 {174 return $this->disallowUndefinedMethodUsage();175 }176 public function disallowUndefinedMethodUsage()177 {178 $this->allowUndefinedMethodsUsage = false;179 return $this;180 }181 public function allowUndefinedMethodInInterface()182 {183 return $this->allowUndefinedMethodUsage();184 }185 public function allowUndefinedMethodUsage()186 {187 $this->allowUndefinedMethodsUsage = true;188 return $this;189 }190 public function undefinedMethodInInterfaceAreAllowed()191 {192 return $this->undefinedMethodUsageIsAllowed();193 }194 public function undefinedMethodUsageIsAllowed()195 {196 return $this->allowUndefinedMethodsUsage === true;197 }198 protected function generateClassMethodCode(\reflectionClass $class)199 {200 $mockedMethods = '';201 $mockedMethodNames = [];202 $className = $class->getName();203 if ($this->allIsInterface && strtolower($className) != $this->testedClass) {204 foreach ($class->getMethods() as $method) {205 if ($this->methodIsMockable($method) === true) {206 $this->orphanize($method->getName());207 }208 }209 }210 $constructor = $class->getConstructor();211 if ($constructor === null || $this->allIsInterface) {212 $mockedMethods .= self::generateDefaultConstructor(false, $this->eachInstanceIsUnique);213 $mockedMethodNames[] = '__construct';214 } elseif ($constructor->isFinal() === false) {215 $constructorName = $constructor->getName();216 $overload = $this->getOverload($constructorName);217 if ($constructor->isPublic() === false) {218 $this->shuntParentClassCalls();219 if ($overload === null) {220 $this->overload(new php\method('__construct'));221 $overload = $this->getOverload('__construct');222 }223 }224 $parameters = $this->getParameters($constructor);225 if ($overload === null) {226 $mockedMethods .= "\t" . 'public function __construct(' . $this->getParametersSignature($constructor) . ')';227 } else {228 $overload229 ->addArgument(230 php\method\argument::get('mockController')231 ->isObject('\\' . __NAMESPACE__ . '\\controller')232 ->setDefaultValue(null)233 )234 ;235 $mockedMethods .= "\t" . $overload;236 }237 $mockedMethods .= PHP_EOL;238 $mockedMethods .= "\t" . '{' . PHP_EOL;239 if ($this->eachInstanceIsUnique === true) {240 $mockedMethods .= self::generateUniqueId();241 }242 if (self::hasVariadic($constructor) === true) {243 $mockedMethods .= "\t\t" . '$arguments = func_get_args();' . PHP_EOL;244 $mockedMethods .= "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL;245 } else {246 $mockedMethods .= "\t\t" . '$arguments = array_merge(array(' . implode(', ', $parameters) . '), array_slice(func_get_args(), ' . count($parameters) . ', -1));' . PHP_EOL;247 $mockedMethods .= "\t\t" . 'if ($mockController === null)' . PHP_EOL;248 $mockedMethods .= "\t\t" . '{' . PHP_EOL;249 $mockedMethods .= "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL;250 $mockedMethods .= "\t\t" . '}' . PHP_EOL;251 }252 $mockedMethods .= "\t\t" . 'if ($mockController !== null)' . PHP_EOL;253 $mockedMethods .= "\t\t" . '{' . PHP_EOL;254 $mockedMethods .= "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL;255 $mockedMethods .= "\t\t" . '}' . PHP_EOL;256 if ($constructor->isAbstract() === true || $this->isShunted('__construct') === true || $this->isShunted($className) === true) {257 $methodName = ($this->isShunted($className) === true ? $className : '__construct');258 $mockedMethods .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === false)' . PHP_EOL;259 $mockedMethods .= "\t\t" . '{' . PHP_EOL;260 $mockedMethods .= "\t\t\t" . '$this->getMockController()->' . $methodName . ' = function() {};' . PHP_EOL;261 $mockedMethods .= "\t\t" . '}' . PHP_EOL;262 $mockedMethods .= "\t\t" . '$this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL;263 } else {264 $mockedMethods .= "\t\t" . 'if (isset($this->getMockController()->' . $constructorName . ') === true)' . PHP_EOL;265 $mockedMethods .= "\t\t" . '{' . PHP_EOL;266 $mockedMethods .= "\t\t\t" . '$this->getMockController()->invoke(\'' . $constructorName . '\', $arguments);' . PHP_EOL;267 $mockedMethods .= "\t\t" . '}' . PHP_EOL;268 $mockedMethods .= "\t\t" . 'else' . PHP_EOL;269 $mockedMethods .= "\t\t" . '{' . PHP_EOL;270 $mockedMethods .= "\t\t\t" . '$this->getMockController()->addCall(\'' . $constructorName . '\', $arguments);' . PHP_EOL;271 if ($this->canCallParent()) {272 $mockedMethods .= "\t\t\t" . 'call_user_func_array(\'parent::' . $constructorName . '\', $arguments);' . PHP_EOL;273 }274 $mockedMethods .= "\t\t" . '}' . PHP_EOL;275 }276 $mockedMethods .= "\t" . '}' . PHP_EOL;277 $mockedMethodNames[] = strtolower($constructorName);278 }279 foreach ($class->getMethods() as $method) {280 if ($method->isConstructor() === false && $this->methodIsMockable($method) === true) {281 $methodName = $method->getName();282 $mockedMethodNames[] = strtolower($methodName);283 $overload = $this->getOverload($methodName);284 $parameters = $this->getParameters($method);285 if ($overload !== null) {286 $mockedMethods .= "\t" . $overload;287 } else {288 $mockedMethods .= "\t" . $this->generateMethodSignature($method);289 }290 $mockedMethods .= PHP_EOL . "\t" . '{' . PHP_EOL;291 if (self::hasVariadic($method) === true) {292 $mockedMethods .= "\t\t" . '$arguments = func_get_args();' . PHP_EOL;293 } else {294 $mockedMethods .= "\t\t" . '$arguments = array_merge(array(' . implode(', ', $parameters) . '), array_slice(func_get_args(), ' . count($parameters) . '));' . PHP_EOL;295 }296 if ($this->isShunted($methodName) === true || $method->isAbstract() === true) {297 $mockedMethods .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === false)' . PHP_EOL;298 $mockedMethods .= "\t\t" . '{' . PHP_EOL;299 $mockedMethods .= "\t\t\t" . '$this->getMockController()->' . $methodName . ' = function() {' . PHP_EOL;300 if ($this->hasReturnType($method) === true && $this->isVoid($method) === false) {301 $returnType = $this->getReflectionType($method);302 switch (true) {303 case (string) $returnType === 'self':304 case (string) $returnType === 'parent':305 case (string) $returnType === $class->getName():306 case interface_exists((string) $returnType) && $class->implementsInterface((string) $returnType):307 $mockedMethods .= "\t\t\t\t" . 'return $this;' . PHP_EOL;308 break;309 default:310 $mockedMethods .= "\t\t\t\t" . 'return null;' . PHP_EOL;311 }312 }313 $mockedMethods .= "\t\t\t" . '};' . PHP_EOL;314 $mockedMethods .= "\t\t" . '}' . PHP_EOL;315 $mockedMethods .= "\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL;316 if ($this->isVoid($method) === false) {317 $mockedMethods .= "\t\t" . 'return $return;' . PHP_EOL;318 }319 } else {320 $mockedMethods .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL;321 $mockedMethods .= "\t\t" . '{' . PHP_EOL;322 $mockedMethods .= "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL;323 if ($this->isVoid($method) === false) {324 $mockedMethods .= "\t\t\t" . 'return $return;' . PHP_EOL;325 }326 $mockedMethods .= "\t\t" . '}' . PHP_EOL;327 $mockedMethods .= "\t\t" . 'else' . PHP_EOL;328 $mockedMethods .= "\t\t" . '{' . PHP_EOL;329 if ($methodName === '__call') {330 $mockedMethods .= "\t\t\t" . '$this->getMockController()->addCall(current(array_slice($arguments, 0, 1)), current(array_slice($arguments, 1)));' . PHP_EOL;331 }332 $mockedMethods .= "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL;333 if ($this->canCallParent()) {334 $mockedMethods .= "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL;335 if ($this->isVoid($method) === false) {336 $mockedMethods .= "\t\t\t" . 'return $return;' . PHP_EOL;337 }338 } else {339 if ($this->hasReturnType($method) === true && $this->isVoid($method) === false) {340 $returnType = $this->getReflectionType($method);341 switch (true) {342 case (string) $returnType === 'self':343 case (string) $returnType === 'parent':344 case (string) $returnType === $class->getName():345 case interface_exists((string) $returnType) && $class->implementsInterface((string) $returnType):346 $mockedMethods .= "\t\t\t" . 'return $this;' . PHP_EOL;347 break;348 default:349 $mockedMethods .= "\t\t\t" . 'return null;' . PHP_EOL;350 }351 }352 }353 $mockedMethods .= "\t\t" . '}' . PHP_EOL;354 }355 $mockedMethods .= "\t" . '}' . PHP_EOL;356 }357 }358 if ($class->isAbstract() && $this->allowUndefinedMethodsUsage === true && in_array('__call', $mockedMethodNames) === false) {359 $mockedMethods .= self::generate__call();360 $mockedMethodNames[] = '__call';361 }362 return $mockedMethods . self::generateGetMockedMethod($mockedMethodNames);363 }364 protected function generateMethodSignature(\reflectionMethod $method)365 {366 return ($method->isPublic() === true ? 'public' : 'protected') . ' function' . ($method->returnsReference() === false ? '' : ' &') . ' ' . $method->getName() . '(' . $this->getParametersSignature($method) . ')' . $this->getReturnType($method);367 }368 protected function generateClassCode(\reflectionClass $class, $mockNamespace, $mockClass)369 {370 return ($this->useStrictTypes ? 'declare(strict_types=1);' . PHP_EOL : '') .371 'namespace ' . ltrim($mockNamespace, '\\') . ' {' . PHP_EOL .372 'final class ' . $mockClass . ' extends \\' . $class->getName() . ' implements \\' . __NAMESPACE__ . '\\aggregator' . PHP_EOL .373 '{' . PHP_EOL .374 self::generateMockControllerMethods() .375 $this->generateClassMethodCode($class) .376 '}' . PHP_EOL .377 '}'378 ;379 }380 protected function generateInterfaceMethodCode(\reflectionClass $class, $addIteratorAggregate)381 {382 $mockedMethods = '';383 $mockedMethodNames = [];384 $hasConstructor = false;385 $methods = $class->getMethods(\reflectionMethod::IS_PUBLIC);386 if ($addIteratorAggregate === true) {387 $iteratorInterface = call_user_func($this->reflectionClassFactory, 'iteratorAggregate');388 $methods = array_merge($methods, $iteratorInterface->getMethods(\reflectionMethod::IS_PUBLIC));389 }390 foreach ($methods as $method) {391 $methodName = $method->getName();392 $mockedMethodNames[] = strtolower($methodName);393 $parameters = $this->getParameters($method);394 switch (true) {395 case $method->isFinal() === false && $method->isStatic() === false:396 $isConstructor = $methodName === '__construct';397 if ($isConstructor === true) {398 $hasConstructor = true;399 }400 $methodCode = "\t" . 'public function' . ($method->returnsReference() === false ? '' : ' &') . ' ' . $methodName . '(' . $this->getParametersSignature($method, $isConstructor) . ')' . $this->getReturnType($method) . PHP_EOL;401 $methodCode .= "\t" . '{' . PHP_EOL;402 if (self::hasVariadic($method) === true) {403 $methodCode .= "\t\t" . '$arguments = func_get_args();' . PHP_EOL;404 } else {405 $methodCode .= "\t\t" . '$arguments = array_merge(array(' . implode(', ', $parameters) . '), array_slice(func_get_args(), ' . count($parameters) . ($isConstructor === false ? '' : ', -1') . '));' . PHP_EOL;406 }407 if ($isConstructor === true) {408 if (self::hasVariadic($method) === true) {409 $methodCode .= "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL;410 } else {411 $methodCode .= "\t\t" . 'if ($mockController === null)' . PHP_EOL;412 $methodCode .= "\t\t" . '{' . PHP_EOL;413 $methodCode .= "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL;414 $methodCode .= "\t\t" . '}' . PHP_EOL;415 }416 $methodCode .= "\t\t" . 'if ($mockController !== null)' . PHP_EOL;417 $methodCode .= "\t\t" . '{' . PHP_EOL;418 $methodCode .= "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL;419 $methodCode .= "\t\t" . '}' . PHP_EOL;420 }421 $methodCode .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === false)' . PHP_EOL;422 $methodCode .= "\t\t" . '{' . PHP_EOL;423 $methodCode .= "\t\t\t" . '$this->getMockController()->' . $methodName . ' = function() {' . PHP_EOL;424 if ($this->hasReturnType($method) === true && $this->isVoid($method) === false) {425 $returnType = $this->getReflectionType($method);426 switch (true) {427 case (string) $returnType === 'self':428 case (string) $returnType === 'parent':429 case (string) $returnType === $class->getName():430 case interface_exists((string) $returnType) && $class->implementsInterface((string) $returnType):431 $methodCode .= "\t\t\t\t" . 'return $this;' . PHP_EOL;432 break;433 default:434 $methodCode .= "\t\t\t\t" . 'return null;' . PHP_EOL;435 }436 }437 $methodCode .= "\t\t\t" . '};' . PHP_EOL;438 $methodCode .= "\t\t" . '}' . PHP_EOL;439 if ($isConstructor === true) {440 $methodCode .= "\t\t" . '$this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL;441 } else {442 $methodCode .= "\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL;443 if ($this->isVoid($method) === false) {444 $methodCode .= "\t\t" . 'return $return;' . PHP_EOL;445 }446 }447 $methodCode .= "\t" . '}' . PHP_EOL;448 break;449 case $method->isStatic() === true:450 $methodCode = "\t" . 'public static function' . ($method->returnsReference() === false ? '' : ' &') . ' ' . $methodName . '(' . $this->getParametersSignature($method) . ')' . PHP_EOL;451 $methodCode .= "\t" . '{' . PHP_EOL;452 $methodCode .= "\t\t" . '$arguments = array_merge(array(' . implode(', ', $parameters) . '), array_slice(func_get_args(), ' . count($parameters) . ', -1));' . PHP_EOL;453 if ($this->isVoid($method) === false) {454 $methodCode .= "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL;455 }456 $methodCode .= "\t" . '}' . PHP_EOL;457 break;458 default:459 $methodCode = '';460 }461 $mockedMethods .= $methodCode;462 }463 if ($hasConstructor === false) {464 $mockedMethods .= self::generateDefaultConstructor(false, $this->eachInstanceIsUnique);465 $mockedMethodNames[] = '__construct';466 }467 if ($this->allowUndefinedMethodsUsage === true) {468 $mockedMethods .= self::generate__call();469 $mockedMethodNames[] = '__call';470 }471 $mockedMethods .= self::generateGetMockedMethod($mockedMethodNames);472 return $mockedMethods;473 }474 protected function generateInterfaceCode(\reflectionClass $class, $mockNamespace, $mockClass)475 {476 $addIteratorAggregate = (477 $class->isInstantiable() === false478 && (479 $class->implementsInterface('traversable') === true480 && $class->implementsInterface('iterator') === false481 && $class->implementsInterface('iteratorAggregate') === false482 )483 );484 return 'namespace ' . ltrim($mockNamespace, '\\') . ' {' . PHP_EOL .485 'final class ' . $mockClass . ' implements \\' . ($addIteratorAggregate === false ? '' : 'iteratorAggregate, \\') . $class->getName() . ', \\' . __NAMESPACE__ . '\\aggregator' . PHP_EOL .486 '{' . PHP_EOL .487 self::generateMockControllerMethods() .488 $this->generateInterfaceMethodCode($class, $addIteratorAggregate) .489 '}' . PHP_EOL .490 '}'491 ;492 }493 protected function getNamespace($class)494 {495 $class = ltrim($class, '\\');496 $lastAntiSlash = strrpos($class, '\\');497 return '\\' . $this->getDefaultNamespace() . ($lastAntiSlash === false ? '' : '\\' . substr($class, 0, $lastAntiSlash));498 }499 protected function getReturnType(\reflectionMethod $method)500 {501 $returnTypeCode = '';502 if ($method->getName() === '__construct' || $this->hasReturnType($method) === false) {503 return $returnTypeCode;504 }505 $returnType = $this->getReflectionType($method);506 $isNullable = $this->isNullable($returnType);507 switch (true) {508 case (string) $returnType === 'self':509 $returnTypeCode = ': ' . ($isNullable ? '?' : '') . '\\' . $method->getDeclaringClass()->getName();510 break;511 case (string) $returnType === 'parent':512 $returnTypeCode = ': ' . ($isNullable ? '?' : '') . '\\' . $method->getDeclaringClass()->getParentClass()->getName();513 break;514 case $returnType->isBuiltin():515 $returnTypeCode = ': ' . ($isNullable ? '?' : '') . $returnType;516 break;517 default:518 $returnTypeCode = ': ' . ($isNullable ? '?' : '') . '\\' . $returnType;519 }520 return $returnTypeCode;521 }522 protected function isNullable(\reflectionType $type)523 {524 return version_compare(PHP_VERSION, '7.0') >= 0 && $type->allowsNull() === true;525 }526 protected function hasReturnType(\reflectionMethod $method)527 {528 return version_compare(PHP_VERSION, '7.0') >= 0 && $method->hasReturnType() === true;529 }530 protected function getReflectionType(\reflectionMethod $method)531 {532 return $this->hasReturnType($method) ? $method->getReturnType() : null;533 }534 protected function isVoid(\reflectionMethod $method)535 {536 return $this->hasReturnType($method) ? (string) $method->getReturnType() === 'void' : false;537 }538 protected static function isNullableParameter(\ReflectionParameter $parameter)539 {540 return version_compare(PHP_VERSION, '7.1') >= 0 &&541 $parameter->allowsNull() &&542 (!$parameter->isDefaultValueAvailable() || ($parameter->isDefaultValueAvailable() && null !== $parameter->getDefaultValue()));543 }544 protected static function isDefaultParameterNull(\ReflectionParameter $parameter)545 {546 return $parameter->allowsNull() &&547 $parameter->isDefaultValueAvailable() &&548 null === $parameter->getDefaultValue();549 }550 protected function getParameters(\reflectionMethod $method)551 {552 $parameters = [];553 $overload = $this->getOverload($method->getName());554 if ($overload === null) {555 foreach ($method->getParameters() as $parameter) {556 $parameters[] = ($parameter->isPassedByReference() === false ? '' : '& ') . '$' . $parameter->getName();557 }558 } else {559 foreach ($overload->getArguments() as $argument) {560 $parameters[] = $argument->getVariable();561 }562 }563 return $parameters;564 }565 protected function getParametersSignature(\reflectionMethod $method, $forceMockController = false)566 {567 $parameters = [];568 $mustBeNull = $this->isOrphanized($method->getName());569 foreach ($method->getParameters() as $parameter) {570 $parameterCode = self::getParameterType($parameter) . ($parameter->isPassedByReference() == false ? '' : '& ') . ($parameter->isVariadic() == false ? '' : '... ') . '$' . $parameter->getName();571 switch (true) {572 case $parameter->isDefaultValueAvailable():573 $parameterCode .= ' = ' . var_export($parameter->getDefaultValue(), true);574 break;575 case self::isDefaultParameterNull($parameter):576 case $parameter->isOptional() && $parameter->isVariadic() == false:577 case $mustBeNull:578 $parameterCode .= ' = null';579 }580 $parameters[] = $parameterCode;581 }582 if (self::hasVariadic($method) === false && ($method->isConstructor() || $forceMockController)) {583 $parameters[] = '\\' . __NAMESPACE__ . '\\controller $mockController = null';584 }585 return implode(', ', $parameters);586 }587 protected function canCallParent()588 {589 return $this->shuntParentClassCalls === false && $this->allIsInterface === false;590 }591 protected static function getClassName($class)592 {593 $class = ltrim($class, '\\');594 $lastAntiSlash = strrpos($class, '\\');595 return ($lastAntiSlash === false ? $class : substr($class, $lastAntiSlash + 1));596 }597 protected static function getParameterType(\reflectionParameter $parameter)598 {599 $prefix = self::isNullableParameter($parameter) ? '?' : '';600 switch (true) {601 case $parameter->isArray():602 return $prefix . 'array ';603 case method_exists($parameter, 'isCallable') && $parameter->isCallable():604 return $prefix . 'callable ';605 case ($class = $parameter->getClass()):606 return $prefix . '\\' . $class->getName() . ' ';607 case method_exists($parameter, 'hasType') && $parameter->hasType():608 return $prefix . $parameter->getType() . ' ';609 default:610 return '';611 }612 }613 protected static function hasVariadic(\reflectionMethod $method)614 {615 $parameters = $method->getParameters();616 if (count($parameters) === 0) {617 return false;618 }619 return end($parameters)->isVariadic();620 }621 protected static function generateMockControllerMethods()622 {623 return624 "\t" . 'public function getMockController()' . PHP_EOL .625 "\t" . '{' . PHP_EOL .626 "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::getForMock($this);' . PHP_EOL .627 "\t\t" . 'if ($mockController === null)' . PHP_EOL .628 "\t\t" . '{' . PHP_EOL .629 "\t\t\t" . '$this->setMockController($mockController = new \\' . __NAMESPACE__ . '\\controller());' . PHP_EOL .630 "\t\t" . '}' . PHP_EOL .631 "\t\t" . 'return $mockController;' . PHP_EOL .632 "\t" . '}' . PHP_EOL .633 "\t" . 'public function setMockController(\\' . __NAMESPACE__ . '\\controller $controller)' . PHP_EOL .634 "\t" . '{' . PHP_EOL .635 "\t\t" . 'return $controller->control($this);' . PHP_EOL .636 "\t" . '}' . PHP_EOL .637 "\t" . 'public function resetMockController()' . PHP_EOL .638 "\t" . '{' . PHP_EOL .639 "\t\t" . '\mageekguy\atoum\mock\controller::getForMock($this)->reset();' . PHP_EOL .640 "\t\t" . 'return $this;' . PHP_EOL .641 "\t" . '}' . PHP_EOL642 ;643 }644 protected static function generateDefaultConstructor($disableMethodChecking = false, $uniqueId = false)645 {646 $defaultConstructor =647 "\t" . 'public function __construct(\\' . __NAMESPACE__ . '\\controller $mockController = null)' . PHP_EOL .648 "\t" . '{' . PHP_EOL;649 if ($uniqueId === true) {650 $defaultConstructor .= self::generateUniqueId();651 }652 $defaultConstructor .=653 "\t\t" . 'if ($mockController === null)' . PHP_EOL .654 "\t\t" . '{' . PHP_EOL .655 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .656 "\t\t" . '}' . PHP_EOL .657 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .658 "\t\t" . '{' . PHP_EOL .659 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .660 "\t\t" . '}' . PHP_EOL661 ;662 if ($disableMethodChecking === true) {663 $defaultConstructor .= "\t\t" . '$this->getMockController()->disableMethodChecking();' . PHP_EOL;664 }665 $defaultConstructor .=666 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .667 "\t\t" . '{' . PHP_EOL .668 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .669 "\t\t" . '}' . PHP_EOL .670 "\t" . '}' . PHP_EOL671 ;672 return $defaultConstructor;673 }674 protected static function generate__call()675 {676 return677 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .678 "\t" . '{' . PHP_EOL .679 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .680 "\t\t" . '{' . PHP_EOL .681 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .682 "\t\t\t" . 'return $return;' . PHP_EOL .683 "\t\t" . '}' . PHP_EOL .684 "\t\t" . 'else' . PHP_EOL .685 "\t\t" . '{' . PHP_EOL .686 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .687 "\t\t" . '}' . PHP_EOL .688 "\t" . '}' . PHP_EOL689 ;690 }691 protected static function generateGetMockedMethod(array $mockedMethodNames)692 {693 return694 "\t" . 'public static function getMockedMethods()' . PHP_EOL .695 "\t" . '{' . PHP_EOL .696 "\t\t" . 'return ' . var_export($mockedMethodNames, true) . ';' . PHP_EOL .697 "\t" . '}' . PHP_EOL698 ;699 }700 protected static function generateUnknownClassCode($mockNamespace, $mockClass, $uniqueId = false, $useStrictTypes = false)701 {702 return ($useStrictTypes ? 'declare(strict_types=1);' . PHP_EOL : '') .703 'namespace ' . ltrim($mockNamespace, '\\') . ' {' . PHP_EOL .704 'final class ' . $mockClass . ' implements \\' . __NAMESPACE__ . '\\aggregator' . PHP_EOL .705 '{' . PHP_EOL .706 self::generateMockControllerMethods() .707 self::generateDefaultConstructor(true, $uniqueId) .708 self::generate__call() .709 self::generateGetMockedMethod(['__call']) .710 '}' . PHP_EOL .711 '}'712 ;713 }714 protected static function methodNameIsReservedWord(\reflectionMethod $method)715 {716 return in_array($method->getName(), self::getMethodNameReservedWordByVersion(), true);...

Full Screen

Full Screen

GenerateCommand.php

Source:GenerateCommand.php Github

copy

Full Screen

...87 if (!$this->input->getOption('no-docblocks')) {88 $factory->autoGenerateDocBlocks();89 }90 if (!$this->input->getOption('no-strict-types')) {91 $factory->useStrictTypes();92 }93 $factory->setPhpTargetVersion((int) $this->input->getOption('php-version'));94 return $factory;95 }96 /**97 * @param SchemaCollection $schemas98 * @return array99 */100 private function generateClasses(SchemaCollection $schemas): array101 {102 $generator = new ClassGenerator($this->buildConfig(), $this->output);103 return $generator->buildClasses($schemas);104 }105 /**...

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1require_once 'generator.php';2$generator = new Generator();3$generator->useStrictTypes();4require_once 'generator.php';5$generator = new Generator();6$generator->useStrictTypes();7require_once 'generator.php';8$generator = new Generator();9$generator->useStrictTypes();10require_once 'generator.php';11$generator = new Generator();12$generator->useStrictTypes();13require_once 'generator.php';14$generator = new Generator();15$generator->useStrictTypes();16require_once 'generator.php';17$generator = new Generator();18$generator->useStrictTypes();19require_once 'generator.php';20$generator = new Generator();21$generator->useStrictTypes();22require_once 'generator.php';23$generator = new Generator();24$generator->useStrictTypes();25require_once 'generator.php';26$generator = new Generator();27$generator->useStrictTypes();28require_once 'generator.php';29$generator = new Generator();30$generator->useStrictTypes();31require_once 'generator.php';32$generator = new Generator();33$generator->useStrictTypes();34require_once 'generator.php';35$generator = new Generator();36$generator->useStrictTypes();37require_once 'generator.php';38$generator = new Generator();39$generator->useStrictTypes();

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1require_once('generator.php');2$generator = new Generator();3$generator->useStrictTypes();4require_once('generator.php');5$generator = new Generator();6$generator->useStrictTypes();7require_once('generator.php');8$generator = new Generator();9$generator->useStrictTypes();10require_once('generator.php');11$generator = new Generator();12$generator->useStrictTypes();13require_once('generator.php');14$generator = new Generator();15$generator->useStrictTypes();16require_once('generator.php');17$generator = new Generator();18$generator->useStrictTypes();19require_once('generator.php');20$generator = new Generator();21$generator->useStrictTypes();22require_once('generator.php');23$generator = new Generator();24$generator->useStrictTypes();25require_once('generator.php');26$generator = new Generator();27$generator->useStrictTypes();28require_once('generator.php');29$generator = new Generator();30$generator->useStrictTypes();31require_once('generator.php');32$generator = new Generator();33$generator->useStrictTypes();34require_once('generator.php');35$generator = new Generator();36$generator->useStrictTypes();37require_once('generator.php');38$generator = new Generator();39$generator->useStrictTypes();40require_once('generator

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->useStrictTypes(true);3$generator = new Generator();4$generator->useStrictTypes(false);5declare(strict_types=1);6use Webfiori\entity\Generator;7require 'path/to/vendor/autoload.php';8$generator = new Generator();9$generator->useStrictTypes(true);10$generator->generate();11declare(strict_types=1);12use Webfiori\entity\Generator;13require 'path/to/vendor/autoload.php';14$generator = new Generator();15$generator->useStrictTypes(true);16$generator->generate();17declare(strict_types=1);18use Webfiori\entity\Generator;19require 'path/to/vendor/autoload.php';20$generator = new Generator();21$generator->useStrictTypes(true);22$generator->generate();

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1require_once 'generator.php';2$generator = new Generator();3$generator->useStrictTypes();4require_once 'generator.php';5$generator = new Generator();6$generator->useStrictTypes();7require_once 'generator.php';8$generator = new Generator();9$generator->useStrictTypes();10require_once 'generator.php';11$generator = new Generator();12$generator->useStrictTypes();13require_once 'generator.php';14$generator = new Generator();15$generator->useStrictTypes();16require_once 'generator.php';17$generator = new Generator();18$generator->useStrictTypes();19require_once 'generator.php';20$generator = new Generator();21$generator->useStrictTypes();22require_once 'generator.php';23$generator = new Generator();24$generator->useStrictTypes();25require_once 'generator.php';26$generator = new Generator();27$generator->useStrictTypes();28require_once 'generator.php';29$generator = new Generator();30$generator->useStrictTypes();31require_once 'generator.php';32$generator = new Generator();33$generator->useStrictTypes();34require_once 'generator.php';35$generator = new Generator();36$generator->useStrictTypes();

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1$generator = new \PhpStrictTypes\Generator();2$generator->useStrictTypes('1.php');3$generator = new \PhpStrictTypes\Generator();4$generator->useStrictTypes('2.php');5$generator = new \PhpStrictTypes\Generator();6$generator->useStrictTypes('3.php');7$generator = new \PhpStrictTypes\Generator();8$generator->useStrictTypes('4.php');9$generator = new \PhpStrictTypes\Generator();10$generator->useStrictTypes('5.php');11$generator = new \PhpStrictTypes\Generator();12$generator->useStrictTypes('6.php');13$generator = new \PhpStrictTypes\Generator();14$generator->useStrictTypes('7.php');15$generator = new \PhpStrictTypes\Generator();16$generator->useStrictTypes('8.php');17$generator = new \PhpStrictTypes\Generator();18$generator->useStrictTypes('9.php');19$generator = new \PhpStrictTypes\Generator();20$generator->useStrictTypes('10.php');21$generator = new \PhpStrictTypes\Generator();22$generator->useStrictTypes('11.php');23$generator = new \PhpStrictTypes\Generator();24$generator->useStrictTypes('12.php');25$generator = new \PhpStrictTypes\Generator();26$generator->useStrictTypes('

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1$generator = new \Picqer\Barcode\BarcodeGenerator();2$generator->useStrictTypes(true);3$barcode = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);4header('Content-Type: image/png');5echo $barcode;6$generator = new \Picqer\Barcode\BarcodeGenerator();7$generator->useStrictTypes(true);8$generator->setHeight(50);9$generator->setWidth(300);10$barcode = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);11header('Content-Type: image/png');12echo $barcode;13$generator = new \Picqer\Barcode\BarcodeGenerator();14$generator->useStrictTypes(true);15$generator->setHeight(50);16$generator->setWidth(300);17$barcode = $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 1, 50);18header('Content-Type: image/png');19echo $barcode;

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1require_once 'generator.php';2$generator = new Generator();3$generator->useStrictTypes();4echo $generator->generate();5require_once 'generator.php';6$generator = new Generator();7$generator->useStrictTypes();8echo $generator->generate();9require_once 'generator.php';10$generator = new Generator();11$generator->useStrictTypes();12echo $generator->generate();13require_once 'generator.php';14$generator = new Generator();15$generator->useStrictTypes();16echo $generator->generate();17require_once 'generator.php';18$generator = new Generator();19$generator->useStrictTypes();20echo $generator->generate();21require_once 'generator.php';22$generator = new Generator();23$generator->useStrictTypes();24echo $generator->generate();25require_once 'generator.php';26$generator = new Generator();27$generator->useStrictTypes();28echo $generator->generate();29require_once 'generator.php';30$generator = new Generator();31$generator->useStrictTypes();32echo $generator->generate();33require_once 'generator.php';34$generator = new Generator();35$generator->useStrictTypes();36echo $generator->generate();37require_once 'generator.php';38$generator = new Generator();39$generator->useStrictTypes();40echo $generator->generate();41require_once 'generator.php';42$generator = new Generator();

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1include_once 'generator.php';2$gen = new Generator();3$gen->useStrictTypes();4include_once 'generator.php';5$gen = new Generator();6$gen->useStrictTypes();7include_once 'generator.php';8$gen = new Generator();9$gen->useStrictTypes();10include_once 'generator.php';11$gen = new Generator();12$gen->useStrictTypes();13include_once 'generator.php';14$gen = new Generator();15$gen->useStrictTypes();16include_once 'generator.php';17$gen = new Generator();18$gen->useStrictTypes();19include_once 'generator.php';20$gen = new Generator();21$gen->useStrictTypes();22include_once 'generator.php';23$gen = new Generator();24$gen->useStrictTypes();25include_once 'generator.php';26$gen = new Generator();27$gen->useStrictTypes();28include_once 'generator.php';29$gen = new Generator();30$gen->useStrictTypes();31include_once 'generator.php';32$gen = new Generator();33$gen->useStrictTypes();34include_once 'generator.php';35$gen = new Generator();36$gen->useStrictTypes();37include_once 'generator.php';38$gen = new Generator();39$gen->useStrictTypes();40include_once 'generator.php';

Full Screen

Full Screen

useStrictTypes

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->useStrictTypes(true);3$generator->generateCode();4declare(strict_types=1);5$generator = new Generator();6$generator->useStrictTypes(false);7$generator->generateCode();8$generator = new Generator();9$generator->useStrictTypes();10$generator->generateCode();11declare(strict_types=1);12$generator = new Generator();13$generator->useStrictTypes(null);14$generator->generateCode();15declare(strict_types=1);16$generator = new Generator();17$generator->useStrictTypes(1);18$generator->generateCode();19declare(strict_types=1);20$generator = new Generator();21$generator->useStrictTypes(0);22$generator->generateCode();23$generator = new Generator();24$generator->useStrictTypes(array());25$generator->generateCode();26$generator = new Generator();27$generator->useStrictTypes(array(1));28$generator->generateCode();29$generator = new Generator();30$generator->useStrictTypes(array(0));31$generator->generateCode();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in generator

Trigger useStrictTypes code on LambdaTest Cloud Grid

Execute automation tests with useStrictTypes on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful