public function testExecuteReplacesBaseClassesAndLinkedDataMergeInFiles()
 {
     $inputMock = $this->getMock(ArrayInput::class, ['getArgument'], [], '', false);
     $inputMock->expects($this->exactly(3))->method('getArgument')->will($this->returnValueMap([['querybase', 'Project/PlanBundle/WidgetQuery'], ['peerbase', 'Project/PlanBundle/WidgetPeer'], ['modelbase', 'Project/PlanBundle/Widget']]));
     $commandUtilityMock = $this->getMock(CommandUtility::class, ['exec']);
     // list directories command
     $commandUtilityMock->expects($this->at(0))->method('exec')->with($this->equalTo('find ./src -type d |grep -v "SOA/SOABundle" |grep "Model/om$"'))->will($this->returnCallback(function ($command, &$output, &$returnVar = 0) {
         $output[] = 'src/Project/PlanBundle/Model/om';
     }));
     // list peers command
     $commandUtilityMock->expects($this->at(1))->method('exec')->with($this->equalTo('find src/Project/PlanBundle/Model/om -maxdepth 1 -type f |grep "Peer.php$"'))->will($this->returnCallback(function ($command, &$output, &$returnVar = 0) {
         $output[] = 'src/Project/PlanBundle/Model/om/WidgetPeer.php';
     }));
     // replace in peers
     $commandUtilityMock->expects($this->at(2))->method('exec');
     // list queries command
     $commandUtilityMock->expects($this->at(3))->method('exec')->with($this->equalTo('find src/Project/PlanBundle/Model/om -maxdepth 1 -type f |grep "Query.php$"'))->will($this->returnCallback(function ($command, &$output, &$returnVar = 0) {
         $output[] = 'src/Project/PlanBundle/Model/om/WidgetQuery.php';
     }));
     // replace in queries
     $commandUtilityMock->expects($this->at(4))->method('exec');
     // list models command
     $commandUtilityMock->expects($this->at(5))->method('exec')->with($this->equalTo('find src/Project/PlanBundle/Model/om -maxdepth 1 -type f |grep -v "Query.php$" |grep -v "Peer.php$"'))->will($this->returnCallback(function ($command, &$output, &$returnVar = 0) {
         $output[] = 'src/Project/PlanBundle/Model/om/Widget.php';
     }));
     // replace in models
     $commandUtilityMock->expects($this->at(6))->method('exec');
     Factory::injectObject(CommandUtility::class, $commandUtilityMock);
     $command = new SoafyModelsCommandMock();
     $command->publicExecute($inputMock, new NullOutput());
 }
 public function testIsAuthorizedReturnsTrueWhenClientIdIsNull()
 {
     $clientPeerMock = $this->getClientPeerMock(null);
     Factory::injectObject(ClientPeer::class, $clientPeerMock);
     $course = new Course();
     $this->assertTrue($course->isAuthorized());
 }
Exemplo n.º 3
0
 public function testInjectObjectWithIndexesCausesSequentialReturnsFromCreateNewObject()
 {
     $mock1 = $this->getMock(stdClass::class, []);
     $mock1->property = 'mock1';
     $mock2 = $this->getMock(stdClass::class, []);
     $mock2->property = 'mock2';
     Factory::injectObject(stdClass::class, $mock1, 0);
     Factory::injectObject(stdClass::class, $mock2, 1);
     $this->assertEquals($mock1, Factory::createNewObject(stdClass::class));
     $this->assertEquals($mock2, Factory::createNewObject(stdClass::class));
 }
Exemplo n.º 4
0
 public function testAddJoinedDataToResultArrayChecksPeerAndAddsResultOfMappedMethod()
 {
     $peerClass = 'MyPeerClass';
     $relation = 'Widget';
     $widgetValue = 'value';
     $peer = new PropelSOAPeer();
     $peer->linkedData = ['Widget' => 'getMyWidgets'];
     $modelMock = $this->getMock(PropelSOAModel::class, ['getMyWidgets']);
     $modelMock->expects($this->once())->method('getMyWidgets')->willReturn($widgetValue);
     $classInfoMock = $this->getMock(SymfonyClassInfo::class, ['parseClassPath', 'getClassPath']);
     $classInfoMock->expects($this->once())->method('parseClassPath')->with($this->equalTo(get_class($modelMock)));
     $classInfoMock->expects($this->once())->method('getClassPath')->with($this->equalTo('peer'))->willReturn($peerClass);
     Factory::injectObject($peerClass, $peer);
     Factory::injectObject(SymfonyClassInfo::class, $classInfoMock);
     $data = [];
     $linkedData = new LinkedData();
     $linkedData->relation = $relation;
     $linkedData->addJoinedDataToResultArray($modelMock, $data);
     $this->assertEquals($widgetValue, $data[$relation]);
 }
Exemplo n.º 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]]);
 }
 public function testExecuteAppendsGeneratedCode()
 {
     $baseUrl = 'http://site.com';
     $controllerClass = 'MyNamespace/ProjectBundle/Controller/DataController';
     $inputMock = $this->getMock(ArrayInput::class, ['getArgument'], [], '', false);
     $inputMock->expects($this->exactly(2))->method('getArgument')->will($this->returnValueMap([['url', $baseUrl], ['directory', 'js/src']]));
     $commandUtilityMock = $this->getMock(CommandUtility::class, ['exec', 'fileGetContents', 'filePutContents']);
     $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';
     }));
     $commandUtilityMock->expects($this->exactly(3))->method('fileGetContents')->will($this->returnValueMap([['http://site.com/query', 'query'], ['http://site.com/collection', 'collection'], ['http://site.com/partial', 'partial']]));
     $commandUtilityMock->expects($this->once())->method('filePutContents')->with($this->equalTo('./js/src/generatedscript.js'), $this->equalTo('querypartialcollection'));
     $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', 'isSubclassOf', 'implementsInterface'], [], '', false);
     $reflectionMock->expects($this->once())->method('isAbstract')->will($this->returnValue(false));
     $reflectionMock->expects($this->once())->method('isSubclassOf')->with($this->equalTo(ModelBasedServiceController::class))->will($this->returnValue(true));
     $reflectionMock->expects($this->exactly(2))->method('implementsInterface')->will($this->returnValueMap([[Collectionable::class, true], [ClientExtendable::class, true]]));
     $routerParams = ['namespace' => 'MyNamespace', 'bundle' => 'Project', 'entity' => 'Data'];
     $routerMock = $this->getMock(stdClass::class, ['generate']);
     $routerMock->expects($this->exactly(3))->method('generate')->will($this->returnValueMap([['propelsoa_generatequery_route', $routerParams, '/query'], ['propelsoa_generatecollection_route', $routerParams, '/collection'], ['propelsoa_generatepartialobject_route', $routerParams, '/partial']]));
     $containerMock = $this->getMock(stdClass::class, ['get']);
     $containerMock->expects($this->once())->method('get')->with($this->equalTo('router'))->will($this->returnValue($routerMock));
     Factory::injectObject(CommandUtility::class, $commandUtilityMock);
     Factory::injectObject(SymfonyClassInfo::class, $classInfoMock);
     Factory::injectObject(ReflectionClass::class, $reflectionMock);
     $command = $this->getMock(GenerateJSClassesCommandMock::class, ['getContainer']);
     $command->expects($this->once())->method('getContainer')->will($this->returnValue($containerMock));
     $command->publicExecute($inputMock, new NullOutput());
 }