Skip to content

Commit 163d732

Browse files
Merge pull request #50 from matthiasnoback/modernize
Modernize the codebase before working on it
2 parents 65868c8 + ab26d6b commit 163d732

16 files changed

+146
-94
lines changed

.github/workflows/code_analysis.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Code Analysis
2+
3+
on:
4+
pull_request: null
5+
push: null
6+
7+
jobs:
8+
code_analysis:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
actions:
13+
-
14+
name: "Composer validate"
15+
run: composer validate
16+
17+
-
18+
name: "PHPUnit"
19+
run: vendor/bin/phpunit --color
20+
21+
name: ${{ matrix.actions.name }}
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: 7.4
30+
coverage: none
31+
32+
- uses: "ramsey/composer-install@v1"
33+
34+
- run: ${{ matrix.actions.run }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
composer.lock
22
phpunit.xml
3-
vendor
3+
vendor
4+
.phpunit.result.cache

Tests/ArgumentValidatorTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44

55
use Matthias\SymfonyServiceDefinitionValidator\ArgumentValidator;
66
use Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException;
7+
use PHPUnit\Framework\TestCase;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
89
use Symfony\Component\DependencyInjection\Definition;
910
use Symfony\Component\DependencyInjection\Reference;
1011
use Symfony\Component\ExpressionLanguage\Expression;
1112

12-
class ArgumentValidatorTest extends \PHPUnit_Framework_TestCase
13+
class ArgumentValidatorTest extends TestCase
1314
{
1415
private $containerBuilder;
1516

16-
protected function setUp()
17+
protected function setUp(): void
1718
{
1819
$this->containerBuilder = new ContainerBuilder();
1920
}
@@ -24,7 +25,7 @@ public function testFailsWhenParameterHasTypeHintButNoReferenceOrDefinitionWasPr
2425

2526
$validator = new ArgumentValidator($this->containerBuilder, $this->createMockResultingClassResolver());
2627

27-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'reference');
28+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'reference');
2829
$validator->validate(new \ReflectionParameter(array($class, '__construct'), 'expected'), new \stdClass());
2930
}
3031

@@ -43,7 +44,7 @@ public function testFailsWhenParameterHasTypeHintForObjectButArgumentIsDefinitio
4344
->will($this->returnValue('Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\WrongClass'));
4445
$validator = new ArgumentValidator($this->containerBuilder, $resultingClassResolver);
4546

46-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
47+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
4748
$validator->validate(new \ReflectionParameter(array($class, '__construct'), 'expected'), $inlineDefinition);
4849
}
4950

@@ -65,7 +66,7 @@ public function testFailsWhenParameterHasTypeHintForObjectButArgumentIsReference
6566
->will($this->returnValue('stdClass'));
6667
$validator = new ArgumentValidator($this->containerBuilder, $resultingClassResolver);
6768

68-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
69+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
6970

7071
$validator->validate($parameter, $argument);
7172
}
@@ -79,7 +80,7 @@ public function testFailsWhenParameterHasArrayTypeHintButArgumentIsNotArray()
7980

8081
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver());
8182

82-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'array');
83+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'array');
8384

8485
$validator->validate($parameter, $argument);
8586
}
@@ -95,6 +96,7 @@ public function testFailsWhenOptionalParameterHasArrayTypeHintAndResultOfExpress
9596

9697
try {
9798
$validator->validate($parameter, $argument);
99+
$this->addToAssertionCount(1);
98100
} catch (TypeHintMismatchException $exception) {
99101
$this->fail('null argument should be allowed');
100102
}
@@ -114,7 +116,7 @@ public function testFailsWhenResultOfExpressionIsNotAnObjectOfTheExpectedClass()
114116

115117
$validator = new ArgumentValidator($containerBuilder, $this->createMockResultingClassResolver(), true);
116118

117-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
119+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
118120

119121
$validator->validate($parameter, $argument);
120122
}
@@ -130,7 +132,7 @@ public function testFailsWhenResultOfExpressionIsNotAnObject()
130132

131133
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver(), true);
132134

133-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
135+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
134136

135137
$validator->validate($parameter, $argument);
136138
}
@@ -148,6 +150,7 @@ public function testFailsWhenResultOfExpressionIsNullButNullIsNotAllowed()
148150

149151
try {
150152
$validator->validate($parameter, $argument);
153+
$this->addToAssertionCount(1);
151154
} catch (TypeHintMismatchException $exception) {
152155
$this->fail('null argument should be allowed');
153156
}
@@ -164,7 +167,7 @@ public function testFailsIfSyntaxOfExpressionIsInvalid()
164167

165168
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver());
166169

167-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\InvalidExpressionSyntaxException');
170+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\InvalidExpressionSyntaxException');
168171

169172
$validator->validate($parameter, $argument);
170173
}
@@ -180,7 +183,7 @@ public function testFailsIfExpressionCouldNotBeEvaluated()
180183

