diff --git a/packages/seal/src/Adapter/AdapterFactory.php b/packages/seal/src/Adapter/AdapterFactory.php index 51e1ff5a..4e050584 100644 --- a/packages/seal/src/Adapter/AdapterFactory.php +++ b/packages/seal/src/Adapter/AdapterFactory.php @@ -87,7 +87,7 @@ public function parseDsn(string $dsn): array if (\str_contains($dsn, ':///')) { // make DSN like loupe:///full/path/project/var/indexes parseable - $dsn = \str_replace(':///', '://' . $adapterName . '/', $dsn); + $dsn = \str_replace(':///', '://' . $adapterName . '/', $dsn . $query); } else { $dsn = $dsn . '@' . $adapterName . $query; } diff --git a/packages/seal/tests/Adapter/AdapterFactoryTest.php b/packages/seal/tests/Adapter/AdapterFactoryTest.php new file mode 100644 index 00000000..d4a5120b --- /dev/null +++ b/packages/seal/tests/Adapter/AdapterFactoryTest.php @@ -0,0 +1,180 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Adapter; + +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\TestCase; +use Schranz\Search\SEAL\Adapter\AdapterFactory; +use Schranz\Search\SEAL\Adapter\AdapterFactoryInterface; +use Schranz\Search\SEAL\Adapter\AdapterInterface; + +#[CoversClass(AdapterFactory::class)] +class AdapterFactoryTest extends TestCase +{ + private AdapterFactory $adapterFactory; + + protected function setUp(): void + { + $this->adapterFactory = new AdapterFactory([ + 'scheme' => $this->createAdapterFactory('scheme'), + ]); + } + + /** + * @param array{ + * scheme: string, + * host: string, + * port?: int, + * user?: string, + * pass?: string, + * path?: string, + * query: array, + * fragment?: string, + * } $expectedResult + */ + #[DataProvider('provideDsn')] + public function testParseDsn(string $dsn, array $expectedResult): void + { + $parsedDsn = $this->adapterFactory->parseDsn($dsn); + + $this->assertSame($expectedResult, $parsedDsn); + } + + public function testAdapterNotFound(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown Search adapter: "not-found" available adapters are "scheme".'); + + $this->adapterFactory->parseDsn('not-found://host:1234'); + } + + public function testInvalidDsn(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid DSN: "".'); + + $this->adapterFactory->parseDsn(''); + } + + /** + * @return \Generator, + * fragment?: string, + * }}> + */ + public static function provideDsn(): \Generator + { + yield 'standard' => [ + 'scheme://host:1234', + [ + 'scheme' => 'scheme', + 'host' => 'host', + 'port' => 1234, + 'query' => [], + ], + ]; + + yield 'standard_full' => [ + 'scheme://user:pass@host:1234/path?queryKey=queryValue#fragment', + [ + 'scheme' => 'scheme', + 'host' => 'host', + 'port' => 1234, + 'user' => 'user', + 'pass' => 'pass', + 'path' => '/path', + 'query' => [ + 'queryKey' => 'queryValue', + ], + 'fragment' => 'fragment', + ], + ]; + + yield 'only_username_password' => [ + 'scheme://user:pass', + [ + 'scheme' => 'scheme', + 'host' => '', + 'user' => 'user', + 'pass' => 'pass', + 'query' => [], + ], + ]; + + yield 'only_username_password_with_query' => [ + 'scheme://user:pass?queryKey=queryValue#fragment', + [ + 'scheme' => 'scheme', + 'host' => '', + 'user' => 'user', + 'pass' => 'pass', + 'query' => [ + 'queryKey' => 'queryValue', + ], + 'fragment' => 'fragment', + ], + ]; + + yield 'path' => [ + 'scheme:///var/data/directory', + [ + 'scheme' => 'scheme', + 'host' => '', + 'path' => '/var/data/directory', + 'query' => [], + ], + ]; + + yield 'path_with_query' => [ + 'scheme:///var/data/directory?queryKey=queryValue#fragment', + [ + 'scheme' => 'scheme', + 'host' => '', + 'path' => '/var/data/directory', + 'query' => [ + 'queryKey' => 'queryValue', + ], + 'fragment' => 'fragment', + ], + ]; + } + + private function createAdapterFactory(string $name): AdapterFactoryInterface + { + $adapterFactory = new class() implements AdapterFactoryInterface { + public static string $name; + + public function createAdapter(array $dsn): AdapterInterface + { + throw new \Exception('Not implemented'); + } + + public static function getName(): string + { + return static::$name; + } + }; + + $adapterFactory::$name = $name; + + return $adapterFactory; + } +} diff --git a/packages/seal/tests/Marshaller/FlattenMarshallerTest.php b/packages/seal/tests/Marshaller/FlattenMarshallerTest.php index 5388b782..5b630539 100644 --- a/packages/seal/tests/Marshaller/FlattenMarshallerTest.php +++ b/packages/seal/tests/Marshaller/FlattenMarshallerTest.php @@ -13,11 +13,13 @@ namespace Schranz\Search\SEAL\Tests\Marshaller; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Schranz\Search\SEAL\Marshaller\FlattenMarshaller; use Schranz\Search\SEAL\Schema\Field; +#[CoversClass(FlattenMarshaller::class)] class FlattenMarshallerTest extends TestCase { /** diff --git a/packages/seal/tests/Marshaller/MarshallerTest.php b/packages/seal/tests/Marshaller/MarshallerTest.php index a7671fca..8366498d 100644 --- a/packages/seal/tests/Marshaller/MarshallerTest.php +++ b/packages/seal/tests/Marshaller/MarshallerTest.php @@ -13,10 +13,12 @@ namespace Schranz\Search\SEAL\Tests\Marshaller; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Schranz\Search\SEAL\Marshaller\Marshaller; use Schranz\Search\SEAL\Testing\TestingHelper; +#[CoversClass(Marshaller::class)] class MarshallerTest extends TestCase { public function testMarshall(): void diff --git a/packages/seal/tests/Schema/IndexTest.php b/packages/seal/tests/Schema/IndexTest.php index ced0483f..014a0dc8 100644 --- a/packages/seal/tests/Schema/IndexTest.php +++ b/packages/seal/tests/Schema/IndexTest.php @@ -13,11 +13,13 @@ namespace Schranz\Search\SEAL\Tests\Schema; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Schranz\Search\SEAL\Schema\Field; use Schranz\Search\SEAL\Schema\Index; +#[CoversClass(Index::class)] class IndexTest extends TestCase { public function testIndex(): void diff --git a/packages/seal/tests/Schema/Loader/PhpFileLoaderTest.php b/packages/seal/tests/Schema/Loader/PhpFileLoaderTest.php index 8668325c..1b585473 100644 --- a/packages/seal/tests/Schema/Loader/PhpFileLoaderTest.php +++ b/packages/seal/tests/Schema/Loader/PhpFileLoaderTest.php @@ -13,10 +13,12 @@ namespace Schranz\Search\SEAL\Tests\Schema\Loader; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Schranz\Search\SEAL\Schema\Field; use Schranz\Search\SEAL\Schema\Loader\PhpFileLoader; +#[CoversClass(PhpFileLoader::class)] class PhpFileLoaderTest extends TestCase { public function testLoadBasic(): void