Skip to content

Commit

Permalink
Merge 8cf9657 into 53ddbdf
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Sep 27, 2020
2 parents 53ddbdf + 8cf9657 commit 201a1c4
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 51 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
# - 7.0
# - 7.1
# - 7.2
- 7.3
- 7.4snapshot
- 7.4
- nightly
cache:
directories:
- vendor
matrix:
allow_failures:
- php: nightly
- php: 7.4snapshot
notifications:
irc: "irc.freenode.org##atoum"
webhooks:
Expand Down
4 changes: 2 additions & 2 deletions classes/includer.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public function getFirstError()
return $firstError;
}

public function errorHandler($error, $message, $file, $line, $context)
public function errorHandler($error, $message, $file, $line, $context = [])
{
$errorReporting = $this->adapter->error_reporting();

if ($errorReporting !== 0 && ($errorReporting & $error)) {
if ($errorReporting & $error) {
foreach (array_reverse(debug_backtrace()) as $trace) {
if (isset($trace['file']) === true && $trace['file'] === $this->path) {
$file = $this->path;
Expand Down
2 changes: 1 addition & 1 deletion classes/iterators/recursives/directory/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use mageekguy\atoum\iterators\filters;

class factory implements \iteratorAggregate
class factory
{
protected $dotFilterFactory = null;
protected $iteratorFactory = null;
Expand Down
55 changes: 42 additions & 13 deletions classes/mock/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,23 +775,52 @@ protected static function getClassName($class)

protected static function getParameterType(\reflectionParameter $parameter)
{
$prefix = self::isNullableParameter($parameter) ? '?' : '';
switch (true) {
case $parameter->isArray():
return $prefix . 'array ';
if (version_compare(PHP_VERSION, '7.1.0', '>=')) {
// PHP 7.1+
if (!$parameter->hasType()) {
return '';
}

case method_exists($parameter, 'isCallable') && $parameter->isCallable():
return $prefix . 'callable ';
$parameterType = $parameter->getType();
$parameterTypes = $parameterType instanceof \ReflectionUnionType
? $parameterType->getTypes()
: [$parameterType];

$names = [];
$hasMixed = false;
foreach ($parameterTypes as $type) {
$name = $type instanceof \reflectionNamedType ? $type->getName() : (string) $type;
if ($name === 'self') {
$name = $parameter->getDeclaringClass()->getName();
}
$names[] = ($type instanceof \reflectionType && !$type->isBuiltin() ? '\\' : '') . $name;

case ($class = $parameter->getClass()):
return $prefix . '\\' . $class->getName() . ' ';
$hasMixed = $hasMixed || $name === 'mixed';
}

case method_exists($parameter, 'hasType') && $parameter->hasType():
$type = $parameter->getType();
return $prefix . ($type instanceof \reflectionNamedType ? $type->getName() : (string) $type) . ' ';
$prefix = !empty($names) && self::isNullableParameter($parameter) && !$hasMixed ? '?' : '';

default:
return '';
return $prefix . implode('|', $names) . ' ';
} else {
// PHP 5.6 and 7.0
$prefix = self::isNullableParameter($parameter) ? '?' : '';

switch (true) {
case $parameter->isArray():
return $prefix . 'array ';

case method_exists($parameter, 'isCallable') && $parameter->isCallable():
return $prefix . 'callable ';

case ($class = $parameter->getClass()):
return $prefix . '\\' . $class->getName() . ' ';

case method_exists($parameter, 'hasType') && $parameter->hasType():
return $prefix . (string) $parameter->getType() . ' ';

default:
return '';
}
}
}

Expand Down
44 changes: 35 additions & 9 deletions classes/php/mocker/funktion.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,44 @@ protected static function getParameters(\reflectionFunction $function)

protected static function getParameterType(\reflectionParameter $parameter)
{
switch (true) {
case $parameter->isArray():
return 'array ';
if (version_compare(PHP_VERSION, '7.1.0', '>=')) {
// PHP 7.1+
if (!$parameter->hasType()) {
return '';
}

case $parameter->isCallable():
return 'callable ';
$parameterType = $parameter->getType();
$parameterTypes = $parameterType instanceof \ReflectionUnionType
? $parameterType->getTypes()
: [$parameterType];

$names = [];
foreach ($parameterTypes as $type) {
$name = $type instanceof \reflectionNamedType ? $type->getName() : (string) $type;
if ($name === 'self') {
$name = $parameter->getDeclaringClass()->getName();
}
$names[] = ($type instanceof \reflectionType && !$type->isBuiltin() ? '\\' : '') . $name;
}
return implode('|', $names) . ' ';
} else {
// PHP 5.6 and 7.0
switch (true) {
case $parameter->isArray():
return 'array ';

case $class = $parameter->getClass():
return '\\' . $class->getName() . ' ';
case method_exists($parameter, 'isCallable') && $parameter->isCallable():
return 'callable ';

default:
return '';
case ($class = $parameter->getClass()):
return '\\' . $class->getName() . ' ';

case method_exists($parameter, 'hasType') && $parameter->hasType():
return (string) $parameter->getType() . ' ';

default:
return '';
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions classes/php/tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function tokenize($string)
break;
}

if ($token === null) {
continue;
}

$this->currentIterator->append(new token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2]));
}

Expand Down
4 changes: 2 additions & 2 deletions classes/scripts/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function useConfigurationCallable(\closure $callback)
$runner = $this->runner;
$errors = [];

$this->adapter->set_error_handler(function ($error, $message, $file, $line, $context) use (&$errors) {
$this->adapter->set_error_handler(function ($error, $message, $file, $line, $context = []) use (&$errors) {
foreach (array_reverse(debug_backtrace()) as $trace) {
if (isset($trace['file']) === true && $trace['file'] === __DIR__) {
$file = __DIR__;
Expand Down Expand Up @@ -691,7 +691,7 @@ function () use (& $autorunner, $calledClass) {
set_error_handler(function ($error, $message, $file, $line) use ($autorunner) {
$errorReporting = error_reporting();

if ($errorReporting !== 0 && $errorReporting & $error) {
if ($errorReporting & $error) {
$autorunner->writeError($message . ' in ' . $file . ' at line ' . $line, $error);

exit(3);
Expand Down
20 changes: 17 additions & 3 deletions classes/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1515,11 +1515,25 @@ public function setDataProvider($testMethodName, $dataProvider = null)
foreach ($reflectedMethod->getParameters() as $parameter) {
$parameterProvider = new test\data\providers\mock($this->mockGenerator);

if (($parameterClass = $parameter->getClass()) === null) {
$parameterClassName = null;
if (version_compare(PHP_VERSION, '7.1.0', '>=')) {
// PHP 7.1+
// TODO Handle Union types and "self" keyword ?
$parameterClassName = $parameter->hasType() && !$parameter->getType()->isBuiltin()
? $parameter->getType()->getName()
: null;
} else {
// PHP 5.6 and 7.0
$parameterClassName = $parameter->getClass()
? $parameter->getClass()->getName()
: null ;
}

if ($parameterClassName === null) {
throw new exceptions\logic\invalidArgument('Could not generate a data provider for ' . $this->class . '::' . $testMethodName . '() because it has at least one argument which is not type-hinted with a class or interface name');
}

$parametersProvider->addProvider($parameterProvider->setClass($parameterClass->getName()));
$parametersProvider->addProvider($parameterProvider->setClass($parameterClassName));
}

$dataProvider = new test\data\set($parametersProvider);
Expand All @@ -1544,7 +1558,7 @@ public function errorHandler($errno, $errstr, $errfile, $errline)
$doNotCallDefaultErrorHandler = true;
$errorReporting = $this->adapter->error_reporting();

if ($errorReporting !== 0 && $errorReporting & $errno) {
if ($errorReporting & $errno) {
list($file, $line) = $this->getBacktrace();

$this->score->addError($file ?: ($errfile ?: $this->path), $this->class, $this->currentMethod, $line ?: $errline, $errno, trim($errstr), $errfile, $errline);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
"require":
{
"php": "^5.6.0 || ^7.0.0 <7.5.0",
"php": "^5.6 || ^7.0 || ^8.0",
"ext-hash": "*",
"ext-json": "*",
"ext-tokenizer": "*",
Expand Down
5 changes: 2 additions & 3 deletions tests/units/classes/includer.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,11 @@ public function testGetFirstError()
set_error_handler($errorHandler);
return null;
})
->and($fileWithError = stream::get())
->and($fileWithError->file_get_contents = '<?php trigger_error(\'' . ($message = uniqid()) . '\', E_USER_WARNING); ?>')
->and($fileWithError = 'data://text/plain,' . urlencode('<?php trigger_error(\'' . ($message = uniqid()) . '\', E_USER_WARNING); ?>'))
->and($includer->includePath($fileWithError))
->then
->array($error = $includer->getFirstError())->isNotEmpty()
->integer($error[0])->isEqualTo(E_USER_WARNING)
->integer($error[0])->isEqualTo(E_USER_WARNING, print_r($error, true))
->string($error[1])->isEqualTo($message)
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

class factory extends atoum\test
{
public function testClass()
{
$this->testedClass->implements(\iteratorAggregate::class);
}

public function test__construct()
{
$this
Expand Down

0 comments on commit 201a1c4

Please sign in to comment.