From 82efa538fd417b759fc7d1ca3819ae0da6584425 Mon Sep 17 00:00:00 2001 From: msiebeneicher Date: Thu, 21 Apr 2016 18:07:44 +0200 Subject: [PATCH 1/3] added execption if jobname (local side) is already used --- src/Exception/JobLoadException.php | 1 + src/Service/JobRepository/BridgeFileSystem.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Exception/JobLoadException.php b/src/Exception/JobLoadException.php index 1352bcd..ae339a7 100644 --- a/src/Exception/JobLoadException.php +++ b/src/Exception/JobLoadException.php @@ -12,4 +12,5 @@ class JobLoadException extends \Exception { const ERROR_CODE_NO_VALID_JSON = 1; + const ERROR_CODE_DUPLICATE_JOB_ID = 2; } \ No newline at end of file diff --git a/src/Service/JobRepository/BridgeFileSystem.php b/src/Service/JobRepository/BridgeFileSystem.php index e541803..b3e50c0 100644 --- a/src/Service/JobRepository/BridgeFileSystem.php +++ b/src/Service/JobRepository/BridgeFileSystem.php @@ -159,10 +159,19 @@ private function getJobFilesFromFileSystem($sPath, array &$aJobFiles = []) /** * @param string $sJobName * @param string $sJobFile + * @throws JobLoadException */ private function setJobFileToMap($sJobName, $sJobFile) { // set path to job file map + if (isset($this->aJobFileMap[$sJobName])) + { + throw new JobLoadException( + sprintf('The jobname "%s" already exists. Jobnames have to be unique - Please check your local jobfiles for duplicate entries.', $sJobName), + JobLoadException::ERROR_CODE_DUPLICATE_JOB_ID + ); + } + $this->aJobFileMap[$sJobName] = $sJobFile; } @@ -204,6 +213,7 @@ private function hasUnsetJobFileFromMap($sJobName, $sJobFile = '') * @param array $aJobFiles * @param bool $bSetToFileMap * @return JobEntity[] + * @throws JobLoadException */ private function loadJobsFromFileContent(array $aJobFiles, $bSetToFileMap) { From 30e52e667e1005e098f9b02347ed6ddaa35d341c Mon Sep 17 00:00:00 2001 From: msiebeneicher Date: Thu, 21 Apr 2016 18:08:06 +0200 Subject: [PATCH 2/3] added unit test for duplicate name case --- .../JobRepository/BridgeFileSystemTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/unit/Service/JobRepository/BridgeFileSystemTest.php b/test/unit/Service/JobRepository/BridgeFileSystemTest.php index 2b43ca6..2e3bd89 100644 --- a/test/unit/Service/JobRepository/BridgeFileSystemTest.php +++ b/test/unit/Service/JobRepository/BridgeFileSystemTest.php @@ -174,4 +174,28 @@ public function testJobLoadException() $_aJobs = $_oFileSystemRepository->getJobs(); $this->assertNull($_aJobs); } + + /** + * @expectedException \Chapi\Exception\JobLoadException + */ + public function testJobLoadExceptionForDuplicateJobNames() + { + $_aStructure = array( + 'directory' => array( + 'jobA.json' => json_encode($this->getValidScheduledJobEntity('JobA')), + ), + 'jobB.json' => json_encode($this->getValidScheduledJobEntity('JobA')), + ); + + $this->oVfsRoot = vfsStream::setup($this->sRepositoryDir, null, $_aStructure); + + $_oFileSystemRepository = new BridgeFileSystem( + $this->oFileSystemService->reveal(), + $this->oCache->reveal(), + vfsStream::url($this->sRepositoryDir) + ); + + $_aJobs = $_oFileSystemRepository->getJobs(); + $this->assertNull($_aJobs); + } } \ No newline at end of file From d71c590397d5334acaabe625980023c3b890621b Mon Sep 17 00:00:00 2001 From: msiebeneicher Date: Thu, 21 Apr 2016 18:08:19 +0200 Subject: [PATCH 3/3] updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0a984..0edaa1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # dev-master (v0.7.x) + 2016-04-21 msiebeneicher + * [issue#50] - Added a unique job name validation + 2016-04-21 msiebeneicher * Updating dependencies (including require-dev) - Updating mikey179/vfsstream (v1.6.2 => v1.6.3)