apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -13,15 +13,14 @@ namespace Chill\CalendarBundle\Tests\Controller;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use function random_int;
/**
* @internal
*
* @coversNothing
*/
final class CalendarControllerTest extends WebTestCase
@@ -75,7 +74,7 @@ final class CalendarControllerTest extends WebTestCase
->join('ac.scopes', 's')
->andWhere('JSON_EXTRACT(s.name,\'fr\') LIKE :s')
->setParameter('s', 'social')
->setFirstResult(random_int(0, $nb - 1))
->setFirstResult(\random_int(0, $nb - 1))
->setMaxResults(1)
->getQuery()
->getSingleScalarResult(),

View File

@@ -23,6 +23,7 @@ use Symfony\Component\Messenger\Transport\InMemoryTransport;
/**
* @internal
*
* @coversNothing
*/
final class RemoteCalendarMSGraphSyncControllerTest extends WebTestCase

View File

@@ -18,6 +18,7 @@ use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
final class CalendarDocTest extends TestCase

View File

@@ -24,6 +24,7 @@ use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
final class CalendarTest extends TestCase

View File

@@ -25,6 +25,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class AgentAggregatorTest extends AbstractAggregatorTest
@@ -59,7 +60,7 @@ final class AgentAggregatorTest extends AbstractAggregatorTest
return [
$em->createQueryBuilder()
->select('count(cal.id)')
->from(Calendar::class, 'cal')
->from(Calendar::class, 'cal'),
];
}
}

View File

@@ -25,6 +25,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class CancelReasonAggregatorTest extends AbstractAggregatorTest
@@ -59,7 +60,7 @@ final class CancelReasonAggregatorTest extends AbstractAggregatorTest
return [
$em->createQueryBuilder()
->select('count(cal.id)')
->from(Calendar::class, 'cal')
->from(Calendar::class, 'cal'),
];
}
}

View File

@@ -25,6 +25,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class JobAggregatorTest extends AbstractAggregatorTest
@@ -46,7 +47,7 @@ final class JobAggregatorTest extends AbstractAggregatorTest
public function getFormData(): array
{
return [
[]
[],
];
}
@@ -59,7 +60,7 @@ final class JobAggregatorTest extends AbstractAggregatorTest
return [
$em->createQueryBuilder()
->select('count(cal.id)')
->from(Calendar::class, 'cal')
->from(Calendar::class, 'cal'),
];
}
}

View File

@@ -25,6 +25,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class LocationAggregatorTest extends AbstractAggregatorTest
@@ -59,7 +60,7 @@ final class LocationAggregatorTest extends AbstractAggregatorTest
return [
$em->createQueryBuilder()
->select('count(cal.id)')
->from(Calendar::class, 'cal')
->from(Calendar::class, 'cal'),
];
}
}

View File

@@ -25,6 +25,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class LocationTypeAggregatorTest extends AbstractAggregatorTest
@@ -59,7 +60,7 @@ final class LocationTypeAggregatorTest extends AbstractAggregatorTest
return [
$em->createQueryBuilder()
->select('count(cal.id)')
->from(Calendar::class, 'cal')
->from(Calendar::class, 'cal'),
];
}
}

View File

@@ -25,6 +25,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class MonthYearAggregatorTest extends AbstractAggregatorTest

View File

@@ -25,6 +25,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class ScopeAggregatorTest extends AbstractAggregatorTest
@@ -59,7 +60,7 @@ final class ScopeAggregatorTest extends AbstractAggregatorTest
return [
$em->createQueryBuilder()
->select('count(cal.id)')
->from(Calendar::class, 'cal')
->from(Calendar::class, 'cal'),
];
}
}

View File

@@ -26,6 +26,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class AgentFilterTest extends AbstractFilterTest
@@ -78,10 +79,9 @@ final class AgentFilterTest extends AbstractFilterTest
$em = self::$container->get(EntityManagerInterface::class);
yield
$em->createQueryBuilder()
->select('cal.id')
->from(Calendar::class, 'cal')
yield $em->createQueryBuilder()
->select('cal.id')
->from(Calendar::class, 'cal')
;
self::ensureKernelShutdown();

View File

