Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnitTest testSqlQueryCount for GetEntity and GetCollection #3602

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/tests/Api/Activities/ListActivitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,12 @@ public function testListActivitiesFilteredByCampPrototypeIsAllowedForUnrelatedUs
['href' => $this->getIriFor('activity1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/activities');

$this->assertSqlQueryCount($client, 19);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/Activities/ReadActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,15 @@ public function testGetSingleActivityFromCampPrototypeIsAllowedForUnrelatedUser(
],
]);
}

public function testSqlQueryCount() {
/** @var Activity $activity */
$activity = static::$fixtures['activity1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/activities/'.$activity->getId());

$this->assertSqlQueryCount($client, 29);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ public function testListActivityProgressLabelsFilteredByCampIsDeniedForUnrelated
$this->assertJsonContains(['totalItems' => 0]);
$this->assertArrayNotHasKey('items', $response->toArray()['_links']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/activity_progress_labels');

$this->assertSqlQueryCount($client, 4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,15 @@ public function testGetSingleActivityProgressLabelIsAllowedForManager() {
],
]);
}

public function testSqlQueryCount() {
/** @var ActivityProgressLabel $activityProgressLabel */
$activityProgressLabel = static::$fixtures['activityProgressLabel1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/activity_progress_labels/'.$activityProgressLabel->getId());

$this->assertSqlQueryCount($client, 5);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,12 @@ public function testListActivityResponsiblesFilteredByCampPrototypeIsAllowedForU
['href' => $this->getIriFor('activityResponsible1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/activity_responsibles');

$this->assertSqlQueryCount($client, 4);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/ActivityResponsibles/ReadActivityResponsibleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,15 @@ public function testGetSingleActivityResponsibleFromCampPrototypeIsAllowedForUnr
],
]);
}

public function testSqlQueryCount() {
/** @var ActivityResponsible $activityResponsible */
$activityResponsible = static::$fixtures['activityResponsible1campPrototype'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/activity_responsibles/'.$activityResponsible->getId());

$this->assertSqlQueryCount($client, 6);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,12 @@ public function testListCampCollaborationsFilteredByCampPrototypeIsAllowedForUnr
['href' => $this->getIriFor('campCollaboration1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/camp_collaborations');

$this->assertSqlQueryCount($client, 23);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/CampCollaborations/ReadCampCollaborationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ public function testGetSingleCampCollaborationFromCampPrototypeIsAllowedForUnrel
],
]);
}

public function testSqlQueryCount() {
/** @var CampCollaboration $campCollaboration */
$campCollaboration = static::$fixtures['campCollaboration1manager'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/camp_collaborations/'.$campCollaboration->getId());

$this->assertSqlQueryCount($client, 13);
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/Camps/ListCampsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ public function testListCampsDoesNotShowCampToInactiveCollaborator() {
['href' => $this->getIriFor('campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/camps');

$this->assertSqlQueryCount($client, 27);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/Camps/ReadCampTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,15 @@ public function testGetSingleCampEmbedsCampCollaborationsAndItsUser() {
],
]);
}

public function testSqlQueryCount() {
/** @var Camp $camp */
$camp = static::$fixtures['camp1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/camps/'.$camp->getId());

$this->assertSqlQueryCount($client, 26);
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/Categories/ListCategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ public function testListCategoriesFilteredByCampPrototypeIsAllowedForUnrelatedUs
['href' => $this->getIriFor('category1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/categories');

$this->assertSqlQueryCount($client, 9);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/Categories/ReadCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,15 @@ public function testGetSingleCategoryFromCampPrototypeIsAllowedForUnrelatedUser(
],
]);
}

public function testSqlQueryCount() {
/** @var Category $category */
$category = static::$fixtures['category1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/categories/'.$category->getId());

$this->assertSqlQueryCount($client, 7);
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/ContentTypes/ListContentTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ public function testListContentTypesIsAllowedForLoggedInUser() {
]);
$this->assertCount(7, $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/content_types');

$this->assertSqlQueryCount($client, 4);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/ContentTypes/ReadContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ public function testGetSingleContentTypeIsAllowedForLoggedInUser() {
],
]);
}

public function testSqlQueryCount() {
/** @var ContentType $contentType */
$contentType = static::$fixtures['contentTypeSafetyConcept'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/content_types/'.$contentType->getId());

$this->assertSqlQueryCount($client, 4);
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/DayResponsibles/ListDayResponsiblesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@ public function testListDayResponsiblesFilteredByDayInCampPrototypeIsAllowedForU
['href' => $this->getIriFor('dayResponsible1day1period1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/day_responsibles');

$this->assertSqlQueryCount($client, 4);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/DayResponsibles/ReadDayResponsibleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,15 @@ public function testGetSingleDayResponsibleInCampPrototypeIsAllowedForUnrelatedU
],
]);
}