181184
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver(), true);
182185

183-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\InvalidExpressionException');
186+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\InvalidExpressionException');
184187

185188
$validator->validate($parameter, $argument);
186189
}
@@ -195,6 +198,7 @@ public function testContainerReferenceArgumentDoesNotFail()
195198
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver());
196199

197200
$validator->validate($parameter, $argument);
201+
$this->addToAssertionCount(1);
198202
}
199203

200204
public function testPassesWhenArgumentIsClassAlias()
@@ -231,14 +235,14 @@ public function testFailsIfContainerReferenceArgumentIsInjectedForParameterWithI
231235
->willReturn('Symfony\Component\DependencyInjection\Container');
232236
$validator = new ArgumentValidator(new ContainerBuilder(), $classResolver);
233237

234-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
238+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\TypeHintMismatchException', 'ExpectedClass');
235239

236240
$validator->validate($parameter, $argument);
237241
}
238242

239243
private function createMockResultingClassResolver()
240244
{
241-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\ResultingClassResolverInterface');
245+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\ResultingClassResolverInterface');
242246
}
243247

244248
private function skipTestIfExpressionsAreNotAvailable()

Tests/ArgumentsValidatorTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace Matthias\SymfonyServiceDefinitionValidator\Tests;
44

55
use Matthias\SymfonyServiceDefinitionValidator\ArgumentsValidator;
6+
use PHPUnit\Framework\TestCase;
67
use Symfony\Component\DependencyInjection\ContainerBuilder;
78

