public function testExecuteDoesNotAlterCodeWhenControllerFoundIsDeclaredAbstract()
 {
     $baseUrl = 'http://nowhere.mysite.com';
     $controllerClass = 'MyNamespace/ProjectBundle/Controller/DataController';
     $inputMock = $this->getMock(ArrayInput::class, ['getArgument'], [], '', false);
     $inputMock->expects($this->once())->method('getArgument')->with($this->equalTo('url'))->will($this->returnValue($baseUrl));
     $commandUtilityMock = $this->getMock(CommandUtility::class, ['exec']);
     $commandUtilityMock->expects($this->at(0))->method('exec')->will($this->returnCallback(function ($command, &$output, &$returnVar = 0) {
         $output[] = 'src/MyNamespace/ProjectBundle/Controller';
     }));
     $commandUtilityMock->expects($this->at(1))->method('exec')->will($this->returnCallback(function ($command, &$output, &$returnVar = 0) {
         $output[] = 'src/MyNamespace/ProjectBundle/Controller/DataController.php';
     }));
     $classInfoMock = $this->getMock(SymfonyClassInfo::class, ['getClassPath']);
     $classInfoMock->expects($this->once())->method('getClassPath')->with($this->equalTo('controller'))->will($this->returnValue($controllerClass));
     $reflectionMock = $this->getMock(ReflectionClass::class, ['isAbstract'], [], '', false);
     $reflectionMock->expects($this->once())->method('isAbstract')->will($this->returnValue(true));
     Factory::injectObject(CommandUtility::class, $commandUtilityMock);
     Factory::injectObject(SymfonyClassInfo::class, $classInfoMock);
     Factory::injectObject(ReflectionClass::class, $reflectionMock);
     $command = $this->getMock(GenerateJSClassesCommandMock::class, ['writeCode']);
     $command->expects($this->once())->method('writeCode');
     $command->publicExecute($inputMock, new NullOutput());
     $testUtility = new TestUtility();
     $this->assertEquals('', $testUtility->getProtectedProperty($command, 'code'));
 }
 public function testTokenReturnsBypassTokenValue()
 {
     $token = 'aaasdf';
     $bypassTokenMock = $this->getMock(BypassToken::class, ['getToken']);
     $bypassTokenMock->expects($this->any())->method('getToken')->willReturn($token);
     $signupMock = $this->getMock(Signup::class, ['getBypassToken']);
     $signupMock->expects($this->any())->method('getBypassToken')->willReturn($bypassTokenMock);
     $testUtility = new TestUtility();
     $notification = new SignupConfirmation($signupMock);
     $tokens = $testUtility->getProtectedProperty($notification, 'tokenDefinitions');
     $tokenCallback = $tokens['TOKEN'];
     $this->assertEquals($token, $tokenCallback());
 }
 public function testGetFinalDataIncludesData()
 {
     $message = 'My Message';
     $code = 'MY_CODE';
     $data = ['data'];
     $testUtility = new TestUtility();
     $successResponse = new PropelSOASuccessResponse(null, 200);
     $testUtility->setProtectedProperty($successResponse, 'message', $message);
     $testUtility->setProtectedProperty($successResponse, 'code', $code);
     $finalData = $testUtility->callProtectedMethod($successResponse, 'getFinalData', [$data]);
     $this->assertEquals($message, $finalData['Message']);
     $this->assertEquals($code, $finalData['Code']);
     $this->assertEquals($data, $finalData['Data']);
     $this->assertEquals('success', $finalData['Type']);
 }
 public function testGetFinalDataIncludesFieldErrors()
 {
     $message = 'My Message';
     $code = 'MY_CODE';
     $data = ['data'];
     $testUtility = new TestUtility();
     $errorResponse = new PropelSOAErrorResponse(null, 404);
     $testUtility->setProtectedProperty($errorResponse, 'message', $message);
     $testUtility->setProtectedProperty($errorResponse, 'code', $code);
     $errorResponse->addFieldError('TestField1', 'Rule1', 'Message1');
     $finalData = $testUtility->callProtectedMethod($errorResponse, 'getFinalData', [$data]);
     $this->assertEquals($message, $finalData['Message']);
     $this->assertEquals($code, $finalData['Code']);
     $this->assertEquals($data, $finalData['Data']);
     $this->assertEquals('error', $finalData['Type']);
     $this->assertEquals('Rule1', $finalData['FieldErrors']['TestField1'][0]['rule']);
 }
Beispiel #5
0
 public function testAddJoinedDataToResultArrayAddsArrayForPluralRelation()
 {
     $data = [];
     $relation = 'Widget';
     $relationType = RelationMap::ONE_TO_MANY;
     $testUtility = new TestUtility();
     $widgetData = ['WidgetId' => 3392];
     $widgetMock = $this->getMock(PropelSOAModel::class, ['toArray']);
     $widgetMock->expects($this->once())->method('toArray')->with($this->equalTo(BasePeer::TYPE_PHPNAME), $this->equalTo(false))->willReturn($widgetData);
     $modelMock = $this->getMock(PropelSOAModel::class, ['getWidgets']);
     $modelMock->expects($this->once())->method('getWidgets')->willReturn($testUtility->convertToCollection([$widgetMock]));
     $relationMapMock = $this->getMock(RelationMap::class, ['getType'], [], '', false);
     $relationMapMock->expects($this->any())->method('getType')->willReturn($relationType);
     $peer = new PropelSOAPeer();
     $peer->oneToOneRelations = [];
     $classInfoMock = $this->getMock(SymfonyClassInfo::class, ['parseClassPath', 'getClassPath']);
     $classInfoMock->expects($this->any())->method('parseClassPath')->with($this->equalTo(get_class($modelMock)));
     $classInfoMock->expects($this->any())->method('getClassPath')->with($this->equalTo('peer'))->willReturn(PropelSOAPeer::class);
     Factory::injectObject(PropelSOAPeer::class, $peer);
     Factory::injectObject(SymfonyClassInfo::class, $classInfoMock);
     $join = new Join();
     $join->joinList = [];
     $join->relation = $relation;
     $testUtility->setProtectedProperty($join, 'relationMap', $relationMapMock);
     $join->addJoinedDataToResultArray($modelMock, $data);
     $this->assertEquals($data, ['Widgets' => [$widgetData]]);
 }
Beispiel #6
0
 public function testOutputAsJSONConvertsDateTimesToStandardValues()
 {
     $dateValue = '2016-09-02';
     $modelData = ['id' => 23490, 'dateCreated' => new DateTime($dateValue)];
     $modelMock = $this->getMock(PropelSOAModel::class, ['toArray']);
     $modelMock->expects($this->once())->method('toArray')->with(BasePeer::TYPE_PHPNAME, false)->willReturn($modelData);
     $testUtility = new TestUtility();
     $modelCollection = $testUtility->convertToCollection([$modelMock]);
     $joinTree = new JoinTree();
     $json = $joinTree->outputAsJSON($modelCollection);
     $objects = json_decode($json);
     $object = $objects[0];
     $this->assertFalse(is_array($object->dateCreated));
     $this->assertFalse(is_object($object->dateCreated));
     $renderedDateTime = new DateTime($object->dateCreated);
     $this->assertEquals($dateValue, $renderedDateTime->format('Y-m-d'));
 }