|
|
@@ -1,4 +1,7 @@
|
|
|
-<?php
|
|
|
+<?php /** @noinspection DuplicatedCode */
|
|
|
+
|
|
|
+/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
+
|
|
|
namespace App\Test\Service\OnChange\Organization;
|
|
|
|
|
|
use App\Entity\Access\Access;
|
|
|
@@ -13,99 +16,133 @@ use App\Message\Command\Typo3\Typo3DeleteCommand;
|
|
|
use App\Message\Command\Typo3\Typo3UndeleteCommand;
|
|
|
use App\Message\Command\Typo3\Typo3UpdateCommand;
|
|
|
use App\Repository\Booking\CourseRepository;
|
|
|
+use App\Service\Network\Utils as NetworkUtils;
|
|
|
use App\Service\OnChange\OnChangeContext;
|
|
|
use App\Service\OnChange\Organization\OnParametersChange;
|
|
|
+use App\Service\Organization\Utils as OrganizationUtils;
|
|
|
use AssertionError;
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Symfony\Component\Messenger\Envelope;
|
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
|
|
|
class OnParametersChangeTest extends TestCase
|
|
|
{
|
|
|
- private Parameters $parameters;
|
|
|
- private OnParametersChange $onParametersChange;
|
|
|
- private CourseRepository $courseRepositoryMock;
|
|
|
- private \App\Service\Network\Utils $networkUtils;
|
|
|
+ private CourseRepository $courseRepository;
|
|
|
+ private NetworkUtils $networkUtils;
|
|
|
private MessageBusInterface $messageBus;
|
|
|
- private \App\Service\Organization\Utils $organizationUtils;
|
|
|
+ private OrganizationUtils $organizationUtils;
|
|
|
|
|
|
public function setUp(): void
|
|
|
{
|
|
|
- $this->courseRepositoryMock = $this->getMockBuilder(CourseRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->networkUtils = $this->getMockBuilder(\App\Service\Network\Utils::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->organizationUtils = $this->getMockBuilder(\App\Service\Organization\Utils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->courseRepository = $this->getMockBuilder(CourseRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->networkUtils = $this->getMockBuilder(NetworkUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->parameters = new Parameters();
|
|
|
- $this->onParametersChange = new OnParametersChange(
|
|
|
- $this->courseRepositoryMock,
|
|
|
- $this->networkUtils,
|
|
|
- $this->organizationUtils,
|
|
|
- $this->messageBus
|
|
|
- );
|
|
|
}
|
|
|
|
|
|
- public function testValidate(): void
|
|
|
+ public function testValidateValid(): void
|
|
|
{
|
|
|
+ $onParametersChange = $this->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['validate'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
- // 1. Is CMF and site web enabled ; 2. Is not CMF and site web disabled ; 3. Is not CMF and site web enabled
|
|
|
- foreach ([[false, true], [true, false], [false, false]] as $params) {
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $consecutiveParams = [
|
|
|
+ [false, true], // Is CMF and site web enabled
|
|
|
+ [true, false], // Is not CMF and site web disabled
|
|
|
+ [false, false] // Is not CMF and site web enabled
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($consecutiveParams as $params) {
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $parameters->method('getOrganization')->willReturn($organization);
|
|
|
+
|
|
|
$parameters->expects(self::once())->method('getDesactivateOpentalentSiteWeb')->willReturn($params[0]);
|
|
|
|
|
|
- $this->networkUtils = $this->getMockBuilder(\App\Service\Network\Utils::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->networkUtils->method('isCMFAndActiveNow')->willReturn($params[1]);
|
|
|
+ $this->networkUtils = $this->getMockBuilder(NetworkUtils::class)->getMock();
|
|
|
+ $this->networkUtils->method('isCMFAndActiveNow')->with($organization)->willReturn($params[1]);
|
|
|
|
|
|
- $this->onParametersChange->validate($parameters, $context);
|
|
|
+ $onParametersChange->validate($parameters, $context);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function testValidateInvalid(): void
|
|
|
{
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $onParametersChange = $this->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['validate'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $parameters->method('getOrganization')->willReturn($organization);
|
|
|
+
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
// Is CMF and site web disabled
|
|
|
$parameters->expects(self::once())->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
|
|
|
- $this->networkUtils->expects(self::once())->method('isCMFAndActiveNow')->willReturn(true);
|
|
|
+ $this->networkUtils->expects(self::once())->method('isCMFAndActiveNow')->with($organization)->willReturn(true);
|
|
|
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
|
|
|
- $this->onParametersChange->validate($parameters, $context);
|
|
|
+ $onParametersChange->validate($parameters, $context);
|
|
|
}
|
|
|
|
|
|
public function testBeforeChange(): void
|
|
|
{
|
|
|
- $onParametersChange = $this
|
|
|
+ $onParametersChange = $this
|
|
|
->getMockBuilder(OnParametersChange::class)
|
|
|
- ->onlyMethods(['onAdvancedEducationNotationTypeChange', 'onMusicalDateChange'])
|
|
|
- ->disableOriginalConstructor()
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['beforeChange'])
|
|
|
->getMock();
|
|
|
|
|
|
- $onParametersChange
|
|
|
- ->expects(self::once())
|
|
|
- ->method('onAdvancedEducationNotationTypeChange')
|
|
|
- ->willReturnSelf();
|
|
|
- $onParametersChange
|
|
|
- ->expects(self::once())
|
|
|
- ->method('onMusicalDateChange')
|
|
|
- ->willReturnSelf();
|
|
|
+ $onParametersChange->expects(self::once())->method('onAdvancedEducationNotationTypeChange');
|
|
|
+
|
|
|
+ $onParametersChange->expects(self::once())->method('onMusicalDateChange');
|
|
|
|
|
|
- $previousParameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
- $previousParameters->method('getAdvancedEducationNotationType')->willReturn('BY_EDUCATION');
|
|
|
$musicalDate = new \DateTime('2022-01-01');
|
|
|
+
|
|
|
+ $previousParameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $previousParameters->method('getAdvancedEducationNotationType')->willReturn('BY_EDUCATION');
|
|
|
$previousParameters->method('getMusicalDate')->willReturn($musicalDate);
|
|
|
+
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
$context->method('previousData')->willReturn($previousParameters);
|
|
|
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getAdvancedEducationNotationType')->willReturn('SOMETHING_ELSE');
|
|
|
$parameters->method('getMusicalDate')->willReturn(new \DateTime('2023-01-01'));
|
|
|
|
|
|
// Both mocked methods should be called once here
|
|
|
$onParametersChange->beforeChange($parameters, $context);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testBeforeChangeNoChange(): void
|
|
|
+ {
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['beforeChange'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $onParametersChange->expects(self::never())->method('onAdvancedEducationNotationTypeChange');
|
|
|
+
|
|
|
+ $onParametersChange->expects(self::never())->method('onMusicalDateChange');
|
|
|
+
|
|
|
+ $musicalDate = new \DateTime('2022-01-01');
|
|
|
+
|
|
|
+ $previousParameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $previousParameters->method('getAdvancedEducationNotationType')->willReturn('BY_EDUCATION');
|
|
|
+ $previousParameters->method('getMusicalDate')->willReturn($musicalDate);
|
|
|
+
|
|
|
+ $context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $context->method('previousData')->willReturn($previousParameters);
|
|
|
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getId')->willReturn(1);
|
|
|
$parameters->method('getAdvancedEducationNotationType')->willReturn('BY_EDUCATION');
|
|
|
$parameters->method('getMusicalDate')->willReturn($musicalDate);
|
|
|
@@ -116,35 +153,47 @@ class OnParametersChangeTest extends TestCase
|
|
|
|
|
|
public function testOnChangeNoChange(): void
|
|
|
{
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onChange'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
$this->messageBus->expects($this->never())->method('dispatch');
|
|
|
|
|
|
- $previousParameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $previousParameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$previousParameters->method('getId')->willReturn(1);
|
|
|
- $previousParameters->expects(self::once())->method('getAverage')->willReturn(20);
|
|
|
- $previousParameters->expects(self::once())->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
- $previousParameters->expects(self::once())->method('getCustomDomain')->willReturn(null);
|
|
|
+ $previousParameters->method('getAverage')->willReturn(20);
|
|
|
+ $previousParameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
+ $previousParameters->method('getCustomDomain')->willReturn(null);
|
|
|
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
$context->method('previousData')->willReturn($previousParameters);
|
|
|
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getId')->willReturn(1);
|
|
|
$parameters->method('getAverage')->willReturn(20);
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
$parameters->method('getCustomDomain')->willReturn(null);
|
|
|
|
|
|
- $this->onParametersChange->onChange($parameters, $context);
|
|
|
+ $onParametersChange->onChange($parameters, $context);
|
|
|
}
|
|
|
|
|
|
public function testOnChangeAverageChanged(): void
|
|
|
{
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onChange'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
$this->messageBus
|
|
|
->expects(self::once())
|
|
|
->method('dispatch')
|
|
|
->with(self::isInstanceOf(AverageChange::class))
|
|
|
->willReturn(new Envelope(new AverageChange(1)));
|
|
|
|
|
|
- $previousParameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $previousParameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$previousParameters->method('getId')->willReturn(1);
|
|
|
$previousParameters->expects(self::once())->method('getAverage')->willReturn(20);
|
|
|
$previousParameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
@@ -153,24 +202,30 @@ class OnParametersChangeTest extends TestCase
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
$context->method('previousData')->willReturn($previousParameters);
|
|
|
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getId')->willReturn(1);
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
$parameters->method('getCustomDomain')->willReturn(null);
|
|
|
$parameters->expects(self::once())->method('getAverage')->willReturn(30);
|
|
|
|
|
|
- $this->onParametersChange->onChange($parameters, $context);
|
|
|
+ $onParametersChange->onChange($parameters, $context);
|
|
|
}
|
|
|
|
|
|
public function testOnChangeCustomDomainChanged(): void
|
|
|
{
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onChange'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
$this->messageBus
|
|
|
->expects(self::once())
|
|
|
->method('dispatch')
|
|
|
->with(self::isInstanceOf(Typo3UpdateCommand::class))
|
|
|
->willReturn(new Envelope(new Typo3UpdateCommand(1)));
|
|
|
|
|
|
- $previousParameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $previousParameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$previousParameters->method('getId')->willReturn(1);
|
|
|
$previousParameters->method('getAverage')->willReturn(20);
|
|
|
$previousParameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
@@ -179,28 +234,34 @@ class OnParametersChangeTest extends TestCase
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
$context->method('previousData')->willReturn($previousParameters);
|
|
|
|
|
|
- $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
$organization->method('getId')->willReturn(1);
|
|
|
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getId')->willReturn(1);
|
|
|
$parameters->method('getOrganization')->willReturn($organization);
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
$parameters->expects(self::once())->method('getCustomDomain')->willReturn('custom');
|
|
|
$parameters->method('getAverage')->willReturn(20);
|
|
|
|
|
|
- $this->onParametersChange->onChange($parameters, $context);
|
|
|
+ $onParametersChange->onChange($parameters, $context);
|
|
|
}
|
|
|
|
|
|
public function testOnChangeWebsiteDisabled(): void
|
|
|
{
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onChange'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
$this->messageBus
|
|
|
->expects(self::once())
|
|
|
->method('dispatch')
|
|
|
->with(self::isInstanceOf(Typo3DeleteCommand::class))
|
|
|
->willReturn(new Envelope(new Typo3DeleteCommand(1)));
|
|
|
|
|
|
- $previousParameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $previousParameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$previousParameters->method('getId')->willReturn(1);
|
|
|
$previousParameters->method('getAverage')->willReturn(20);
|
|
|
$previousParameters->expects(self::once())->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
@@ -209,21 +270,27 @@ class OnParametersChangeTest extends TestCase
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
$context->method('previousData')->willReturn($previousParameters);
|
|
|
|
|
|
- $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
$organization->method('getId')->willReturn(1);
|
|
|
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getId')->willReturn(1);
|
|
|
$parameters->method('getOrganization')->willReturn($organization);
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
|
|
|
$parameters->method('getCustomDomain')->willReturn(null);
|
|
|
$parameters->method('getAverage')->willReturn(20);
|
|
|
|
|
|
- $this->onParametersChange->onChange($parameters, $context);
|
|
|
+ $onParametersChange->onChange($parameters, $context);
|
|
|
}
|
|
|
|
|
|
public function testOnChangeWebsiteEnabled(): void
|
|
|
{
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onChange'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
$this->messageBus
|
|
|
->expects(self::exactly(2))
|
|
|
->method('dispatch')
|
|
|
@@ -237,7 +304,7 @@ class OnParametersChangeTest extends TestCase
|
|
|
throw new AssertionError('unexpected message : ' . $message::class);
|
|
|
});
|
|
|
|
|
|
- $previousParameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $previousParameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$previousParameters->method('getId')->willReturn(1);
|
|
|
$previousParameters->method('getAverage')->willReturn(20);
|
|
|
$previousParameters->expects(self::once())->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
|
|
|
@@ -246,17 +313,17 @@ class OnParametersChangeTest extends TestCase
|
|
|
$context = $this->getMockBuilder(OnChangeContext::class)->disableOriginalConstructor()->getMock();
|
|
|
$context->method('previousData')->willReturn($previousParameters);
|
|
|
|
|
|
- $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
$organization->method('getId')->willReturn(1);
|
|
|
|
|
|
- $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getId')->willReturn(1);
|
|
|
$parameters->method('getOrganization')->willReturn($organization);
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
$parameters->method('getCustomDomain')->willReturn(null);
|
|
|
$parameters->method('getAverage')->willReturn(20);
|
|
|
|
|
|
- $this->onParametersChange->onChange($parameters, $context);
|
|
|
+ $onParametersChange->onChange($parameters, $context);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -264,19 +331,27 @@ class OnParametersChangeTest extends TestCase
|
|
|
*/
|
|
|
public function testOnAdvancedEducationNotationTypeByTeachersChange(): void
|
|
|
{
|
|
|
- $educationNotationConfig = new EducationNotationConfig();
|
|
|
- $educationCurriculum = new EducationCurriculum();
|
|
|
- $educationNotationConfig->addEducationCurriculum($educationCurriculum);
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onAdvancedEducationNotationTypeChange'])
|
|
|
+ ->getMock();
|
|
|
|
|
|
- $organization = new Organization();
|
|
|
- $organization->addEducationNotationConfig($educationNotationConfig);
|
|
|
+ $educationCurriculum = $this->getMockBuilder(EducationCurriculum::class)->getMock();
|
|
|
|
|
|
- $this->parameters->setAdvancedEducationNotationType(AdvancedEducationNotationTypeEnum::BY_TEACHER()->getValue());
|
|
|
- $this->parameters->setOrganization($organization);
|
|
|
+ $educationNotationConfig = $this->getMockBuilder(EducationNotationConfig::class)->getMock();
|
|
|
+ $educationNotationConfig->method('getEducationCurriculums')->willReturn(new ArrayCollection([$educationCurriculum]));
|
|
|
|
|
|
- $this->assertCount(1, $educationNotationConfig->getEducationCurriculums());
|
|
|
- $this->onParametersChange->onAdvancedEducationNotationTypeChange($this->parameters);
|
|
|
- $this->assertNull($educationNotationConfig->getEducationCurriculums()->first()->getEducationNotationConfig());
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organization->method('getEducationNotationConfigs')->willReturn(new ArrayCollection([$educationNotationConfig]));
|
|
|
+
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $parameters->method('getOrganization')->willReturn($organization);
|
|
|
+ $parameters->method('getAdvancedEducationNotationType')->willReturn(AdvancedEducationNotationTypeEnum::BY_TEACHER()->getValue());
|
|
|
+
|
|
|
+ $educationCurriculum->expects(self::once())->method('setEducationNotationConfig')->with(null);
|
|
|
+
|
|
|
+ $onParametersChange->onAdvancedEducationNotationTypeChange($parameters);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -284,19 +359,27 @@ class OnParametersChangeTest extends TestCase
|
|
|
*/
|
|
|
public function testOnAdvancedEducationNotationTypeByEducationChange(): void
|
|
|
{
|
|
|
- $educationNotationConfig = new EducationNotationConfig();
|
|
|
- $teacher = new Access();
|
|
|
- $educationNotationConfig->addTeacher($teacher);
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onAdvancedEducationNotationTypeChange'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $teacher = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+
|
|
|
+ $educationNotationConfig = $this->getMockBuilder(EducationNotationConfig::class)->getMock();
|
|
|
+ $educationNotationConfig->method('getTeachers')->willReturn(new ArrayCollection([$teacher]));
|
|
|
|
|
|
- $organization = new Organization();
|
|
|
- $organization->addEducationNotationConfig($educationNotationConfig);
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organization->method('getEducationNotationConfigs')->willReturn(new ArrayCollection([$educationNotationConfig]));
|
|
|
+
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $parameters->method('getOrganization')->willReturn($organization);
|
|
|
+ $parameters->method('getAdvancedEducationNotationType')->willReturn(AdvancedEducationNotationTypeEnum::BY_EDUCATION()->getValue());
|
|
|
|
|
|
- $this->parameters->setAdvancedEducationNotationType(AdvancedEducationNotationTypeEnum::BY_EDUCATION()->getValue());
|
|
|
- $this->parameters->setOrganization($organization);
|
|
|
+ $teacher->expects(self::once())->method('setEducationNotationConfig')->with(null);
|
|
|
|
|
|
- $this->assertCount(1, $educationNotationConfig->getTeachers());
|
|
|
- $this->onParametersChange->onAdvancedEducationNotationTypeChange($this->parameters);
|
|
|
- $this->assertNull($educationNotationConfig->getTeachers()->first()->getEducationNotationConfig());
|
|
|
+ $onParametersChange->onAdvancedEducationNotationTypeChange($parameters);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -306,28 +389,38 @@ class OnParametersChangeTest extends TestCase
|
|
|
*/
|
|
|
public function testOnMusicalDateChangeToPast(): void
|
|
|
{
|
|
|
- $this->parameters->setMusicalDate(new \DateTime('2022-09-01'));
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onMusicalDateChange'])
|
|
|
+ ->getMock();
|
|
|
|
|
|
- $organization = new Organization();
|
|
|
- $this->parameters->setOrganization($organization);
|
|
|
- $organization->setParameters($this->parameters);
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $organization->method('getParameters')->willReturn($parameters);
|
|
|
+ $parameters->method('getOrganization')->willReturn($organization);
|
|
|
|
|
|
- $this->organizationUtils->expects(self::once())->method('getActivityYearSwitchDate')->willReturn(2022);
|
|
|
+ $parameters->method('getMusicalDate')->willReturn(new \DateTime('2022-09-01'));
|
|
|
|
|
|
- $course = new Course();
|
|
|
- $course->setStartYear(2021);
|
|
|
- $course->setEndYear(2022);
|
|
|
- $course->setDatetimeStart(new \DateTime('2022-09-02'));
|
|
|
+ $startDate = new \DateTime('2022-09-02');
|
|
|
|
|
|
- $this->courseRepositoryMock
|
|
|
- ->method('getCoursesToFrom')
|
|
|
- ->willReturn([$course])
|
|
|
- ;
|
|
|
+ $this->organizationUtils
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('getActivityYearSwitchDate')
|
|
|
+ ->with($organization, $startDate)
|
|
|
+ ->willReturn(2022);
|
|
|
+
|
|
|
+ $course = $this->getMockBuilder(Course::class)->getMock();
|
|
|
+ $course->method('getStartYear')->willReturn(2021);
|
|
|
+ $course->method('getEndYear')->willReturn(2022);
|
|
|
+ $course->method('getDatetimeStart')->willReturn($startDate);
|
|
|
|
|
|
- $this->onParametersChange->onMusicalDateChange($this->parameters, new \DateTime('2022-09-05'));
|
|
|
+ $this->courseRepository->method('getCoursesToFrom')->willReturn([$course]);
|
|
|
|
|
|
- $this->assertEquals(2022, $course->getStartYear());
|
|
|
- $this->assertEquals(2023, $course->getEndYear());
|
|
|
+ $course->expects(self::once())->method('setStartYear')->with(2022);
|
|
|
+ $course->expects(self::once())->method('setEndYear')->with(2023);
|
|
|
+
|
|
|
+ $onParametersChange->onMusicalDateChange($parameters, new \DateTime('2022-09-05'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -338,27 +431,40 @@ class OnParametersChangeTest extends TestCase
|
|
|
*/
|
|
|
public function testOnMusicalDateChangeToFuture(): void
|
|
|
{
|
|
|
- $this->parameters->setMusicalDate(new \DateTime('2022-09-05'));
|
|
|
+ $onParametersChange = $this
|
|
|
+ ->getMockBuilder(OnParametersChange::class)
|
|
|
+ ->setConstructorArgs([$this->courseRepository, $this->networkUtils, $this->organizationUtils, $this->messageBus])
|
|
|
+ ->setMethodsExcept(['onMusicalDateChange'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $organization->method('getParameters')->willReturn($parameters);
|
|
|
+ $parameters->method('getOrganization')->willReturn($organization);
|
|
|
|
|
|
- $organization = new Organization();
|
|
|
- $this->parameters->setOrganization($organization);
|
|
|
- $organization->setParameters($this->parameters);
|
|
|
+ $parameters->method('getMusicalDate')->willReturn(new \DateTime('2022-09-05'));
|
|
|
|
|
|
- $this->organizationUtils->expects(self::once())->method('getActivityYearSwitchDate')->willReturn(2021);
|
|
|
+ $startDate = new \DateTime('2022-09-02');
|
|
|
+
|
|
|
+ $this->organizationUtils
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('getActivityYearSwitchDate')
|
|
|
+ ->with($organization, $startDate)
|
|
|
+ ->willReturn(2021);
|
|
|
|
|
|
- $course = new Course();
|
|
|
- $course->setStartYear(2022);
|
|
|
- $course->setEndYear(2023);
|
|
|
- $course->setDatetimeStart(new \DateTime('2022-09-02'));
|
|
|
+ $course = $this->getMockBuilder(Course::class)->getMock();
|
|
|
+ $course->method('getStartYear')->willReturn(2022);
|
|
|
+ $course->method('getEndYear')->willReturn(2023);
|
|
|
+ $course->method('getDatetimeStart')->willReturn($startDate);
|
|
|
|
|
|
- $this->courseRepositoryMock
|
|
|
+ $this->courseRepository
|
|
|
->method('getCoursesToFrom')
|
|
|
->willReturn([$course])
|
|
|
;
|
|
|
|
|
|
- $this->onParametersChange->onMusicalDateChange($this->parameters, new \DateTime('2022-09-01'));
|
|
|
+ $course->expects(self::once())->method('setStartYear')->with(2021);
|
|
|
+ $course->expects(self::once())->method('setEndYear')->with(2022);
|
|
|
|
|
|
- $this->assertEquals(2021, $course->getStartYear());
|
|
|
- $this->assertEquals(2022, $course->getEndYear());
|
|
|
+ $onParametersChange->onMusicalDateChange($parameters, new \DateTime('2022-09-01'));
|
|
|
}
|
|
|
}
|