Skip to content

Commit 895d666

Browse files
authored
Refactor the tests to pass github actions pipeline (#202)
1 parent 9b07c50 commit 895d666

File tree

15 files changed

+672
-642
lines changed

15 files changed

+672
-642
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,39 @@ jobs:
1111
include:
1212
- operating-system: 'ubuntu-latest'
1313
php-version: '7.1'
14+
composer-require-checker-version: '2.1.0'
1415

1516
- operating-system: 'ubuntu-latest'
1617
php-version: '7.2'
18+
composer-require-checker-version: '2.1.0'
1719

1820
- operating-system: 'ubuntu-latest'
1921
php-version: '7.3'
22+
composer-require-checker-version: '2.1.0'
2023

2124
- operating-system: 'ubuntu-latest'
2225
php-version: '7.4'
26+
composer-require-checker-version: '3.6.0'
2327

2428
- operating-system: 'ubuntu-latest'
2529
php-version: '8.0'
30+
composer-require-checker-version: '3.6.0'
2631

2732
- operating-system: 'ubuntu-latest'
2833
php-version: '8.1'
34+
composer-require-checker-version: '3.6.0'
2935

3036
- operating-system: 'ubuntu-latest'
3137
php-version: '8.2'
38+
composer-require-checker-version: '3.6.0'
3239

3340
- operating-system: 'ubuntu-latest'
3441
php-version: '8.3'
42+
composer-require-checker-version: '3.6.0'
3543

3644
- operating-system: 'ubuntu-latest'
3745
php-version: '8.4'
46+
composer-require-checker-version: '3.6.0'
3847

3948
name: PHP ${{ matrix.php-version }} ${{ matrix.job-description }}
4049

@@ -87,7 +96,7 @@ jobs:
8796
if: runner.os != 'Windows'
8897

8998
- name: Install composer-require-checker
90-
run: php -r 'file_put_contents("composer-require-checker.phar", file_get_contents("https://github.com/maglnet/ComposerRequireChecker/releases/download/3.6.0/composer-require-checker.phar"));'
99+
run: php -r 'file_put_contents("composer-require-checker.phar", file_get_contents("https://github.com/maglnet/ComposerRequireChecker/releases/download/{{ matrix.composer-require-checker-version }}/composer-require-checker.phar"));'
91100
if: runner.os != 'Windows' && matrix.composer-require-checker-version != 'none'
92101

93102
- name: Run composer-require-checker

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor/
22
composer.lock
33
.idea
4+
.phpunit.result.cache

.php-cs-fixer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return (new \PhpCsFixer\Config())
4+
->setFinder(
5+
(new \PhpCsFixer\Finder())
6+
->in(__DIR__ . "/lib")
7+
->in(__DIR__ . "/test")
8+
);

.php_cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

composer-require-check.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"symbol-whitelist" : [
3+
"apc_fetch",
4+
"apc_store",
5+
"array",
6+
"false",
7+
"null",
8+
"parent",
9+
"self",
10+
"true"
11+
]
12+
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"php": ">=7.1"
2929
},
3030
"require-dev": {
31-
"phpunit/phpunit": "^4.8",
32-
"fabpot/php-cs-fixer": "~1.9",
31+
"phpunit/phpunit": "^7 || ^8",
32+
"friendsofphp/php-cs-fixer": "^2",
3333
"athletic/athletic": "~0.1"
3434
},
3535
"autoload": {

lib/CachingReflector.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
class CachingReflector implements Reflector
66
{
7-
const CACHE_KEY_CLASSES = 'auryn.refls.classes.';
8-
const CACHE_KEY_CTORS = 'auryn.refls.ctors.';
9-
const CACHE_KEY_CTOR_PARAMS = 'auryn.refls.ctor-params.';
10-
const CACHE_KEY_FUNCS = 'auryn.refls.funcs.';
11-
const CACHE_KEY_METHODS = 'auryn.refls.methods.';
7+
public const CACHE_KEY_CLASSES = 'auryn.refls.classes.';
8+
public const CACHE_KEY_CTORS = 'auryn.refls.ctors.';
9+
public const CACHE_KEY_CTOR_PARAMS = 'auryn.refls.ctor-params.';
10+
public const CACHE_KEY_FUNCS = 'auryn.refls.funcs.';
11+
public const CACHE_KEY_METHODS = 'auryn.refls.methods.';
1212

1313
private $reflector;
1414
private $cache;
1515

1616
public function __construct(?Reflector $reflector = null, ?ReflectionCache $cache = null)
1717
{
18-
$this->reflector = $reflector ?: new StandardReflector;
19-
$this->cache = $cache ?: new ReflectionCacheArray;
18+
$this->reflector = $reflector ?: new StandardReflector();
19+
$this->cache = $cache ?: new ReflectionCacheArray();
2020
}
2121

2222
public function getClass($class)

lib/InjectionException.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
class InjectionException extends InjectorException
66
{
77
public $dependencyChain;
8-
8+
99
public function __construct(array $inProgressMakes, $message = "", $code = 0, ?\Exception $previous = null)
1010
{
1111
$this->dependencyChain = array_flip($inProgressMakes);
1212
ksort($this->dependencyChain);
13-
13+
1414
parent::__construct($message, $code, $previous);
1515
}
1616

@@ -26,12 +26,12 @@ public static function fromInvalidCallable(
2626

2727
if (is_string($callableOrMethodStr)) {
2828
$callableString .= $callableOrMethodStr;
29-
} else if (is_array($callableOrMethodStr) &&
29+
} elseif (is_array($callableOrMethodStr) &&
3030
array_key_exists(0, $callableOrMethodStr) &&
3131
array_key_exists(0, $callableOrMethodStr)) {
3232
if (is_string($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) {
3333
$callableString .= $callableOrMethodStr[0].'::'.$callableOrMethodStr[1];
34-
} else if (is_object($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) {
34+
} elseif (is_object($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) {
3535
$callableString .= sprintf(
3636
"[object(%s), '%s']",
3737
get_class($callableOrMethodStr[0]),
@@ -41,7 +41,7 @@ public static function fromInvalidCallable(
4141
}
4242

4343
if ($callableString) {
44-
// Prevent accidental usage of long strings from filling logs.
44+
// Prevent accidental usage of long strings from filling logs.
4545
$callableString = substr($callableString, 0, 250);
4646
$message = sprintf(
4747
"%s. Invalid callable was '%s'",

lib/Injector.php

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@
44

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

4242
private $reflector;
4343
private $classDefinitions = array();
@@ -50,7 +50,7 @@ class Injector
5050

5151
public function __construct(?Reflector $reflector = null)
5252
{
53-
$this->reflector = $reflector ?: new CachingReflector;
53+
$this->reflector = $reflector ?: new CachingReflector();
5454
}
5555

5656
public function __clone()
@@ -141,7 +141,7 @@ public function alias($original, $alias)
141141

142142
private function normalizeName($className)
143143
{
144-
return ltrim(strtolower($className), '\\');
144+
return ltrim(strtolower($className), '\\?');
145145
}
146146

147147
/**
@@ -380,12 +380,7 @@ public function make($name, array $args = array())
380380
}
381381

382382
unset($this->inProgressMakes[$normalizedClass]);
383-
}
384-
catch (\Throwable $exception) {
385-
unset($this->inProgressMakes[$normalizedClass]);
386-
throw $exception;
387-
}
388-
catch (\Exception $exception) {
383+
} catch (\Throwable $exception) {
389384
unset($this->inProgressMakes[$normalizedClass]);
390385
throw $exception;
391386
}
@@ -441,7 +436,7 @@ private function instantiateWithoutCtorParams($className)
441436
);
442437
}
443438

444-
return new $className;
439+
return new $className();
445440
}
446441

447442
private function provisionFuncArgs(\ReflectionFunctionAbstract $reflFunc, array $definition, ?array $reflParams = null, $className = null)
@@ -593,7 +588,11 @@ private function prepareInstance($obj, $normalizedClass)
593588
}
594589
}
595590

596-
$interfaces = @class_implements($obj);
591+
if ($obj !== null) {
592+
$interfaces = @class_implements($obj);
593+
} else {
594+
$interfaces = false;
595+
}
597596

598597
if ($interfaces === false) {
599598
throw new InjectionException(

lib/ReflectionCacheApc.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ReflectionCacheApc implements ReflectionCache
99

1010
public function __construct(?ReflectionCache $localCache = null)
1111
{
12-
$this->localCache = $localCache ?: new ReflectionCacheArray;
12+
$this->localCache = $localCache ?: new ReflectionCacheArray();
1313
}
1414

1515
public function setTimeToLive($seconds)
@@ -26,11 +26,11 @@ public function fetch($key)
2626

2727
if ($localData != false) {
2828
return $localData;
29-
} else {
30-
$success = null; // stupid by-ref parameter that scrutinizer complains about
31-
$data = apc_fetch($key, $success);
32-
return $success ? $data : false;
3329
}
30+
31+
$success = null; // stupid by-ref parameter that scrutinizer complains about
32+
$data = apc_fetch($key, $success);
33+
return $success ? $data : false;
3434
}
3535

3636
public function store($key, $data)

0 commit comments

Comments
 (0)