Ejemplo n.º 1
0
 public function testCreate()
 {
     $client = static::createClient();
     $note = Fixture\Note::getEntity();
     $payload = $this->serializer->normalize($note);
     $payload['id'] = null;
     $customTitle = uniqid();
     $payload['title'] = $customTitle;
     $client->request('POST', '/note', [], [], $this->getHeaders(), json_encode($payload, JSON_FORCE_OBJECT));
     $this->checkResponse($client);
     $repository = $this->entityManager->getRepository(Note::class);
     /**
      * @var Note $createdEntity
      */
     $createdEntity = $repository->findOneBy(['title' => $customTitle]);
     $this->assertTrue(!is_null($createdEntity), 'Created entity not found!');
     if ($createdEntity) {
         /** @var PersistentCollection $labels */
         $labels = $createdEntity->getLabels();
         $this->assertEquals(1, $labels->count());
         $NoteLabel = $labels->offsetGet(0);
         $label = Fixture\Note\Label::getEntity();
         $this->assertEquals($label->getId(), $NoteLabel->getId());
     }
 }
Ejemplo n.º 2
0
 public function testDelete()
 {
     $client = static::createClient();
     $label = Fixture\Note\Label::getEntity();
     $client->request('DELETE', '/label/' . $label->getId(), [], [], $this->getHeaders());
     $this->checkResponse($client);
     $repository = $this->entityManager->getRepository(Label::class);
     $deletedEntity = $repository->find($label->getId());
     $this->assertTrue(is_null($deletedEntity), 'Entity was not deleted!');
     $this->assertEquals(json_encode([]), $client->getResponse()->getContent());
 }