diff --git a/composer.json b/composer.json index e52892c..12689c2 100644 --- a/composer.json +++ b/composer.json @@ -22,11 +22,12 @@ "php": ">=7.4", "ext-pdo": "*", "squirrelphp/debug": "^0.5", - "doctrine/dbal": "^2.5" + "doctrine/dbal": "^3.0" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.3", "captainhook/plugin-composer": "^5.0", + "phpunit/phpunit": "^9.0", "mockery/mockery": "^1.0" }, "suggest": { @@ -59,7 +60,7 @@ "psalm_base": "vendor/bin/psalm --set-baseline=psalm-baseline.xml", "phpunit": "vendor/bin/phpunit --colors=always", "phpunit_clover": "vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml", - "codecoverage": "vendor/bin/phpunit --coverage-html tests/_reports", + "coverage": "vendor/bin/phpunit --coverage-html tests/_reports", "phpcs": "vendor/bin/phpcs --standard=ruleset.xml --extensions=php --cache=.phpcs-cache --colors src tests", "phpcsfix": "vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --cache=.phpcs-cache src tests", "binupdate": "@composer bin all update --ansi", diff --git a/docker/compose-coverage.yml b/docker/compose-coverage.yml new file mode 100644 index 0000000..0b95cde --- /dev/null +++ b/docker/compose-coverage.yml @@ -0,0 +1,64 @@ +version: "3.7" +services: + squirrel_queries_coverage: + image: thecodingmachine/php:7.4-v3-cli + container_name: squirrel_queries_coverage + tty: true + working_dir: /usr/src/app + # --path-coverage could be added later, it is much too slow currently and only supported by xdebug + command: [ "vendor/bin/phpunit", "--colors=always", "--stop-on-defect", "--coverage-html", "tests/_reports"] + volumes: + - ./src:/usr/src/app/src + - ./tests:/usr/src/app/tests + - ./composer.json:/usr/src/app/composer.json + - ./phpunit.xml.dist:/usr/src/app/phpunit.xml.dist + - ./vendor-bin:/usr/src/app/vendor-bin + environment: + # We currently use PCOV because it is at least 8x faster + # - 3 seconds compared to 23 seconds (or 5 minutes with path coverage enabled) + PHP_EXTENSION_XDEBUG: 1 + #PHP_EXTENSION_PCOV: 1 + PHP_EXTENSION_APCU: 0 + PHP_EXTENSION_REDIS: 0 + PHP_EXTENSION_SQLITE3: 1 + PHP_EXTENSION_PDO_MYSQL: 1 + PHP_EXTENSION_PDO_PGSQL: 1 + PHP_EXTENSION_PDO_SQLITE: 1 + PHP_INI_MEMORY_LIMIT: 1g + PHP_INI_ERROR_REPORTING: E_ALL + SQUIRREL_TEST_SQLITE: 'sqlite:///:memory:' + SQUIRREL_TEST_POSTGRES: 'postgres://user:password@squirrel_queries_postgres/postgres?charset=UTF-8' + SQUIRREL_TEST_MYSQL: 'mysql://user:password@squirrel_queries_mysql/shop' + SQUIRREL_TEST_MARIADB: 'mysql://user:password@squirrel_queries_mariadb/shop' + STARTUP_COMMAND_1: composer update --no-scripts --quiet + STARTUP_COMMAND_2: rm -rf /usr/src/app/tests/_reports/* + depends_on: + - squirrel_queries_postgres + - squirrel_queries_mysql + - squirrel_queries_mariadb + + squirrel_queries_postgres: + image: postgres:latest + container_name: squirrel_queries_postgres + environment: + POSTGRES_USER: 'user' + POSTGRES_PASSWORD: 'password' + + squirrel_queries_mysql: + image: mysql/mysql-server:latest + container_name: squirrel_queries_mysql + command: --default-authentication-plugin=mysql_native_password + environment: + MYSQL_ROOT_PASSWORD: 'whatever' + MYSQL_DATABASE: 'shop' + MYSQL_USER: 'user' + MYSQL_PASSWORD: 'password' + + squirrel_queries_mariadb: + image: mariadb:latest + container_name: squirrel_queries_mariadb + environment: + MYSQL_ROOT_PASSWORD: 'whatever' + MYSQL_DATABASE: 'shop' + MYSQL_USER: 'user' + MYSQL_PASSWORD: 'password' \ No newline at end of file diff --git a/docker/compose-test.yml b/docker/compose-test.yml index 7967e76..8a02bda 100644 --- a/docker/compose-test.yml +++ b/docker/compose-test.yml @@ -1,8 +1,8 @@ version: "3.7" services: - squirrel_queries_74: + squirrel_queries_test: image: thecodingmachine/php:7.4-v3-cli - container_name: squirrel_queries_74 + container_name: squirrel_queries_test tty: true working_dir: /usr/src/app command: ["vendor/bin/phpunit", "--colors=always", "--filter", "Integration"] @@ -26,7 +26,6 @@ services: SQUIRREL_TEST_MYSQL: 'mysql://user:password@squirrel_queries_mysql/shop' SQUIRREL_TEST_MARIADB: 'mysql://user:password@squirrel_queries_mariadb/shop' STARTUP_COMMAND_1: composer update --no-scripts --quiet - STARTUP_COMMAND_2: composer bin all update --quiet depends_on: - squirrel_queries_postgres - squirrel_queries_mysql diff --git a/docker/coverage b/docker/coverage new file mode 100755 index 0000000..12d106d --- /dev/null +++ b/docker/coverage @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# Get directory of this script +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +# Remove all running docker containers +docker-compose -f "$DIR/compose-coverage.yml" --project-directory "$DIR/.." down -v --remove-orphans + +# Test SQLite and real live tests with PostgreSQL and MySQL +docker-compose -f "$DIR/compose-coverage.yml" --project-directory "$DIR/.." up --build --force-recreate --renew-anon-volumes squirrel_queries_coverage + +# Remove all running docker containers +docker-compose -f "$DIR/compose-coverage.yml" --project-directory "$DIR/.." down -v \ No newline at end of file diff --git a/docker/test-pull b/docker/pull similarity index 61% rename from docker/test-pull rename to docker/pull index fcc8fdf..d1a6fec 100755 --- a/docker/test-pull +++ b/docker/pull @@ -2,8 +2,6 @@ # Get directory of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -# Remove all running docker containers -docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." down -v --remove-orphans - # Pull new docker images in case there were updates -docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." pull \ No newline at end of file +docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." pull +docker-compose -f "$DIR/compose-coverage.yml" --project-directory "$DIR/.." pull \ No newline at end of file diff --git a/docker/test b/docker/test index 4ef33c7..065d0aa 100755 --- a/docker/test +++ b/docker/test @@ -6,7 +6,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." down -v --remove-orphans # Test SQLite and real live tests with PostgreSQL and MySQL -docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." up --build --force-recreate --renew-anon-volumes squirrel_queries_74 +docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." up --build --force-recreate --renew-anon-volumes squirrel_queries_test # Remove all running docker containers docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." down -v \ No newline at end of file diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3092817..a524203 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -20,3 +20,8 @@ parameters: count: 1 path: src/Builder/SelectEntries.php + - + message: "#^Cannot access offset 'v' on array\\\\|false\\.$#" + count: 1 + path: src/Doctrine/DBSQLiteImplementation.php + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d643236..41480ac 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,16 @@ - - - - - tests - - - - - - src - - src/TestHelpers - - - + + + + src + + + src/TestHelpers + + + + + tests + + diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 16803dc..6134bf1 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,11 +1,11 @@ - + - int[] + bool[] float[] + int[] string[] - bool[] @@ -18,4 +18,9 @@ $lowerLayer + + + $select['offset'] ?? null + + diff --git a/src/Doctrine/DBAbstractImplementation.php b/src/Doctrine/DBAbstractImplementation.php index d7723c6..1638bcd 100644 --- a/src/Doctrine/DBAbstractImplementation.php +++ b/src/Doctrine/DBAbstractImplementation.php @@ -3,7 +3,6 @@ namespace Squirrel\Queries\Doctrine; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\FetchMode; use Squirrel\Debug\Debug; use Squirrel\Queries\DBInterface; use Squirrel\Queries\DBRawInterface; @@ -76,10 +75,10 @@ public function select($query, array $vars = []): DBSelectQueryInterface // Prepare and execute query $statement = $this->connection->prepare($query); - $statement->execute($vars); + $statementResult = $statement->execute($vars); // Return select query object with PDO statement - return new DBSelectQuery($statement); + return new DBSelectQuery($statementResult); } public function fetch(DBSelectQueryInterface $selectQuery): ?array @@ -94,7 +93,7 @@ public function fetch(DBSelectQueryInterface $selectQuery): ?array } // Get the result - can be an array of the entry, or false if it is empty - $result = $selectQuery->getStatement()->fetch(FetchMode::ASSOCIATIVE); + $result = $selectQuery->getStatement()->fetchAssociative(); // Return one result as an array return ($result === false ? null : $result); @@ -112,7 +111,7 @@ public function clear(DBSelectQueryInterface $selectQuery): void } // Close the result set - $selectQuery->getStatement()->closeCursor(); + $selectQuery->getStatement()->free(); } public function fetchOne($query, array $vars = []): ?array @@ -135,11 +134,11 @@ public function fetchAll($query, array $vars = []): array // Prepare and execute query $statement = $this->connection->prepare($query); - $statement->execute($vars); + $statementResult = $statement->execute($vars); // Get result and close result set - $result = $statement->fetchAll(FetchMode::ASSOCIATIVE); - $statement->closeCursor(); + $result = $statementResult->fetchAllAssociative(); + $statementResult->free(); // Return query result return $result; @@ -188,8 +187,8 @@ public function insert(string $tableName, array $row = [], string $autoIncrement ($columnValue instanceof LargeObject) ? \PDO::PARAM_LOB : \PDO::PARAM_STR, ); } - $statement->execute(); - $statement->closeCursor(); + $statementResult = $statement->execute(); + $statementResult->free(); // No autoincrement index - no insert ID return value needed if (\strlen($autoIncrementIndex) === 0) { @@ -262,13 +261,13 @@ public function change(string $query, array $vars = []): int ($columnValue instanceof LargeObject) ? \PDO::PARAM_LOB : \PDO::PARAM_STR, ); } - $statement->execute(); + $statementResult = $statement->execute(); // Get affected rows - $result = $statement->rowCount(); + $result = $statementResult->rowCount(); // Close query - $statement->closeCursor(); + $statementResult->free(); // Return affected rows return $result; diff --git a/src/Doctrine/DBErrorHandler.php b/src/Doctrine/DBErrorHandler.php index 908ec88..151ec2d 100644 --- a/src/Doctrine/DBErrorHandler.php +++ b/src/Doctrine/DBErrorHandler.php @@ -379,11 +379,6 @@ protected function attemptReconnect(array $connectionRetries): ?array // Close connection and establish a new connection $connection->close(); $connection->connect(); - - // If we still do not have a connection we need to try again - if ($connection->ping() === false) { - return $this->attemptReconnect($connectionRetries); - } } catch (ConnectionException $e) { // Connection could not be established - try again return $this->attemptReconnect($connectionRetries); } diff --git a/src/Doctrine/DBMySQLImplementation.php b/src/Doctrine/DBMySQLImplementation.php index 598513f..9932802 100644 --- a/src/Doctrine/DBMySQLImplementation.php +++ b/src/Doctrine/DBMySQLImplementation.php @@ -52,7 +52,7 @@ public function insertOrUpdate(string $tableName, array $row = [], array $indexC ); } - $statement->execute(); - $statement->closeCursor(); + $statementResult = $statement->execute(); + $statementResult->free(); } } diff --git a/src/Doctrine/DBPostgreSQLImplementation.php b/src/Doctrine/DBPostgreSQLImplementation.php index 9dba12b..da25c8f 100644 --- a/src/Doctrine/DBPostgreSQLImplementation.php +++ b/src/Doctrine/DBPostgreSQLImplementation.php @@ -74,8 +74,8 @@ public function insertOrUpdate(string $tableName, array $row = [], array $indexC ); } - $statement->execute(); - $statement->closeCursor(); + $statementResult = $statement->execute(); + $statementResult->free(); } protected function generateUpsertSQLAndParameters( diff --git a/src/Doctrine/DBSQLiteImplementation.php b/src/Doctrine/DBSQLiteImplementation.php index ee1028a..d6de076 100644 --- a/src/Doctrine/DBSQLiteImplementation.php +++ b/src/Doctrine/DBSQLiteImplementation.php @@ -2,6 +2,10 @@ namespace Squirrel\Queries\Doctrine; +use Squirrel\Debug\Debug; +use Squirrel\Queries\DBInterface; +use Squirrel\Queries\Exception\DBInvalidOptionException; + /** * DB SQLite implementation using Doctrine DBAL with custom upsert functionality * @@ -23,7 +27,20 @@ public function insertOrUpdate( if ($this->sqliteVersion === null) { $connection = $this->getConnection(); - $this->sqliteVersion = \floatval($connection->query('select sqlite_version() AS "v"')->fetch()['v']); + $statement = $connection->prepare('select sqlite_version() AS "v"'); + $statementResult = $statement->execute(); + $result = $statementResult->fetchAssociative(); + $statementResult->free(); + + if (!isset($result['v'])) { + throw Debug::createException( + DBInvalidOptionException::class, + DBInterface::class, + 'SQLite version could not be retrieved', + ); + } + + $this->sqliteVersion = \floatval($result['v']); } // SQLite below version 3.24 does not offer native upsert, so emulate it diff --git a/src/Doctrine/DBSelectQuery.php b/src/Doctrine/DBSelectQuery.php index 6141dff..ecacff1 100644 --- a/src/Doctrine/DBSelectQuery.php +++ b/src/Doctrine/DBSelectQuery.php @@ -2,19 +2,19 @@ namespace Squirrel\Queries\Doctrine; -use Doctrine\DBAL\Driver\ResultStatement; +use Doctrine\DBAL\Result; use Squirrel\Queries\DBSelectQueryInterface; class DBSelectQuery implements DBSelectQueryInterface { - private ResultStatement $statement; + private Result $statement; - public function __construct(ResultStatement $statement) + public function __construct(Result $statement) { $this->statement = $statement; } - public function getStatement(): ResultStatement + public function getStatement(): Result { return $this->statement; } diff --git a/tests/DoctrineErrorHandlerTest.php b/tests/DoctrineErrorHandlerTest.php index 076446c..6f01f64 100644 --- a/tests/DoctrineErrorHandlerTest.php +++ b/tests/DoctrineErrorHandlerTest.php @@ -3,7 +3,7 @@ namespace Squirrel\Queries\Tests; use Doctrine\DBAL\Driver\Connection; -use Doctrine\DBAL\Driver\PDOException; +use Doctrine\DBAL\Driver\PDO\Exception as PDOException; use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Exception\DeadlockException; use Doctrine\DBAL\Exception\DriverException; @@ -369,8 +369,8 @@ public function testRedoTransactionAfterDeadlock() ->with(\Mockery::mustBe($func), \Mockery::mustBe($a), \Mockery::mustBe($b), \Mockery::mustBe($c)) ->andThrow( new DeadlockException( - 'Deadlock occured!', - new PDOException(new \PDOException('pdo deadlock exception')), + PDOException::new(new \PDOException('pdo deadlock exception')), + null, ), ); @@ -438,8 +438,8 @@ public function testRedoTransactionAfterConnectionProblem() ->with(\Mockery::mustBe($func), \Mockery::mustBe($a), \Mockery::mustBe($b), \Mockery::mustBe($c)) ->andThrow( new ConnectionException( - 'Connection lost', - new PDOException(new \PDOException('MySQL server has gone away')), + PDOException::new(new \PDOException('MySQL server has gone away')), + null, ), ); @@ -473,12 +473,6 @@ public function testRedoTransactionAfterConnectionProblem() ->once() ->withNoArgs(); - $connection - ->shouldReceive('ping') - ->once() - ->withNoArgs() - ->andReturn(true); - $lowerLayer ->shouldReceive('setTransaction') ->once() @@ -523,8 +517,8 @@ public function testRedoTransactionAfterConnectionProblemMultipleAttempts() ->with(\Mockery::mustBe($func), \Mockery::mustBe($a), \Mockery::mustBe($b), \Mockery::mustBe($c)) ->andThrow( new ConnectionException( - 'Connection lost', - new PDOException(new \PDOException('MySQL server has gone away')), + PDOException::new(new \PDOException('MySQL server has gone away')), + null, ), ); @@ -555,31 +549,19 @@ public function testRedoTransactionAfterConnectionProblemMultipleAttempts() $connection ->shouldReceive('connect') - ->times(3) - ->withNoArgs(); - - $connection - ->shouldReceive('ping') - ->once() - ->withNoArgs() - ->andReturn(false); - - $connection - ->shouldReceive('ping') - ->once() + ->times(2) ->withNoArgs() ->andThrow( new ConnectionException( - 'Connection lost', - new PDOException(new \PDOException('MySQL server has gone away')), + PDOException::new(new \PDOException('MySQL server has gone away')), + null, ), ); $connection - ->shouldReceive('ping') - ->once() - ->withNoArgs() - ->andReturn(true); + ->shouldReceive('connect') + ->times(1) + ->withNoArgs(); $lowerLayer ->shouldReceive('setTransaction') @@ -627,8 +609,8 @@ public function testExceptionNoRetriesTransactionAfterDeadlock() ->with(\Mockery::mustBe($func), \Mockery::mustBe($a), \Mockery::mustBe($b), \Mockery::mustBe($c)) ->andThrow( new DeadlockException( - 'Deadlock occured!', - new PDOException(new \PDOException('pdo deadlock exception')), + PDOException::new(new \PDOException('pdo deadlock exception')), + null, ), ); @@ -689,8 +671,8 @@ public function testExceptionNoRetriesTransactionAfterConnectionProblem() ->with(\Mockery::mustBe($func), \Mockery::mustBe($a), \Mockery::mustBe($b), \Mockery::mustBe($c)) ->andThrow( new ConnectionException( - 'Connection lost', - new PDOException(new \PDOException('MySQL server has gone away')), + PDOException::new(new \PDOException('MySQL server has gone away')), + null, ), ); @@ -757,8 +739,8 @@ public function testExceptionFromDriverLikeBadSQL() ->with(\Mockery::mustBe($func), \Mockery::mustBe($a), \Mockery::mustBe($b), \Mockery::mustBe($c)) ->andThrow( new DriverException( - 'Connection lost', - new PDOException(new \PDOException('MySQL server has gone away')), + PDOException::new(new \PDOException('MySQL server has gone away')), + null, ), ); @@ -862,8 +844,8 @@ public function testExceptionSelectWithinTransactionDeadlock() ->with('SELECT * FROM table') ->andThrow( new DeadlockException( - 'Deadlock occured!', - new PDOException(new \PDOException('pdo deadlock exception')), + PDOException::new(new \PDOException('pdo deadlock exception')), + null, ), ); @@ -896,8 +878,8 @@ public function testExceptionNoRetriesSelectAfterDeadlock() ->with('SELECT * FROM table') ->andThrow( new DeadlockException( - 'Deadlock occured!', - new PDOException(new \PDOException('pdo deadlock exception')), + PDOException::new(new \PDOException('pdo deadlock exception')), + null, ), ); @@ -930,8 +912,8 @@ public function testExceptionSelectWithinTransactionConnectionProblem() ->with('SELECT * FROM table') ->andThrow( new ConnectionException( - 'Connection lost', - new PDOException(new \PDOException('MySQL server has gone away')), + PDOException::new(new \PDOException('MySQL server has gone away')), + null, ), ); @@ -964,8 +946,8 @@ public function testExceptionNoRetriesSelectAfterConnectionProblem() ->with('SELECT * FROM table') ->andThrow( new ConnectionException( - 'Connection lost', - new PDOException(new \PDOException('MySQL server has gone away')), + PDOException::new(new \PDOException('MySQL server has gone away')), + null, ), ); @@ -1022,8 +1004,8 @@ public function testExceptionSelectFromDriver() ->with('SELECT * FROM table') ->andThrow( new DriverException( - 'Connection lost', - new PDOException(new \PDOException('MySQL server has gone away')), + PDOException::new(new \PDOException('MySQL server has gone away')), + null, ), ); diff --git a/tests/DoctrineImplementationTest.php b/tests/DoctrineImplementationTest.php index af6592e..c06dac1 100644 --- a/tests/DoctrineImplementationTest.php +++ b/tests/DoctrineImplementationTest.php @@ -3,9 +3,9 @@ namespace Squirrel\Queries\Tests; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\ResultStatement; -use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Result; +use Doctrine\DBAL\Statement; use Squirrel\Queries\DBSelectQueryInterface; use Squirrel\Queries\Doctrine\DBAbstractImplementation; use Squirrel\Queries\Doctrine\DBSelectQuery; @@ -131,8 +131,9 @@ public function testSelect() $query = 'SELECT blabla FROM yudihui'; $vars = [0, 'dada', 3.5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -145,30 +146,30 @@ public function testSelect() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $result = $this->db->select($query, $vars); // Make sure the query has ended with the correct result - $this->assertEquals(new DBSelectQuery($statement), $result); + $this->assertEquals(new DBSelectQuery($statementResult), $result); } public function testFetch() { - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine result + $statementResult = \Mockery::mock(Result::class); // Select query object - $selectQuery = new DBSelectQuery($statement); + $selectQuery = new DBSelectQuery($statementResult); // Return value from fetch $returnValue = ['fieldName' => 'dada']; // Fetch result set - $statement - ->shouldReceive('fetch') + $statementResult + ->shouldReceive('fetchAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // Make the fetch call @@ -180,15 +181,15 @@ public function testFetch() public function testClear() { - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine result + $statementResult = \Mockery::mock(Result::class); // Select query object - $selectQuery = new DBSelectQuery($statement); + $selectQuery = new DBSelectQuery($statementResult); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Make the fetch call @@ -204,8 +205,9 @@ public function testFetchOne() $query = 'SELECT blabla FROM yudihui'; $vars = [0, 'dada', 3.5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -218,21 +220,21 @@ public function testFetchOne() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); // Return value from fetch $returnValue = ['dada']; // Fetch result set - $statement - ->shouldReceive('fetch') + $statementResult + ->shouldReceive('fetchAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchOne($query, $vars); @@ -247,8 +249,9 @@ public function testFetchAll() $query = 'SELECT blabla FROM yudihui'; $vars = [0, 'dada', 3.5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -261,21 +264,21 @@ public function testFetchAll() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); // Return value from fetch $returnValue = ['dada', 'mumu', 'hihihi']; // Fetch result set - $statement - ->shouldReceive('fetchAll') + $statementResult + ->shouldReceive('fetchAllAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchAll($query, $vars); @@ -302,8 +305,9 @@ public function testInsert() $query = 'INSERT INTO "tableName" ("id","name","active","lastUpdate") VALUES (?,?,?,?)'; $vars = [5, 'Dada', 1, 43535]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -318,11 +322,12 @@ public function testInsert() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Insert query call @@ -343,8 +348,9 @@ public function testLastInsertId() $query = 'INSERT INTO "tableName" ("id","name","lastUpdate") VALUES (?,?,?)'; $vars = [5, 'Dada', 43535]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -359,11 +365,12 @@ public function testLastInsertId() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $this->connection @@ -420,8 +427,9 @@ public function testChange() $query = 'INSERT INTO "tableName" ("id","name","active","lastUpdate") VALUES (?,?,?,?)'; $vars = [5, 'Dada', 1, 43535]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -436,17 +444,18 @@ public function testChange() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(5); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Insert query call @@ -466,8 +475,9 @@ public function testChangeSimple() // Expected query and parameters $query = 'INSERT INTO "tableName" ("id","name","lastUpdate") VALUES (5,"Dada",4534)'; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -480,17 +490,18 @@ public function testChangeSimple() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(5); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Insert query call @@ -510,8 +521,9 @@ public function testInsertOrUpdateEmulationUpdate() ->shouldReceive('beginTransaction') ->once(); - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -526,17 +538,18 @@ public function testInsertOrUpdateEmulationUpdate() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(1); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $this->connection @@ -561,8 +574,9 @@ public function testInsertOrUpdateEmulationInsert() ->shouldReceive('beginTransaction') ->once(); - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -577,17 +591,18 @@ public function testInsertOrUpdateEmulationInsert() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(0); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Expected query and parameters @@ -595,7 +610,8 @@ public function testInsertOrUpdateEmulationInsert() $insertVars = [13, 'Andy']; // Doctrine statement - $insertStatement = \Mockery::mock(ResultStatement::class); + $insertStatement = \Mockery::mock(Statement::class); + $insertStatementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -610,17 +626,18 @@ public function testInsertOrUpdateEmulationInsert() $insertStatement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($insertStatementResult); // "RowCount" call on doctrine result statement - $insertStatement + $insertStatementResult ->shouldReceive('rowCount') ->once() ->andReturn(1); // Close result set - $insertStatement - ->shouldReceive('closeCursor') + $insertStatementResult + ->shouldReceive('free') ->once(); $this->connection @@ -645,8 +662,9 @@ public function testInsertOrUpdateEmulationDoNothingInsert() ->shouldReceive('beginTransaction') ->once(); - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -661,17 +679,18 @@ public function testInsertOrUpdateEmulationDoNothingInsert() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(0); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Expected query and parameters @@ -679,7 +698,8 @@ public function testInsertOrUpdateEmulationDoNothingInsert() $insertVars = [13, 'Andy']; // Doctrine statement - $insertStatement = \Mockery::mock(ResultStatement::class); + $insertStatement = \Mockery::mock(Statement::class); + $insertStatementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -694,17 +714,18 @@ public function testInsertOrUpdateEmulationDoNothingInsert() $insertStatement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($insertStatementResult); // "RowCount" call on doctrine result statement - $insertStatement + $insertStatementResult ->shouldReceive('rowCount') ->once() ->andReturn(1); // Close result set - $insertStatement - ->shouldReceive('closeCursor') + $insertStatementResult + ->shouldReceive('free') ->once(); $this->connection @@ -725,8 +746,9 @@ public function testDelete() $query = 'DELETE FROM "tablename" WHERE "mamamia"=? AND "fumbal" IN (?,?,?)'; $vars = [13, 3, 5, 9]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -741,17 +763,18 @@ public function testDelete() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(5); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Insert query call @@ -769,8 +792,9 @@ public function testDeleteSimple() // Expected query and parameters $query = 'DELETE FROM "tablename" WHERE ("mamamia"=1)'; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -783,17 +807,18 @@ public function testDeleteSimple() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(5); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Insert query call @@ -862,8 +887,9 @@ public function testSelectStructuredSimple() $query = 'SELECT "blabla" FROM "yudihui" WHERE "lala"=?'; $vars = [5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -876,7 +902,8 @@ public function testSelectStructuredSimple() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $result = $this->db->select([ 'fields' => [ @@ -891,7 +918,7 @@ public function testSelectStructuredSimple() ]); // Make sure the query has ended with the correct result - $this->assertEquals(new DBSelectQuery($statement), $result); + $this->assertEquals(new DBSelectQuery($statementResult), $result); $result = $this->db->select([ 'field' => 'blabla', @@ -902,7 +929,7 @@ public function testSelectStructuredSimple() ]); // Make sure the query has ended with the correct result - $this->assertEquals(new DBSelectQuery($statement), $result); + $this->assertEquals(new DBSelectQuery($statementResult), $result); } public function testSelectStructuredCatchAll() @@ -911,8 +938,9 @@ public function testSelectStructuredCatchAll() $query = 'SELECT "a".*,"b"."lala" FROM "yudihui" "a","ahoi" "b" WHERE "a"."lala"=?'; $vars = [5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -925,7 +953,8 @@ public function testSelectStructuredCatchAll() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $result = $this->db->select([ 'fields' => [ @@ -942,14 +971,15 @@ public function testSelectStructuredCatchAll() ]); // Make sure the query has ended with the correct result - $this->assertEquals(new DBSelectQuery($statement), $result); + $this->assertEquals(new DBSelectQuery($statementResult), $result); // Query parameters $query = 'SELECT a.*,"b"."lala" FROM "yudihui" "a","ahoi" "b" WHERE "a"."lala"=?'; $vars = [5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -962,7 +992,8 @@ public function testSelectStructuredCatchAll() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $result = $this->db->select([ 'fields' => [ @@ -979,7 +1010,7 @@ public function testSelectStructuredCatchAll() ]); // Make sure the query has ended with the correct result - $this->assertEquals(new DBSelectQuery($statement), $result); + $this->assertEquals(new DBSelectQuery($statementResult), $result); } public function testSelectStructuredCatchAllNoFields() @@ -988,8 +1019,9 @@ public function testSelectStructuredCatchAllNoFields() $query = 'SELECT * FROM "yudihui" "a","ahoi" "b" WHERE "a"."lala"=?'; $vars = [5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1002,7 +1034,8 @@ public function testSelectStructuredCatchAllNoFields() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $result = $this->db->select([ 'tables' => [ @@ -1015,7 +1048,7 @@ public function testSelectStructuredCatchAllNoFields() ]); // Make sure the query has ended with the correct result - $this->assertEquals(new DBSelectQuery($statement), $result); + $this->assertEquals(new DBSelectQuery($statementResult), $result); } public function testSelectStructuredNoWhere() @@ -1024,8 +1057,9 @@ public function testSelectStructuredNoWhere() $query = 'SELECT * FROM "yudihui" "a","ahoi" "b"'; $vars = []; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1038,7 +1072,8 @@ public function testSelectStructuredNoWhere() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $result = $this->db->select([ 'tables' => [ @@ -1049,7 +1084,7 @@ public function testSelectStructuredNoWhere() ]); // Make sure the query has ended with the correct result - $this->assertEquals(new DBSelectQuery($statement), $result); + $this->assertEquals(new DBSelectQuery($statementResult), $result); } public function testSelectStructuredComplicated() @@ -1078,8 +1113,9 @@ public function testSelectStructuredComplicated() ->once() ->andReturn($platform); - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1092,7 +1128,8 @@ public function testSelectStructuredComplicated() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $result = $this->db->select([ 'fields' => [ @@ -1125,7 +1162,7 @@ public function testSelectStructuredComplicated() ]); // Make sure the query has ended with the correct result - $this->assertEquals(new DBSelectQuery($statement), $result); + $this->assertEquals(new DBSelectQuery($statementResult), $result); } public function testFetchOneStructured() @@ -1158,8 +1195,9 @@ public function testFetchOneStructured() ->once() ->andReturn($platform); - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1172,21 +1210,21 @@ public function testFetchOneStructured() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); // Return value from fetch $returnValue = ['id' => '5', 'hash' => 'fhsdkj']; // Fetch result set - $statement - ->shouldReceive('fetch') + $statementResult + ->shouldReceive('fetchAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchOne($structuredQuery); @@ -1216,8 +1254,9 @@ public function testFetchAllStructured() ], ]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1230,21 +1269,21 @@ public function testFetchAllStructured() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); // Return value from fetch $returnValue = [['id' => '5', 'hash' => 'fhsdkj']]; // Fetch result set - $statement - ->shouldReceive('fetchAll') + $statementResult + ->shouldReceive('fetchAllAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchAll($structuredQuery); @@ -1274,8 +1313,9 @@ public function testFetchAllStructuredFlattened() ], ]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1288,21 +1328,21 @@ public function testFetchAllStructuredFlattened() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); // Return value from fetch $returnValue = [['id' => '5', 'hash' => 'fhsdkj']]; // Fetch result set - $statement - ->shouldReceive('fetchAll') + $statementResult + ->shouldReceive('fetchAllAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchAllAndFlatten($structuredQuery); @@ -1360,8 +1400,9 @@ public function testFetchOneStructured2() ->once() ->andReturn($platform); - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1374,21 +1415,21 @@ public function testFetchOneStructured2() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); // Return value from fetch $returnValue = ['id' => '5', 'hash' => 'fhsdkj']; // Fetch result set - $statement - ->shouldReceive('fetch') + $statementResult + ->shouldReceive('fetchAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchOne($structuredQuery); @@ -1432,8 +1473,9 @@ public function testFetchOneStructured2() ], ]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1446,21 +1488,21 @@ public function testFetchOneStructured2() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); // Return value from fetch $returnValue = ['id' => '5', 'hash' => 'fhsdkj']; // Fetch result set - $statement - ->shouldReceive('fetch') + $statementResult + ->shouldReceive('fetchAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchOne($structuredQuery); @@ -1483,8 +1525,9 @@ public function testUpdateStructured() ->once() ->andReturn($platform); - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1499,17 +1542,18 @@ public function testUpdateStructured() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(33); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->update('blobs.aa_sexy', [ @@ -1526,8 +1570,9 @@ public function testUpdateStructuredNULL() $query = 'UPDATE "blobs"."aa_sexy" SET "anyfieldname"=?,"nullentry"=?,"active"=? WHERE "blabla"=?'; $vars = ['nicevalue', null, 1, 5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -1542,17 +1587,18 @@ public function testUpdateStructuredNULL() $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // "RowCount" call on doctrine result statement - $statement + $statementResult ->shouldReceive('rowCount') ->once() ->andReturn(33); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->update('blobs.aa_sexy', [ diff --git a/tests/DoctrineMySQLImplementationTest.php b/tests/DoctrineMySQLImplementationTest.php index 532edbd..4e34947 100644 --- a/tests/DoctrineMySQLImplementationTest.php +++ b/tests/DoctrineMySQLImplementationTest.php @@ -3,6 +3,7 @@ namespace Squirrel\Queries\Tests; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Statement; use Squirrel\Queries\Doctrine\DBMySQLImplementation; use Squirrel\Queries\Exception\DBInvalidOptionException; @@ -76,15 +77,17 @@ public function testUpsert() 1, ]; - // Statement and the data values it should receive + // Doctrine statement and result $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); $this->bindValues($statement, $vars); $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // SQL query should be received by "prepare" $this->connection @@ -94,8 +97,8 @@ public function testUpsert() ->andReturn($statement); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Test the upsert @@ -165,15 +168,17 @@ public function testUpsertCustomUpdate() 'laaaast', ]; - // Statement and the data values it should receive + // Doctrine statement and result $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); $this->bindValues($statement, $vars); $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // SQL query should be received by "prepare" $this->connection @@ -183,8 +188,8 @@ public function testUpsertCustomUpdate() ->andReturn($statement); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Test the upsert @@ -240,15 +245,17 @@ public function testUpsertCustomUpdateWithVars() 'laaaast', ]; - // Statement and the data values it should receive + // Doctrine statement and result $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); $this->bindValues($statement, $vars); $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // SQL query should be received by "prepare" $this->connection @@ -258,8 +265,8 @@ public function testUpsertCustomUpdateWithVars() ->andReturn($statement); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Test the upsert @@ -302,15 +309,17 @@ public function testUpsertNoUpdateRows() 6, ]; - // Statement and the data values it should receive + // Doctrine statement and result $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); $this->bindValues($statement, $vars); $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // SQL query should be received by "prepare" $this->connection @@ -320,8 +329,8 @@ public function testUpsertNoUpdateRows() ->andReturn($statement); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Test the upsert diff --git a/tests/DoctrinePostgreSQLImplementationTest.php b/tests/DoctrinePostgreSQLImplementationTest.php index ecc7b53..4f6f98b 100644 --- a/tests/DoctrinePostgreSQLImplementationTest.php +++ b/tests/DoctrinePostgreSQLImplementationTest.php @@ -3,8 +3,7 @@ namespace Squirrel\Queries\Tests; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\ResultStatement; -use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Statement; use Squirrel\Queries\Doctrine\DBPostgreSQLImplementation; use Squirrel\Queries\Exception\DBInvalidOptionException; @@ -55,8 +54,9 @@ public function testFetchOne() $query = 'SELECT blob FROM yudihui WHERE active = ? AND name = ? AND balance = ?'; $vars = [0, 'dada', 3.5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -69,22 +69,22 @@ public function testFetchOne() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $fp = \fopen('php://temp', 'rb+'); \fwrite($fp, 'binary data!'); \fseek($fp, 0); - $statement - ->shouldReceive('fetch') + $statementResult + ->shouldReceive('fetchAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn([ 'blob' => $fp, ]); - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchOne($query, $vars); @@ -99,8 +99,9 @@ public function testFetchAll() $query = 'SELECT blob FROM yudihui WHERE active = ? AND name = ? AND balance = ?'; $vars = [0, 'dada', 3.5]; - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -113,22 +114,22 @@ public function testFetchAll() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); $fp = \fopen('php://temp', 'rb+'); \fwrite($fp, 'binary data!'); \fseek($fp, 0); - $statement - ->shouldReceive('fetchAll') + $statementResult + ->shouldReceive('fetchAllAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn([[ 'blob' => $fp, ]]); - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchAll($query, $vars); @@ -167,15 +168,17 @@ public function testUpsert() 1, ]; - // Statement and the data values it should receive + // Doctrine statement and result $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); $this->bindValues($statement, $vars); $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // SQL query should be received by "prepare" $this->connection @@ -185,8 +188,8 @@ public function testUpsert() ->andReturn($statement); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Test the upsert @@ -257,15 +260,17 @@ public function testUpsertCustomUpdate() 'laaaast', ]; - // Statement and the data values it should receive + // Doctrine statement and result $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); $this->bindValues($statement, $vars); $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // SQL query should be received by "prepare" $this->connection @@ -275,8 +280,8 @@ public function testUpsertCustomUpdate() ->andReturn($statement); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Test the upsert @@ -333,15 +338,17 @@ public function testUpsertCustomUpdateWithVars() 'laaaast', ]; - // Statement and the data values it should receive + // Doctrine statement and result $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); $this->bindValues($statement, $vars); $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); + ->withNoArgs() + ->andReturn($statementResult); // SQL query should be received by "prepare" $this->connection @@ -351,8 +358,8 @@ public function testUpsertCustomUpdateWithVars() ->andReturn($statement); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Test the upsert @@ -394,17 +401,19 @@ public function testUpsertNoUpdateRows() 6, ]; - // Statement and the data values it should receive + // Doctrine statement and result $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); $this->bindValues($statement, $vars); $statement ->shouldReceive('execute') ->once() - ->withNoArgs(); - $statement - ->shouldReceive('fetchAll') + ->withNoArgs() + ->andReturn($statementResult); + $statementResult + ->shouldReceive('fetchAllAssociative') ->once() ->andReturn([ ['case' => 'update'], @@ -418,8 +427,8 @@ public function testUpsertNoUpdateRows() ->andReturn($statement); // Close result set - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); // Test the upsert diff --git a/tests/DoctrineSQLiteImplementationTest.php b/tests/DoctrineSQLiteImplementationTest.php index 63a776c..2e660ca 100644 --- a/tests/DoctrineSQLiteImplementationTest.php +++ b/tests/DoctrineSQLiteImplementationTest.php @@ -3,9 +3,9 @@ namespace Squirrel\Queries\Tests; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\ResultStatement; -use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Result; +use Doctrine\DBAL\Statement; use Squirrel\Queries\Doctrine\DBSQLiteImplementation; class DoctrineSQLiteImplementationTest extends \PHPUnit\Framework\TestCase @@ -93,8 +93,9 @@ public function testFetchOneStructured2() ->once() ->andReturn($platform); - // Doctrine statement - $statement = \Mockery::mock(ResultStatement::class); + // Doctrine statement and result + $statement = \Mockery::mock(Statement::class); + $statementResult = \Mockery::mock(Result::class); // "Prepare" call to doctrine connection $this->connection @@ -107,21 +108,21 @@ public function testFetchOneStructured2() $statement ->shouldReceive('execute') ->once() - ->with(\Mockery::mustBe($vars)); + ->with(\Mockery::mustBe($vars)) + ->andReturn($statementResult); // Return value from fetch $returnValue = ['id' => '5', 'hash' => 'fhsdkj']; // Fetch result set - $statement - ->shouldReceive('fetch') + $statementResult + ->shouldReceive('fetchAssociative') ->once() - ->with(\Mockery::mustBe(FetchMode::ASSOCIATIVE)) ->andReturn($returnValue); // "Execute" call on doctrine result statement - $statement - ->shouldReceive('closeCursor') + $statementResult + ->shouldReceive('free') ->once(); $result = $this->db->fetchOne($structuredQuery); diff --git a/vendor-bin/phpunit/composer.json b/vendor-bin/phpunit/composer.json deleted file mode 100644 index fa6d328..0000000 --- a/vendor-bin/phpunit/composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require": { - "phpunit/phpunit": "^9.0" - } -}