Skip to content

Commit 63c709a

Browse files
Upgrade PHPUnit, switch to GitHub actions
1 parent 65868c8 commit 63c709a

16 files changed

+121
-83
lines changed

.github/workflows/code_analysis.yaml

+34
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

+2-1
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

+13-12
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
}
@@ -114,7 +115,7 @@ public function testFailsWhenResultOfExpressionIsNotAnObjectOfTheExpectedClass()
114115

115116
$validator = new ArgumentValidator($containerBuilder, $this->createMockResultingClassResolver(), true);
116117

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

119120
$validator->validate($parameter, $argument);
120121
}
@@ -130,7 +131,7 @@ public function testFailsWhenResultOfExpressionIsNotAnObject()
130131

131132
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver(), true);
132133

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

135136
$validator->validate($parameter, $argument);
136137
}
@@ -164,7 +165,7 @@ public function testFailsIfSyntaxOfExpressionIsInvalid()
164165

165166
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver());
166167

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

169170
$validator->validate($parameter, $argument);
170171
}
@@ -180,7 +181,7 @@ public function testFailsIfExpressionCouldNotBeEvaluated()
180181

181182
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver(), true);
182183

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

185186
$validator->validate($parameter, $argument);
186187
}
@@ -231,14 +232,14 @@ public function testFailsIfContainerReferenceArgumentIsInjectedForParameterWithI
231232
->willReturn('Symfony\Component\DependencyInjection\Container');
232233
$validator = new ArgumentValidator(new ContainerBuilder(), $classResolver);
233234

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

236237
$validator->validate($parameter, $argument);
237238
}
238239

239240
private function createMockResultingClassResolver()
240241
{
241-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\ResultingClassResolverInterface');
242+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\ResultingClassResolverInterface');
242243
}
243244

244245
private function skipTestIfExpressionsAreNotAvailable()

Tests/ArgumentsValidatorTest.php

+4-3
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

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use Matthias\SymfonyServiceDefinitionValidator\BatchServiceDefinitionValidator;
66
use Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\InvalidServiceDefinitionException;
7+
use PHPUnit\Framework\TestCase;
78

8-
class BatchServiceDefinitionValidatorTest extends \PHPUnit_Framework_TestCase
9+
class BatchServiceDefinitionValidatorTest extends TestCase
910
{
1011
public function testCreatesErrorListAndTransformsValidationExceptionIntoErrors()
1112
{
@@ -60,12 +61,12 @@ public function testCreatesErrorListAndTransformsValidationExceptionIntoErrors()
6061

6162
private function createMockErrorFactory()
6263
{
63-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorFactoryInterface');
64+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorFactoryInterface');
6465
}
6566

6667
private function createMockErrorList()
6768
{
68-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\Tests\Error\ValidationErrorListInterface');
69+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\Tests\Error\ValidationErrorListInterface');
6970
}
7071

7172
private function createMockDefinition()
@@ -78,7 +79,7 @@ private function createMockDefinition()
7879

7980
private function createMockValidator()
8081
{
81-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\ServiceDefinitionValidatorInterface');
82+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\ServiceDefinitionValidatorInterface');
8283
}
8384

8485
private function createException()
@@ -88,6 +89,6 @@ private function createException()
8889

8990
private function createMockError()
9091
{
91-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorInterface');
92+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorInterface');
9293
}
9394
}

Tests/ConstructorResolverTest.php

+6-5
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

+4-3
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

+3-2
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

+3-4
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
}

Tests/Error/ValidationErrorListTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace Matthias\SymfonyServiceDefinitionValidator\Tests\Error;
44

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

7-
class ValidationErrorListTest extends \PHPUnit_Framework_TestCase
8+
class ValidationErrorListTest extends TestCase
89
{
910
public function testAddsErrorToList()
1011
{
@@ -24,6 +25,6 @@ public function testAddsErrorToList()
2425

2526
private function createMockError()
2627
{
27-
return $this->getMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorInterface');
28+
return $this->createMock('Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorInterface');
2829
}
2930
}

Tests/Error/ValidationErrorTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace Matthias\SymfonyServiceDefinitionValidator\Tests\Error;
44

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

7-
class ValidationErrorTest extends \PHPUnit_Framework_TestCase
8+
class ValidationErrorTest extends TestCase
89
{
910
public function testConstructor()
1011
{
@@ -29,8 +30,6 @@ private function createMockDefinition()
2930

3031
private function createMockException()
3132
{
32-
return $this
33-
->getMockBuilder('\Exception')
34-
->getMock();
33+
return $this->createMock('\Exception');
3534
}
3635
}

0 commit comments

Comments
 (0)