diff --git a/src/Surfnet/ServiceProviderDashboard/Domain/Entity/Constants.php b/src/Surfnet/ServiceProviderDashboard/Domain/Entity/Constants.php index 4658af89f..0b0b69a6e 100644 --- a/src/Surfnet/ServiceProviderDashboard/Domain/Entity/Constants.php +++ b/src/Surfnet/ServiceProviderDashboard/Domain/Entity/Constants.php @@ -48,6 +48,8 @@ class Constants final public const OIDC_SECRET_LENGTH = 20; + final public const TYPE_OF_SERVICE_LOCATION = __DIR__ . '/../../../../../assets/type_of_service.json'; + public static function getValidNameIdFormats(): array { return [ diff --git a/src/Surfnet/ServiceProviderDashboard/Domain/Exception/TypeOfServiceException.php b/src/Surfnet/ServiceProviderDashboard/Domain/Exception/TypeOfServiceException.php new file mode 100644 index 000000000..127dca99c --- /dev/null +++ b/src/Surfnet/ServiceProviderDashboard/Domain/Exception/TypeOfServiceException.php @@ -0,0 +1,27 @@ +typeOfServiceLocation)) { - throw new RuntimeException( + $typeOfServiceLocation = Constants::TYPE_OF_SERVICE_LOCATION; + if (!file_exists($typeOfServiceLocation)) { + throw new TypeOfServiceException( sprintf( 'Please review the file location of the type of services json blob. %s', - $this->typeOfServiceLocation + $typeOfServiceLocation ) ); } - $fileContents = file_get_contents($this->typeOfServiceLocation); + $fileContents = file_get_contents($typeOfServiceLocation); if (!$fileContents) { - throw new RuntimeException('Unable to load the type of service json file.'); + throw new TypeOfServiceException('Unable to load the type of service json file.'); } $data = json_decode($fileContents); if (!is_array($data)) { - throw new RuntimeException('The json can not be parsed into an array of service types'); + throw new TypeOfServiceException('The json can not be parsed into an array of service types'); } $this->collection = new TypeOfServiceCollection(); foreach ($data as $entry) { diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml index 2f723c089..5d9215e34 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Resources/config/services.yml @@ -235,12 +235,10 @@ services: Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Repository\AttributeRepository: arguments: [ '%kernel.project_dir%/assets/attributes.json' ] - Surfnet\ServiceProviderDashboard\Domain\Repository\TypeOfServiceRepository: - alias: Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Repository\TypeOfServiceRepositoryFromConfig - - Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Repository\TypeOfServiceRepositoryFromConfig: + Surfnet\ServiceProviderDashboard\Domain\Repository\TypeOfServiceRepositoryFromConfig: - arguments: [ '%kernel.project_dir%/assets/type_of_service.json' ] + Surfnet\ServiceProviderDashboard\Domain\Repository\TypeOfServiceRepository: + alias: Surfnet\ServiceProviderDashboard\Domain\Repository\TypeOfServiceRepositoryFromConfig Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Repository\PrivacyQuestionsRepository: public: true diff --git a/tests/unit/Infrastructure/DashboardBundle/Repository/Fixtures/type_of_service.json b/tests/unit/Domain/Repository/Fixtures/type_of_service.json similarity index 100% rename from tests/unit/Infrastructure/DashboardBundle/Repository/Fixtures/type_of_service.json rename to tests/unit/Domain/Repository/Fixtures/type_of_service.json diff --git a/tests/unit/Infrastructure/DashboardBundle/Repository/Fixtures/type_of_service_corrupt_json.json b/tests/unit/Domain/Repository/Fixtures/type_of_service_corrupt_json.json similarity index 100% rename from tests/unit/Infrastructure/DashboardBundle/Repository/Fixtures/type_of_service_corrupt_json.json rename to tests/unit/Domain/Repository/Fixtures/type_of_service_corrupt_json.json diff --git a/tests/unit/Infrastructure/DashboardBundle/Repository/TypeOfServiceRepositoryFromConfigTest.php b/tests/unit/Domain/Repository/TypeOfServiceRepositoryFromConfigTest.php similarity index 83% rename from tests/unit/Infrastructure/DashboardBundle/Repository/TypeOfServiceRepositoryFromConfigTest.php rename to tests/unit/Domain/Repository/TypeOfServiceRepositoryFromConfigTest.php index fa4bcd229..6222a6fa8 100644 --- a/tests/unit/Infrastructure/DashboardBundle/Repository/TypeOfServiceRepositoryFromConfigTest.php +++ b/tests/unit/Domain/Repository/TypeOfServiceRepositoryFromConfigTest.php @@ -15,12 +15,13 @@ * limitations under the License. */ -namespace Surfnet\ServiceProviderDashboard\Tests\Unit\Infrastructure\DashboardBundle\Repository; +namespace Surfnet\ServiceProviderDashboard\Tests\Unit\Domain\DashboardBundle\Repository; use PHPUnit\Framework\TestCase; use Surfnet\ServiceProviderDashboard\Application\Exception\RuntimeException; +use Surfnet\ServiceProviderDashboard\Domain\Exception\TypeOfServiceException; +use Surfnet\ServiceProviderDashboard\Domain\Repository\TypeOfServiceRepositoryFromConfig; use Surfnet\ServiceProviderDashboard\Domain\ValueObject\TypeOfService; -use Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Repository\TypeOfServiceRepositoryFromConfig; class TypeOfServiceRepositoryFromConfigTest extends TestCase { @@ -34,14 +35,14 @@ public function test_it_loads_types_of_service() } public function test_it_rejects_non_existing_file() { - self::expectException(RuntimeException::class); + self::expectException(TypeOfServiceException::class); self::expectExceptionMessageMatches('/Please review the file location of the type of services json blob/'); $typesRepo = new TypeOfServiceRepositoryFromConfig('/Fixtures/shes_not_there.json'); $typesRepo->getTypesOfServiceChoices(); } public function test_it_rejects_faulty_json() { - self::expectException(RuntimeException::class); + self::expectException(TypeOfServiceException::class); self::expectExceptionMessage('The json can not be parsed into an array of service types'); $typesRepo = new TypeOfServiceRepositoryFromConfig(__DIR__ . '/Fixtures/type_of_service_corrupt_json.json'); $typesRepo->getTypesOfServiceChoices();