Skip to content

Commit

Permalink
Added method imgFinder:repositories() to return all available reposit…
Browse files Browse the repository at this point in the history
…ories
  • Loading branch information
ginfarma committed Dec 22, 2020
1 parent 78b30da commit 31abf1e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ $imagesUrls = $response->toArray();
*/
```

## Show all public repositories

To show all available repositories.

```php
...

$finder = new ImgFinder($config);
$finder->repositories();

/**
array:10 [
0 => "pexels"
1 => "unsplash"
]
*/

```

## Cache optional

If you wish, you can cache requests to improve performance and not stress the image repositories.
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"require": {
"php": ">=7.3",
"ext-json": "*",
"ext-yaml": "*",
"cocur/slugify": "^4.0",
"guzzlehttp/guzzle": "^6.5",
"psr/cache": "^1.0",
Expand Down
6 changes: 0 additions & 6 deletions src/ImgFinder/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ public function repository(): RepositoryService
}


public function repositoryNames(): iterable
{
return $this->repositoryService->names();
}


private function __construct()
{
}
Expand Down
13 changes: 13 additions & 0 deletions src/ImgFinder/ImgFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,23 @@ public function __construct(Config $config)
}


/**
* @param RequestInterface $request
* @return ResponseInterface
*/
public function search(RequestInterface $request): ResponseInterface
{
$request = $this->translator->translate($request);

return $this->imgRepo->findImages($request);
}


/**
* @return string[]
*/
public function repositories(): iterable
{
return $this->imgRepo->names();
}
}
14 changes: 9 additions & 5 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
use ImgFinder\Service\RepositoryService;
use ImgFinder\Service\TranslatorService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;

class ConfigTest extends TestCase
{
/**
* @test
*/
public function it_should_make_config_instance()
public function it_should_make_config_instance_from_yml_file()
{
$yaml = __DIR__ . '/../doc/examples/config.yml';
$config = Config::fromYaml($yaml);
Expand All @@ -28,11 +29,14 @@ public function it_should_make_config_instance()
/**
* @test
*/
public function it_should_return_repository_names()
public function it_should_make_config_instance_from_array()
{
$yaml = __DIR__ . '/../doc/examples/config.yml';
$config = Config::fromYaml($yaml);
$yaml = __DIR__ . '/../doc/examples/config.yml';
$settings = Yaml::parseFile($yaml);
$config = Config::fromArray($settings);

self::assertSame(['spy-repository'], $config->repositoryNames());
self::assertInstanceOf(Config::class, $config);
self::assertInstanceOf(RepositoryService::class, $config->repository());
self::assertInstanceOf(TranslatorService::class, $config->translator());
}
}
13 changes: 13 additions & 0 deletions tests/ImgFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ public function it_should_search_images()
}


/**
* @test
*/
public function it_should_return_repository_names()
{
$yaml = __DIR__ . '/../doc/examples/config.yml';
$config = Config::fromYaml($yaml);
$finder = new ImgFinder($config);

self::assertSame(['spy-repository'], $finder->repositories());
}


/**
* @return Config
*/
Expand Down

0 comments on commit 31abf1e

Please sign in to comment.