Skip to content

Commit ab4e2b2

Browse files
committed
Updated the method that adds user- and project- ids to the request and renamed it
1 parent fdf6d21 commit ab4e2b2

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

Symfony/src/Codebender/BuilderBundle/Controller/DefaultController.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function compile($contents)
8787
{
8888
$apiHandler = $this->get('codebender_builder.handler');
8989

90-
$contents = $this->checkForUserIdProjectId($contents);
90+
$contents = $this->addUserIdProjectIdIfNotInRequest($contents);
9191

9292
$files = $contents["files"];
9393

@@ -210,17 +210,10 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
210210
* @param array $requestContents
211211
* @return array
212212
*/
213-
protected function checkForUserIdProjectId($requestContents)
213+
protected function addUserIdProjectIdIfNotInRequest($requestContents)
214214
{
215-
if (!array_key_exists('userId', $requestContents)) {
216-
$requestContents['userId'] = 'null';
217-
}
218-
219-
if (!array_key_exists('projectId', $requestContents)) {
220-
$requestContents['projectId'] = 'null';
221-
}
222-
223-
return $requestContents;
215+
$nullDefaults = ['userId' => 'null', 'projectId' => 'null'];
216+
return array_merge($nullDefaults, (array)$requestContents);
224217
}
225218
}
226219

Symfony/src/Codebender/BuilderBundle/Tests/Controller/DefaultControllerUnitTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function testCompileNonJsonCompilerResponse() {
158158
// Override previous controller mock. More class member functions need to get mocked.
159159
$controller = $this->getMockBuilder('Codebender\BuilderBundle\Controller\DefaultController')
160160
->disableOriginalConstructor()
161-
->setMethods(['get', 'getRequest', 'checkForUserIdProjectId', 'returnProvidedAndFetchedLibraries'])
161+
->setMethods(['get', 'getRequest', 'addUserIdProjectIdIfNotInRequest', 'returnProvidedAndFetchedLibraries'])
162162
->getMock();
163163

164164
$controller->setContainer($container);
@@ -170,7 +170,7 @@ public function testCompileNonJsonCompilerResponse() {
170170

171171
$controller->expects($this->at(0))->method('get')->with('codebender_builder.handler')
172172
->willReturn($apiHandler);
173-
$controller->expects($this->at(1))->method('checkForUserIdProjectId')->with(['files' => []])
173+
$controller->expects($this->at(1))->method('addUserIdProjectIdIfNotInRequest')->with(['files' => []])
174174
->willReturn(['files' => []]);
175175
$controller->expects($this->at(2))->method('returnProvidedAndFetchedLibraries')->with([])
176176
->willReturn(['libraries' => []]);
@@ -191,7 +191,7 @@ public function testCompileFalseCompilationWithoutStepIncluded() {
191191
// Override previous controller mock. More class member functions need to get mocked.
192192
$controller = $this->getMockBuilder('Codebender\BuilderBundle\Controller\DefaultController')
193193
->disableOriginalConstructor()
194-
->setMethods(['get', 'getRequest', 'checkForUserIdProjectId', 'returnProvidedAndFetchedLibraries'])
194+
->setMethods(['get', 'getRequest', 'addUserIdProjectIdIfNotInRequest', 'returnProvidedAndFetchedLibraries'])
195195
->getMock();
196196

197197
$controller->setContainer($container);
@@ -203,7 +203,7 @@ public function testCompileFalseCompilationWithoutStepIncluded() {
203203

204204
$controller->expects($this->at(0))->method('get')->with('codebender_builder.handler')
205205
->willReturn($apiHandler);
206-
$controller->expects($this->at(1))->method('checkForUserIdProjectId')->with(['files' => []])
206+
$controller->expects($this->at(1))->method('addUserIdProjectIdIfNotInRequest')->with(['files' => []])
207207
->willReturn(['files' => []]);
208208
$controller->expects($this->at(2))->method('returnProvidedAndFetchedLibraries')->with([])
209209
->willReturn(['libraries' => []]);
@@ -228,7 +228,7 @@ public function testCompileFalseCompilationWithStepIncluded() {
228228
// Override previous controller mock. More class member functions need to get mocked.
229229
$controller = $this->getMockBuilder('Codebender\BuilderBundle\Controller\DefaultController')
230230
->disableOriginalConstructor()
231-
->setMethods(['get', 'getRequest', 'checkForUserIdProjectId', 'returnProvidedAndFetchedLibraries'])
231+
->setMethods(['get', 'getRequest', 'addUserIdProjectIdIfNotInRequest', 'returnProvidedAndFetchedLibraries'])
232232
->getMock();
233233

234234
$controller->setContainer($container);
@@ -240,7 +240,7 @@ public function testCompileFalseCompilationWithStepIncluded() {
240240

241241
$controller->expects($this->at(0))->method('get')->with('codebender_builder.handler')
242242
->willReturn($apiHandler);
243-
$controller->expects($this->at(1))->method('checkForUserIdProjectId')->with(['files' => []])
243+
$controller->expects($this->at(1))->method('addUserIdProjectIdIfNotInRequest')->with(['files' => []])
244244
->willReturn(['files' => []]);
245245
$controller->expects($this->at(2))->method('returnProvidedAndFetchedLibraries')->with([])
246246
->willReturn(['libraries' => []]);
@@ -435,7 +435,7 @@ public function testcheckUserIdProjectIdHasNone() {
435435
/*
436436
* Use ReflectionMethod class to make compile protected function accessible from current context
437437
*/
438-
$function = $this->getMethod('checkForUserIdProjectId');
438+
$function = $this->getMethod('addUserIdProjectIdIfNotInRequest');
439439

440440
$requestContent = ['files' => [['filename' => 'project.ino', 'content' =>'']]];
441441

@@ -451,7 +451,7 @@ public function testcheckUserIdProjectIdHasOnlyUserId() {
451451
/*
452452
* Use ReflectionMethod class to make compile protected function accessible from current context
453453
*/
454-
$function = $this->getMethod('checkForUserIdProjectId');
454+
$function = $this->getMethod('addUserIdProjectIdIfNotInRequest');
455455

456456
$requestContent = ['userId' => 1, 'files' => [['filename' => 'project.ino', 'content' =>'']]];
457457

@@ -467,7 +467,7 @@ public function testcheckUserIdProjectIdHasOnlyProjectId() {
467467
/*
468468
* Use ReflectionMethod class to make compile protected function accessible from current context
469469
*/
470-
$function = $this->getMethod('checkForUserIdProjectId');
470+
$function = $this->getMethod('addUserIdProjectIdIfNotInRequest');
471471

472472
$projectFiles = ['projectId' => 1, 'files' => [['filename' => 'project.ino', 'content' =>'']]];
473473

0 commit comments

Comments
 (0)