tests for GET and POST: attempt

This commit is contained in:
Julie Lenaerts 2021-11-01 16:01:21 +01:00
parent 1d774b19e8
commit 84dfcb2899

View File

@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Controller;
use Symfony\Component\HttpFoundation\Request;
use Chill\PersonBundle\Repository\PersonRepository;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class RelationshipApiControllerTest extends WebTestCase
{
public static function setUpBeforeClass()
{
static::bootKernel();
}
public function setUp()
{
$this->client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'fred',
'PHP_AUTH_PW' => 'password',
));
}
/**
* @dataProvider personProvider
*/
public function testGetRelationshipByPerson($personId)
{
$this->client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId));
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200');
}
/**
* @dataProvider relationProvider
*/
public function testPostRelationship($fromPersonId, $toPersonId, $relationId, $isReverse): void
{
$this->client->request(Request::METHOD_POST,
'/api/1.0/person/relations/relationship.json',
[],
[],
[],
\json_encode([
'type' => 'relationship',
'fromPerson' => ['id' => $fromPersonId, 'type' => 'person'],
'toPerson' => ['id' => $toPersonId, 'type' => 'person'],
'relation' => ['id' => $relationId, 'type' => 'relation'],
'reverse' => $isReverse
]));
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function relationProvider(): array
{
//TODO: which different cases to test?
return [
[333, 334, 1, true],
];
}
public function personProvider(): array
{
//TODO: which different cases to test?
return [
[333],
];
}
}