Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: similar to functions added #56

Merged
merged 3 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSql NOT SIMILAR TO.
*
* @see https://www.postgresql.org/docs/9.6/functions-matching.html
*
* @author Igor Lazarev <strider2038@yandex.ru>
*/
class NotSimilarTo extends BaseFunction
{
protected function customiseFunction(): void
{
$this->setFunctionPrototype('%s not similar to %s');
$this->addNodeMapping('StringPrimary');
$this->addNodeMapping('StringPrimary');
}
}
22 changes: 22 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/SimilarTo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSql SIMILAR TO.
*
* @see https://www.postgresql.org/docs/9.6/functions-matching.html
*
* @author Igor Lazarev <strider2038@yandex.ru>
*/
class SimilarTo extends BaseFunction
{
protected function customiseFunction(): void
{
$this->setFunctionPrototype('%s similar to %s');
$this->addNodeMapping('StringPrimary');
$this->addNodeMapping('StringPrimary');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Tests\Doctrine\ORM\Query\AST\Functions;

use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\NotSimilarTo;
use MartinGeorgiev\Tests\Doctrine\Fixtures\Entity\ContainsText;

class NotSimilarToTest extends TestCase
{
protected function getStringFunctions(): array
{
return [
'NOT_SIMILAR_TO' => NotSimilarTo::class,
];
}

protected function getExpectedSqlStatements(): array
{
return [
"SELECT c0_.text not similar to 'TEST' AS sclr_0 FROM ContainsText c0_",
];
}

protected function getDqlStatements(): array
{
return [
\sprintf("SELECT NOT_SIMILAR_TO(e.text,'TEST') FROM %s e", ContainsText::class),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Tests\Doctrine\ORM\Query\AST\Functions;

use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\SimilarTo;
use MartinGeorgiev\Tests\Doctrine\Fixtures\Entity\ContainsText;

class SimilarToTest extends TestCase
{
protected function getStringFunctions(): array
{
return [
'SIMILAR_TO' => SimilarTo::class,
];
}

protected function getExpectedSqlStatements(): array
{
return [
"SELECT c0_.text similar to 'TEST' AS sclr_0 FROM ContainsText c0_",
];
}

protected function getDqlStatements(): array
{
return [
\sprintf("SELECT SIMILAR_TO(e.text,'TEST') FROM %s e", ContainsText::class),
];
}
}