@@ -22,11 +22,11 @@ use Chill\CalendarBundle\Entity\Calendar;
use Chill\CalendarBundle\Export\Filter\BetweenDatesFilter;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class BetweenDatesFilterTest extends AbstractFilterTest

View File

@@ -27,6 +27,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class JobFilterTest extends AbstractFilterTest
@@ -65,8 +66,8 @@ final class JobFilterTest extends AbstractFilterTest
return [
[
'job' => new ArrayCollection($array)
]
'job' => new ArrayCollection($array),
],
];
}
@@ -79,7 +80,7 @@ final class JobFilterTest extends AbstractFilterTest
return [
$em->createQueryBuilder()
->select('cal.id')
->from(Calendar::class, 'cal')
->from(Calendar::class, 'cal'),
];
}
}

View File

@@ -27,6 +27,7 @@ use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class ScopeFilterTest extends AbstractFilterTest
@@ -65,8 +66,8 @@ final class ScopeFilterTest extends AbstractFilterTest
return [
[
'scope' => new ArrayCollection($array)
]
'scope' => new ArrayCollection($array),
],
];
}
@@ -79,7 +80,7 @@ final class ScopeFilterTest extends AbstractFilterTest
return [
$em->createQueryBuilder()
->select('cal.id')
->from(Calendar::class, 'cal')
->from(Calendar::class, 'cal'),
];
}
}

View File

