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 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')); }