Open Data Catalog v2.0.0
ImporterListTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Dkan\Datastore\Importer;
4 use Dkan\Datastore\Resource;
7 use Drupal\dkan_datastore\Service\Resource as ResourceService;
9 use MockChain\Sequence;
10 use FileFetcher\FileFetcher;
11 use MockChain\Chain;
12 use MockChain\Options;
13 use PHPUnit\Framework\TestCase;
14 use Procrastinator\Result;
17 use Drupal\dkan_datastore\Service\Import as ImportService;
18 
22 class ImporterListTest extends TestCase {
23 
27  public function test() {
28 
29  $options = (new Options())
30  ->add('total_bytes_copied', 20)
31  ->add('total_bytes', 30)
32  ->add("hello", "hello")
33  ->add("source", "hello")
34  ->index(0);
35 
36  $fileFetcher = (new Chain($this))
37  ->add(FileFetcher::class, "getStateProperty", $options)
38  ->add(FileFetcher::class, "getResult", Result::class)
39  ->add(Result::class, "getStatus", Result::DONE)
40  ->getMock();
41 
42  $sequence = new Sequence();
43  $sequence->add(["1"]);
44  $sequence->add([]);
45 
46  $jobStore = (new Chain($this))
47  ->add(JobStore::class, "retrieveAll", $sequence)
48  ->getMock();
49 
50  $jobStoreFactory = (new Chain($this))
51  ->add(JobStoreFactory::class, "getInstance", $jobStore)
52  ->getMock();
53 
54  $resourceServiceFactory = (new Chain($this))
55  ->add(ResourceFactory::class, "getInstance", ResourceService::class)
56  ->add(ResourceService::class, "getFileFetcher", $fileFetcher)
57  ->add(ResourceService::class, "get", new Resource("blah", "", "text/csv"))
58  ->getMock();
59 
60  $importServiceFactory = (new Chain($this))
61  ->add(ImportFactory::class, "getInstance", ImportService::class)
62  ->add(ImportService::class, "getImporter", Importer::class)
63  ->getMock();
64 
65  $list = ImporterList::getList($jobStoreFactory, $resourceServiceFactory, $importServiceFactory);
66  $this->assertTrue(is_array($list));
67  }
68 
69 }
Drupal\dkan_datastore\Service\Factory\Resource
Definition: Resource.php:16
Drupal\dkan_datastore\Service\Resource
Definition: Resource.php:16
ImporterListTest
Definition: ImporterListTest.php:22
ImporterListTest\test
test()
Definition: ImporterListTest.php:27
Drupal\dkan_datastore\Storage\JobStore
Definition: JobStore.php:12
Drupal\dkan_datastore\Service\Factory\Import
Definition: Import.php:15
Drupal\dkan_datastore\Service\Import
Definition: Import.php:16
Drupal\dkan_datastore\Service\ImporterList\ImporterList
Definition: ImporterList.php:13
Drupal\dkan_datastore\Storage\JobStoreFactory
Definition: JobStoreFactory.php:11