Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the tests for newer Phpunit version #201

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
.idea
.phpunit.result.cache
8 changes: 8 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return (new \PhpCsFixer\Config())
->setFinder(
(new \PhpCsFixer\Finder())
->in(__DIR__ . "/lib")
->in(__DIR__ . "/test")
);
15 changes: 0 additions & 15 deletions .php_cs

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"fabpot/php-cs-fixer": "~1.9",
"athletic/athletic": "~0.1"
"phpunit/phpunit": ">=7",
"friendsofphp/php-cs-fixer": ">=2",
"athletic/athletic": "^0.1"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 7 additions & 7 deletions lib/CachingReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

class CachingReflector implements Reflector
{
const CACHE_KEY_CLASSES = 'auryn.refls.classes.';
const CACHE_KEY_CTORS = 'auryn.refls.ctors.';
const CACHE_KEY_CTOR_PARAMS = 'auryn.refls.ctor-params.';
const CACHE_KEY_FUNCS = 'auryn.refls.funcs.';
const CACHE_KEY_METHODS = 'auryn.refls.methods.';
public const CACHE_KEY_CLASSES = 'auryn.refls.classes.';
public const CACHE_KEY_CTORS = 'auryn.refls.ctors.';
public const CACHE_KEY_CTOR_PARAMS = 'auryn.refls.ctor-params.';
public const CACHE_KEY_FUNCS = 'auryn.refls.funcs.';
public const CACHE_KEY_METHODS = 'auryn.refls.methods.';

private $reflector;
private $cache;

public function __construct(?Reflector $reflector = null, ?ReflectionCache $cache = null)
{
$this->reflector = $reflector ?: new StandardReflector;
$this->cache = $cache ?: new ReflectionCacheArray;
$this->reflector = $reflector ?: new StandardReflector();
$this->cache = $cache ?: new ReflectionCacheArray();
}

public function getClass($class)
Expand Down
10 changes: 5 additions & 5 deletions lib/InjectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
class InjectionException extends InjectorException
{
public $dependencyChain;

public function __construct(array $inProgressMakes, $message = "", $code = 0, ?\Exception $previous = null)
{
$this->dependencyChain = array_flip($inProgressMakes);
ksort($this->dependencyChain);

parent::__construct($message, $code, $previous);
}

Expand All @@ -26,12 +26,12 @@ public static function fromInvalidCallable(

if (is_string($callableOrMethodStr)) {
$callableString .= $callableOrMethodStr;
} else if (is_array($callableOrMethodStr) &&
} elseif (is_array($callableOrMethodStr) &&
array_key_exists(0, $callableOrMethodStr) &&
array_key_exists(0, $callableOrMethodStr)) {
if (is_string($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) {
$callableString .= $callableOrMethodStr[0].'::'.$callableOrMethodStr[1];
} else if (is_object($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) {
} elseif (is_object($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) {
$callableString .= sprintf(
"[object(%s), '%s']",
get_class($callableOrMethodStr[0]),
Expand All @@ -41,7 +41,7 @@ public static function fromInvalidCallable(
}

if ($callableString) {
// Prevent accidental usage of long strings from filling logs.
// Prevent accidental usage of long strings from filling logs.
$callableString = substr($callableString, 0, 250);
$message = sprintf(
"%s. Invalid callable was '%s'",
Expand Down
79 changes: 37 additions & 42 deletions lib/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@

class Injector
{
const A_RAW = ':';
const A_DELEGATE = '+';
const A_DEFINE = '@';
const I_BINDINGS = 1;
const I_DELEGATES = 2;
const I_PREPARES = 4;
const I_ALIASES = 8;
const I_SHARES = 16;
const I_ALL = 31;

const E_NON_EMPTY_STRING_ALIAS = 1;
const M_NON_EMPTY_STRING_ALIAS = "Invalid alias: non-empty string required at arguments 1 and 2";
const E_SHARED_CANNOT_ALIAS = 2;
const M_SHARED_CANNOT_ALIAS = "Cannot alias class %s to %s because it is currently shared";
const E_SHARE_ARGUMENT = 3;
const M_SHARE_ARGUMENT = "%s::share() requires a string class name or object instance at Argument 1; %s specified";
const E_ALIASED_CANNOT_SHARE = 4;
const M_ALIASED_CANNOT_SHARE = "Cannot share class %s because it is currently aliased to %s";
const E_INVOKABLE = 5;
const M_INVOKABLE = "Invalid invokable: callable or provisional string required";
const E_NON_PUBLIC_CONSTRUCTOR = 6;
const M_NON_PUBLIC_CONSTRUCTOR = "Cannot instantiate protected/private constructor in class %s";
const E_NEEDS_DEFINITION = 7;
const M_NEEDS_DEFINITION = "Injection definition required for %s %s";
const E_MAKE_FAILURE = 8;
const M_MAKE_FAILURE = "Could not make %s: %s";
const E_UNDEFINED_PARAM = 9;
const M_UNDEFINED_PARAM = "No definition available to provision typeless parameter \$%s at position %d in %s()%s";
const E_DELEGATE_ARGUMENT = 10;
const M_DELEGATE_ARGUMENT = "%s::delegate expects a valid callable or executable class::method string at Argument 2%s";
const E_CYCLIC_DEPENDENCY = 11;
const M_CYCLIC_DEPENDENCY = "Detected a cyclic dependency while provisioning %s";
const E_MAKING_FAILED = 12;
const M_MAKING_FAILED = "Making %s did not result in an object, instead result is of type '%s'";
public const A_RAW = ':';
public const A_DELEGATE = '+';
public const A_DEFINE = '@';
public const I_BINDINGS = 1;
public const I_DELEGATES = 2;
public const I_PREPARES = 4;
public const I_ALIASES = 8;
public const I_SHARES = 16;
public const I_ALL = 31;

public const E_NON_EMPTY_STRING_ALIAS = 1;
public const M_NON_EMPTY_STRING_ALIAS = "Invalid alias: non-empty string required at arguments 1 and 2";
public const E_SHARED_CANNOT_ALIAS = 2;
public const M_SHARED_CANNOT_ALIAS = "Cannot alias class %s to %s because it is currently shared";
public const E_SHARE_ARGUMENT = 3;
public const M_SHARE_ARGUMENT = "%s::share() requires a string class name or object instance at Argument 1; %s specified";
public const E_ALIASED_CANNOT_SHARE = 4;
public const M_ALIASED_CANNOT_SHARE = "Cannot share class %s because it is currently aliased to %s";
public const E_INVOKABLE = 5;
public const M_INVOKABLE = "Invalid invokable: callable or provisional string required";
public const E_NON_PUBLIC_CONSTRUCTOR = 6;
public const M_NON_PUBLIC_CONSTRUCTOR = "Cannot instantiate protected/private constructor in class %s";
public const E_NEEDS_DEFINITION = 7;
public const M_NEEDS_DEFINITION = "Injection definition required for %s %s";
public const E_MAKE_FAILURE = 8;
public const M_MAKE_FAILURE = "Could not make %s: %s";
public const E_UNDEFINED_PARAM = 9;
public const M_UNDEFINED_PARAM = "No definition available to provision typeless parameter \$%s at position %d in %s()%s";
public const E_DELEGATE_ARGUMENT = 10;
public const M_DELEGATE_ARGUMENT = "%s::delegate expects a valid callable or executable class::method string at Argument 2%s";
public const E_CYCLIC_DEPENDENCY = 11;
public const M_CYCLIC_DEPENDENCY = "Detected a cyclic dependency while provisioning %s";
public const E_MAKING_FAILED = 12;
public const M_MAKING_FAILED = "Making %s did not result in an object, instead result is of type '%s'";

private $reflector;
private $classDefinitions = array();
Expand All @@ -50,7 +50,7 @@ class Injector

public function __construct(?Reflector $reflector = null)
{
$this->reflector = $reflector ?: new CachingReflector;
$this->reflector = $reflector ?: new CachingReflector();
}

public function __clone()
Expand Down Expand Up @@ -380,12 +380,7 @@ public function make($name, array $args = array())
}

unset($this->inProgressMakes[$normalizedClass]);
}
catch (\Throwable $exception) {
unset($this->inProgressMakes[$normalizedClass]);
throw $exception;
}
catch (\Exception $exception) {
} catch (\Throwable $exception) {
unset($this->inProgressMakes[$normalizedClass]);
throw $exception;
}
Expand Down Expand Up @@ -441,7 +436,7 @@ private function instantiateWithoutCtorParams($className)
);
}

return new $className;
return new $className();
}

private function provisionFuncArgs(\ReflectionFunctionAbstract $reflFunc, array $definition, ?array $reflParams = null, $className = null)
Expand Down
2 changes: 1 addition & 1 deletion lib/ReflectionCacheApc.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ReflectionCacheApc implements ReflectionCache

public function __construct(?ReflectionCache $localCache = null)
{
$this->localCache = $localCache ?: new ReflectionCacheArray;
$this->localCache = $localCache ?: new ReflectionCacheArray();
}

public function setTimeToLive($seconds)
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand Down
4 changes: 2 additions & 2 deletions test/Benchmark/Noop.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public function noop()
{
// call-target, intentionally left empty
}

public function namedNoop($name)
{
// call-target, intentionally left empty
}

public function typehintedNoop(noop $noop)
{
// call-target, intentionally left empty
Expand Down
Loading
Loading