@@ -35,11 +35,9 @@ use Chill\PersonBundle\Form\DataTransformer\PersonsToIdDataTransformer;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Form\DataTransformer\ThirdPartiesToIdDataTransformer;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\Collection;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionProperty;
use Symfony\Component\Form\PreloadedExtension;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -48,6 +46,7 @@ use Symfony\Component\Security\Core\Security;
/**
* @internal
*
* @coversNothing
*/
final class CalendarTypeTest extends TypeTestCase
@@ -112,8 +111,8 @@ final class CalendarTypeTest extends TypeTestCase
$form->submit($formData);
$this->assertTrue($form->isSynchronized());
$this->assertEquals(DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2022-05-05 14:00:00'), $calendar->getStartDate());
$this->assertEquals(DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2022-05-05 14:30:00'), $calendar->getEndDate());
$this->assertEquals(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2022-05-05 14:00:00'), $calendar->getStartDate());
$this->assertEquals(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2022-05-05 14:30:00'), $calendar->getEndDate());
$this->assertEquals(7, $calendar->getPersons()->first()->getId());
$this->assertEquals(8, $calendar->getCalendarRange()->getId());
$this->assertEquals(9, $calendar->getLocation()->getId());
@@ -181,7 +180,7 @@ final class CalendarTypeTest extends TypeTestCase
return array_map(
static function ($id) use ($objClass) {
$obj = new $objClass();
$reflectionProperty = new ReflectionProperty($objClass, 'id');
$reflectionProperty = new \ReflectionProperty($objClass, 'id');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($obj, (int) $id);
@@ -209,7 +208,7 @@ final class CalendarTypeTest extends TypeTestCase
return null;
}
$obj = new $class();
$reflectionProperty = new ReflectionProperty($class, 'id');
$reflectionProperty = new \ReflectionProperty($class, 'id');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($obj, (int) $args[0]);

View File

@@ -27,10 +27,10 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Templating\EngineInterface;
/**
* @internal
*
* @coversNothing
*/
final class AddressConverterTest extends TestCase

View File

@@ -22,7 +22,6 @@ use Chill\CalendarBundle\Entity\Calendar;
use Chill\CalendarBundle\Entity\CalendarRange;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteToLocalSync\CalendarRangeSyncer;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
@@ -33,6 +32,7 @@ use Symfony\Component\HttpClient\Response\MockResponse;
/**
* @internal
*
* @coversNothing
*/
final class CalendarRangeSyncerTest extends TestCase
@@ -228,8 +228,8 @@ final class CalendarRangeSyncerTest extends TestCase
$calendarRange = new CalendarRange();
$calendarRange
->setUser($user = new User())
->setStartDate(new DateTimeImmutable('2020-01-01 15:00:00'))
->setEndDate(new DateTimeImmutable('2020-01-01 15:30:00'))
->setStartDate(new \DateTimeImmutable('2020-01-01 15:00:00'))
->setEndDate(new \DateTimeImmutable('2020-01-01 15:30:00'))
->addRemoteAttributes([
'lastModifiedDateTime' => 0,
'changeKey' => 'abc',
@@ -244,11 +244,11 @@ final class CalendarRangeSyncerTest extends TestCase
$this->assertStringContainsString(
'2022-06-10T15:30:00',
$calendarRange->getStartDate()->format(DateTimeImmutable::ATOM)
$calendarRange->getStartDate()->format(\DateTimeImmutable::ATOM)
);
$this->assertStringContainsString(
'2022-06-10T17:30:00',
$calendarRange->getEndDate()->format(DateTimeImmutable::ATOM)
$calendarRange->getEndDate()->format(\DateTimeImmutable::ATOM)
);
$this->assertTrue($calendarRange->preventEnqueueChanges);
}

View File

@@ -24,8 +24,6 @@ use Chill\CalendarBundle\Entity\Invite;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteToLocalSync\CalendarSyncer;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Repository\UserRepositoryInterface;
use DateTimeImmutable;
use DateTimeZone;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
@@ -35,6 +33,7 @@ use Symfony\Component\HttpClient\Response\MockResponse;
/**
* @internal
*
* @coversNothing
*/
final class CalendarSyncerTest extends TestCase
@@ -362,9 +361,9 @@ final class CalendarSyncerTest extends TestCase
parent::setUp();
// all tests should run when timezone = +02:00
$brussels = new DateTimeZone('Europe/Brussels');
$brussels = new \DateTimeZone('Europe/Brussels');
if (7200 === $brussels->getOffset(new DateTimeImmutable())) {
if (7200 === $brussels->getOffset(new \DateTimeImmutable())) {
date_default_timezone_set('Europe/Brussels');
} else {
date_default_timezone_set('Europe/Moscow');
@@ -403,8 +402,8 @@ final class CalendarSyncerTest extends TestCase
$calendar = new Calendar();
$calendar
->setMainUser($user = new User())
->setStartDate(new DateTimeImmutable('2022-06-11 14:30:00'))
->setEndDate(new DateTimeImmutable('2022-06-11 15:30:00'))
->setStartDate(new \DateTimeImmutable('2022-06-11 14:30:00'))
->setEndDate(new \DateTimeImmutable('2022-06-11 15:30:00'))
->addUser($userA)
->addUser($userB)
->setCalendarRange(new CalendarRange())
@@ -480,8 +479,8 @@ final class CalendarSyncerTest extends TestCase
$calendar = new Calendar();
$calendar
->setMainUser($user = new User())
->setStartDate(new DateTimeImmutable('2020-01-01 10:00:00'))
->setEndDate(new DateTimeImmutable('2020-01-01 12:00:00'))
->setStartDate(new \DateTimeImmutable('2020-01-01 10:00:00'))
->setEndDate(new \DateTimeImmutable('2020-01-01 12:00:00'))
->setCalendarRange(new CalendarRange())
->addRemoteAttributes([
'lastModifiedDateTime' => 0,
@@ -498,11 +497,11 @@ final class CalendarSyncerTest extends TestCase
$this->assertStringContainsString(
'2022-06-10T15:30:00',
$calendar->getStartDate()->format(DateTimeImmutable::ATOM)
$calendar->getStartDate()->format(\DateTimeImmutable::ATOM)
);
$this->assertStringContainsString(
'2022-06-10T17:30:00',
$calendar->getEndDate()->format(DateTimeImmutable::ATOM)
$calendar->getEndDate()->format(\DateTimeImmutable::ATOM)
);
$this->assertTrue($calendar->preventEnqueueChanges);
$this->assertGreaterThan($previousVersion, $calendar->getDateTimeVersion());
@@ -524,8 +523,8 @@ final class CalendarSyncerTest extends TestCase
$calendar = new Calendar();
$calendar
->setMainUser($user = new User())
->setStartDate(new DateTimeImmutable('2022-06-10 15:30:00'))
->setEndDate(new DateTimeImmutable('2022-06-10 17:30:00'))
->setStartDate(new \DateTimeImmutable('2022-06-10 15:30:00'))
->setEndDate(new \DateTimeImmutable('2022-06-10 17:30:00'))
->setCalendarRange(new CalendarRange())
->addRemoteAttributes([
'lastModifiedDateTime' => 0,
@@ -541,11 +540,11 @@ final class CalendarSyncerTest extends TestCase
$this->assertStringContainsString(
'2022-06-10T15:30:00',
$calendar->getStartDate()->format(DateTimeImmutable::ATOM)
$calendar->getStartDate()->format(\DateTimeImmutable::ATOM)
);
$this->assertStringContainsString(
'2022-06-10T17:30:00',
$calendar->getEndDate()->format(DateTimeImmutable::ATOM)
$calendar->getEndDate()->format(\DateTimeImmutable::ATOM)
);
$this->assertTrue($calendar->preventEnqueueChanges);
$this->assertEquals(Calendar::STATUS_VALID, $calendar->getStatus());
@@ -568,8 +567,8 @@ final class CalendarSyncerTest extends TestCase
$calendar = new Calendar();
$calendar
->setMainUser($user = new User())
->setStartDate(new DateTimeImmutable('2020-01-01 10:00:00'))
->setEndDate(new DateTimeImmutable('2020-01-01 12:00:00'))
->setStartDate(new \DateTimeImmutable('2020-01-01 10:00:00'))
->setEndDate(new \DateTimeImmutable('2020-01-01 12:00:00'))
->setCalendarRange(new CalendarRange())
->addRemoteAttributes([
'lastModifiedDateTime' => 0,
@@ -585,11 +584,11 @@ final class CalendarSyncerTest extends TestCase
$this->assertStringContainsString(
'2020-01-01T10:00:00',
$calendar->getStartDate()->format(DateTimeImmutable::ATOM)
$calendar->getStartDate()->format(\DateTimeImmutable::ATOM)
);
$this->assertStringContainsString(
'2020-01-01T12:00:00',
$calendar->getEndDate()->format(DateTimeImmutable::ATOM)
$calendar->getEndDate()->format(\DateTimeImmutable::ATOM)
);
$this->assertEquals(Calendar::STATUS_VALID, $calendar->getStatus());

View File

@@ -30,6 +30,7 @@ use Prophecy\PhpUnit\ProphecyTrait;
/**
* @internal
*
* @coversNothing
*/
final class LocationConverterTest extends TestCase

View File

@@ -22,6 +22,7 @@ use Symfony\Component\HttpClient\Response\MockResponse;
/**
* @internal
*
* @coversNothing
*/
class MSUserAbsenceReaderTest extends TestCase
@@ -55,7 +56,7 @@ class MSUserAbsenceReaderTest extends TestCase
$absenceReader = new MSUserAbsenceReader($client, $mapUser->reveal(), $clock);
self::assertNull($absenceReader->isUserAbsent($user), "when no user found, absence should be null");
self::assertNull($absenceReader->isUserAbsent($user), 'when no user found, absence should be null');
}
public function provideDataTestUserAbsence(): iterable
@@ -81,7 +82,7 @@ class MSUserAbsenceReaderTest extends TestCase
}
JSON,
false,
"User is present"
'User is present',
];
yield [
@@ -103,7 +104,7 @@ class MSUserAbsenceReaderTest extends TestCase
}
JSON,
true,
'User is absent with absence scheduled, we are within this period'
'User is absent with absence scheduled, we are within this period',
];
yield [
@@ -125,7 +126,7 @@ class MSUserAbsenceReaderTest extends TestCase
}
JSON,
false,
'User is present: absence is scheduled for later'
'User is present: absence is scheduled for later',
];
yield [
@@ -147,7 +148,7 @@ class MSUserAbsenceReaderTest extends TestCase
}
JSON,
false,
'User is present: absence is past'
'User is present: absence is past',
];
yield [
@@ -169,7 +170,7 @@ class MSUserAbsenceReaderTest extends TestCase
}
JSON,
true,
"User is absent: absence is always enabled"
'User is absent: absence is always enabled',
];
}
}

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
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;
@@ -22,6 +21,7 @@ use Symfony\Component\Clock\MockClock;
/**
* @internal
*
* @coversNothing
*/
class MSUserAbsenceSyncTest extends TestCase
@@ -48,21 +48,21 @@ class MSUserAbsenceSyncTest extends TestCase
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"];
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->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"];
$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"];
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"];
$user->setAbsenceStart($abs = new \DateTimeImmutable('2023-07-01T12:00:00'));
yield [$user, null, true, $abs, 'user not syncable: absence do not change'];
}
}

View File

@@ -15,13 +15,13 @@ use Chill\CalendarBundle\Repository\CalendarACLAwareRepository;
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
*
* @coversNothing
*/
final class CalendarACLAwareRepositoryTest extends KernelTestCase
@@ -51,7 +51,7 @@ final class CalendarACLAwareRepositoryTest extends KernelTestCase
$this->entityManager
);
$count = $calendarRepository->countByPerson($person, new DateTimeImmutable('yesterday'), new DateTimeImmutable('tomorrow'));
$count = $calendarRepository->countByPerson($person, new \DateTimeImmutable('yesterday'), new \DateTimeImmutable('tomorrow'));
$this->assertIsInt($count);
}

View File

@@ -16,12 +16,12 @@ use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTimeImmutable;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
*
* @coversNothing
*/
final class CalendarNormalizerTest extends KernelTestCase
@@ -41,8 +41,8 @@ final class CalendarNormalizerTest extends KernelTestCase
->setComment(
$comment = new CommentEmbeddable()
)
->setStartDate(DateTimeImmutable::createFromFormat(DateTimeImmutable::ATOM, '2020-10-15T15:00:00+0000'))
->setEndDate(DateTimeImmutable::createFromFormat(DateTimeImmutable::ATOM, '2020-15-15T15:30:00+0000'))
->setStartDate(\DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, '2020-10-15T15:00:00+0000'))
->setEndDate(\DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, '2020-15-15T15:30:00+0000'))
->addPerson(new Person())
->addPerson(new Person())
->addUser(new User())

