Skip to content

Improve require versions #29

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build/
.buildpath
.project
composer.lock
coverage.xml
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
language: php

php:
- 5.6
- 7.1
- 7.2
- 7.3

before_script:
- travis_retry composer self-update
- travis_retry composer update --no-interaction

script:
- vendor/bin/phpunit
- composer test-cover

after_success:
- bash <(curl -s https://codecov.io/bash)
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@
}
],
"require": {
"php": ">=5.4",
"php": "^5.6 | ^7.0",
"doctrine/dbal": "~2.4",
"doctrine/orm": "~2.4"
},
"require-dev": {
"phpunit/phpunit": "^6.5"
"phpunit/phpunit": "^5.7 | ^6.5"
},
"autoload": {
"psr-4": {
"Opsway\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"OpsWay\\Tests\\": "tests/"
}
},
"scripts": {
"test-cover": "phpunit --coverage-clover=coverage.xml"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
Expand Down
34 changes: 34 additions & 0 deletions tests/EmTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace OpsWay\Tests;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use PHPUnit\Framework\TestCase;

class EmTestCase extends TestCase
{
/** @var EntityManager */
protected $em;

protected function customStringFunctions() : array
{
return [];
}

protected function setUp()
{
$config = Setup::createConfiguration(true);
$driverImpl = $config->newDefaultAnnotationDriver([__DIR__]);
$config->setMetadataDriverImpl($driverImpl);
$this->em = EntityManager::create([
'driver' => 'pdo_sqlite',
'memory' => true,
], $config);

foreach ($this->customStringFunctions() as $name => $className) {
$this->em->getConfiguration()->addCustomStringFunction($name, $className);
}
}
}

16 changes: 16 additions & 0 deletions tests/Entity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace OpsWay\Tests;

/** @Entity */
class Entity
{
/** @Id @Column(type="string") @GeneratedValue */
private $id;

/**
* @var array
* @Column(type="json", nullable=true, options={"jsonb": true})
*/
private $metaData;
}
53 changes: 25 additions & 28 deletions tests/Unit/ORM/Query/AST/Functions/TsConcatTest.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
<?php

namespace Opsway\Tests\Doctrine\ORM\Query\AST\Functions;
namespace OpsWay\Tests\Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\AST\ParenthesisExpression;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use OpsWay\Tests\EmTestCase;
use Opsway\Doctrine\ORM\Query\AST\Functions\TsConcat;
use PHPUnit\Framework\TestCase;

class TsConcatTest extends TestCase
class TsConcatTest extends EmTestCase
{
private $tsConcat;

public function setUp()
protected function customStringFunctions() : array
{
$this->tsConcat = new TsConcat('test');
return [
'TS_CONCAT_OP' => TsConcat::class,
];
}

public function testFunction()
/** @dataProvider functionData */
public function testFunction(string $dql, string $sql)
{
$parser = $this->prophesize(Parser::class);
$expr = $this->prophesize(ParenthesisExpression::class);
$lexer = $this->prophesize(Lexer::class);

$parser->match()->shouldBeCalled()->withArguments([Lexer::T_IDENTIFIER]);
$parser->match()->shouldBeCalled()->withArguments([Lexer::T_OPEN_PARENTHESIS]);
$parser->StringPrimary()->shouldBeCalled()->willReturn($expr->reveal());
$parser->match()->shouldBeCalled()->withArguments([Lexer::T_COMMA]);
$parser->match()->shouldBeCalled()->withArguments([Lexer::T_CLOSE_PARENTHESIS]);
$parser->getLexer()->shouldBeCalled()->willReturn($lexer->reveal());
$sqlWalker = $this->prophesize(SqlWalker::class);

$this->tsConcat->parse($parser->reveal());

$expr->dispatch()->shouldBeCalled()->withArguments([$sqlWalker->reveal()])->willReturn('test');
$query = $this->em->createQuery($dql);
$this->assertEquals($sql, $query->getSql());
}

$this->assertEquals('test || test', $this->tsConcat->getSql($sqlWalker->reveal()));
public function functionData()
{
return [
[
'SELECT TS_CONCAT_OP(e.id, e.id) FROM OpsWay\Tests\Entity e',
'SELECT e0_.id || e0_.id AS sclr_0 FROM Entity e0_',
],
[
'SELECT TS_CONCAT_OP(e.id, e.id, e.id) FROM OpsWay\Tests\Entity e',
'SELECT e0_.id || e0_.id || e0_.id AS sclr_0 FROM Entity e0_',
],
];
}
}