public function testSqlQueryCount() {
/** @var DayResponsible $dayResponsible */
$dayResponsible = static::$fixtures['dayResponsible1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/day_responsibles/'.$dayResponsible->getId());

$this->assertSqlQueryCount($client, 7);
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/Days/ListDaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,12 @@ public function testListDaysFilteredByPeriodInCampPrototypeIsAllowedForCollabora
['href' => $this->getIriFor('day1period1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/days');

$this->assertSqlQueryCount($client, 15);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/Days/ReadDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,15 @@ public function testDatesFormatProperlyInTimezoneBehindUTC() {
'end' => '2023-05-02T00:00:00+00:00',
]);
}

public function testSqlQueryCount() {
/** @var Day $day */
$day = static::$fixtures['day1period1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/days/'.$day->getId());

$this->assertSqlQueryCount($client, 9);
}
}
12 changes: 12 additions & 0 deletions api/tests/Api/ECampApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Entity\User;
use App\Metadata\Resource\OperationHelper;
use App\Repository\ProfileRepository;
use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector;
use Doctrine\ORM\EntityManagerInterface;
use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseTrait;
use Symfony\Component\BrowserKit\Cookie;
Expand Down Expand Up @@ -297,4 +298,15 @@ protected function assertJsonSchemaError(ResponseInterface $response, string $pr
$this->assertEquals($propertyName, $responseArray['violations'][0]['propertyPath']);
$this->assertStringStartsWith('Provided JSON doesn\'t match required schema', $responseArray['violations'][0]['message']);
}

/**
* Validates the number of executed SqlQueries.
* requieres $client->enableProfiler().
*/
protected function assertSqlQueryCount(Client $client, int $expected) {
/** @var DoctrineDataCollector $collector */
$collector = $client->getProfile()->getCollector('db');

$this->assertEquals($expected, $collector->getQueryCount());
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/MaterialItems/ListMaterialItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,12 @@ public function testListMaterialItemsFilteredByPeriodInCampPrototypeIsAllowedFor
['href' => $this->getIriFor('materialItem1period1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/material_items');

$this->assertSqlQueryCount($client, 4);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/MaterialItems/ReadMaterialItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,15 @@ public function testGetSingleMaterialItemInCampPrototypeIsAllowedForUnrelatedUse
],
]);
}

public function testSqlQueryCount() {
/** @var MaterialItem $materialItem */
$materialItem = static::$fixtures['materialItem1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/material_items/'.$materialItem->getId());

$this->assertSqlQueryCount($client, 6);
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/MaterialLists/ListMaterialListsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ public function testListMaterialListsFilteredByCampPrototypeIsAllowedForUnrelate
['href' => $this->getIriFor('materialList1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/material_lists');

$this->assertSqlQueryCount($client, 4);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/MaterialLists/ReadMaterialListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,15 @@ public function testGetSingleMaterialListFromCampPrototypeIsAllowedForUnrelatedU
],
]);
}

public function testSqlQueryCount() {
/** @var MaterialList $materialList */
$materialList = static::$fixtures['materialList1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/material_lists/'.$materialList->getId());

$this->assertSqlQueryCount($client, 5);
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/Periods/ListPeriodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ public function testListPeriodsFilteredByCampPrototypeIsAllowedForUnrelatedUser(
['href' => $this->getIriFor('period1campPrototype')],
], $response->toArray()['_links']['items']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/periods');

$this->assertSqlQueryCount($client, 4);
}
}
11 changes: 11 additions & 0 deletions api/tests/Api/Periods/ReadPeriodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,15 @@ public function testGetSinglePeriodFromCampPrototypeIsAllowedForUnrelatedUser()
],
]);
}

public function testSqlQueryCount() {
/** @var Period $period */
$period = static::$fixtures['period1'];

$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/periods/'.$period->getId());

$this->assertSqlQueryCount($client, 17);
}
}
8 changes: 8 additions & 0 deletions api/tests/Api/Profiles/ListProfilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public function testListProfilesFilteredByCampPrototypeIsDeniedForUnrelatedUser(
$this->assertJsonContains(['totalItems' => 0]);
$this->assertArrayNotHasKey('items', $response->toArray()['_links']);
}

public function testSqlQueryCount() {
$client = static::createClientWithCredentials();
$client->enableProfiler();
$client->request('GET', '/profiles');

$this->assertSqlQueryCount($client, 4);
}
}
Loading