5 use Drupal\Core\Extension\Extension;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use PHPUnit\Framework\TestCase;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10 use Symfony\Component\HttpFoundation\Request;
11 use Symfony\Component\HttpFoundation\RequestStack;
13 use MockChain\Options;
26 $response = $controller->getVersions();
28 $spec =
'{"version":1,"url":"\/api\/1"}';
30 $this->assertEquals($spec, $response->getContent());
38 ->add(RequestStack::class,
'getCurrentRequest', Request::class)
39 ->add(Request::class,
'get', NULL);
41 $spec =
'{"openapi":"3.0.1","info":{"title":"API Documentation","version":"Alpha"},"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic"}}},"paths":{"\/api\/1\/metastore\/schemas\/dataset\/items\/{identifier}":{"get":{"summary":"Get this dataset","tags":["Dataset"],"parameters":[{"name":"identifier","in":"path","description":"Dataset uuid","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Ok"}}},"delete":{"summary":"This operation should not be present in dataset-specific docs.","security":[{"basicAuth":[]}],"responses":{"200":{"description":"Ok"}}},"post":null},"\/api\/1\/some\/other\/path":{"patch":{"summary":"This path and operation should not be present in dataset-specific docs.","security":[{"basicAuth":[]}],"responses":{"200":{"description":"Ok"}}}}}}';
44 $response = $controller->getComplete();
46 $this->assertEquals($spec, $response->getContent());
54 ->add(RequestStack::class,
'getCurrentRequest', Request::class)
55 ->add(Request::class,
'get',
'false');
57 $spec =
'{"openapi":"3.0.1","info":{"title":"API Documentation","version":"Alpha"},"components":[],"paths":{"\/api\/1\/metastore\/schemas\/dataset\/items\/{identifier}":{"get":{"summary":"Get this dataset","tags":["Dataset"],"parameters":[{"name":"identifier","in":"path","description":"Dataset uuid","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Ok"}}},"post":null}}}';
60 $response = $controller->getComplete();
62 $this->assertEquals($spec, $response->getContent());
69 $options = (
new Options())
70 ->add(
'module_handler', ModuleHandlerInterface::class)
71 ->add(
'request_stack', RequestStack::class)
74 $mockChain = (
new Chain($this))
75 ->add(ContainerInterface::class,
'get', $options)
76 ->add(ModuleHandlerInterface::class,
'getModule', Extension::class)
77 ->add(Extension::class,
'getPath', __DIR__);