Merge branch 'rector/rules-up-to-php82' into rector/rules-symfony

This commit is contained in:
2023-07-19 23:22:57 +02:00
577 changed files with 18339 additions and 2168 deletions

View File

@@ -0,0 +1,176 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Tests\RemoteCalendar\Connector\MSGraph;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MapCalendarToUser;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MSUserAbsenceReader;
use Chill\MainBundle\Entity\User;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Clock\MockClock;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
/**
* @internal
* @coversNothing
*/
class MSUserAbsenceReaderTest extends TestCase
{
use ProphecyTrait;
/**
* @dataProvider provideDataTestUserAbsence
*/
public function testUserAbsenceReader(string $mockResponse, bool $expected, string $message): void
{
$user = new User();
$client = new MockHttpClient([new MockResponse($mockResponse)]);
$mapUser = $this->prophesize(MapCalendarToUser::class);
$mapUser->getUserId($user)->willReturn('1234');
$clock = new MockClock(new \DateTimeImmutable('2023-07-07T12:00:00'));
$absenceReader = new MSUserAbsenceReader($client, $mapUser->reveal(), $clock);
self::assertEquals($expected, $absenceReader->isUserAbsent($user), $message);
}
public function testIsUserAbsentWithoutRemoteId(): void
{
$user = new User();
$client = new MockHttpClient();
$mapUser = $this->prophesize(MapCalendarToUser::class);
$mapUser->getUserId($user)->willReturn(null);
$clock = new MockClock(new \DateTimeImmutable('2023-07-07T12:00:00'));
$absenceReader = new MSUserAbsenceReader($client, $mapUser->reveal(), $clock);
self::assertNull($absenceReader->isUserAbsent($user), "when no user found, absence should be null");
}
public function provideDataTestUserAbsence(): iterable
{
// contains data that was retrieved from microsoft graph api on 2023-07-06
yield [
<<<'JSON'
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4feb0ae3-7ffb-48dd-891e-c86b2cdeefd4')/mailboxSettings/automaticRepliesSetting",
"status": "disabled",
"externalAudience": "none",
"internalReplyMessage": "Je suis en congé.",
"externalReplyMessage": "",
"scheduledStartDateTime": {
"dateTime": "2023-07-06T12:00:00.0000000",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": "2023-07-07T12:00:00.0000000",
"timeZone": "UTC"
}
}
JSON,
false,
"User is present"
];
yield [
<<<'JSON'
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4feb0ae3-7ffb-48dd-891e-c86b2cdeefd4')/mailboxSettings/automaticRepliesSetting",
"status": "scheduled",
"externalAudience": "none",
"internalReplyMessage": "Je suis en congé.",
"externalReplyMessage": "",
"scheduledStartDateTime": {
"dateTime": "2023-07-06T11:00:00.0000000",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": "2023-07-21T11:00:00.0000000",
"timeZone": "UTC"
}
}
JSON,
true,
'User is absent with absence scheduled, we are within this period'
];
yield [
<<<'JSON'
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4feb0ae3-7ffb-48dd-891e-c86b2cdeefd4')/mailboxSettings/automaticRepliesSetting",
"status": "scheduled",
"externalAudience": "none",
"internalReplyMessage": "Je suis en congé.",
"externalReplyMessage": "",
"scheduledStartDateTime": {
"dateTime": "2023-07-08T11:00:00.0000000",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": "2023-07-21T11:00:00.0000000",
"timeZone": "UTC"
}
}
JSON,
false,
'User is present: absence is scheduled for later'
];
yield [
<<<'JSON'
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4feb0ae3-7ffb-48dd-891e-c86b2cdeefd4')/mailboxSettings/automaticRepliesSetting",
"status": "scheduled",
"externalAudience": "none",
"internalReplyMessage": "Je suis en congé.",
"externalReplyMessage": "",
"scheduledStartDateTime": {
"dateTime": "2023-07-05T11:00:00.0000000",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": "2023-07-06T11:00:00.0000000",
"timeZone": "UTC"
}
}
JSON,
false,
'User is present: absence is past'
];
yield [
<<<'JSON'
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4feb0ae3-7ffb-48dd-891e-c86b2cdeefd4')/mailboxSettings/automaticRepliesSetting",
"status": "alwaysEnabled",
"externalAudience": "none",
"internalReplyMessage": "Je suis en congé.",
"externalReplyMessage": "",
"scheduledStartDateTime": {
"dateTime": "2023-07-06T12:00:00.0000000",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": "2023-07-07T12:00:00.0000000",
"timeZone": "UTC"
}
}
JSON,
true,
"User is absent: absence is always enabled"
];
}
}

View File

@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Tests\RemoteCalendar\Connector\MSGraph;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MSUserAbsenceReader;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MSUserAbsenceReaderInterface;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MSUserAbsenceSync;
use Chill\MainBundle\Entity\User;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\NullLogger;
use Symfony\Component\Clock\MockClock;
/**
* @internal
* @coversNothing
*/
class MSUserAbsenceSyncTest extends TestCase
{
use ProphecyTrait;
/**
* @dataProvider provideDataTestSyncUserAbsence
*/
public function testSyncUserAbsence(User $user, ?bool $absenceFromMicrosoft, bool $expectedAbsence, ?\DateTimeImmutable $expectedAbsenceStart, string $message): void
{
$userAbsenceReader = $this->prophesize(MSUserAbsenceReaderInterface::class);
$userAbsenceReader->isUserAbsent($user)->willReturn($absenceFromMicrosoft);
$clock = new MockClock(new \DateTimeImmutable('2023-07-01T12:00:00'));
$syncer = new MSUserAbsenceSync($userAbsenceReader->reveal(), $clock, new NullLogger());
$syncer->syncUserAbsence($user);
self::assertEquals($expectedAbsence, $user->isAbsent(), $message);
self::assertEquals($expectedAbsenceStart, $user->getAbsenceStart(), $message);
}
public function provideDataTestSyncUserAbsence(): iterable
{
yield [new User(), false, false, null, "user present remains present"];
yield [new User(), true, true, new \DateTimeImmutable('2023-07-01T12:00:00'), "user present becomes absent"];
$user = new User();
$user->setAbsenceStart($abs = new \DateTimeImmutable("2023-07-01T12:00:00"));
yield [$user, true, true, $abs, "user absent remains absent"];
$user = new User();
$user->setAbsenceStart($abs = new \DateTimeImmutable("2023-07-01T12:00:00"));
yield [$user, false, false, null, "user absent becomes present"];
yield [new User(), null, false, null, "user not syncable: presence do not change"];
$user = new User();
$user->setAbsenceStart($abs = new \DateTimeImmutable("2023-07-01T12:00:00"));
yield [$user, null, true, $abs, "user not syncable: absence do not change"];
}
}