public function testNormalize()
 {
     $collection = new Collection();
     $collection->setId('foo');
     $folder = new Folder();
     $folder->setId('bar');
     $request = new Request();
     $request->setId(42);
     $request->setName('Get users list');
     $request->setCollection($collection);
     $request->setDataMode(Request::DATA_MODE_RAW);
     $request->setDescription('This request returns a users list');
     $request->setFolder($folder);
     $request->setFromCollection(true);
     $request->addHeader('Authorization', 'Bearer access-token-admin');
     $request->addTest(new Test('Successful GET request', 'responseCode.code === 200'));
     $request->setResource($this->prophesize('Dunglas\\ApiBundle\\Api\\ResourceInterface')->reveal());
     $request->setMethod('GET');
     $request->setUrl('http://127.0.0.1/users');
     $request->setTime(12345);
     $normalizer = new RequestNormalizer();
     $this->assertEquals(['id' => 42, 'url' => 'http://127.0.0.1/users', 'method' => 'GET', 'tests' => 'tests["Successful GET request"] = responseCode.code === 200;', 'folder' => 'bar', 'name' => 'Get users list', 'description' => 'This request returns a users list', 'preRequestScript' => '', 'pathVariables' => new \stdClass(), 'data' => [], 'dataMode' => 'raw', 'rawModeData' => '{}', 'version' => 2, 'currentHelper' => 'normal', 'helperAttributes' => new \stdClass(), 'time' => 12345, 'fromCollection' => true, 'collectionRequest' => null, 'collectionId' => 'foo', 'headers' => "Authorization: Bearer access-token-admin\n"], $normalizer->normalize($request, 'json'));
     $request->setRawModeData(['foo' => 'bar']);
     $this->assertEquals(['id' => 42, 'url' => 'http://127.0.0.1/users', 'method' => 'GET', 'tests' => 'tests["Successful GET request"] = responseCode.code === 200;', 'folder' => 'bar', 'name' => 'Get users list', 'description' => 'This request returns a users list', 'preRequestScript' => '', 'pathVariables' => new \stdClass(), 'data' => [], 'dataMode' => 'raw', 'rawModeData' => "{\n    \"foo\":\"bar\"\n}", 'version' => 2, 'currentHelper' => 'normal', 'helperAttributes' => new \stdClass(), 'time' => 12345, 'fromCollection' => true, 'collectionRequest' => null, 'collectionId' => 'foo', 'headers' => "Authorization: Bearer access-token-admin\n"], $normalizer->normalize($request, 'json'));
 }
 /**
  * {@inheritdoc}
  */
 public function parse(Request $request)
 {
     $shortName = Inflector::camelize($request->getResource()->getShortName());
     switch ($request->getMethod()) {
         case 'POST':
             $request->setName(sprintf('Create %s', $shortName));
             break;
         case 'PUT':
         case 'PATCH':
             $request->setName(sprintf('Update %s', $shortName));
             break;
         case 'DELETE':
             $request->setName(sprintf('Delete %s', $shortName));
             break;
         case 'GET':
             if (!preg_match(UriRequestParser::PATTERN, $request->getUrl())) {
                 $shortName = Inflector::pluralize($shortName) . ' list';
             }
             $request->setName(sprintf('Get %s', $shortName));
             break;
     }
 }
 /**
  * {@inheritdoc}
  *
  * @return Request[]
  */
 public function generate(ResourceInterface $resource = null)
 {
     /** @var OperationInterface[] $operations */
     $operations = array_merge($resource->getCollectionOperations(), $resource->getItemOperations());
     $requests = [];
     foreach ($operations as $operation) {
         $route = $operation->getRoute();
         foreach ($route->getMethods() as $method) {
             $request = new Request();
             $request->setResource($resource);
             $request->setId((string) Uuid::uuid4());
             $request->setUrl($this->baseUrl . $route->getPath());
             $request->setMethod($method);
             if (isset($operation->getContext()['hydra:title'])) {
                 $request->setName($operation->getContext()['hydra:title']);
             }
             $this->requestParser->parse($request);
             $requests[] = $request;
         }
     }
     return $requests;
 }