diff --git a/.gitignore b/.gitignore index 247dd84..d4843b1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ build/ .buildpath .project composer.lock +coverage.xml diff --git a/.travis.yml b/.travis.yml index 17db0d6..60508d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file + - composer test-cover + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/composer.json b/composer.json index 58b2557..39f2efb 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/tests/EmTestCase.php b/tests/EmTestCase.php new file mode 100644 index 0000000..10719ba --- /dev/null +++ b/tests/EmTestCase.php @@ -0,0 +1,34 @@ +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); + } + } +} + diff --git a/tests/Entity.php b/tests/Entity.php new file mode 100644 index 0000000..a03d7ba --- /dev/null +++ b/tests/Entity.php @@ -0,0 +1,16 @@ +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_', + ], + ]; } } +