Skip to content

Commit 3c77822

Browse files
committed
do not use PHPUnit mock objects without configured expectations
1 parent 344efc1 commit 3c77822

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

Test/CompoundConstraintTestCase.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\ExpectationFailedException;
1515
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\Translation\IdentityTranslator;
1617
use Symfony\Component\Validator\Constraint;
1718
use Symfony\Component\Validator\Constraints\Compound;
1819
use Symfony\Component\Validator\Constraints\CompoundValidator;
@@ -21,7 +22,6 @@
2122
use Symfony\Component\Validator\Context\ExecutionContextInterface;
2223
use Symfony\Component\Validator\Validation;
2324
use Symfony\Component\Validator\Validator\ValidatorInterface;
24-
use Symfony\Contracts\Translation\TranslatorInterface;
2525

2626
/**
2727
* A test case to ease testing Compound Constraints.
@@ -58,10 +58,7 @@ protected function createValidator(): ValidatorInterface
5858

5959
protected function createContext(?ValidatorInterface $validator = null): ExecutionContextInterface
6060
{
61-
$translator = $this->createMock(TranslatorInterface::class);
62-
$translator->expects($this->any())->method('trans')->willReturnArgument(0);
63-
64-
return new ExecutionContext($validator ?? $this->createValidator(), $this->root, $translator);
61+
return new ExecutionContext($validator ?? $this->createValidator(), $this->root, new IdentityTranslator());
6562
}
6663

6764
public function assertViolationsRaisedByCompound(Constraint|array $constraints): void

Tests/Mapping/Loader/PropertyInfoLoaderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function getTypes(string $class, string $property, array $context = []):
111111
}
112112
};
113113

114-
$propertyAccessExtractor = $this->createMock(PropertyAccessExtractorInterface::class);
114+
$propertyAccessExtractor = $this->createStub(PropertyAccessExtractorInterface::class);
115115
$propertyAccessExtractor
116116
->method('isWritable')
117117
->willReturn(
@@ -247,7 +247,7 @@ public function getTypes(string $class, string $property, array $context = []):
247247
}
248248
};
249249

250-
$propertyAccessExtractor = $this->createMock(PropertyAccessExtractorInterface::class);
250+
$propertyAccessExtractor = $this->createStub(PropertyAccessExtractorInterface::class);
251251

252252
$propertyInfoLoader = new PropertyInfoLoader($propertyListExtractor, $propertyTypeExtractor, $propertyAccessExtractor, $classValidatorRegexp);
253253

@@ -287,7 +287,7 @@ public function getTypes(string $class, string $property, array $context = []):
287287
};
288288
}
289289

290-
$propertyAccessExtractor = $this->createMock(PropertyAccessExtractorInterface::class);
290+
$propertyAccessExtractor = $this->createStub(PropertyAccessExtractorInterface::class);
291291

292292
$propertyInfoLoader = new PropertyInfoLoader($propertyListExtractor, $propertyTypeExtractor, $propertyAccessExtractor, '{.*}');
293293
$validator = Validation::createValidatorBuilder()

0 commit comments

Comments
 (0)