From 3fda396726c255bd3c151ec95aff54bb64d28efb Mon Sep 17 00:00:00 2001 From: Ilyar Date: Sun, 3 Mar 2019 19:07:44 +0200 Subject: [PATCH 1/4] test: setup service codecov --- .gitignore | 1 + .travis.yml | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) 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..1831694 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,7 @@ before_script: - travis_retry composer update --no-interaction script: - - vendor/bin/phpunit \ No newline at end of file + - vendor/bin/phpunit --coverage-clover=coverage.xml + +after_success: + - bash <(curl -s https://codecov.io/bash) From 63e589bca1ad987c1b4a6c6c915013ef4a6855cd Mon Sep 17 00:00:00 2001 From: Ilyar Date: Sun, 3 Mar 2019 19:10:10 +0200 Subject: [PATCH 2/4] test: add test env with EntityManager --- composer.json | 5 +++++ tests/EmTestCase.php | 34 ++++++++++++++++++++++++++++++++++ tests/Entity.php | 16 ++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 tests/EmTestCase.php create mode 100644 tests/Entity.php diff --git a/composer.json b/composer.json index 58b2557..aeb9efd 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,11 @@ "Opsway\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "OpsWay\\Tests\\": "tests/" + } + }, "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 @@ + Date: Sun, 3 Mar 2019 19:11:55 +0200 Subject: [PATCH 3/4] test: improve test for TsConcat function and up coverage --- .../ORM/Query/AST/Functions/TsConcatTest.php | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/tests/Unit/ORM/Query/AST/Functions/TsConcatTest.php b/tests/Unit/ORM/Query/AST/Functions/TsConcatTest.php index 615e881..9436cdc 100644 --- a/tests/Unit/ORM/Query/AST/Functions/TsConcatTest.php +++ b/tests/Unit/ORM/Query/AST/Functions/TsConcatTest.php @@ -1,41 +1,38 @@ 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_', + ], + ]; } } + From f5b26a89478d477518500f859098cb804ec46e61 Mon Sep 17 00:00:00 2001 From: Ilyar Date: Mon, 4 Mar 2019 21:39:09 +0200 Subject: [PATCH 4/4] build: add script for test cover and extended versions PHP for testing --- .travis.yml | 4 +++- composer.json | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1831694..60508d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +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 --coverage-clover=coverage.xml + - composer test-cover after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/composer.json b/composer.json index aeb9efd..39f2efb 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,12 @@ } ], "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": { @@ -27,6 +27,9 @@ "OpsWay\\Tests\\": "tests/" } }, + "scripts": { + "test-cover": "phpunit --coverage-clover=coverage.xml" + }, "extra": { "branch-alias": { "dev-master": "1.0-dev"