Add pear modules, mail and net_smtp via composer (#93)

Add pear modules, mail and net_smtp via composer, remove php 5.6 build due to phpunit 6
This commit is contained in:
Thilina Hasantha
2018-01-08 23:13:43 +01:00
committed by GitHub
parent 359e3f8382
commit e7792e7d79
2349 changed files with 117270 additions and 83170 deletions

View File

@@ -61,11 +61,11 @@ class ObjectStateToken implements TokenInterface
$actual = call_user_func(array($argument, $this->name));
$comparator = $this->comparatorFactory->getComparatorFor(
$actual, $this->value
$this->value, $actual
);
try {
$comparator->assertEquals($actual, $this->value);
$comparator->assertEquals($this->value, $actual);
return 8;
} catch (ComparisonFailure $failure) {
return false;

View File

@@ -11,6 +11,7 @@
namespace Prophecy\Call;
use Prophecy\Exception\Prophecy\MethodProphecyException;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Argument\ArgumentsWildcard;
@@ -96,16 +97,24 @@ class CallCenter
@usort($matches, function ($match1, $match2) { return $match2[0] - $match1[0]; });
// If Highest rated method prophecy has a promise - execute it or return null instead
$methodProphecy = $matches[0][1];
$returnValue = null;
$exception = null;
if ($promise = $matches[0][1]->getPromise()) {
if ($promise = $methodProphecy->getPromise()) {
try {
$returnValue = $promise->execute($arguments, $prophecy, $matches[0][1]);
$returnValue = $promise->execute($arguments, $prophecy, $methodProphecy);
} catch (\Exception $e) {
$exception = $e;
}
}
if ($methodProphecy->hasReturnVoid() && $returnValue !== null) {
throw new MethodProphecyException(
"The method \"$methodName\" has a void return type, but the promise returned a value",
$methodProphecy
);
}
$this->recordedCalls[] = new Call(
$methodName, $arguments, $returnValue, $exception, $file, $line
);

View File

@@ -51,7 +51,8 @@ class KeywordPatch implements ClassPatchInterface
*
* @return int Priority number (higher - earlier)
*/
public function getPriority() {
public function getPriority()
{
return 49;
}
@@ -60,7 +61,11 @@ class KeywordPatch implements ClassPatchInterface
*
* @return array
*/
private function getKeywords() {
private function getKeywords()
{
if (\PHP_VERSION_ID >= 70000) {
return array('__halt_compiler');
}
return array(
'__halt_compiler',

View File

@@ -51,23 +51,27 @@ class MagicCallPatch implements ClassPatchInterface
*/
public function apply(ClassNode $node)
{
$parentClass = $node->getParentClass();
$reflectionClass = new \ReflectionClass($parentClass);
$types = array_filter($node->getInterfaces(), function ($interface) {
return 0 !== strpos($interface, 'Prophecy\\');
});
$types[] = $node->getParentClass();
$tagList = $this->tagRetriever->getTagList($reflectionClass);
foreach ($types as $type) {
$reflectionClass = new \ReflectionClass($type);
$tagList = $this->tagRetriever->getTagList($reflectionClass);
foreach($tagList as $tag) {
$methodName = $tag->getMethodName();
foreach($tagList as $tag) {
$methodName = $tag->getMethodName();
if (empty($methodName)) {
continue;
}
if (empty($methodName)) {
continue;
}
if (!$reflectionClass->hasMethod($methodName)) {
$methodNode = new MethodNode($methodName);
$methodNode->setStatic($tag->isStatic());
$node->addMethod($methodNode);
if (!$reflectionClass->hasMethod($methodName)) {
$methodNode = new MethodNode($methodName);
$methodNode->setStatic($tag->isStatic());
$node->addMethod($methodNode);
}
}
}
}

View File

@@ -50,9 +50,15 @@ class ProphecySubjectPatch implements ClassPatchInterface
continue;
}
$method->setCode(
'return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());'
);
if ($method->getReturnType() === 'void') {
$method->setCode(
'$this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());'
);
} else {
$method->setCode(
'return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());'
);
}
}
$prophecySetter = new MethodNode('setProphecy');

View File

@@ -34,7 +34,6 @@ class SplFileInfoPatch implements ClassPatchInterface
if (null === $node->getParentClass()) {
return false;
}
return 'SplFileInfo' === $node->getParentClass()
|| is_subclass_of($node->getParentClass(), 'SplFileInfo')
;
@@ -61,7 +60,15 @@ class SplFileInfoPatch implements ClassPatchInterface
}
if ($this->nodeIsSplFileObject($node)) {
$constructor->setCode('return parent::__construct("' . __FILE__ .'");');
$filePath = str_replace('\\','\\\\',__FILE__);
$constructor->setCode('return parent::__construct("' . $filePath .'");');
return;
}
if ($this->nodeIsSymfonySplFileInfo($node)) {
$filePath = str_replace('\\','\\\\',__FILE__);
$constructor->setCode('return parent::__construct("' . $filePath .'", "", "");');
return;
}
@@ -102,4 +109,15 @@ class SplFileInfoPatch implements ClassPatchInterface
return 'SplFileObject' === $parent
|| is_subclass_of($parent, 'SplFileObject');
}
/**
* @param ClassNode $node
* @return boolean
*/
private function nodeIsSymfonySplFileInfo(ClassNode $node)
{
$parent = $node->getParentClass();
return 'Symfony\\Component\\Finder\\SplFileInfo' === $parent;
}
}

View File

@@ -60,20 +60,44 @@ class ClassCodeGenerator
$method->returnsReference() ? '&':'',
$method->getName(),
implode(', ', $this->generateArguments($method->getArguments())),
version_compare(PHP_VERSION, '7.0', '>=') && $method->hasReturnType()
? sprintf(': %s', $method->getReturnType())
: ''
$this->getReturnType($method)
);
$php .= $method->getCode()."\n";
return $php.'}';
}
/**
* @return string
*/
private function getReturnType(Node\MethodNode $method)
{
if (version_compare(PHP_VERSION, '7.1', '>=')) {
if ($method->hasReturnType()) {
return $method->hasNullableReturnType()
? sprintf(': ?%s', $method->getReturnType())
: sprintf(': %s', $method->getReturnType());
}
}
if (version_compare(PHP_VERSION, '7.0', '>=')) {
return $method->hasReturnType() && $method->getReturnType() !== 'void'
? sprintf(': %s', $method->getReturnType())
: '';
}
return '';
}
private function generateArguments(array $arguments)
{
return array_map(function (Node\ArgumentNode $argument) {
$php = '';
if (version_compare(PHP_VERSION, '7.1', '>=')) {
$php .= $argument->isNullable() ? '?' : '';
}
if ($hint = $argument->getTypeHint()) {
switch ($hint) {
case 'array':
@@ -81,6 +105,15 @@ class ClassCodeGenerator
$php .= $hint;
break;
case 'iterable':
if (version_compare(PHP_VERSION, '7.1', '>=')) {
$php .= $hint;
break;
}
$php .= '\\'.$hint;
break;
case 'string':
case 'int':
case 'float':

View File

@@ -143,7 +143,7 @@ class ClassMirror
$node->setReturnsReference();
}
if (version_compare(PHP_VERSION, '7.0', '>=') && true === $method->hasReturnType()) {
if (version_compare(PHP_VERSION, '7.0', '>=') && $method->hasReturnType()) {
$returnType = (string) $method->getReturnType();
$returnTypeLower = strtolower($returnType);
@@ -155,6 +155,10 @@ class ClassMirror
}
$node->setReturnType($returnType);
if (version_compare(PHP_VERSION, '7.1', '>=') && $method->getReturnType()->allowsNull()) {
$node->setNullableReturnType(true);
}
}
if (is_array($params = $method->getParameters()) && count($params)) {

View File

@@ -24,6 +24,7 @@ class ArgumentNode
private $optional = false;
private $byReference = false;
private $isVariadic = false;
private $isNullable = false;
/**
* @param string $name
@@ -88,4 +89,14 @@ class ArgumentNode
{
return $this->isVariadic;
}
public function isNullable()
{
return $this->isNullable;
}
public function setAsNullable($isNullable = true)
{
$this->isNullable = $isNullable;
}
}

View File

@@ -26,6 +26,7 @@ class MethodNode
private $static = false;
private $returnsReference = false;
private $returnType;
private $nullableReturnType = false;
/**
* @var ArgumentNode[]
@@ -116,12 +117,14 @@ class MethodNode
$this->returnType = null;
break;
case 'string';
case 'string':
case 'float':
case 'int':
case 'bool':
case 'array':
case 'callable':
case 'iterable':
case 'void':
$this->returnType = $type;
break;
@@ -148,6 +151,22 @@ class MethodNode
return $this->returnType;
}
/**
* @param bool $bool
*/
public function setNullableReturnType($bool = true)
{
$this->nullableReturnType = (bool) $bool;
}
/**
* @return bool
*/
public function hasNullableReturnType()
{
return $this->nullableReturnType;
}
/**
* @param string $code
*/

View File

@@ -34,24 +34,22 @@ class ThrowPromise implements PromiseInterface
/**
* Initializes promise.
*
* @param string|\Exception $exception Exception class name or instance
* @param string|\Exception|\Throwable $exception Exception class name or instance
*
* @throws \Prophecy\Exception\InvalidArgumentException
*/
public function __construct($exception)
{
if (is_string($exception)) {
if (!class_exists($exception)
&& 'Exception' !== $exception
&& !is_subclass_of($exception, 'Exception')) {
if (!class_exists($exception) || !$this->isAValidThrowable($exception)) {
throw new InvalidArgumentException(sprintf(
'Exception class or instance expected as argument to ThrowPromise, but got %s.',
'Exception / Throwable class or instance expected as argument to ThrowPromise, but got %s.',
$exception
));
}
} elseif (!$exception instanceof \Exception) {
} elseif (!$exception instanceof \Exception && !$exception instanceof \Throwable) {
throw new InvalidArgumentException(sprintf(
'Exception class or instance expected as argument to ThrowPromise, but got %s.',
'Exception / Throwable class or instance expected as argument to ThrowPromise, but got %s.',
is_object($exception) ? get_class($exception) : gettype($exception)
));
}
@@ -88,4 +86,14 @@ class ThrowPromise implements PromiseInterface
throw $this->exception;
}
/**
* @param string $exception
*
* @return bool
*/
private function isAValidThrowable($exception)
{
return is_a($exception, 'Exception', true) || is_subclass_of($exception, 'Throwable', true);
}
}

View File

@@ -33,6 +33,7 @@ class MethodProphecy
private $prediction;
private $checkedPredictions = array();
private $bound = false;
private $voidReturnType = false;
/**
* Initializes method prophecy.
@@ -71,6 +72,12 @@ class MethodProphecy
if (version_compare(PHP_VERSION, '7.0', '>=') && true === $reflectedMethod->hasReturnType()) {
$type = (string) $reflectedMethod->getReturnType();
if ('void' === $type) {
$this->voidReturnType = true;
return;
}
$this->will(function () use ($type) {
switch ($type) {
case 'string': return '';
@@ -157,12 +164,19 @@ class MethodProphecy
/**
* Sets return promise to the prophecy.
*
* @see Prophecy\Promise\ReturnPromise
* @see \Prophecy\Promise\ReturnPromise
*
* @return $this
*/
public function willReturn()
{
if ($this->voidReturnType) {
throw new MethodProphecyException(
"The method \"$this->methodName\" has a void return type, and so cannot return anything",
$this
);
}
return $this->will(new Promise\ReturnPromise(func_get_args()));
}
@@ -171,19 +185,23 @@ class MethodProphecy
*
* @param int $index The zero-indexed number of the argument to return
*
* @see Prophecy\Promise\ReturnArgumentPromise
* @see \Prophecy\Promise\ReturnArgumentPromise
*
* @return $this
*/
public function willReturnArgument($index = 0)
{
if ($this->voidReturnType) {
throw new MethodProphecyException("The method \"$this->methodName\" has a void return type", $this);
}
return $this->will(new Promise\ReturnArgumentPromise($index));
}
/**
* Sets throw promise to the prophecy.
*
* @see Prophecy\Promise\ThrowPromise
* @see \Prophecy\Promise\ThrowPromise
*
* @param string|\Exception $exception Exception class or instance
*
@@ -225,7 +243,7 @@ class MethodProphecy
/**
* Sets call prediction to the prophecy.
*
* @see Prophecy\Prediction\CallPrediction
* @see \Prophecy\Prediction\CallPrediction
*
* @return $this
*/
@@ -237,7 +255,7 @@ class MethodProphecy
/**
* Sets no calls prediction to the prophecy.
*
* @see Prophecy\Prediction\NoCallsPrediction
* @see \Prophecy\Prediction\NoCallsPrediction
*
* @return $this
*/
@@ -249,7 +267,7 @@ class MethodProphecy
/**
* Sets call times prediction to the prophecy.
*
* @see Prophecy\Prediction\CallTimesPrediction
* @see \Prophecy\Prediction\CallTimesPrediction
*
* @param $count
*
@@ -282,7 +300,7 @@ class MethodProphecy
));
}
if (null === $this->promise) {
if (null === $this->promise && !$this->voidReturnType) {
$this->willReturn();
}
@@ -306,7 +324,7 @@ class MethodProphecy
/**
* Checks call prediction.
*
* @see Prophecy\Prediction\CallPrediction
* @see \Prophecy\Prediction\CallPrediction
*
* @return $this
*/
@@ -318,7 +336,7 @@ class MethodProphecy
/**
* Checks no calls prediction.
*
* @see Prophecy\Prediction\NoCallsPrediction
* @see \Prophecy\Prediction\NoCallsPrediction
*
* @return $this
*/
@@ -330,7 +348,7 @@ class MethodProphecy
/**
* Checks no calls prediction.
*
* @see Prophecy\Prediction\NoCallsPrediction
* @see \Prophecy\Prediction\NoCallsPrediction
* @deprecated
*
* @return $this
@@ -343,7 +361,7 @@ class MethodProphecy
/**
* Checks call times prediction.
*
* @see Prophecy\Prediction\CallTimesPrediction
* @see \Prophecy\Prediction\CallTimesPrediction
*
* @param int $count
*
@@ -426,6 +444,14 @@ class MethodProphecy
return $this->argumentsWildcard;
}
/**
* @return bool
*/
public function hasReturnVoid()
{
return $this->voidReturnType;
}
private function bindToObjectProphecy()
{
if ($this->bound) {

View File

@@ -158,11 +158,12 @@ class ExportUtil
return 'Array &' . $key;
}
$array = $value;
$key = $processed->add($value);
$values = '';
if (count($value) > 0) {
foreach ($value as $k => $v) {
if (count($array) > 0) {
foreach ($array as $k => $v) {
$values .= sprintf(
'%s %s => %s' . "\n",
$whitespace,