Commit 56208ab2 authored by François Agneray's avatar François Agneray
Browse files

Add operators tests

parent f2a88e57
Pipeline #5121 passed with stages
in 2 minutes and 51 seconds
......@@ -61,7 +61,7 @@ class JsonPostgres extends Operator
default:
$expr = '';
}
return $$expr;
return $expr;
}
private function getColumn(): string
......
......@@ -16,7 +16,6 @@ use PHPUnit\Framework\TestCase;
use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\Response;
use Slim\Exception\HttpNotFoundException;
use Slim\Exception\HttpBadRequestException;
use App\tests\EntityManagerBuilder;
use App\Entity\Database;
use App\Entity\Project;
......
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\Between;
final class BetweenTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('gte')
->willReturn('test >= 10');
$expr->method('lte')
->willReturn('test <= 20');
$this->operator = new Between($expr, 'test', 'integer', '10', '20');
}
public function testGetExpression(): void
{
$this->assertSame('(test >= 10) AND (test <= 20)', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\Equal;
final class EqualTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('eq')
->willReturn('test = 10');
$this->operator = new Equal($expr, 'test', 'integer', '10');
}
public function testGetExpression(): void
{
$this->assertSame('test = 10', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\GreaterThanEqual;
final class GreaterThanEqualTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('gte')
->willReturn('test >= 10');
$this->operator = new GreaterThanEqual($expr, 'test', 'integer', '10');
}
public function testGetExpression(): void
{
$this->assertSame('test >= 10', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\GreaterThan;
final class GreaterThanTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('gt')
->willReturn('IN (10, 20, 30)');
$this->operator = new GreaterThan($expr, 'test', 'integer', '10');
}
public function testGetExpression(): void
{
$this->assertSame('IN (10, 20, 30)', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\In;
final class InTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('in')
->willReturn('test IN(10, 20, 30)');
$this->operator = new In($expr, 'test', 'integer', array('10', '20', '30'));
}
public function testGetExpression(): void
{
$this->assertSame('test IN(10, 20, 30)', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\LessThanEqual;
final class LessThanEqualTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('lte')
->willReturn('test <= 10');
$this->operator = new LessThanEqual($expr, 'test', 'integer', '10');
}
public function testGetExpression(): void
{
$this->assertSame('test <= 10', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\LessThan;
final class LessThanTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('lt')
->willReturn('test < 10');
$this->operator = new LessThan($expr, 'test', 'integer', '10');
}
public function testGetExpression(): void
{
$this->assertSame('test < 10', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\Like;
use Doctrine\DBAL\Connection;
final class LikeTest extends TestCase
{
private $operator;
protected function setUp(): void
{
// $connection = $this->createMock(Connection::class);
// $connection->method('quote')
// ->willReturn('\'%toto%\'');
// $expr = new ExpressionBuilder($connection);
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('like')
->willReturn('CAST(test AS text) LIKE \'%toto%\'');
$this->operator = new Like($expr, 'test', 'string', 'toto');
}
public function testGetExpression(): void
{
$this->assertSame('CAST(test AS text) LIKE \'%toto%\'', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\NotEqual;
final class NotEqualTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('neq')
->willReturn('test <> 10');
$this->operator = new NotEqual($expr, 'test', 'integer', '10');
}
public function testGetExpression(): void
{
$this->assertSame('test <> 10', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\NotIn;
final class NotInTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('notIn')
->willReturn('NOT IN(10, 20, 30)');
$this->operator = new NotIn($expr, 'test', 'integer', array('10', '20', '30'));
}
public function testGetExpression(): void
{
$this->assertSame('NOT IN(10, 20, 30)', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\NotLike;
final class NotLikeTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('notLike')
->willReturn('CAST(test AS text) NOT LIKE \'%toto%\'');
$this->operator = new NotLike($expr, 'test', 'string', 'toto');
}
public function testGetExpression(): void
{
$this->assertSame('CAST(test AS text) NOT LIKE \'%toto%\'', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\OperatorNotNull;
final class OperatorNotNullTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('isNotNull')
->willReturn('test IS NOT NULL');
$this->operator = new OperatorNotNull($expr, 'test', 'integer');
}
public function testGetExpression(): void
{
$this->assertSame('test IS NOT NULL', $this->operator->getExpression());
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query\Operator;
use PHPUnit\Framework\TestCase;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use App\Search\Query\Operator\OperatorNull;
final class OperatorNullTest extends TestCase
{
private $operator;
protected function setUp(): void
{
$expr = $this->createMock(ExpressionBuilder::class);
$expr->method('isNull')
->willReturn('test IS NULL');
$this->operator = new OperatorNull($expr, 'test', 'integer');
}
public function testGetExpression(): void
{
$this->assertSame('test IS NULL', $this->operator->getExpression());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment