diff --git a/api/fixtures/campCollaborations.yml b/api/fixtures/campCollaborations.yml index 87e8088174..dc36db4dfd 100644 --- a/api/fixtures/campCollaborations.yml +++ b/api/fixtures/campCollaborations.yml @@ -17,7 +17,7 @@ App\Entity\CampCollaboration: campCollaboration4invited: camp: '@camp1' inviteKey: "myInviteKey" - inviteKeyHash: "sl3hC12VkIUzT89mMggYyoMmFuo=" + inviteKeyHash: "" inviteEmail: "e.mail@test.com" status: invited role: member @@ -54,7 +54,7 @@ App\Entity\CampCollaboration: campCollaboration2invitedCampUnrelated: camp: '@campUnrelated' inviteKey: "myInviteKey2" - inviteKeyHash: "oNp2IShH2P5DIgvcdBZOwCqExZ0=" + inviteKeyHash: "" inviteEmail: "e.mail2@test.com" status: invited role: member @@ -67,7 +67,7 @@ App\Entity\CampCollaboration: user: '@user6invited' camp: '@camp2' inviteKey: "myInviteKeyCamp2" - inviteKeyHash: "ufVn1nkIodzMXLPB/ZI4JwNwSRg=" + inviteKeyHash: "" status: invited role: member campCollaboration1campPrototype: diff --git a/api/fixtures/contentTypes.yml b/api/fixtures/contentTypes.yml index 2d2fcb10fd..39461fbb58 100644 --- a/api/fixtures/contentTypes.yml +++ b/api/fixtures/contentTypes.yml @@ -1,34 +1,34 @@ App\Entity\ContentType: contentTypeSafetyConcept: - name: 'SafetyConcept' + name: active: true entityClass: 'App\Entity\ContentNode\SingleText' contentTypeStoryContext: - name: 'Storycontext' + name: active: true entityClass: 'App\Entity\ContentNode\SingleText' contentTypeNotes: - name: 'Notes' + name: active: true entityClass: 'App\Entity\ContentNode\SingleText' contentTypeColumnLayout: - name: 'ColumnLayout' + name: active: true entityClass: 'App\Entity\ContentNode\ColumnLayout' contentTypeResponsiveLayout: - name: 'ResponsiveLayout' + name: active: true entityClass: 'App\Entity\ContentNode\ResponsiveLayout' contentTypeStoryboard: - name: 'Storyboard' + name: active: true entityClass: 'App\Entity\ContentNode\Storyboard' contentTypeMaterial: - name: 'Material' + name: active: true entityClass: 'App\Entity\ContentNode\MaterialNode' contentTypeMultiSelect: - name: 'LAThematicArea' + name: active: true entityClass: 'App\Entity\ContentNode\MultiSelect' jsonConfig: { items: [ 'outdoorTechnique', 'security', 'natureAndEnvironment', 'pioneeringTechnique', 'campsiteAndSurroundings', 'preventionAndIntegration' ] } diff --git a/api/fixtures/profiles.yml b/api/fixtures/profiles.yml index d4b184a86a..a1f9cc8d13 100644 --- a/api/fixtures/profiles.yml +++ b/api/fixtures/profiles.yml @@ -1,7 +1,7 @@ App\Entity\Profile: profile1manager: user: '@user1manager' - email: test@example.com + email: firstname: Robert surname: Baden-Powell nickname: Bi-Pi @@ -65,7 +65,7 @@ App\Entity\Profile: roles: [ 'ROLE_USER' ] profileAdmin: user: '@admin' - email: admin@example.com + email: firstname: Admi surname: Nistrator nickname: Administrator diff --git a/api/tests/Api/ECampApiTestCase.php b/api/tests/Api/ECampApiTestCase.php index e89d1bb9d8..7039be7437 100644 --- a/api/tests/Api/ECampApiTestCase.php +++ b/api/tests/Api/ECampApiTestCase.php @@ -12,10 +12,8 @@ use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use ApiPlatform\Symfony\Bundle\Test\Client; use App\Entity\BaseEntity; -use App\Entity\Profile; use App\Entity\User; use App\Metadata\Resource\OperationHelper; -use App\Repository\ProfileRepository; use App\Util\ArrayDeepSort; use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector; use Doctrine\ORM\EntityManagerInterface; @@ -81,16 +79,9 @@ public static function deepCloneArray(array $array): mixed { * @throws ServerExceptionInterface * @throws TransportExceptionInterface */ - protected static function createClientWithCredentials(?array $credentials = null, ?array $headers = null): Client { + protected static function createClientWithCredentials(string $userFixtureName = 'user1manager', ?array $headers = null): Client { $client = static::createBasicClient($headers); - - /** @var Profile $profile */ - $profile = static::getContainer()->get(ProfileRepository::class) - ->findOneBy( - array_diff_key($credentials ?: ['email' => 'test@example.com'], ['password' => '']) - ) - ; - $user = $profile->user; + $user = self::getFixture($userFixtureName); $jwtToken = static::getContainer()->get('lexik_jwt_authentication.jwt_manager')->create($user); $lastPeriodPosition = strrpos($jwtToken, '.'); @@ -111,7 +102,7 @@ protected static function createClientWithCredentials(?array $credentials = null * @throws TransportExceptionInterface */ protected static function createClientWithAdminCredentials(?array $headers = null): Client { - return static::createClientWithCredentials(['email' => 'admin@example.com']); + return static::createClientWithCredentials('user1admin', $headers); } protected static function createBasicClient(?array $headers = null): Client { diff --git a/api/tests/Api/SnapshotTests/EndpointQueryCountTest.php b/api/tests/Api/SnapshotTests/EndpointQueryCountTest.php index 2a811323b4..e0e55381e8 100644 --- a/api/tests/Api/SnapshotTests/EndpointQueryCountTest.php +++ b/api/tests/Api/SnapshotTests/EndpointQueryCountTest.php @@ -5,6 +5,7 @@ use App\Tests\Api\ECampApiTestCase; use App\Tests\Spatie\Snapshots\Driver\ECampYamlSnapshotDriver; use Hautelook\AliceBundle\PhpUnit\FixtureStore; +use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseState; use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; @@ -31,34 +32,40 @@ class EndpointQueryCountTest extends ECampApiTestCase { * @throws TransportExceptionInterface */ public function testNumberOfQueriesDidNotChangeForStableEndpoints() { - $numberOfQueries = []; - $responseCodes = []; - $collectionEndpoints = self::getCollectionEndpoints(); - foreach ($collectionEndpoints as $collectionEndpoint) { - if ('/users' !== $collectionEndpoint && !str_contains($collectionEndpoint, '/content_node')) { - list($statusCode, $queryCount, $executionTimeSeconds) = $this->measurePerformanceFor($collectionEndpoint); - $responseCodes[$collectionEndpoint] = $statusCode; - $numberOfQueries[$collectionEndpoint] = [ - 'queryCount' => $queryCount, - 'executionTimeSeconds' => $executionTimeSeconds, - ]; - } - - if (!str_contains($collectionEndpoint, '/content_node')) { - $fixtureFor = $this->getFixtureFor($collectionEndpoint); - list($statusCode, $queryCount, $executionTimeSeconds) = $this->measurePerformanceFor("{$collectionEndpoint}/{$fixtureFor->getId()}"); - $responseCodes["{$collectionEndpoint}/item"] = $statusCode; - $numberOfQueries["{$collectionEndpoint}/item"] = [ - 'queryCount' => $queryCount, - 'executionTimeSeconds' => $executionTimeSeconds, - ]; + RefreshDatabaseState::setDbPopulated(false); + + try { + $numberOfQueries = []; + $responseCodes = []; + $collectionEndpoints = self::getCollectionEndpoints(); + foreach ($collectionEndpoints as $collectionEndpoint) { + if ('/users' !== $collectionEndpoint && !str_contains($collectionEndpoint, '/content_node')) { + list($statusCode, $queryCount, $executionTimeSeconds) = $this->measurePerformanceFor($collectionEndpoint); + $responseCodes[$collectionEndpoint] = $statusCode; + $numberOfQueries[$collectionEndpoint] = [ + 'queryCount' => $queryCount, + 'executionTimeSeconds' => $executionTimeSeconds, + ]; + } + + if (!str_contains($collectionEndpoint, '/content_node')) { + $fixtureFor = $this->getFixtureFor($collectionEndpoint); + list($statusCode, $queryCount, $executionTimeSeconds) = $this->measurePerformanceFor("{$collectionEndpoint}/{$fixtureFor->getId()}"); + $responseCodes["{$collectionEndpoint}/item"] = $statusCode; + $numberOfQueries["{$collectionEndpoint}/item"] = [ + 'queryCount' => $queryCount, + 'executionTimeSeconds' => $executionTimeSeconds, + ]; + } } - } - $not200Responses = array_filter($responseCodes, fn ($value) => 200 != $value); - assertThat($not200Responses, isEmpty()); + $not200Responses = array_filter($responseCodes, fn ($value) => 200 != $value); + assertThat($not200Responses, isEmpty()); - $this->assertMatchesSnapshot($numberOfQueries, new ECampYamlSnapshotDriver()); + $this->assertMatchesSnapshot($numberOfQueries, new ECampYamlSnapshotDriver()); + } finally { + RefreshDatabaseState::setDbPopulated(false); + } } /** @@ -146,6 +153,10 @@ public static function getContentNodeEndpoints(): array { }); } + protected static function getLoadFixturesNTimes($container): int { + return 1e4; + } + private static function getContentNodeEndpointQueryCountRanges(): array { return [ '/content_nodes' => [8, 9], diff --git a/api/tests/Api/SnapshotTests/__snapshots__/EndpointQueryCountTest__testNumberOfQueriesDidNotChangeForStableEndpoints__1.yml b/api/tests/Api/SnapshotTests/__snapshots__/EndpointQueryCountTest__testNumberOfQueriesDidNotChangeForStableEndpoints__1.yml index c67c5ca046..e077622b70 100644 --- a/api/tests/Api/SnapshotTests/__snapshots__/EndpointQueryCountTest__testNumberOfQueriesDidNotChangeForStableEndpoints__1.yml +++ b/api/tests/Api/SnapshotTests/__snapshots__/EndpointQueryCountTest__testNumberOfQueriesDidNotChangeForStableEndpoints__1.yml @@ -69,7 +69,7 @@ executionTimeSeconds: 0.01 /periods/item: queryCount: 19 - executionTimeSeconds: 0.03 + executionTimeSeconds: 0.02 /profiles: queryCount: 6 executionTimeSeconds: 0.01