View File

@@ -33,11 +33,10 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use function array_key_exists;
use function count;
/**
* @internal
*
* @coversNothing
*/
final class CalendarContextTest extends TestCase
@@ -85,13 +84,13 @@ final class CalendarContextTest extends TestCase
// so, we expect the call to be twice for each method
$formBuilder->add('thirdParty', EntityType::class, Argument::type('array'))
->should(static function ($calls, $object, $method) use ($tp1, $tp2) {
if (2 !== count($calls)) {
throw new FailedPredictionException(sprintf('the $builder->add should be called exactly 2, %d receivved', count($calls)));
if (2 !== \count($calls)) {
throw new FailedPredictionException(sprintf('the $builder->add should be called exactly 2, %d receivved', \count($calls)));
}
$opts = $calls[0]->getArguments()[2];
if (!array_key_exists('label', $opts)) {
if (!\array_key_exists('label', $opts)) {
throw new FailedPredictionException('the $builder->add should have a label key');
}
@@ -105,13 +104,13 @@ final class CalendarContextTest extends TestCase
});
$formBuilder->add('mainPerson', EntityType::class, Argument::type('array'))
->should(static function ($calls, $object, $method) use ($p1) {
if (2 !== count($calls)) {
throw new FailedPredictionException(sprintf('the $builder->add should be called exactly 2, %d receivved', count($calls)));
if (2 !== \count($calls)) {
throw new FailedPredictionException(sprintf('the $builder->add should be called exactly 2, %d receivved', \count($calls)));
}
$opts = $calls[0]->getArguments()[2];
if (!array_key_exists('label', $opts)) {
if (!\array_key_exists('label', $opts)) {
throw new FailedPredictionException('the $builder->add should have a label key');
}
@@ -178,7 +177,7 @@ final class CalendarContextTest extends TestCase
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(CalendarDoc::class))->should(
static function ($calls, $object, $method) use ($storedObject) {
if (1 !== count($calls)) {
if (1 !== \count($calls)) {
throw new FailedPredictionException('the persist method should be called once');
}
@@ -189,7 +188,7 @@ final class CalendarContextTest extends TestCase
throw new FailedPredictionException('the stored object is not correct');
}
if ($calendarDoc->getStoredObject()->getTitle() !== 'blabla') {
if ('blabla' !== $calendarDoc->getStoredObject()->getTitle()) {
throw new FailedPredictionException('the doc title should be the one provided');
}
@@ -203,8 +202,8 @@ final class CalendarContextTest extends TestCase
}
private function buildCalendarContext(
?EntityManagerInterface $entityManager = null,
?NormalizerInterface $normalizer = null
EntityManagerInterface $entityManager = null,
NormalizerInterface $normalizer = null
): CalendarContext {
$baseContext = $this->prophesize(BaseContextData::class);
$baseContext->getData(null)->willReturn(['base_context' => 'data']);

View File

@@ -18,7 +18,6 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Tests\Service\ShortMessageNotification;
use ArrayIterator;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\CalendarBundle\Service\ShortMessageNotification\BulkCalendarShortMessageSender;
use Chill\CalendarBundle\Service\ShortMessageNotification\CalendarForShortMessageProvider;
@@ -27,20 +26,18 @@ use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Service\ShortMessage\ShortMessage;
use Chill\MainBundle\Test\PrepareUserTrait;
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
use DateInterval;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use libphonenumber\PhoneNumberUtil;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\NullLogger;
use stdClass;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
/**
* @internal
*
* @coversNothing
*/
final class BulkCalendarShortMessageSenderTest extends KernelTestCase
@@ -79,26 +76,26 @@ final class BulkCalendarShortMessageSenderTest extends KernelTestCase
$calendar
->addPerson($this->getRandomPerson($em))
->setMainUser($user = $this->prepareUser([]))
->setStartDate(new DateTimeImmutable('now'))
->setEndDate($calendar->getStartDate()->add(new DateInterval('PT30M')))
->setStartDate(new \DateTimeImmutable('now'))
->setEndDate($calendar->getStartDate()->add(new \DateInterval('PT30M')))
->setSendSMS(true);
$user->setUsername(uniqid());
$user->setEmail(uniqid() . '@gmail.com');
$user->setEmail(uniqid().'@gmail.com');
$calendar->getPersons()->first()->setAcceptSMS(true);
// hack to prevent side effect with messages
$calendar->preventEnqueueChanges = true;
$em->persist($user);
//$this->toDelete[] = [User::class, $user->getId()];
// $this->toDelete[] = [User::class, $user->getId()];
$em->persist($calendar);
//$this->toDelete[] = [Calendar::class, $calendar->getId()];
// $this->toDelete[] = [Calendar::class, $calendar->getId()];
$em->flush();
$provider = $this->prophesize(CalendarForShortMessageProvider::class);
$provider->getCalendars(Argument::type(DateTimeImmutable::class))
->willReturn(new ArrayIterator([$calendar]));
$provider->getCalendars(Argument::type(\DateTimeImmutable::class))
->willReturn(new \ArrayIterator([$calendar]));
$messageBuilder = $this->prophesize(ShortMessageForCalendarBuilderInterface::class);
$messageBuilder->buildMessageForCalendar(Argument::type(Calendar::class))
@@ -114,7 +111,7 @@ final class BulkCalendarShortMessageSenderTest extends KernelTestCase
$bus = $this->prophesize(MessageBusInterface::class);
$bus->dispatch(Argument::type(ShortMessage::class))
->willReturn(new Envelope(new stdClass()))
->willReturn(new Envelope(new \stdClass()))
->shouldBeCalledTimes(1);
$bulk = new BulkCalendarShortMessageSender(

View File

@@ -23,15 +23,14 @@ use Chill\CalendarBundle\Repository\CalendarRepository;
use Chill\CalendarBundle\Service\ShortMessageNotification\CalendarForShortMessageProvider;
use Chill\CalendarBundle\Service\ShortMessageNotification\DefaultRangeGenerator;
use Chill\CalendarBundle\Service\ShortMessageNotification\RangeGeneratorInterface;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use function count;
/**
* @internal
*
* @coversNothing
*/
final class CalendarForShortMessageProviderTest extends TestCase
@@ -42,13 +41,13 @@ final class CalendarForShortMessageProviderTest extends TestCase
{
$calendarRepository = $this->prophesize(CalendarRepository::class);
$calendarRepository->findByNotificationAvailable(
Argument::type(DateTimeImmutable::class),
Argument::type(DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type('int'),
Argument::exact(0)
)->shouldBeCalledTimes(0);
$rangeGenerator = $this->prophesize(RangeGeneratorInterface::class);
$rangeGenerator->generateRange(Argument::type(DateTimeImmutable::class))->willReturn(null);
$rangeGenerator->generateRange(Argument::type(\DateTimeImmutable::class))->willReturn(null);
$em = $this->prophesize(EntityManagerInterface::class);
$em->clear()->shouldNotBeCalled();
@@ -59,23 +58,23 @@ final class CalendarForShortMessageProviderTest extends TestCase
$rangeGenerator->reveal()
);
$calendars = iterator_to_array($provider->getCalendars(new DateTimeImmutable('now')));
$calendars = iterator_to_array($provider->getCalendars(new \DateTimeImmutable('now')));
$this->assertEquals(0, count($calendars));
$this->assertEquals(0, \count($calendars));
}
public function testGetCalendars()
{
$calendarRepository = $this->prophesize(CalendarRepository::class);
$calendarRepository->findByNotificationAvailable(
Argument::type(DateTimeImmutable::class),
Argument::type(DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type('int'),
Argument::exact(0)
)->will(static fn ($args) => array_fill(0, $args[2], new Calendar()))->shouldBeCalledTimes(1);
$calendarRepository->findByNotificationAvailable(
Argument::type(DateTimeImmutable::class),
Argument::type(DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type('int'),
Argument::not(0)
)->will(static fn ($args) => array_fill(0, $args[2] - 1, new Calendar()))->shouldBeCalledTimes(1);
@@ -89,10 +88,10 @@ final class CalendarForShortMessageProviderTest extends TestCase
new DefaultRangeGenerator()
);
$calendars = iterator_to_array($provider->getCalendars(new DateTimeImmutable('now')));
$calendars = iterator_to_array($provider->getCalendars(new \DateTimeImmutable('now')));
$this->assertGreaterThan(1, count($calendars));
$this->assertLessThan(100, count($calendars));
$this->assertGreaterThan(1, \count($calendars));
$this->assertLessThan(100, \count($calendars));
$this->assertContainsOnly(Calendar::class, $calendars);
}
@@ -100,14 +99,14 @@ final class CalendarForShortMessageProviderTest extends TestCase
{
$calendarRepository = $this->prophesize(CalendarRepository::class);
$calendarRepository->findByNotificationAvailable(
Argument::type(DateTimeImmutable::class),
Argument::type(DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type('int'),
Argument::exact(0)
)->will(static fn ($args) => array_fill(0, 1, new Calendar()))->shouldBeCalledTimes(1);
$calendarRepository->findByNotificationAvailable(
Argument::type(DateTimeImmutable::class),
Argument::type(DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type(\DateTimeImmutable::class),
Argument::type('int'),
Argument::not(0)
)->will(static fn ($args) => [])->shouldBeCalledTimes(1);
@@ -121,9 +120,9 @@ final class CalendarForShortMessageProviderTest extends TestCase
new DefaultRangeGenerator()
);
$calendars = iterator_to_array($provider->getCalendars(new DateTimeImmutable('now')));
$calendars = iterator_to_array($provider->getCalendars(new \DateTimeImmutable('now')));
$this->assertEquals(1, count($calendars));
$this->assertEquals(1, \count($calendars));
$this->assertContainsOnly(Calendar::class, $calendars);
}
}

View File

@@ -19,12 +19,11 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Tests\Service\ShortMessageNotification;
use Chill\CalendarBundle\Service\ShortMessageNotification\DefaultRangeGenerator;
use DateTimeImmutable;
use Iterator;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
final class DefaultRangeGeneratorTest extends TestCase
@@ -36,46 +35,46 @@ final class DefaultRangeGeneratorTest extends TestCase
* * Jeudi => envoi des rdv du samedi et dimanche
* * Vendredi => Envoi des rdv du lundi.
*/
public function generateData(): Iterator
public function generateData(): \Iterator
{
yield [
new DateTimeImmutable('2022-06-13 10:45:00'),
new DateTimeImmutable('2022-06-14 00:00:00'),
new DateTimeImmutable('2022-06-16 00:00:00'),
new \DateTimeImmutable('2022-06-13 10:45:00'),
new \DateTimeImmutable('2022-06-14 00:00:00'),
new \DateTimeImmutable('2022-06-16 00:00:00'),
];
yield [
new DateTimeImmutable('2022-06-14 15:45:00'),
new DateTimeImmutable('2022-06-16 00:00:00'),
new DateTimeImmutable('2022-06-17 00:00:00'),
new \DateTimeImmutable('2022-06-14 15:45:00'),
new \DateTimeImmutable('2022-06-16 00:00:00'),
new \DateTimeImmutable('2022-06-17 00:00:00'),
];
yield [
new DateTimeImmutable('2022-06-15 13:45:18'),
new DateTimeImmutable('2022-06-17 00:00:00'),
new DateTimeImmutable('2022-06-18 00:00:00'),
new \DateTimeImmutable('2022-06-15 13:45:18'),
new \DateTimeImmutable('2022-06-17 00:00:00'),
new \DateTimeImmutable('2022-06-18 00:00:00'),
];
yield [
new DateTimeImmutable('2022-06-16 01:30:55'),
new DateTimeImmutable('2022-06-18 00:00:00'),
new DateTimeImmutable('2022-06-20 00:00:00'),
new \DateTimeImmutable('2022-06-16 01:30:55'),
new \DateTimeImmutable('2022-06-18 00:00:00'),
new \DateTimeImmutable('2022-06-20 00:00:00'),
];
yield [
new DateTimeImmutable('2022-06-17 21:30:55'),
new DateTimeImmutable('2022-06-20 00:00:00'),
new DateTimeImmutable('2022-06-21 00:00:00'),
new \DateTimeImmutable('2022-06-17 21:30:55'),
new \DateTimeImmutable('2022-06-20 00:00:00'),
new \DateTimeImmutable('2022-06-21 00:00:00'),
];
yield [
new DateTimeImmutable('2022-06-18 21:30:55'),
new \DateTimeImmutable('2022-06-18 21:30:55'),
null,
null,
];
yield [
new DateTimeImmutable('2022-06-19 21:30:55'),
new \DateTimeImmutable('2022-06-19 21:30:55'),
null,
null,
];
@@ -84,7 +83,7 @@ final class DefaultRangeGeneratorTest extends TestCase
/**
* @dataProvider generateData
*/
public function testGenerateRange(DateTimeImmutable $date, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate)
public function testGenerateRange(\DateTimeImmutable $date, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate)
{
$generator = new DefaultRangeGenerator();
@@ -94,8 +93,8 @@ final class DefaultRangeGeneratorTest extends TestCase
$this->assertNull($actualStartDate);
$this->assertNull($actualEndDate);
} else {
$this->assertEquals($startDate->format(DateTimeImmutable::ATOM), $actualStartDate->format(DateTimeImmutable::ATOM));
$this->assertEquals($endDate->format(DateTimeImmutable::ATOM), $actualEndDate->format(DateTimeImmutable::ATOM));
$this->assertEquals($startDate->format(\DateTimeImmutable::ATOM), $actualStartDate->format(\DateTimeImmutable::ATOM));
$this->assertEquals($endDate->format(\DateTimeImmutable::ATOM), $actualEndDate->format(\DateTimeImmutable::ATOM));
}
}
}

View File

@@ -23,17 +23,15 @@ use Chill\CalendarBundle\Service\ShortMessageNotification\DefaultShortMessageFor
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
use DateInterval;
use DateTimeImmutable;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberUtil;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Templating\EngineInterface;
/**
* @internal
*
* @coversNothing
*/
final class DefaultShortMessageForCalendarBuilderTest extends TestCase
@@ -51,8 +49,8 @@ final class DefaultShortMessageForCalendarBuilderTest extends TestCase
{
$calendar = new Calendar();
$calendar
->setStartDate(new DateTimeImmutable('now'))
->setEndDate($calendar->getStartDate()->add(new DateInterval('PT30M')))
->setStartDate(new \DateTimeImmutable('now'))
->setEndDate($calendar->getStartDate()->add(new \DateInterval('PT30M')))
->setMainUser($user = new User())
->addPerson($person = new Person())
->setSendSMS(false);