public function testNormalize() { $collection = new Collection(); $collection->setId('foo'); $request = new Request(); $request->setId(42); $folder = new Folder(); $folder->setId('bar'); $folder->setCollection($collection); $folder->setName('Foo'); $folder->setRequests([$request]); $normalizer = new FolderNormalizer(); $this->assertEquals(['id' => 'bar', 'collectionId' => 'foo', 'name' => 'Foo', 'owner' => 0, 'order' => [42]], $normalizer->normalize($folder, 'json')); }
/** * {@inheritdoc} */ public function parse(Request $request) { switch ($request->getMethod()) { case 'POST': $request->addTest(new Test('Successful POST request', 'responseCode.code === 201 || responseCode.code === 202')); $request->addTest(new Test('Content-Type is correct', 'postman.getResponseHeader("Content-Type") === "application/ld+json"')); break; case 'PUT': case 'PATCH': case 'GET': $request->addTest(new Test(sprintf('Successful %s request', $request->getMethod()), 'responseCode.code === 200')); $request->addTest(new Test('Content-Type is correct', 'postman.getResponseHeader("Content-Type") === "application/ld+json"')); break; case 'DELETE': $request->addTest(new Test('Successful DELETE request', 'responseCode.code === 204')); 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; }
/** * {@inheritdoc} */ public function parse(Request $request) { $request->addHeader('Authorization', 'Bearer {{oauth2_access_token}}'); }
/** * {@inheritdoc} */ public function supports(Request $request) { return null === $request->getName(); }
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 supports(Request $request) { return in_array($request->getMethod(), ['POST', 'PUT', 'PATCH']); }
/** * {@inheritdoc} */ public function supports(Request $request) { return 1 === preg_match(self::PATTERN, $request->getUrl()); }