Przeglądaj źródła

Test & fix performance

Vincent 2 lat temu
rodzic
commit
52d15b42a6

+ 36 - 0
config/services.yaml

@@ -3,6 +3,42 @@
 parameters:
 
 services:
+    ########### Speeds up api-platform cache build substantially ###########
+    #### see https://github.com/api-platform/core/issues/4975  ####
+    api_platform.cache.metadata.property:
+        parent: cache.system
+        tags: [ cache.pool ]
+    api_platform.cache.metadata.resource:
+        parent: cache.system
+        tags: [ cache.pool ]
+    api_platform.cache.metadata.resource_collection:
+        parent: cache.system
+        tags: [ cache.pool ]
+    api_platform.cache.route_name_resolver:
+        parent: cache.system
+        tags: [ cache.pool ]
+    api_platform.cache.identifiers_extractor:
+        parent: cache.system
+        tags: [ cache.pool ]
+    api_platform.elasticsearch.cache.metadata.document:
+        parent: cache.system
+        tags: [ cache.pool ]
+
+    # May have to be removed soon when api-platform removes these services
+    # see vendor/api-platform/core/src/Symfony/Bundle/Resources/config/metadata/property.xml:41
+    api_platform.cache.metadata.identifier:
+        parent: cache.adapter.array
+        tags: [ cache.pool ]
+    api_platform.metadata.property.identifier_metadata_factory.cached:
+        class: ApiPlatform\Metadata\Property\Factory\CachedPropertyMetadataFactory
+        decorates: api_platform.metadata.property.identifier_metadata_factory
+        decoration_priority: 99
+        arguments:
+            - '@api_platform.cache.metadata.identifier'
+            - '@api_platform.metadata.property.identifier_metadata_factory.cached.inner'
+
+    ########### End Speeds up api-platform cache build substantially ###########
+
     # default configuration for services in *this* file
     _defaults:
         autowire: true      # Automatically injects dependencies in your services.

+ 5 - 1
src/Service/File/FileManager.php

@@ -4,6 +4,8 @@ declare(strict_types=1);
 namespace App\Service\File;
 
 use ApiPlatform\Api\IriConverterInterface;
+use ApiPlatform\Api\UrlGeneratorInterface;
+use ApiPlatform\Metadata\Get;
 use App\ApiResources\DownloadRequest;
 use App\Entity\Core\File;
 use App\Enum\Core\FileHostEnum;
@@ -72,8 +74,10 @@ class FileManager
      */
     public function getDownloadIri(File $file): string
     {
-        return $this->iriConverter->getItemIriFromResourceClass(
+        return $this->iriConverter->getIriFromResource(
             DownloadRequest::class,
+            UrlGeneratorInterface::ABS_PATH,
+            new Get(),
             ['fileId' => $file->getId()]
         );
     }

+ 1 - 1
src/Service/MercureHub.php

@@ -53,7 +53,7 @@ class MercureHub
         }
 
         $data = $this->encoder->encode([
-            'iri' => $this->iriConverter->getIriFromItem($entity),
+            'iri' => $this->iriConverter->getIriFromResource($entity),
             'operation' => $operationType,
             'data' => $this->serializer->serialize($entity, 'jsonld')
         ], 'jsonld');

+ 0 - 64
tests/AuthentificationTest.php

@@ -1,64 +0,0 @@
-<?php
-
-// tests/AuthenticationTest.php
-
-namespace App\Tests;
-
-use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
-use App\Entity\Access\Access;
-use App\Entity\Organization\Organization;
-use App\Entity\Person\Person;
-use Hautelook\AliceBundle\PhpUnit\ReloadDatabaseTrait;
-
-class AuthentificationTest extends ApiTestCase
-{
-    use ReloadDatabaseTrait;
-
-    public function testLogin(): void
-    {
-        $client = self::createClient();
-        $container = self::getContainer();
-
-        $organization = new Organization();
-        $access = new Access();
-
-        $user = new Person();
-        $user->setUsername('foo');
-        $user->setPassword(
-            $container->get('security.user_password_hasher')->hashPassword($user, '$3CR3T')
-        );
-
-        $access->setPerson($user);
-        $organization->addAccess($access);
-
-        $manager = $container->get('doctrine')->getManager();
-        $manager->persist($organization);
-        $manager->flush();
-
-        // retrieve a token
-        $response = $client->request('POST', '/login_check', [
-            'headers' => ['Content-Type' => 'application/json'],
-            'json' => [
-                'username' => 'foo',
-                'password' => '$3CR3T',
-            ],
-        ]);
-
-        $json = $response->toArray();
-        self::assertResponseIsSuccessful();
-        $this->assertArrayHasKey('token', $json);
-
-        // test not authorized
-        $client->request('GET', '/my_profile/1');
-        self::assertResponseStatusCodeSame(401);
-
-        // test authorized
-        $client->request('GET', '/my_profile/1',
-            [
-                'Content-Type' => 'application/ld+json',
-                'authorization' => sprintf('BEARER %s', $json['token']),
-                'x-accessid' => 1
-            ]);
-        self::assertResponseIsSuccessful();
-    }
-}

+ 5 - 3
tests/Service/File/FileManagerTest.php

@@ -2,7 +2,9 @@
 
 namespace App\Tests\Service\File;
 
-use ApiPlatform\Core\Api\IriConverterInterface;
+use ApiPlatform\Api\IriConverterInterface;
+use ApiPlatform\Api\UrlGeneratorInterface;
+use ApiPlatform\Metadata\Get;
 use App\ApiResources\DownloadRequest;
 use App\Entity\Core\File;
 use App\Enum\Core\FileHostEnum;
@@ -121,8 +123,8 @@ class FileManagerTest extends TestCase
 
         $this->iriConverter
             ->expects(self::once())
-            ->method('getItemIriFromResourceClass')
-            ->with(DownloadRequest::class, ['fileId' => 1])
+            ->method('getIriFromResource')
+            ->with(DownloadRequest::class, UrlGeneratorInterface::ABS_PATH, new Get(),['fileId' => 1])
             ->willReturn('/api/download/1');
 
         $this->assertEquals(

+ 2 - 2
tests/Service/MercureHubTest.php

@@ -2,7 +2,7 @@
 
 namespace App\Tests\Service;
 
-use ApiPlatform\Core\Api\IriConverterInterface;
+use ApiPlatform\Api\IriConverterInterface;
 use App\Entity\Organization\Organization;
 use App\Service\MercureHub;
 use PHPUnit\Framework\TestCase;
@@ -59,7 +59,7 @@ class MercureHubTest extends TestCase
 
         $entity = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
 
-        $this->iriConverter->expects(self::once())->method('getIriFromItem')->with($entity)->willReturn('/api/entity/1');
+        $this->iriConverter->expects(self::once())->method('getIriFromResource')->with($entity)->willReturn('/api/entity/1');
         $this->serializer->expects(self::once())->method('serialize')->with($entity, 'jsonld', [])->willReturn("{'foo': 1}");
 
         $this->encoder