<commit_before><?php

/**
 * Copyright 2016 SURFnet B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Surfnet\StepupMiddleware\CommandHandlingBundle\Tests\Configuration\CommandHandler;

use Broadway\CommandHandling\CommandHandlerInterface;
use Broadway\EventHandling\EventBusInterface;
use Broadway\EventSourcing\AggregateFactory\PublicConstructorAggregateFactory;
use Broadway\EventStore\EventStoreInterface;
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationAddedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationContactInformationChangedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRelocatedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRemovedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRenamedEvent;
use Surfnet\Stepup\Configuration\EventSourcing\InstitutionConfigurationRepository;
use Surfnet\Stepup\Configuration\Value\Institution;
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId;
use Surfnet\Stepup\Configuration\Value\RaLocationId;
use Surfnet\Stepup\Configuration\Value\RaLocationName;
use Surfnet\Stepup\Configuration\Value\ContactInformation;
use Surfnet\Stepup\Configuration\Value\Location;
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption;
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\AddRaLocationCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ChangeRaLocationCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveRaLocationCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\CommandHandler\InstitutionConfigurationCommandHandler;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Tests\CommandHandlerTest;

class InstitutionConfigurationCommandHandlerTest extends CommandHandlerTest
{
    /**
     * @test
     * @group command-handler
     */
    public function an_institution_configuration_is_created_when_there_is_none_for_a_given_institution()
    {
        $command              = new CreateInstitutionConfigurationCommand();
        $command->institution = 'An institution';

        $institution                            = new Institution($command->institution);
        $institutionConfigurationId             = InstitutionConfigurationId::from($institution);
        $defaultUseRaLocationsOption            = new UseRaLocationsOption(false);
        $defaultShowRaaContactInformationOption = new ShowRaaContactInformationOption(true);

        $this->scenario
            ->withAggregateId($institutionConfigurationId)
            ->when($command)
            ->then([
                new NewInstitutionConfigurationCreatedEvent(
                    $institutionConfigurationId,
                    $institution,
                    $defaultUseRaLocationsOption,
                    $defaultShowRaaContactInformationOption
                )
            ]);
    }

    /**
     * @test
     * @group command-handler
     */
    public function an_institution_configuration_cannot_be_created_when_there_already_is_one_for_a_given_institution()
    {
        $this->setExpectedException('Broadway\EventStore\EventStoreException', 'already committed');

        $command                     = new CreateInstitutionConfigurationCommand();
        $command->institution        = 'An institution';

        $institution                     = new Institution($command->institution);
        $institutionConfigurationId      = InstitutionConfigurationId::from($institution);
        $useRaLocationsOption            = new UseRaLocationsOption(true);
        $showRaaContactInformationOption = new ShowRaaContactInformationOption(true);

        $this->scenario
            ->withAggregateId($institutionConfigurationId)
            ->given([
                new NewInstitutionConfigurationCreatedEvent(
                    $institutionConfigurationId,
                    $institution,
                    $useRaLocationsOption,
                    $showRaaContactInformationOption
                ),
            ])
            ->when($command);
    }

    /**
     * @test
     * @group command-handler
     */<commit_msg>Change test variable to reasonable default value<commit_after><?php

/**
 * Copyright 2016 SURFnet B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Surfnet\StepupMiddleware\CommandHandlingBundle\Tests\Configuration\CommandHandler;

use Broadway\CommandHandling\CommandHandlerInterface;
use Broadway\EventHandling\EventBusInterface;
use Broadway\EventSourcing\AggregateFactory\PublicConstructorAggregateFactory;
use Broadway\EventStore\EventStoreInterface;
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationAddedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationContactInformationChangedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRelocatedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRemovedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRenamedEvent;
use Surfnet\Stepup\Configuration\EventSourcing\InstitutionConfigurationRepository;
use Surfnet\Stepup\Configuration\Value\Institution;
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId;
use Surfnet\Stepup\Configuration\Value\RaLocationId;
use Surfnet\Stepup\Configuration\Value\RaLocationName;
use Surfnet\Stepup\Configuration\Value\ContactInformation;
use Surfnet\Stepup\Configuration\Value\Location;
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption;
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\AddRaLocationCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ChangeRaLocationCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveRaLocationCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\CommandHandler\InstitutionConfigurationCommandHandler;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Tests\CommandHandlerTest;

class InstitutionConfigurationCommandHandlerTest extends CommandHandlerTest
{
    /**
     * @test
     * @group command-handler
     */
    public function an_institution_configuration_is_created_when_there_is_none_for_a_given_institution()
    {
        $command              = new CreateInstitutionConfigurationCommand();
        $command->institution = 'An institution';

        $institution                            = new Institution($command->institution);
        $institutionConfigurationId             = InstitutionConfigurationId::from($institution);
        $defaultUseRaLocationsOption            = new UseRaLocationsOption(false);
        $defaultShowRaaContactInformationOption = new ShowRaaContactInformationOption(true);

        $this->scenario
            ->withAggregateId($institutionConfigurationId)
            ->when($command)
            ->then([
                new NewInstitutionConfigurationCreatedEvent(
                    $institutionConfigurationId,
                    $institution,
                    $defaultUseRaLocationsOption,
                    $defaultShowRaaContactInformationOption
                )
            ]);
    }

    /**
     * @test
     * @group command-handler
     */
    public function an_institution_configuration_cannot_be_created_when_there_already_is_one_for_a_given_institution()
    {
        $this->setExpectedException('Broadway\EventStore\EventStoreException', 'already committed');

        $command                     = new CreateInstitutionConfigurationCommand();
        $command->institution        = 'An institution';

        $institution                     = new Institution($command->institution);
        $institutionConfigurationId      = InstitutionConfigurationId::from($institution);
        $useRaLocationsOption            = new UseRaLocationsOption(false);
        $showRaaContactInformationOption = new ShowRaaContactInformationOption(true);

        $this->scenario
            ->withAggregateId($institutionConfigurationId)
            ->given([
                new NewInstitutionConfigurationCreatedEvent(
                    $institutionConfigurationId,
                    $institution,
                    $useRaLocationsOption,
                    $showRaaContactInformationOption
                ),
            ])
            ->when($command);
    }

    /**
     * @test
     * @group command-handler
     */
{'fraction_non_alphanumeric': 0.07388663967611336, 'fraction_numerical': 0.0016194331983805667, 'mean_word_length': 3.5724201758445164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '266139', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2398, 'n_words': 428}