diff --git a/README.md b/README.md index 4dd527c..15de69e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/composer.json b/composer.json index 6585293..d6d6c7e 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,6 @@ "require": { "php": ">=7.3", "ext-json": "*", - "ext-yaml": "*", "cocur/slugify": "^4.0", "guzzlehttp/guzzle": "^6.5", "psr/cache": "^1.0", diff --git a/src/ImgFinder/Config.php b/src/ImgFinder/Config.php index ccde924..ba030a3 100644 --- a/src/ImgFinder/Config.php +++ b/src/ImgFinder/Config.php @@ -78,12 +78,6 @@ public function repository(): RepositoryService } - public function repositoryNames(): iterable - { - return $this->repositoryService->names(); - } - - private function __construct() { } diff --git a/src/ImgFinder/ImgFinder.php b/src/ImgFinder/ImgFinder.php index 0a5d46e..a6b3a64 100644 --- a/src/ImgFinder/ImgFinder.php +++ b/src/ImgFinder/ImgFinder.php @@ -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(); + } } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 9b1c99c..269fc96 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -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); @@ -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()); } } diff --git a/tests/ImgFinderTest.php b/tests/ImgFinderTest.php index 70772a6..2ca3f82 100644 --- a/tests/ImgFinderTest.php +++ b/tests/ImgFinderTest.php @@ -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 */