コード例 #1
0
 public function testSimpleRun()
 {
     $client = new Client();
     $client->setName('Alexandar')->setSurname('Sapogova');
     $data = $this->serializer->serialize($client, 'json');
     $resp = $this->action->setRequestContent($data)->setClassName('Test\\TestBundle\\Entity\\Client')->init()->run();
     $this->assertTrue($resp->isSuccess());
     $this->assertEquals(RestResponse::STATUS_CODE_OK, $resp->getStatusCode());
     /** @var Client $clientFromResp */
     $clientFromResp = $resp->getData();
     $this->assertNotNull($clientFromResp);
     $this->assertEquals($client->getName(), $clientFromResp->getName());
     $this->assertEquals($client->getSurname(), $clientFromResp->getSurname());
     $this->em->clear();
     /** @var Client $clientFromDB */
     $clientFromDB = $this->em->getRepository('Test\\TestBundle\\Entity\\Client')->find($clientFromResp->getId());
     $this->assertNotNull($clientFromDB);
     $this->assertEquals($client->getName(), $clientFromDB->getName());
     $this->assertEquals($client->getSurname(), $clientFromDB->getSurname());
 }
コード例 #2
0
 public function testRunWithAdditionalGroup()
 {
     /** @var Client $clientOld */
     $clientOld = $this->em->getRepository('Test\\TestBundle\\Entity\\Client')->find(1);
     $this->em->detach($clientOld);
     $clientToSerialize = new Client();
     $clientToSerialize->setName('Oper');
     $clientToSerialize->setPatronymic('Polyiakova');
     $context = SerializationContext::create()->setGroups([PatchAction::GROUP_DEFAULT, PatchAction::GROUP_PATCH, 'some']);
     $resp = $this->action->setClassName('Test\\TestBundle\\Entity\\Client')->setEntityId(1)->setRequestContent($this->serializer->serialize($clientToSerialize, 'json', $context))->setSerializationContextGroups(['some'])->init()->run();
     $this->em->clear();
     $this->assertTrue($resp->isSuccess());
     $this->assertEquals(RestResponse::STATUS_CODE_OK, $resp->getStatusCode());
     /** @var Client $clientFromResp */
     $clientFromResp = $resp->getData();
     /** @var Client $clientFromDB */
     $clientFromDB = $this->em->getRepository('Test\\TestBundle\\Entity\\Client')->find(1);
     $this->assertEquals(1, $clientFromDB->getId());
     $this->assertEquals(1, $clientFromResp->getId());
     $this->assertEquals('Oper', $clientFromDB->getName());
     $this->assertEquals('Oper', $clientFromResp->getName());
     $this->assertEquals('Polyiakova', $clientFromDB->getPatronymic());
     $this->assertEquals('Polyiakova', $clientFromResp->getPatronymic());
 }