Skip to content

Commit ab26d6b

Browse files
Get rid of warnings and risky tests
1 parent 63c709a commit ab26d6b

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

Tests/ArgumentValidatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function testFailsWhenOptionalParameterHasArrayTypeHintAndResultOfExpress
9696

9797
try {
9898
$validator->validate($parameter, $argument);
99+
$this->addToAssertionCount(1);
99100
} catch (TypeHintMismatchException $exception) {
100101
$this->fail('null argument should be allowed');
101102
}
@@ -149,6 +150,7 @@ public function testFailsWhenResultOfExpressionIsNullButNullIsNotAllowed()
149150

150151
try {
151152
$validator->validate($parameter, $argument);
153+
$this->addToAssertionCount(1);
152154
} catch (TypeHintMismatchException $exception) {
153155
$this->fail('null argument should be allowed');
154156
}
@@ -196,6 +198,7 @@ public function testContainerReferenceArgumentDoesNotFail()
196198
$validator = new ArgumentValidator(new ContainerBuilder(), $this->createMockResultingClassResolver());
197199

198200
$validator->validate($parameter, $argument);
201+
$this->addToAssertionCount(1);
199202
}
200203

201204
public function testPassesWhenArgumentIsClassAlias()

Tests/BatchServiceDefinitionValidatorTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Matthias\SymfonyServiceDefinitionValidator\BatchServiceDefinitionValidator;
66
use Matthias\SymfonyServiceDefinitionValidator\Tests\Fixtures\InvalidServiceDefinitionException;
77
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\DependencyInjection\Definition;
89

910
class BatchServiceDefinitionValidatorTest extends TestCase
1011
{
@@ -34,24 +35,21 @@ public function testCreatesErrorListAndTransformsValidationExceptionIntoErrors()
3435

3536
$exception = $this->createException();
3637

37-
38-
3938
$errorFactory
4039
->expects($this->once())
4140
->method('createValidationError')
4241
->with('bad_service', $badDefinition, $exception)
4342
->will($this->returnValue($error));
4443

4544
$validator = $this->createMockValidator();
46-
$validator
47-
->expects($this->at(0))
48-
->method('validate')
49-
->with($goodDefinition);
50-
$validator
51-
->expects($this->at(1))
52-
->method('validate')
53-
->with($badDefinition)
54-
->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+
);
5553

5654
$batchValidator = new BatchServiceDefinitionValidator($validator, $errorFactory);
5755
$result = $batchValidator->validate($definitions);

Tests/Functional/FunctionalTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function testIfTheServiceDefinitionsAreCorrectTheContainerWillBeCompiled(
4848
}
4949

5050
$this->container->compile();
51+
52+
$this->addToAssertionCount(1);
5153
}
5254

5355
public function testIfAServiceDefinitionWithAnExpressionArgumentIsCorrectTheContainerWillBeCompiled()
@@ -62,6 +64,8 @@ public function testIfAServiceDefinitionWithAnExpressionArgumentIsCorrectTheCont
6264
$loader->load('service_definition_with_expression.xml');
6365

6466
$this->container->compile();
67+
68+
$this->addToAssertionCount(1);
6569
}
6670

6771
public function testIfAServiceDefinitionWithAFactoryIsCorrectTheContainerWillBeCompiled()
@@ -74,6 +78,8 @@ public function testIfAServiceDefinitionWithAFactoryIsCorrectTheContainerWillBeC
7478
$loader->load('service_definition_with_factory.xml');
7579

7680
$this->container->compile();
81+
82+
$this->addToAssertionCount(1);
7783
}
7884

7985
public function testIfAServiceDefinitionIsNotCorrectAnExceptionWillBeThrown()

Tests/ServiceDefinitionValidatorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function testResolvesClassWithParameterName()
4141
);
4242

4343
$validator->validate($definition);
44+
45+
$this->addToAssertionCount(1);
4446
}
4547

4648
public function testSyntheticDefinitionCanHaveNoClass()
@@ -56,6 +58,7 @@ public function testSyntheticDefinitionCanHaveNoClass()
5658

5759
try {
5860
$validator->validate($definition);
61+
$this->addToAssertionCount(1);
5962
} catch (DefinitionHasNoClassException $e) {
6063
$this->fail('Synthetic definitions should be allowed to have no class');
6164
}
@@ -74,6 +77,7 @@ public function testAbstractDefinitionCanHaveNoClass()
7477

7578
try {
7679
$validator->validate($definition);
80+
$this->addToAssertionCount(1);
7781
} catch (DefinitionHasNoClassException $e) {
7882
$this->fail('Abstract definitions should be allowed to have no class');
7983
}
@@ -90,6 +94,7 @@ public function testDefinedClassCanBeInterface()
9094
try {
9195
// The choice for Serializable is arbitrary, any PHP interface would do
9296
$validator->validate(new Definition('Serializable'));
97+
$this->addToAssertionCount(1);
9398
} catch (ClassNotFoundException $e) {
9499
$this->fail('Definition should be allowed to have an interface as class');
95100
}
@@ -251,6 +256,8 @@ public function factoryCanBeProvidedByServiceDefinition()
251256
);
252257

253258
$validator->validate($definition);
259+
260+
$this->addToAssertionCount(1);
254261
}
255262

256263
/**

0 commit comments

Comments
 (0)