feat: upgrade phpunit to 12.5
This commit is contained in:
@@ -17,19 +17,22 @@ use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
class ApiClientReceiveTest extends TestCase
|
||||
{
|
||||
private ApiClient $apiClient;
|
||||
private ?ApiClient $apiClient = null;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->logger = $this->createStub(LoggerInterface::class);
|
||||
}
|
||||
|
||||
$this->apiClient = new ApiClient(
|
||||
$this->createMock(SerializerInterface::class),
|
||||
$this->createMock(ApiResponseParser::class),
|
||||
$this->createMock(FilesystemOperator::class),
|
||||
private function apiClient(): ApiClient
|
||||
{
|
||||
return $this->apiClient ??= new ApiClient(
|
||||
$this->createStub(SerializerInterface::class),
|
||||
$this->createStub(ApiResponseParser::class),
|
||||
$this->createStub(FilesystemOperator::class),
|
||||
$this->logger,
|
||||
$this->createMock(BookingDataProcessor::class),
|
||||
$this->createStub(BookingDataProcessor::class),
|
||||
new RequestStack(),
|
||||
new RequestIdGenerator(),
|
||||
[
|
||||
@@ -43,6 +46,8 @@ class ApiClientReceiveTest extends TestCase
|
||||
|
||||
public function testEmptyResponseThrowsImmediateConnectionCloseException(): void
|
||||
{
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$stream = fopen('php://memory', 'r+');
|
||||
// Write nothing — stream is immediately at EOF
|
||||
rewind($stream);
|
||||
@@ -82,18 +87,18 @@ class ApiClientReceiveTest extends TestCase
|
||||
{
|
||||
$method = new \ReflectionMethod(ApiClient::class, 'receive');
|
||||
|
||||
return $method->invoke($this->apiClient, $socket);
|
||||
return $method->invoke($this->apiClient(), $socket);
|
||||
}
|
||||
|
||||
private function setOperationStartTime(): void
|
||||
{
|
||||
$property = new \ReflectionProperty(ApiClient::class, 'operationStartTime');
|
||||
$property->setValue($this->apiClient, microtime(true));
|
||||
$property->setValue($this->apiClient(), microtime(true));
|
||||
}
|
||||
|
||||
private function setSelectedPort(int $port): void
|
||||
{
|
||||
$property = new \ReflectionProperty(ApiClient::class, 'selectedPort');
|
||||
$property->setValue($this->apiClient, $port);
|
||||
$property->setValue($this->apiClient(), $port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class TravelDataLoaderTest extends TestCase
|
||||
->with('test_file.xml')
|
||||
->willReturn($xmlContent);
|
||||
|
||||
$hotelLoader = $this->createMock(HotelLoader::class);
|
||||
$hotelLoader = $this->createStub(HotelLoader::class);
|
||||
$travelParser = $this->createMock(TravelParser::class);
|
||||
|
||||
$expectedTravel = new Travel();
|
||||
|
||||
@@ -40,8 +40,8 @@ class BookingDataProcessorTest extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
// Create a mock InsuranceManager
|
||||
$insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$insuranceService = $this->createStub(InsuranceManager::class);
|
||||
$priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
|
||||
// Mock getSelectableInsurances to return empty array (not used in these tests)
|
||||
$insuranceService->method('getSelectableInsurances')
|
||||
@@ -851,7 +851,7 @@ class BookingDataProcessorTest extends TestCase
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
$bookingDto->participants = [$applicant, $dependent];
|
||||
|
||||
$insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$insuranceService = $this->createStub(InsuranceManager::class);
|
||||
// Both insurances must already look eligible, otherwise the submit-time
|
||||
// reconciliation step (added for stale-insurance re-validation) would clear
|
||||
// them before propagation even runs - this test is only about propagation.
|
||||
@@ -864,11 +864,11 @@ class BookingDataProcessorTest extends TestCase
|
||||
1 => null,
|
||||
]);
|
||||
|
||||
$priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$priceCalculatorService->method('calculateIndividualParticipantPriceExcludingInsurance')->willReturn(0.0);
|
||||
$priceCalculatorService->method('resolveInsuranceTravelPrice')->willReturn(0.0);
|
||||
|
||||
$payloadBuilder = $this->createMock(BookingPayloadBuilder::class);
|
||||
$payloadBuilder = $this->createStub(BookingPayloadBuilder::class);
|
||||
$payloadBuilder->method('buildCreatePayload')->willReturn([]);
|
||||
|
||||
$processor = new BookingDataProcessor(
|
||||
@@ -911,14 +911,14 @@ class BookingDataProcessorTest extends TestCase
|
||||
$dependent = $formData->participants[1];
|
||||
$dependent->insurance = $dependentInsurance;
|
||||
|
||||
$insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$insuranceService = $this->createStub(InsuranceManager::class);
|
||||
$insuranceService->method('getSelectableInsurances')->willReturn([]);
|
||||
$insuranceService->method('batchAssignInsuranceToParticipants')->willReturn([
|
||||
0 => $familyInsurance,
|
||||
1 => null,
|
||||
]);
|
||||
|
||||
$priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$priceCalculatorService->method('calculateIndividualParticipantPriceExcludingInsurance')->willReturn(0.0);
|
||||
|
||||
$processor = new BookingDataProcessor(
|
||||
@@ -961,18 +961,18 @@ class BookingDataProcessorTest extends TestCase
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
$bookingDto->participants = [$applicant];
|
||||
|
||||
$insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$insuranceService = $this->createStub(InsuranceManager::class);
|
||||
$insuranceService->method('getSelectableInsurances')->willReturn([$staleInsurance, $correctTierInsurance]);
|
||||
// Only the higher tier is eligible at the current (updated) price.
|
||||
$insuranceService->method('getEligibleInsurances')->willReturn([$correctTierInsurance]);
|
||||
$insuranceService->method('reassignInsuranceForPriceChange')->willReturn($correctTierInsurance);
|
||||
$insuranceService->method('batchAssignInsuranceToParticipants')->willReturn([0 => $correctTierInsurance]);
|
||||
|
||||
$priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$priceCalculatorService->method('calculateIndividualParticipantPriceExcludingInsurance')->willReturn(0.0);
|
||||
$priceCalculatorService->method('resolveInsuranceTravelPrice')->willReturn(2600.0);
|
||||
|
||||
$payloadBuilder = $this->createMock(BookingPayloadBuilder::class);
|
||||
$payloadBuilder = $this->createStub(BookingPayloadBuilder::class);
|
||||
$payloadBuilder->method('buildCreatePayload')->willReturn([]);
|
||||
|
||||
$processor = new BookingDataProcessor(
|
||||
@@ -1009,17 +1009,17 @@ class BookingDataProcessorTest extends TestCase
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
$bookingDto->participants = [$applicant];
|
||||
|
||||
$insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$insuranceService = $this->createStub(InsuranceManager::class);
|
||||
$insuranceService->method('getSelectableInsurances')->willReturn([$staleInsurance]);
|
||||
$insuranceService->method('getEligibleInsurances')->willReturn([]);
|
||||
$insuranceService->method('reassignInsuranceForPriceChange')->willReturn(null);
|
||||
$insuranceService->method('batchAssignInsuranceToParticipants')->willReturn([0 => null]);
|
||||
|
||||
$priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$priceCalculatorService->method('calculateIndividualParticipantPriceExcludingInsurance')->willReturn(0.0);
|
||||
$priceCalculatorService->method('resolveInsuranceTravelPrice')->willReturn(9999.0);
|
||||
|
||||
$payloadBuilder = $this->createMock(BookingPayloadBuilder::class);
|
||||
$payloadBuilder = $this->createStub(BookingPayloadBuilder::class);
|
||||
$payloadBuilder->method('buildCreatePayload')->willReturn([]);
|
||||
|
||||
$processor = new BookingDataProcessor(
|
||||
@@ -1056,16 +1056,16 @@ class BookingDataProcessorTest extends TestCase
|
||||
$bookingDto = new BookingDto($this->createMockTravel(), 1);
|
||||
$bookingDto->participants = [$applicant];
|
||||
|
||||
$insuranceService = $this->createMock(InsuranceManager::class);
|
||||
$insuranceService = $this->createStub(InsuranceManager::class);
|
||||
$insuranceService->method('getSelectableInsurances')->willReturn([$insurance]);
|
||||
$insuranceService->method('getEligibleInsurances')->willReturn([$insurance]);
|
||||
$insuranceService->method('batchAssignInsuranceToParticipants')->willReturn([0 => $insurance]);
|
||||
|
||||
$priceCalculatorService = $this->createMock(BookingPriceCalculator::class);
|
||||
$priceCalculatorService = $this->createStub(BookingPriceCalculator::class);
|
||||
$priceCalculatorService->method('calculateIndividualParticipantPriceExcludingInsurance')->willReturn(0.0);
|
||||
$priceCalculatorService->method('resolveInsuranceTravelPrice')->willReturn(500.0);
|
||||
|
||||
$payloadBuilder = $this->createMock(BookingPayloadBuilder::class);
|
||||
$payloadBuilder = $this->createStub(BookingPayloadBuilder::class);
|
||||
$payloadBuilder->method('buildCreatePayload')->willReturn([]);
|
||||
|
||||
$processor = new BookingDataProcessor(
|
||||
|
||||
@@ -15,7 +15,7 @@ class BookingStatusRuleRegistryTest extends TestCase
|
||||
{
|
||||
public function testReturnsDefaultStatusWhenNoRulesMatch(): void
|
||||
{
|
||||
$rule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$rule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$rule->method('evaluate')->willReturn(false);
|
||||
$rule->method('getPriority')->willReturn(100);
|
||||
|
||||
@@ -27,7 +27,7 @@ class BookingStatusRuleRegistryTest extends TestCase
|
||||
|
||||
public function testReturnsMatchingRuleStatus(): void
|
||||
{
|
||||
$rule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$rule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$rule->method('evaluate')->willReturn(true);
|
||||
$rule->method('getStatus')->willReturn('O');
|
||||
$rule->method('getPriority')->willReturn(100);
|
||||
@@ -40,12 +40,12 @@ class BookingStatusRuleRegistryTest extends TestCase
|
||||
|
||||
public function testHigherPriorityRuleTakesPrecedence(): void
|
||||
{
|
||||
$lowPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$lowPriorityRule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$lowPriorityRule->method('evaluate')->willReturn(true);
|
||||
$lowPriorityRule->method('getStatus')->willReturn('L');
|
||||
$lowPriorityRule->method('getPriority')->willReturn(50);
|
||||
|
||||
$highPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$highPriorityRule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$highPriorityRule->method('evaluate')->willReturn(true);
|
||||
$highPriorityRule->method('getStatus')->willReturn('H');
|
||||
$highPriorityRule->method('getPriority')->willReturn(100);
|
||||
@@ -66,12 +66,12 @@ class BookingStatusRuleRegistryTest extends TestCase
|
||||
|
||||
public function testFirstMatchingRuleWinsForSamePriority(): void
|
||||
{
|
||||
$firstMatchingRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$firstMatchingRule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$firstMatchingRule->method('evaluate')->willReturn(true);
|
||||
$firstMatchingRule->method('getStatus')->willReturn('A');
|
||||
$firstMatchingRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$secondMatchingRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$secondMatchingRule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$secondMatchingRule->method('evaluate')->willReturn(true);
|
||||
$secondMatchingRule->method('getStatus')->willReturn('B');
|
||||
$secondMatchingRule->method('getPriority')->willReturn(100);
|
||||
@@ -84,12 +84,12 @@ class BookingStatusRuleRegistryTest extends TestCase
|
||||
|
||||
public function testNonMatchingHighPriorityRuleDoesNotBlockLowerPriority(): void
|
||||
{
|
||||
$highPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$highPriorityRule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$highPriorityRule->method('evaluate')->willReturn(false);
|
||||
$highPriorityRule->method('getStatus')->willReturn('H');
|
||||
$highPriorityRule->method('getPriority')->willReturn(100);
|
||||
|
||||
$lowPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$lowPriorityRule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$lowPriorityRule->method('evaluate')->willReturn(true);
|
||||
$lowPriorityRule->method('getStatus')->willReturn('L');
|
||||
$lowPriorityRule->method('getPriority')->willReturn(50);
|
||||
@@ -102,7 +102,7 @@ class BookingStatusRuleRegistryTest extends TestCase
|
||||
|
||||
public function testSelection1473RuleWinsOverLowerPriorityRule(): void
|
||||
{
|
||||
$lowerPriorityRule = $this->createMock(BookingStatusRuleInterface::class);
|
||||
$lowerPriorityRule = $this->createStub(BookingStatusRuleInterface::class);
|
||||
$lowerPriorityRule->method('evaluate')->willReturn(true);
|
||||
$lowerPriorityRule->method('getStatus')->willReturn('X');
|
||||
$lowerPriorityRule->method('getPriority')->willReturn(100);
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
namespace App\Tests\BusProNet\Utility;
|
||||
|
||||
use App\BusProNet\Utility\DayTimeUtility;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DayTimeUtilityTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider dayTimeProvider
|
||||
*/
|
||||
#[DataProvider('dayTimeProvider')]
|
||||
public function testMapTime(?string $time, ?string $dayTime): void
|
||||
{
|
||||
$utility = new DayTimeUtility();
|
||||
@@ -18,7 +17,7 @@ class DayTimeUtilityTest extends TestCase
|
||||
$this->assertEquals($dayTime, $result);
|
||||
}
|
||||
|
||||
public function dayTimeProvider(): array
|
||||
public static function dayTimeProvider(): array
|
||||
{
|
||||
return [
|
||||
[null, null],
|
||||
|
||||
@@ -7,7 +7,9 @@ namespace App\Tests\BusProNet\XmlLoader;
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\XmlLoader\PickupLoader;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
class PickupLoaderTest extends TestCase
|
||||
{
|
||||
@@ -15,17 +17,21 @@ class PickupLoaderTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->loader = $this->createPartialMock(PickupLoader::class, ['loadById']);
|
||||
$this->loader->method('loadById')->willReturnCallback(function (int $id): Pickup {
|
||||
$pickup = new Pickup();
|
||||
$pickup->id = $id;
|
||||
$pickup->code = 'Z'.$id;
|
||||
$pickup->city = 'City '.$id;
|
||||
$pickup->postalCode = '0000'.$id;
|
||||
$pickup->street = 'Street '.$id;
|
||||
// patchPickupsDetails() is the unit under test; loadById() only has to hand back
|
||||
// a Pickup per id, so a subclass beats a partial mock over the XML/cache stack.
|
||||
$this->loader = new class($this->createStub(CacheInterface::class), $this->createStub(FilesystemOperator::class)) extends PickupLoader {
|
||||
public function loadById(int $id, ?string $filename = 'zustiege.xml'): ?Pickup
|
||||
{
|
||||
$pickup = new Pickup();
|
||||
$pickup->id = $id;
|
||||
$pickup->code = 'Z'.$id;
|
||||
$pickup->city = 'City '.$id;
|
||||
$pickup->postalCode = '0000'.$id;
|
||||
$pickup->street = 'Street '.$id;
|
||||
|
||||
return $pickup;
|
||||
});
|
||||
return $pickup;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public function testDropOffsAreOrderedInReverseOfSortedPickups(): void
|
||||
|
||||
Reference in New Issue
Block a user