courseRepositoryMock = $this->getMockBuilder(CourseRepository::class)->disableOriginalConstructor()->getMock(); $this->networkUtils = $this->getMockBuilder(\App\Service\Network\Utils::class)->disableOriginalConstructor()->getMock(); $this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock(); $this->parameters = new Parameters(); $this->onParametersChange = new OnParametersChange( $this->courseRepositoryMock, $this->networkUtils, $this->messageBus ); } /** * @see OnParametersChange::onAdvancedEducationNotationTypeChange() */ public function testOnAdvancedEducationNotationTypeByTeachersChange(){ $educationNotationConfig = new EducationNotationConfig(); $educationCurriculum = new EducationCurriculum(); $educationNotationConfig->addEducationCurriculum($educationCurriculum); $organization = new Organization(); $organization->addEducationNotationConfig($educationNotationConfig); $this->parameters->setAdvancedEducationNotationType(AdvancedEducationNotationTypeEnum::BY_TEACHER()->getValue()); $this->parameters->setOrganization($organization); $this->assertCount(1, $educationNotationConfig->getEducationCurriculums()); $this->onParametersChange->onAdvancedEducationNotationTypeChange($this->parameters); $this->assertNull($educationNotationConfig->getEducationCurriculums()->first()->getEducationNotationConfig()); } /** * @see OnParametersChange::onAdvancedEducationNotationTypeChange() */ public function testOnAdvancedEducationNotationTypeByEducationChange(){ $educationNotationConfig = new EducationNotationConfig(); $teacher = new Access(); $educationNotationConfig->addTeacher($teacher); $organization = new Organization(); $organization->addEducationNotationConfig($educationNotationConfig); $this->parameters->setAdvancedEducationNotationType(AdvancedEducationNotationTypeEnum::BY_EDUCATION()->getValue()); $this->parameters->setOrganization($organization); $this->assertCount(1, $educationNotationConfig->getTeachers()); $this->onParametersChange->onAdvancedEducationNotationTypeChange($this->parameters); $this->assertNull($educationNotationConfig->getTeachers()->first()->getEducationNotationConfig()); } /** * Un cours qui débute le 2/09/2022, si l'année musical passe du 05/09 au 01/09 alors le cours passe de l'année 2021/2022 à 2022/2023 * @throws \Exception * @see OnParametersChange::onMusicalDateChange() */ public function testOnMusicalDateChange(){ $organization = new Organization(); $this->parameters->setMusicalDate(new \DateTime('2022-09-01')); $organization->setParameters($this->parameters); $course = new Course(); $course->setStartYear(2021); $course->setEndYear(2022); $course->setDatetimeStart(new \DateTime('2022-09-02')); $this->courseRepositoryMock ->method('getCoursesToFrom') ->willReturn([$course]) ; $this->onParametersChange->onMusicalDateChange($organization, new \DateTime('2022-09-05')); $this->assertEquals(2022, $course->getStartYear()); $this->assertEquals(2023, $course->getEndYear()); } }