diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e2d112573577bb3cc1bb8fef6f5ad62fa40facb4..e86ce69780e6fd5682874dbbcccc2ee3539ed4b8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: registry.gitlab.com/silvioq/php-base-image:7.4 +image: registry.gitlab.com/silvioq/php-base-image:8.1 include: template: SAST.gitlab-ci.yml @@ -20,20 +20,22 @@ cache: paths: - ./vendor -analisis-7.4: +analisis-8.1: stage: analisis + image: registry.gitlab.com/silvioq/php-base-image:8.1 script: - composer install - ./vendor/bin/phpstan analyze -analisis-8.1: +analisis-8.2: stage: analisis image: registry.gitlab.com/silvioq/php-base-image:8.1 script: - composer install - ./vendor/bin/phpstan analyze -test-74-with-extension: +test-81-with-extension: + image: registry.gitlab.com/silvioq/php-base-image:8.1 coverage: '/^\s*Lines:\s*\d+.\d+\%/' stage: test artifacts: @@ -44,16 +46,16 @@ test-74-with-extension: - composer install - ./vendor/bin/phpunit --coverage-text --colors=never --coverage-html Tests/output/coverage -test-74: +test-81: + image: registry.gitlab.com/silvioq/php-base-image:8.1 coverage: '/^\s*Lines:\s*\d+.\d+\%/' stage: test - image: registry.gitlab.com/silvioq/php-base-image:7.4 script: - composer install - ./vendor/bin/phpunit --coverage-text --colors=never -test-81-with-extension: - image: registry.gitlab.com/silvioq/php-base-image:8.1 +test-82-with-extension: + image: registry.gitlab.com/silvioq/php-base-image:8.2 coverage: '/^\s*Lines:\s*\d+.\d+\%/' stage: test artifacts: @@ -64,8 +66,8 @@ test-81-with-extension: - composer install - ./vendor/bin/phpunit --coverage-text --colors=never --coverage-html Tests/output/coverage -test-81: - image: registry.gitlab.com/silvioq/php-base-image:8.1 +test-82: + image: registry.gitlab.com/silvioq/php-base-image:8.2 coverage: '/^\s*Lines:\s*\d+.\d+\%/' stage: test script: diff --git a/README.md b/README.md index d289b23d82601255d58ca09074ca17e843388a30..03c8708a58e5852dfebaae4fa655e9c620f49067 100644 --- a/README.md +++ b/README.md @@ -75,4 +75,19 @@ class SimpleController extends Controller [](https://gitlab.com/silvioq/symfony-report-datatable/commits/master) -[](https://gitlab.com/silvioq/symfony-report-datatable/commits/master) \ No newline at end of file +[](https://gitlab.com/silvioq/symfony-report-datatable/commits/master) + + +## Testeo +```bash +docker run -ti --rm \ + --user $(id -u):$(id -g) -v $(pwd):/app -w /app \ + -v $HOME/.cache/composer:/opt/composer/cache \ + registry.gitlab.com/silvioq/php-base-image:8.1 \ + composer install +docker run -ti --rm \ + --user $(id -u):$(id -g) -v $(pwd):/app -w /app \ + -v $HOME/.cache/composer:/opt/composer/cache \ + registry.gitlab.com/silvioq/php-base-image:8.1 \ + vendor/bin/phpunit +``` diff --git a/Tests/Datatable/FilterTest.php b/Tests/Datatable/FilterTest.php index 8e45e85ce68cfb9e37ec30f536df11183ce73302..98d4d592d1e10331216264ffdff251bfbb444fcd 100644 --- a/Tests/Datatable/FilterTest.php +++ b/Tests/Datatable/FilterTest.php @@ -60,17 +60,20 @@ class FilterTest extends TestCase ->will( $this->returnValue($result)) ; - $metadataMock->expects($this->at(1)) - ->method('getTypeOfField') - ->with( $this->equalTo('field1')) - ->will( $this->returnValue(ORMType::INTEGER)) - ; + $expected = [ + 'field1' => ORMType::INTEGER, + 'field2' => ORMType::INTEGER + ]; - $metadataMock->expects($this->at(2)) + $metadataMock->expects($this->exactly(2)) ->method('getTypeOfField') - ->with( $this->equalTo('field2')) - ->will( $this->returnValue(ORMType::INTEGER)) - ; + ->willReturnCallback(function($field) use ($expected) { + $this->assertArrayHasKey($field, $expected); + $e = $expected[$field]; + // $field debe ser el primer elemento del array + array_shift($expected); + return $e; + }); $metadataMock->expects($this->once()) ->method('getFieldNames') diff --git a/Tests/Datatable/SearchTest.php b/Tests/Datatable/SearchTest.php index 62a042338ff5e2b5e6f829c5baf01d0e7b8bba9d..dfbe10e199afeb1ea16c0d83798204802d1d7422 100644 --- a/Tests/Datatable/SearchTest.php +++ b/Tests/Datatable/SearchTest.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Types\Types as ORMType; use Doctrine\DBAL\Platforms\MySQL80Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; use Doctrine\DBAL\Platforms\MariaDb1027Platform; +use Doctrine\DBAL\Platforms\MariaDBPlatform; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; @@ -44,23 +45,21 @@ class SearchTest extends TestCase ->will($this->returnValue($metadataMock)) ; - $metadataMock->expects($this->at(1)) - ->method('getTypeOfField') - ->with( $this->equalTo('field1')) - ->will( $this->returnValue(ORMType::STRING)) - ; - - $metadataMock->expects($this->at(2)) - ->method('getTypeOfField') - ->with( $this->equalTo('field2')) - ->will( $this->returnValue(ORMType::STRING)) - ; + $expected = [ + 'field1' => ORMType::STRING, + 'field2' => ORMType::STRING, + 'field3' => ORMType::JSON, + ]; - $metadataMock->expects($this->at(3)) + $metadataMock->expects($this->exactly(3)) ->method('getTypeOfField') - ->with( $this->equalTo('field3')) - ->will( $this->returnValue(ORMType::JSON)) - ; + ->willReturnCallback(function($field) use (&$expected) { + $this->assertArrayHasKey($field, $expected); + $e = $expected[$field]; + // $field debe ser el primer elemento del array + array_shift($expected); + return $e; + }); $metadataMock->expects($this->once()) ->method('getFieldNames') @@ -156,17 +155,20 @@ class SearchTest extends TestCase ->will($this->returnValue($metadataMock)) ; - $metadataMock->expects($this->at(1)) - ->method('getTypeOfField') - ->with( $this->equalTo('field1')) - ->will( $this->returnValue($numericType)) - ; + $expected = [ + 'field1' => $numericType, + 'field2' => ORMType::STRING, + ]; - $metadataMock->expects($this->at(2)) + $metadataMock->expects($this->exactly(2)) ->method('getTypeOfField') - ->with( $this->equalTo('field2')) - ->will( $this->returnValue(ORMType::STRING)) - ; + ->willReturnCallback(function($field) use (&$expected) { + $this->assertArrayHasKey($field, $expected); + $e = $expected[$field]; + // $field debe ser el primer elemento del array + array_shift($expected); + return $e; + }); $metadataMock->expects($this->once()) ->method('getFieldNames') @@ -261,17 +263,21 @@ class SearchTest extends TestCase ->will($this->returnValue($metadataMock)) ; - $metadataMock->expects($this->at(1)) - ->method('getTypeOfField') - ->with( $this->equalTo('field1')) - ->will( $this->returnValue($numericType)) - ; + + $expected = [ + 'field1' => $numericType, + 'field2' => $numericType, + ]; - $metadataMock->expects($this->at(2)) + $metadataMock->expects($this->exactly(2)) ->method('getTypeOfField') - ->with( $this->equalTo('field2')) - ->will( $this->returnValue($numericType)) - ; + ->willReturnCallback(function($field) use (&$expected) { + $this->assertArrayHasKey($field, $expected); + $e = $expected[$field]; + // $field debe ser el primer elemento del array + array_shift($expected); + return $e; + }); $metadataMock->expects($this->once()) ->method('getFieldNames') @@ -494,7 +500,7 @@ class SearchTest extends TestCase } - public function testSearchBetweenDate() + public function testSearchBetweenDate() { $emMock = $this->createMock('\Doctrine\ORM\EntityManager', array('getRepository', 'getClassMetadata'), array(), '', false); @@ -521,10 +527,20 @@ class SearchTest extends TestCase ->will($this->returnValue($metadataMock)) ; - $metadataMock->expects($this->at(1)) + $expected = [ + 'field1' => ORMType::DATETIME_MUTABLE, + 'field2' => ORMType::DATETIME_MUTABLE, + ]; + + $metadataMock->expects($this->exactly(2)) ->method('getTypeOfField') - ->with( $this->equalTo('field1')) - ->will( $this->returnValue(ORMType::DATETIME_MUTABLE)) + ->willReturnCallback(function($field) use (&$expected) { + $this->assertArrayHasKey($field, $expected); + $e = $expected[$field]; + // $field debe ser el primer elemento del array + array_shift($expected); + return $e; + }); ; $repoMock->expects($this->once()) @@ -539,10 +555,19 @@ class SearchTest extends TestCase ->will($this->returnSelf() ) ; + $expected2 = [ + ['ppp1', '1900-01-01'], + ['ppp2','2012-01-01'] + ]; + $qbMock->expects($this->exactly(2)) ->method('setParameter') - ->withConsecutive( ['ppp1', '1900-01-01'], ['ppp2','2012-01-01'] ) - ->will($this->returnSelf()) + ->willReturnCallback(function($param, $value) use (&$expected2) { + $e = \array_shift($expected2); + $this->assertSame($e[0], $param); + $this->assertSame($e[1], $value); + $this->returnSelf(); + }) ; $e = new Expr(); @@ -639,10 +664,19 @@ class SearchTest extends TestCase ->will($this->returnSelf() ) ; + $expected2 = [ + ['ppp1', 'A'], + ['ppp2', 'Z'] + ]; + $qbMock->expects($this->exactly(2)) ->method('setParameter') - ->withConsecutive( ['ppp1', 'A'], ['ppp2','Z'] ) - ->will($this->returnSelf()) + ->willReturnCallback(function($param, $value) use (&$expected2) { + $e = \array_shift($expected2); + $this->assertSame($e[0], $param); + $this->assertSame($e[1], $value); + $this->returnSelf(); + }) ; $e = new Expr(); @@ -712,17 +746,21 @@ class SearchTest extends TestCase ->will($this->returnValue($metadataMock)) ; - $metadataMock->expects($this->at(1)) - ->method('getTypeOfField') - ->with( $this->equalTo('field1')) - ->will( $this->returnValue(ORMType::BOOLEAN)) - ; + $expected = [ + 'field1' => ORMType::BOOLEAN, + 'field2' => ORMType::STRING, + ]; - $metadataMock->expects($this->at(2)) + $metadataMock->expects($this->exactly(2)) ->method('getTypeOfField') - ->with( $this->equalTo('field2')) - ->will( $this->returnValue(ORMType::STRING)) - ; + ->willReturnCallback(function($field) use (&$expected) { + $this->assertArrayHasKey($field, $expected); + $e = $expected[$field]; + // $field debe ser el primer elemento del array + array_shift($expected); + return $e; + }); + $metadataMock->expects($this->once()) ->method('getFieldNames') @@ -904,10 +942,10 @@ class SearchTest extends TestCase ->will($this->returnValue($metadataMock)) ; - $metadataMock->expects($this->at(1)) + $metadataMock->expects($this->exactly(1)) ->method('getTypeOfField') - ->with( $this->equalTo('field1')) - ->will( $this->returnValue($ormType)) + ->with($this->equalTo('field1')) + ->will($this->returnValue($ormType)) ; $metadataMock->expects($this->once()) @@ -983,7 +1021,7 @@ class SearchTest extends TestCase $platforms = [ MySQL80Platform::class, MySQL57Platform::class, - MariaDb1027Platform::class, + MariaDBPlatform::class, PostgreSQL100Platform::class, PostgreSQLPlatform::class, OraclePlatform::class, @@ -1005,7 +1043,7 @@ class SearchTest extends TestCase } array_push($ret, [ ORMType::JSON, 'stringVal', MySQL80Platform::class, "LOWER(a.field1) LIKE :ppp1"] ); - array_push($ret, [ ORMType::JSON, 'stringVal', MariaDb1027Platform::class, "LOWER(a.field1) LIKE :ppp1"] ); + array_push($ret, [ ORMType::JSON, 'stringVal', MariaDBPlatform::class, "LOWER(a.field1) LIKE :ppp1"] ); array_push($ret, [ ORMType::JSON, 'stringVal', PostgreSQLPlatform::class, false] ); return $ret; @@ -1036,7 +1074,7 @@ class SearchTest extends TestCase ->will($this->returnValue($metadataMock)) ; - $metadataMock->expects($this->at(1)) + $metadataMock->expects($this->once()) ->method('getTypeOfField') ->with( $this->equalTo('field1')) ->will( $this->returnValue('unknown_type')) diff --git a/Tests/Datatable/WheresTest.php b/Tests/Datatable/WheresTest.php index c5c1d7c187ab72336f004c2d39ba0010d7c9beef..803019d42fc8aa9eb87114391d388033c4009ad3 100644 --- a/Tests/Datatable/WheresTest.php +++ b/Tests/Datatable/WheresTest.php @@ -313,13 +313,16 @@ class WheresTest extends TestCase ->will( $this->returnValue($queryMock) ) ; - $qbMock->expects($this->at(1)) + $expected = [ + 'a.field2 = 2', + 'a.field1 = 1', + ]; + $qbMock->expects($this->exactly(2)) ->method('andWhere') - ->with($this->equalTo( 'a.field2 = 2') ) - ; - $qbMock->expects($this->at(2)) - ->method('andWhere') - ->with($this->equalTo( 'a.field1 = 1') ) + ->willReturnCallback(function(...$arg) use(&$expected) { + $e = \array_shift($expected); + $this->assertSame($e, $arg[0]); + }) ; $queryMock->expects($this->once()) diff --git a/composer.json b/composer.json index 7cce160dff8b6277f866c481de7a786912fddf05..b98a46b0a965d835dd3f0c37920e6da17d8834a2 100644 --- a/composer.json +++ b/composer.json @@ -4,12 +4,12 @@ "type": "library", "license": "MIT", "require": { - "php": ">=7.4", + "php": ">=8.1", "ext-intl": "*", - "doctrine/orm": "^2.9", - "symfony/http-foundation": "^5", - "symfony/http-kernel": "^5", - "symfony/options-resolver": "^5", + "doctrine/orm": "^2", + "symfony/http-foundation": "^6", + "symfony/http-kernel": "^6", + "symfony/options-resolver": "^6", "doctrine/annotations": "^1.13" }, "autoload": { @@ -30,8 +30,8 @@ ], "require-dev": { "matthiasnoback/symfony-dependency-injection-test": "^4", - "phpunit/phpunit": "9.5.*", - "phpstan/phpstan": "^1.2" + "phpunit/phpunit": "^9.6", + "phpstan/phpstan": "^1" }, "archive": { "exclude": ["Tests", "phpunit.xml.dist", ".travis.yml"] diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c1b45ffc45952d033ff0de28a2aaf495581c9f27..08c58f9f62b7918467db699db8553445336cca60 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,25 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> -<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" - backupGlobals="false" - colors="true" - bootstrap="vendor/autoload.php" -> - <php> - <ini name="error_reporting" value="-1" /> - </php> - - <testsuites> - <testsuite name="Report"> - <directory>./Tests/</directory> - </testsuite> - </testsuites> - - <filter> - <whitelist> - <directory>src</directory> - </whitelist> - </filter> - - +<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php"> + <coverage> + <include> + <directory>src</directory> + </include> + </coverage> + <php> + <ini name="error_reporting" value="-1"/> + </php> + <testsuites> + <testsuite name="Report"> + <directory>./Tests/</directory> + </testsuite> + </testsuites> </phpunit>