Пример #1
0
 public function testAllBasic()
 {
     $entity = $this->getFactory(TestEntity::class)->json();
     $this->assertJson($entity);
     $entityModel = $this->getFactory(TestEntity::class)->make();
     $this->assertUuid($entityModel->entity_id);
     $factoryWithBasicEntity = $this->getFactory(TestEntity::class);
     $factoryWithBasicEntity->append('check', 'result');
     $factoryWithBasicEntity->showOnly(['entity_id']);
     $factoryWithBasicEntity->setTransformer(EloquentModelTransformer::class);
     $entity = $factoryWithBasicEntity->transformed();
     $this->assertUuid($entity['entityId']);
     $this->assertEquals($entity['check'], 'result');
     $factoryWithBasicEntity->append('check', 'result');
     $encodedEntity = $factoryWithBasicEntity->toJson();
     $this->assertEquals(json_decode($encodedEntity, JSON_OBJECT_AS_ARRAY)['entityId'], $entity['entityId']);
     $collection = $this->getFactory(TestEntity::class)->setModel($entityModel)->count(3)->make();
     foreach ($collection as $item) {
         $this->assertInstanceOf(TestEntity::class, $item);
     }
     $modelFactory = new ModelFactory();
     $entity = $modelFactory->make(TestEntity::class);
     $this->assertInstanceOf(TestEntity::class, $entity);
     $entity = $modelFactory->json(TestEntity::class);
     $this->assertJson($entity);
 }
Пример #2
0
 /**
  * @param string|null $factoryName
  * @param string|null $definedName
  * @return ModelFactoryInstance
  */
 public function getFactory($factoryName = null, $definedName = 'default')
 {
     return $this->modelFactory->get($factoryName, $definedName);
 }