Skip to content

Commit

Permalink
Extract common mock chain from dkan_metastore service test (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrydallacroce authored Dec 4, 2019
1 parent e4751f1 commit 6274d9a
Showing 1 changed file with 23 additions and 55 deletions.
78 changes: 23 additions & 55 deletions modules/custom/dkan_metastore/tests/src/Unit/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ class ServiceTest extends TestCase {
*
*/
public function testGetSchemas() {
$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "getAllIds", ["1"])
->add(SchemaRetriever::class, "retrieve", json_encode("blah"));
$container = $this->getCommonMockChain()
->add(SchemaRetriever::class, "getAllIds", ["1"]);

$service = Service::create($container->getMock());
$this->assertEquals(json_encode(["1" => "blah"]), json_encode($service->getSchemas()));
Expand All @@ -36,12 +31,7 @@ public function testGetSchemas() {
*
*/
public function testGetSchema() {
$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"));
$container = $this->getCommonMockChain();

$service = Service::create($container->getMock());
$this->assertEquals(json_encode("blah"), json_encode($service->getSchema("1")));
Expand All @@ -51,12 +41,7 @@ public function testGetSchema() {
*
*/
public function testGetAll() {
$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"))
$container = $this->getCommonMockChain()
->add(Sae::class, "getInstance", Engine::class)
->add(Engine::class, "get", [json_encode("blah")]);

Expand All @@ -69,12 +54,7 @@ public function testGetAll() {
*
*/
public function testGet() {
$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"))
$container = $this->getCommonMockChain()
->add(Sae::class, "getInstance", Engine::class)
->add(Engine::class, "get", json_encode("blah"));

Expand All @@ -94,12 +74,7 @@ public function testGetResources() {
],
];

$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"))
$container = $this->getCommonMockChain()
->add(Sae::class, "getInstance", Engine::class)
->add(Engine::class, "get", json_encode($dataset));

Expand All @@ -113,12 +88,7 @@ public function testGetResources() {
*
*/
public function testPost() {
$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"))
$container = $this->getCommonMockChain()
->add(Sae::class, "getInstance", Engine::class)
->add(Engine::class, "post", "1");

Expand All @@ -131,12 +101,7 @@ public function testPost() {
*
*/
public function testPut() {
$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"))
$container = $this->getCommonMockChain()
->add(Sae::class, "getInstance", Engine::class)
->add(Engine::class, "put", "1")
->add(Engine::class, "get", "1");
Expand All @@ -151,12 +116,7 @@ public function testPut() {
*
*/
public function testPatch() {
$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"))
$container = $this->getCommonMockChain()
->add(Sae::class, "getInstance", Engine::class)
->add(Engine::class, "patch", "1")
->add(Engine::class, "get", "1");
Expand All @@ -170,12 +130,7 @@ public function testPatch() {
*
*/
public function testDelete() {
$container = (new Chain($this))
->add(Container::class, "get", (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class)
)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"))
$container = $this->getCommonMockChain()
->add(Sae::class, "getInstance", Engine::class)
->add(Engine::class, "delete", "1")
->add(Engine::class, "get", "1");
Expand All @@ -185,4 +140,17 @@ public function testDelete() {
$this->assertEquals("1", $service->delete("dataset", "1"));
}

/**
* @return \Drupal\dkan_common\Tests\Mock\Chain
*/
public function getCommonMockChain() {
$options = (new Options())
->add('dkan_schema.schema_retriever', SchemaRetriever::class)
->add('dkan_metastore.sae_factory', Sae::class);

return (new Chain($this))
->add(Container::class, "get", $options)
->add(SchemaRetriever::class, "retrieve", json_encode("blah"));
}

}

0 comments on commit 6274d9a

Please sign in to comment.