8-
class ArgumentsValidatorTest extends \PHPUnit_Framework_TestCase
9+
class ArgumentsValidatorTest extends TestCase
910
{
1011
/**
1112
* @test
@@ -16,13 +17,13 @@ public function ifRequiredArgumentIsMissingFails()
1617
$class = 'Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\ClassWithRequiredConstructorArguments';
1718
$method = new \ReflectionMethod($class, '__construct');
1819

19-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\MissingRequiredArgumentException');
20+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\MissingRequiredArgumentException');
2021

2122
$validator->validate($method, array('argument1'));
2223
}
2324

2425
private function createMockArgumentValidator()
2526
{
26-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\ArgumentValidatorInterface');
27+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\ArgumentValidatorInterface');
2728
}
2829
}

Tests/BatchServiceDefinitionValidatorTest.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Matthias\SymfonyServiceDefinitionValidator\BatchServiceDefinitionValidator;
66
use Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\InvalidServiceDefinitionException;
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\DependencyInjection\Definition;
79

8-
class BatchServiceDefinitionValidatorTest extends \PHPUnit_Framework_TestCase
10+
class BatchServiceDefinitionValidatorTest extends TestCase
911
{
1012
public function testCreatesErrorListAndTransformsValidationExceptionIntoErrors()
1113
{
@@ -33,24 +35,21 @@ public function testCreatesErrorListAndTransformsValidationExceptionIntoErrors()
3335

3436
$exception = $this->createException();
3537

36-
37-
3838
$errorFactory
3939
->expects($this->once())
4040
->method('createValidationError')
4141
->with('bad_service', $badDefinition, $exception)
4242
->will($this->returnValue($error));
4343

4444
$validator = $this->createMockValidator();
45-
$validator
46-
->expects($this->at(0))
47-
->method('validate')
48-
->with($goodDefinition);
49-
$validator
50-
->expects($this->at(1))
51-
->method('validate')
52-
->with($badDefinition)
53-
->will($this->throwException($exception));
45+
$validator->method('validate')
46+
->willReturnCallback(
47+
function (Definition $definition) use ($exception, &$badDefinition) {
48+
if ($definition === $badDefinition) {
49+
throw $exception;
50+
}
51+
}
52+
);
5453

5554
$batchValidator = new BatchServiceDefinitionValidator($validator, $errorFactory);
5655
$result = $batchValidator->validate($definitions);
@@ -60,12 +59,12 @@ public function testCreatesErrorListAndTransformsValidationExceptionIntoErrors()
6059

6160
private function createMockErrorFactory()
6261
{
63-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorFactoryInterface');
62+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorFactoryInterface');
6463
}
6564

6665
private function createMockErrorList()
6766
{
68-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\Tests\Error\ValidationErrorListInterface');
67+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\Tests\Error\ValidationErrorListInterface');
6968
}
7069

7170
private function createMockDefinition()
@@ -78,7 +77,7 @@ private function createMockDefinition()
7877

7978
private function createMockValidator()
8079
{
81-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\ServiceDefinitionValidatorInterface');
80+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\ServiceDefinitionValidatorInterface');
8281
}
8382

8483
private function createException()
@@ -88,6 +87,6 @@ private function createException()
8887

8988
private function createMockError()
9089
{
91-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorInterface');
90+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorInterface');
9291
}
9392
}

Tests/ConstructorResolverTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
use Matthias\SymfonyServiceDefinitionValidator\ConstructorResolver;
66
use Matthias\SymfonyServiceDefinitionValidator\ResultingClassResolver;
7+
use PHPUnit\Framework\TestCase;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
89
use Symfony\Component\DependencyInjection\Definition;
910
use Symfony\Component\DependencyInjection\Reference;
1011

11-
class ConstructorResolverTest extends \PHPUnit_Framework_TestCase
12+
class ConstructorResolverTest extends TestCase
1213
{
1314
/**
1415
* @test
@@ -50,7 +51,7 @@ public function ifConstructorIsNotPublicItFails()
5051
// ClassWithNonPublicConstructor has a non-public constructor
5152
$definition = new Definition('Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\ClassWithNonPublicConstructor');
5253

53-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\NonPublicConstructorException');
54+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\NonPublicConstructorException');
5455
$this->assertSame(null, $resolver->resolve($definition));
5556
}
5657

@@ -141,7 +142,7 @@ public function ifFactoryClassDoesNotExistFails(Definition $definition)
141142
$containerBuilder = new ContainerBuilder();
142143
$resolver = new ConstructorResolver($containerBuilder, new ResultingClassResolver($containerBuilder));
143144

144-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\ClassNotFoundException');
145+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\ClassNotFoundException');
145146
$resolver->resolve($definition);
146147
}
147148

@@ -179,7 +180,7 @@ public function ifFactoryMethodIsNotStaticItFails(Definition $definition)
179180
$containerBuilder = new ContainerBuilder();
180181
$resolver = new ConstructorResolver($containerBuilder, new ResultingClassResolver($containerBuilder));
181182

182-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\NonStaticFactoryMethodException');
183+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\NonStaticFactoryMethodException');
183184
$resolver->resolve($definition);
184185
}
185186

@@ -241,7 +242,7 @@ public function ifFactoryFunctionDoesNotExistFails()
241242
$definition = new Definition();
242243
$definition->setFactory('NotExistingFactoryCallback');
243244

244-
$this->setExpectedException('Matthias\SymfonyServiceDefinitionValidator\Exception\FunctionNotFoundException');
245+
$this->expectException('Matthias\SymfonyServiceDefinitionValidator\Exception\FunctionNotFoundException');
245246
$resolver->resolve($definition);
246247
}
247248
}

Tests/DefinitionArgumentsValidatorTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace Matthias\SymfonyServiceDefinitionValidator\Tests;
44

55
use Matthias\SymfonyServiceDefinitionValidator\DefinitionArgumentsValidator;
6+
use PHPUnit\Framework\TestCase;
67
use Symfony\Component\DependencyInjection\Definition;
78

8-
class DefinitionArgumentsValidatorTest extends \PHPUnit_Framework_TestCase
9+
class DefinitionArgumentsValidatorTest extends TestCase
910
{
1011
/**
1112
* @test
@@ -128,11 +129,11 @@ public function itConvertsAnAssociativeArrayOfArgumentsToANumericallyIndexedOrde
128129

129130
private function createMockConstructorResolver()
130131
{
131-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\ConstructorResolverInterface');
132+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\ConstructorResolverInterface');
132133
}
133134

134135
private function createMockArgumentsValidator()
135136
{
136-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\ArgumentsValidatorInterface');
137+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\ArgumentsValidatorInterface');
137138
}
138139
}

Tests/Error/Printer/SimpleErrorListPrinterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use Matthias\SymfonyServiceDefinitionValidator\Error\Printer\SimpleErrorListPrinter;
66
use Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorList;
7+
use PHPUnit\Framework\TestCase;
78

8-
class SimpleErrorListPrinterTest extends \PHPUnit_Framework_TestCase
9+
class SimpleErrorListPrinterTest extends TestCase
910
{
1011
public function testPrintsErrorMessageInAList()
1112
{
@@ -34,7 +35,7 @@ public function testPrintsErrorMessageInAList()
3435

3536
private function createMockError($serviceId, \Exception $exception)
3637
{
37-
$error = $this->getMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorInterface');
38+
$error = $this->createMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorInterface');
3839

3940
$error
4041
->expects($this->any())

Tests/Error/ValidationErrorFactoryTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace Matthias\SymfonyServiceDefinitionValidator\Tests\Error;
44

55
use Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorFactory;
6+
use PHPUnit\Framework\TestCase;
67

7-
class ValidationErrorFactoryTest extends \PHPUnit_Framework_TestCase
8+
class ValidationErrorFactoryTest extends TestCase
89
{
910
public function testCreatesValidationError()
1011
{
@@ -42,8 +43,6 @@ private function createMockDefinition()
4243

4344
private function createMockException()
4445
{
45-
return $this
46-
->getMockBuilder('\Exception')
47-
->getMock();
46+
return $this->createMock('\Exception');
4847
}
4948
}

0 commit comments

Comments
 (0)