Skip to content

Commit 5369e8a

Browse files
authored
Merge pull request #44 from facile-it/feature/phpunit7
PhpUnit 7 integration and drop support for php70
2 parents f9d3c12 + 7e31c2e commit 5369e8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+683
-399
lines changed

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ cache:
66

77
matrix:
88
include:
9-
- php: 7.0
10-
env:
9+
- php: 7.1
10+
env:
1111
- DEPS="low"
12-
- php: 7.0
13-
env:
12+
- php: 7.2
13+
env:
1414
- TEST_COVERAGE=true
15-
- php: 7.1
1615
- php: nightly
1716
fast_finish: true
1817
allow_failures:

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"src/Plugin/PHPUnit/PHPUnitPlugin.php",
3838
"src/Plugin/PHPUnit/moka.php",
3939
"src/Plugin/Prophecy/ProphecyPlugin.php",
40-
"src/Plugin/Prophecy/moka.php"
40+
"src/Plugin/Prophecy/moka.php",
41+
"src/functions.php"
4142
]
4243
},
4344
"autoload-dev": {
@@ -46,18 +47,18 @@
4647
}
4748
},
4849
"require": {
49-
"php": ">=7.0",
50+
"php": ">=7.1",
5051
"phpcollection/phpcollection": "^0.5",
51-
"phpunit/phpunit-mock-objects": "^5.0",
52+
"phpunit/phpunit-mock-objects": "^6.0",
5253
"psr/container": "^1.0"
5354
},
5455
"require-dev": {
5556
"friendsofphp/php-cs-fixer": "^2.3",
5657
"mockery/mockery": "^0.9.9",
5758
"phake/phake": "^3.0",
5859
"phpspec/prophecy": "^1.7",
59-
"phpunit/phpunit": "^6.0",
60-
"sebastian/diff": "^2.0"
60+
"phpunit/phpunit": "^7.0",
61+
"sebastian/diff": "^3.0"
6162
},
6263
"suggest": {
6364
"phpspec/prophecy": "To allow loading of ProphecyPlugin",

src/Builder/ProxyBuilder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(MockingStrategyInterface $mockingStrategy)
4040
/**
4141
* @return void
4242
*/
43-
public function reset()
43+
public function reset(): void
4444
{
4545
$this->container = new ProxyContainer();
4646
}
@@ -52,6 +52,8 @@ public function reset()
5252
*
5353
* @throws MockNotCreatedException
5454
* @throws InvalidIdentifierException
55+
* @throws InvalidArgumentException
56+
* @throws \ReflectionException
5557
*/
5658
public function getProxy(string $fqcnOrAlias, string $alias = null): ProxyInterface
5759
{
@@ -74,6 +76,7 @@ public function getProxy(string $fqcnOrAlias, string $alias = null): ProxyInterf
7476
* @param string $fqcn
7577
* @return ProxyInterface
7678
*
79+
* @throws \ReflectionException
7780
* @throws InvalidArgumentException
7881
* @throws MockNotCreatedException
7982
*/

src/Factory/ProxyBuilderFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function get(MockingStrategyInterface $mockingStrategy): ProxyBuil
3737
*/
3838
private static function key(MockingStrategyInterface $mockingStrategy): string
3939
{
40-
return get_class($mockingStrategy);
40+
return \get_class($mockingStrategy);
4141
}
4242

4343
/**
@@ -52,7 +52,7 @@ protected static function build(MockingStrategyInterface $mockingStrategy): Prox
5252
/**
5353
* @return void
5454
*/
55-
public static function reset()
55+
public static function reset(): void
5656
{
5757
foreach (self::$mockBuilders as $mockBuilder) {
5858
$mockBuilder->reset();

src/Factory/ProxyGeneratorFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function get(MockingStrategyInterface $mockingStrategy): ProxyGene
3737
*/
3838
private static function key(MockingStrategyInterface $mockingStrategy): string
3939
{
40-
return get_class($mockingStrategy);
40+
return \get_class($mockingStrategy);
4141
}
4242

4343
/**

src/Factory/StubFactory.php

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

src/Factory/buildStub.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Moka\Factory;
5+
6+
use Moka\Stub\MethodStub;
7+
use Moka\Stub\PropertyStub;
8+
use Moka\Stub\StubInterface;
9+
use function Moka\Stub\Helper\isPropertyName;
10+
11+
/**
12+
* @param string $name
13+
* @param mixed $value
14+
* @return StubInterface
15+
*/
16+
function buildStub(string $name, $value): StubInterface
17+
{
18+
return isPropertyName($name)
19+
? new PropertyStub($name, $value)
20+
: new MethodStub($name, $value);
21+
}

src/Factory/buildStubs.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Moka\Factory;
5+
6+
use Moka\Exception\InvalidArgumentException;
7+
use Moka\Stub\StubInterface;
8+
use Moka\Stub\StubSet;
9+
10+
/**
11+
* @param array $namesWithValues
12+
* @return StubSet|StubInterface[]
13+
*
14+
* @throws InvalidArgumentException
15+
*/
16+
function buildStubs(array $namesWithValues): StubSet
17+
{
18+
$stubSet = new StubSet();
19+
foreach ($namesWithValues as $name => $value) {
20+
try {
21+
$stub = buildStub($name, $value);
22+
} catch (\Error $error) {
23+
throw new InvalidArgumentException($error->getMessage());
24+
}
25+
26+
$stubSet->add($stub);
27+
}
28+
29+
return $stubSet;
30+
}

src/Generator/ProxyGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ public function __construct(MockingStrategyInterface $mockingStrategy)
3636
*
3737
* @throws MockNotCreatedException
3838
* @throws InvalidArgumentException
39+
* @throws \ReflectionException
3940
*/
4041
public function get(string $fqcn): ProxyInterface
4142
{
4243
$mock = $this->mockingStrategy->build($fqcn);
43-
$mockFQCN = get_class($this->mockingStrategy->get($mock));
44+
$mockFQCN = \get_class($this->mockingStrategy->get($mock));
4445
$mockClass = new \ReflectionClass($mockFQCN);
4546

4647
$proxyCode = ClassTemplate::generate($mockClass);
@@ -54,6 +55,7 @@ public function get(string $fqcn): ProxyInterface
5455
/**
5556
* @param string $proxyFQCN
5657
* @return ProxyInterface|ProxyTrait
58+
* @throws \ReflectionException
5759
*/
5860
protected function getInstance(string $proxyFQCN): ProxyInterface
5961
{

src/Generator/Template/ClassTemplate.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Moka\Generator\Template;
55

6+
use Moka\Exception\InvalidArgumentException;
67
use Moka\Proxy\ProxyInterface;
78
use Moka\Proxy\ProxyTrait;
89

@@ -12,11 +13,11 @@
1213
*/
1314
class ClassTemplate implements TemplateInterface
1415
{
15-
const UNSAFE_METHODS = ['__construct', '__destruct', '__call', '__get', '__clone'];
16+
private const UNSAFE_METHODS = ['__construct', '__destruct', '__call', '__get', '__clone'];
1617

17-
const TEMPLATE_FQCN = 'Moka_%s_%s';
18+
private const TEMPLATE_FQCN = 'Moka_%s_%s';
1819

19-
const TEMPLATE_CLASS = '
20+
private const TEMPLATE_CLASS = '
2021
class %s extends %s implements %s
2122
{
2223
use %s;
@@ -45,7 +46,7 @@ public function __get(%s $name)
4546
';
4647

4748
/**
48-
* @param \ReflectionClass $class
49+
* @param \Reflector|\ReflectionClass $class
4950
* @return string
5051
*/
5152
public static function generate(\Reflector $class): string
@@ -56,6 +57,8 @@ public static function generate(\Reflector $class): string
5657
/**
5758
* @param \ReflectionClass $class
5859
* @return string
60+
* @throws \RuntimeException
61+
* @throws InvalidArgumentException
5962
*/
6063
protected static function doGenerate(\ReflectionClass $class): string
6164
{
@@ -82,7 +85,7 @@ protected static function doGenerate(\ReflectionClass $class): string
8285
foreach ($methods as $method) {
8386
if (
8487
!$method->isFinal() &&
85-
!in_array($method->name, self::UNSAFE_METHODS, true)
88+
!\in_array($method->name, self::UNSAFE_METHODS, $strict = true)
8689
) {
8790
$methodsCode[] = MethodTemplate::generate($method);
8891
}
@@ -106,7 +109,7 @@ protected static function doGenerate(\ReflectionClass $class): string
106109
random_int($min = 0, $max = PHP_INT_MAX)
107110
);
108111

109-
list($callNameType, $callArgumentsType) = $callParametersTypes;
112+
[$callNameType, $callArgumentsType] = $callParametersTypes;
110113

111114
return sprintf(
112115
self::TEMPLATE_CLASS,

0 commit comments

Comments
 (0)