コード例 #1
0
 /** @test */
 public function itShouldLoadASchemaFromACacheStore()
 {
     $schemaFile = 'file://fake-schema.yml';
     $schema = $this->prophesize(Schema::class);
     $item = $this->prophesize(CacheItemInterface::class);
     $item->isHit()->shouldBeCalled()->willReturn(true);
     $item->get()->shouldBeCalled()->willReturn($schema);
     $cache = $this->prophesize(CacheItemPoolInterface::class);
     $cache->getItem('3f470a326a5926a2e323aaadd767c0e64302a080')->willReturn($item);
     $schemaFactory = $this->prophesize(SchemaFactory::class);
     $schemaFactory->createSchema(Argument::any())->shouldNotBeCalled();
     $cachedSchema = new CachedSchemaFactoryDecorator($cache->reveal(), $schemaFactory->reveal());
     $expectedSchema = $schema->reveal();
     $actualSchema = $cachedSchema->createSchema($schemaFile);
     assertThat($actualSchema, isInstanceOf(Schema::class));
     assertThat($actualSchema, equalTo($expectedSchema));
 }
コード例 #2
0
 public function build($schemaPath)
 {
     // Build serializer
     if ($this->serializer === null) {
         if (empty($this->encoders)) {
             $this->encoders = [new JsonEncoder(), new XmlEncoder()];
         }
         if (empty($this->denormalizers)) {
             $this->denormalizers[] = new ResourceDenormalizer($this->paginationProvider);
         }
         $this->serializer = new Serializer($this->denormalizers, $this->encoders);
     }
     if ($this->uriFactory === null) {
         $this->uriFactory = UriFactoryDiscovery::find();
     }
     if ($this->messageFactory === null) {
         $this->messageFactory = MessageFactoryDiscovery::find();
     }
     if ($this->httpClient === null) {
         $this->httpClient = HttpClientDiscovery::find();
     }
     $schemaFactory = new SwaggerSchemaFactory();
     if ($this->cache !== null) {
         $schemaFactory = new CachedSchemaFactoryDecorator($this->cache, $schemaFactory);
     }
     $this->schema = $schemaFactory->createSchema($schemaPath);
     if (!isset($this->requestValidator)) {
         $this->requestValidator = new MessageValidator(new Validator(), new SymfonyDecoderAdapter(new ChainDecoder($this->encoders)));
     }
     return new ApiService($this->uriFactory, new UriTemplate(), $this->httpClient, $this->messageFactory, $this->schema, $this->requestValidator, $this->serializer, $this->config);
 }