Пример #1
1
 /**
  * @covers \app\Domain\Entities\ClientEntity::getId
  * @covers \app\Domain\Entities\ClientEntity::getFirstName
  * @covers \app\Domain\Entities\ClientEntity::getLastName
  * @covers \app\Domain\Entities\ClientEntity::getEmail
  * @covers \app\Domain\Entities\ClientEntity::getAge
  * @covers \app\Domain\Entities\ClientEntity::toArray
  */
 public function testGetData()
 {
     $client = new ClientEntity();
     $client->setId("1234");
     $client->setFirstName("Silex");
     $client->setLastName("Project");
     $client->setEmail("*****@*****.**");
     $client->setAge('1');
     $expected = ['id' => $client->getId(), 'first_name' => $client->getFirstName(), 'last_name' => $client->getLastName(), 'email' => $client->getEmail(), 'age' => $client->getAge()];
     $this->assertEquals($expected, $client->toArray());
 }
Пример #2
1
 /**
  * @cover \app\Domain\Collectors\ClientCollector:attach
  * @cover \app\Domain\Collectors\ClientCollector:toArray
  */
 public function testGetCollectionMustReturnArray()
 {
     $collector = new ClientCollector();
     $client = new ClientEntity();
     $client->setId("1234");
     $client->setFirstName("Silex");
     $client->setLastName("Project");
     $client->setEmail("*****@*****.**");
     $client->setAge('1');
     $collector->add($client);
     $expected[] = ['id' => '1234', 'first_name' => 'Silex', 'last_name' => 'Project', 'email' => '*****@*****.**', 'age' => '1'];
     $this->assertEquals($expected, $collector->toArray());
 }
Пример #3
1
 /**
  * @var \Domain\Entities\ClientEntity
  *
  * @return \Domain\Collectors\ClientCollector
  */
 public function search($client)
 {
     if (!$client instanceof ClientEntity) {
         throw new \InvalidArgumentException('Expected ClientEntity in saveClient');
     }
     $result = $this->repository->search($client);
     $clientCollector = new ClientCollector();
     foreach ($result as $users) {
         $clientEntity = new ClientEntity();
         $clientEntity->setId((string) $users['_id']);
         $clientEntity->setFirstName($users['first_name']);
         $clientEntity->setLastName($users['last_name']);
         $clientEntity->setEmail($users['email']);
         $clientEntity->setAge($users['age']);
         $clientCollector->add($clientEntity);
     }
     return $clientCollector;
 }
Пример #4
1
 public function searchAction(Request $request, Application $app)
 {
     $formCreate = new SearchClientFormProvider($app);
     $form = $formCreate->create();
     $form->handleRequest($request);
     if ($request->getMethod() === 'POST' && $form->isValid()) {
         $mongoDbService = new MongoDbService(new MongoDbRepository($app['config']));
         $data = $request->request->get('form');
         $clientEntity = new ClientEntity();
         $clientEntity->setFirstName($data['first_name']);
         $clientEntity->setLastName($data['last_name']);
         $clientEntity->setEmail($data['email']);
         $clientEntity->setAge($data['age']);
         $search = $mongoDbService->search($clientEntity);
         return new Response(json_encode($search->toArray()), 200, ['Content-Type' => 'application/json']);
     }
     return new Response(json_encode(['result' => false]), 503, ['Content-Type' => 'application/json']);
 }