diff --git a/composer.json b/composer.json index 01c5abc97ec..2aee2db3913 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "doctrine/coding-standard": "^4.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.10.1", + "phpstan/phpstan-phpunit": "dev-GetMockBuilderDynamicReturnTypeExtension-with-undefined-class as 0.10.0.999", "phpunit/phpunit": "^7.1.2", "phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5", "symfony/console": "^2.0.5|^3.0|^4.0", @@ -44,5 +45,11 @@ "dev-master": "2.9.x-dev", "dev-develop": "3.0.x-dev" } - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/Majkl578/phpstan-phpunit" + } + ] } diff --git a/composer.lock b/composer.lock index 8eb6bc50ee9..78774367416 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c1b5ddb5a1259c7ac793dd9c6e6d657a", + "content-hash": "650a295a6568ba5cb375b4a3bbeabafc", "packages": [ { "name": "doctrine/cache", @@ -1522,6 +1522,63 @@ "description": "PHPStan - PHP Static Analysis Tool", "time": "2018-07-01T18:22:12+00:00" }, + { + "name": "phpstan/phpstan-phpunit", + "version": "dev-GetMockBuilderDynamicReturnTypeExtension-with-undefined-class", + "source": { + "type": "git", + "url": "https://github.com/Majkl578/phpstan-phpunit.git", + "reference": "3c06d9735432b3ec55bb6805bdd2433424287944" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Majkl578/phpstan-phpunit/zipball/3c06d9735432b3ec55bb6805bdd2433424287944", + "reference": "3c06d9735432b3ec55bb6805bdd2433424287944", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.0", + "php": "~7.1", + "phpstan/phpstan": "^0.10" + }, + "conflict": { + "phpunit/phpunit": "<7.0" + }, + "require-dev": { + "consistence/coding-standard": "^3.0.1", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "jakub-onderka/php-parallel-lint": "^1.0", + "phing/phing": "^2.16.0", + "phpstan/phpstan-strict-rules": "^0.10", + "phpunit/phpunit": "^7.0", + "satooshi/php-coveralls": "^1.0", + "slevomat/coding-standard": "^4.5.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.10-dev" + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "autoload-dev": { + "classmap": [ + "tests/" + ] + }, + "license": [ + "MIT" + ], + "description": "PHPUnit extensions and rules for PHPStan", + "support": { + "source": "https://github.com/Majkl578/phpstan-phpunit/tree/GetMockBuilderDynamicReturnTypeExtension-with-undefined-class" + }, + "time": "2018-08-18T01:48:14+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "6.0.5", @@ -2997,9 +3054,18 @@ "time": "2018-01-29T19:49:41+00:00" } ], - "aliases": [], + "aliases": [ + { + "alias": "0.10.0.999", + "alias_normalized": "0.10.0.999", + "version": "dev-GetMockBuilderDynamicReturnTypeExtension-with-undefined-class", + "package": "phpstan/phpstan-phpunit" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "phpstan/phpstan-phpunit": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 406cc2a530e..ac07254ed22 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,9 +2,14 @@ parameters: level: 3 paths: - %currentWorkingDirectory%/lib + - %currentWorkingDirectory%/tests autoload_files: - %currentWorkingDirectory%/tests/phpstan-polyfill.php reportUnmatchedIgnoredErrors: false + earlyTerminatingMethodCalls: + PHPUnit\Framework\Assert: + - markTestSkipped + - markTestIncomplete ignoreErrors: # extension not available - '~^(Used )?(Function|Constant) sasql_\S+ not found\.\z~i' @@ -44,3 +49,11 @@ parameters: # weird class name, doesn't exist in stubs either - '~unknown class OCI-(Lob|Collection)~' + + # impossible inference for covariance + - '~^Property Doctrine\\Tests\\DBAL\\Types\\\S+Test::\$type \(Doctrine\\DBAL\\Types\\\S+Type\) does not accept Doctrine\\DBAL\\Types\\Type\.\z~' + - '~^Property Doctrine\\Tests\\DBAL\\Tools\\Console\\RunSqlCommandTest::\$command \(Doctrine\\DBAL\\Tools\\Console\\Command\\RunSqlCommand\) does not accept Symfony\\Component\\Console\\Command\\Command\.\z~' + +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon diff --git a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php index 5bc77c911c3..6a0e0483b66 100644 --- a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php +++ b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php @@ -28,7 +28,7 @@ class QueryCacheProfileTest extends DbalTestCase private $params = [666]; /** - * @var string[] + * @var int[] */ private $types = [ParameterType::INTEGER]; diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 7a49b3f9577..927c76593a0 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -91,7 +91,7 @@ public function getSQLState() $message = 'DBAL exception message'; foreach ($data as $item) { - /** @var $driverException \Doctrine\DBAL\Driver\DriverException */ + /** @var DriverException $driverException */ list($driverException, $convertedExceptionClassName) = $item; $convertedException = $this->driver->convertException($message, $driverException); diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php index 96691bacd9c..48867a0e2cd 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php @@ -24,7 +24,7 @@ class PDOExceptionTest extends DbalTestCase /** * The wrapped PDO exception mock. * - * @var \PDOException|\PHPUnit_Framework_MockObject_MockObject + * @var \PDOException */ private $wrappedException; diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index 6fd187e3d28..c5599fd218d 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -103,9 +103,6 @@ protected function createDriver() return new Driver(); } - /** - * @throws \PHPUnit_Framework_SkippedTestError - */ private function skipWhenNotUsingPhp56AndPdoPgsql() { if (! defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) { diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index f63e397c65b..13e6455cc25 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -743,11 +743,11 @@ public function testFetchAllSupportFetchClass() $results = $stmt->fetchAll( FetchMode::CUSTOM_OBJECT, - __NAMESPACE__.'\\MyFetchClass' + MyFetchClass::class ); self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(MyFetchClass::class, $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -781,12 +781,12 @@ public function testSetFetchModeClassFetchAll() $sql = "SELECT * FROM fetch_table"; $stmt = $this->_conn->query($sql); - $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); + $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, MyFetchClass::class); $results = $stmt->fetchAll(); self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(MyFetchClass::class, $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -803,7 +803,7 @@ public function testSetFetchModeClassFetch() $sql = "SELECT * FROM fetch_table"; $stmt = $this->_conn->query($sql); - $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); + $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, MyFetchClass::class); $results = array(); while ($row = $stmt->fetch()) { @@ -811,7 +811,7 @@ public function testSetFetchModeClassFetch() } self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(MyFetchClass::class, $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php index 59b42a75635..49691ae1ca7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php @@ -5,8 +5,10 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2; use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; +use Doctrine\DBAL\Statement; use Doctrine\Tests\DbalFunctionalTestCase; use PHPUnit\Framework\Error\Notice; +use function assert; use function extension_loaded; class DB2StatementTest extends DbalFunctionalTestCase @@ -27,6 +29,7 @@ protected function setUp() public function testExecutionErrorsAreNotSuppressed() { $stmt = $this->_conn->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?'); + assert($stmt instanceof Statement); // unwrap the statement to prevent the wrapper from handling the PHPUnit-originated exception $wrappedStmt = $stmt->getWrappedStatement(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php index 90430e92a02..be86fa566c7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php @@ -3,8 +3,10 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8; use Doctrine\DBAL\Driver\OCI8\Driver; +use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; +use function assert; use function extension_loaded; class OCI8ConnectionTest extends DbalFunctionalTestCase @@ -26,7 +28,11 @@ protected function setUp() $this->markTestSkipped('oci8 only test.'); } - $this->driverConnection = $this->_conn->getWrappedConnection(); + + $wrappedConnection = $this->_conn->getWrappedConnection(); + assert($wrappedConnection instanceof OCI8Connection); + + $this->driverConnection = $wrappedConnection; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php index 29f18f8c78f..33205b1c22b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php @@ -24,11 +24,13 @@ protected function setUp() parent::setUp(); - $this->driverConnection = $this->_conn->getWrappedConnection(); + $wrappedConnection = $this->_conn->getWrappedConnection(); - if ( ! $this->driverConnection instanceof PDOConnection) { + if (! $wrappedConnection instanceof PDOConnection) { $this->markTestSkipped('PDO connection only test.'); } + + $this->driverConnection = $wrappedConnection; } protected function tearDown() diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index 88c87d7e08b..b3ec5f0b61f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -3,9 +3,11 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlsrv; use Doctrine\DBAL\Driver\Connection as Connection; +use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use PDO; +use function assert; use function extension_loaded; class DriverTest extends AbstractDriverTest @@ -68,6 +70,7 @@ public function testConnectionOptions() : void public function testDriverOptions() : void { $connection = $this->getConnection([PDO::ATTR_CASE => PDO::CASE_UPPER]); + assert($connection instanceof PDOConnection); self::assertSame(PDO::CASE_UPPER, $connection->getAttribute(PDO::ATTR_CASE)); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 8b4c01e31d2..0b26e25f436 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -7,6 +7,7 @@ use Doctrine\Tests\DbalFunctionalTestCase; use const CASE_LOWER; use function array_change_key_case; +use function assert; use function sprintf; use function strlen; use function strtolower; @@ -47,7 +48,10 @@ protected function setUp() private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSlaveConnection { - return DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave)); + $connection = DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave)); + assert($connection instanceof MasterSlaveConnection); + + return $connection; } private function createMasterSlaveConnectionParams(bool $keepSlave = false) : array diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index f95f5bed47a..c2e557cfd53 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -155,7 +155,7 @@ public function testPortabilityPdoSqlServer() $connection = new ConnectionPortability($params, $driverMock); - $connection->connect($params); + $connection->connect(); self::assertEquals($portability, $connection->getPortability()); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 40d0f03f108..bd29c05e8f9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Types\Type; use function array_map; use function array_pop; +use function assert; use function count; use function strtolower; @@ -43,6 +44,8 @@ public function testGetSearchPath() */ public function testGetSchemaNames() { + assert($this->_sm instanceof Schema\PostgreSqlSchemaManager); + $names = $this->_sm->getSchemaNames(); self::assertInternalType('array', $names); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 70210133b1f..a7557d3690e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -3,8 +3,10 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\ParameterType; use PDO; +use function assert; use function in_array; /** @@ -38,7 +40,7 @@ protected function setUp() protected function tearDown() { if ($this->running) { - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $this->configureEmulatedPrepares(false); } parent::tearDown(); @@ -72,7 +74,7 @@ public function testBooleanConversionBoolParamRealPrepares() public function testBooleanConversionBoolParamEmulatedPrepares() { - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + $this->configureEmulatedPrepares(true); $platform = $this->_conn->getDatabasePlatform(); @@ -96,7 +98,7 @@ public function testBooleanConversionNullParamEmulatedPrepares( $statementValue, $databaseConvertedValue ) { - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + $this->configureEmulatedPrepares(true); $platform = $this->_conn->getDatabasePlatform(); @@ -120,7 +122,7 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB $statementValue, $databaseConvertedValue ) { - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + $this->configureEmulatedPrepares(true); $platform = $this->_conn->getDatabasePlatform(); @@ -168,4 +170,12 @@ public function booleanTypeConversionWithoutPdoTypeProvider() array(null, null) ); } + + private function configureEmulatedPrepares(bool $enabled) : void + { + $wrappedConnection = $this->_conn->getWrappedConnection(); + assert($wrappedConnection instanceof PDOConnection); + + $wrappedConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $enabled); + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index bca9063c55c..1829bac970b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -2,12 +2,14 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; +use function assert; abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase { @@ -877,6 +879,8 @@ public function testInitializesTsvectorTypeMapping() */ public function testReturnsDisallowDatabaseConnectionsSQL() { + assert($this->_platform instanceof PostgreSqlPlatform); + self::assertSame( "UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'", $this->_platform->getDisallowDatabaseConnectionsSQL('foo') @@ -888,6 +892,8 @@ public function testReturnsDisallowDatabaseConnectionsSQL() */ public function testReturnsCloseActiveDatabaseConnectionsSQL() { + assert($this->_platform instanceof PostgreSqlPlatform); + self::assertSame( "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'", $this->_platform->getCloseActiveDatabaseConnectionsSQL('foo') @@ -970,6 +976,8 @@ public function testQuotesSchemaNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() { + assert($this->_platform instanceof PostgreSqlPlatform); + self::assertContains( "'Foo''Bar\\\\'", $this->_platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"), diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 72864db1250..9c6e20270b6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -2,12 +2,14 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; +use function assert; use function sprintf; abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCase @@ -1123,6 +1125,8 @@ protected function getQuotesDropConstraintSQL() */ public function testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL($table, $column, $expectedSql) { + assert($this->_platform instanceof SQLServerPlatform); + self::assertSame($expectedSql, $this->_platform->getDefaultConstraintDeclarationSQL($table, $column)); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 5e270b4a1e7..8e3f1b89003 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; use function array_walk; +use function assert; use function preg_replace; use function strtoupper; use function uniqid; @@ -615,6 +616,8 @@ public function getAlterTableRenameColumnSQL() */ public function testReturnsDropAutoincrementSQL($table, $expectedSql) { + assert($this->_platform instanceof OraclePlatform); + self::assertSame($expectedSql, $this->_platform->getDropAutoincrementSql($table)); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php index 0189dbdfe36..c3785c0a809 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL92Platform; use Doctrine\DBAL\Types\Type; +use function assert; class PostgreSQL92PlatformTest extends AbstractPostgreSqlPlatformTestCase { @@ -63,6 +64,8 @@ public function testInitializesJsonTypeMapping() */ public function testReturnsCloseActiveDatabaseConnectionsSQL() { + assert($this->_platform instanceof PostgreSQL92Platform); + self::assertSame( "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo'", $this->_platform->getCloseActiveDatabaseConnectionsSQL('foo') diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 3975b8fd2c7..61be06b86f2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; +use function assert; class SqlitePlatformTest extends AbstractPlatformTestCase { @@ -76,6 +77,8 @@ public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers( */ public function testGeneratesTypeDeclarationForTinyIntegers() { + assert($this->_platform instanceof SqlitePlatform); + self::assertEquals( 'TINYINT', $this->_platform->getTinyIntTypeDeclarationSQL(array()) @@ -105,6 +108,8 @@ public function testGeneratesTypeDeclarationForTinyIntegers() */ public function testGeneratesTypeDeclarationForSmallIntegers() { + assert($this->_platform instanceof SqlitePlatform); + self::assertEquals( 'SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array()) @@ -138,6 +143,8 @@ public function testGeneratesTypeDeclarationForSmallIntegers() */ public function testGeneratesTypeDeclarationForMediumIntegers() { + assert($this->_platform instanceof SqlitePlatform); + self::assertEquals( 'MEDIUMINT', $this->_platform->getMediumIntTypeDeclarationSQL(array()) diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php index e8129d3a20f..75ce3a889a0 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\MySqlSchemaManager; +use PHPUnit\Framework\MockObject\MockObject; use function array_map; class MySqlSchemaManagerTest extends \PHPUnit\Framework\TestCase @@ -15,7 +16,7 @@ class MySqlSchemaManagerTest extends \PHPUnit\Framework\TestCase */ private $manager; - /** @var Connection */ + /** @var Connection|MockObject */ private $conn; protected function setUp() diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index 81db2c51e08..72b5ef86990 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -388,7 +388,9 @@ public function testVisitsVisitor() $visitor->expects($this->exactly(2)) ->method('acceptSequence'); - self::assertNull($schema->visit($visitor)); + $schema->visit($visitor); + + self::doesNotPerformAssertions(); // FIXME } /** @@ -449,6 +451,8 @@ public function testVisitsNamespaceVisitor() $visitor->expects($this->exactly(2)) ->method('acceptSequence'); - self::assertNull($schema->visit($visitor)); + $schema->visit($visitor); + + self::doesNotPerformAssertions(); // FIXME } } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index 9c96cbfc975..a6ac930d964 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -20,7 +20,9 @@ namespace Doctrine\Tests\DBAL\Sharding; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; +use function assert; /** * @requires extension pdo_sqlite @@ -40,6 +42,8 @@ public function testConnect() 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); + assert($conn instanceof PoolingShardConnection); + self::assertFalse($conn->isConnected(0)); $conn->connect(0); self::assertEquals(1, $conn->fetchColumn('SELECT 1')); @@ -184,6 +188,8 @@ public function testSwitchShardWithOpenTransactionException() 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); + assert($conn instanceof PoolingShardConnection); + $conn->beginTransaction(); $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); @@ -203,6 +209,8 @@ public function testGetActiveShardId() 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); + assert($conn instanceof PoolingShardConnection); + self::assertNull($conn->getActiveShardId()); $conn->connect(0); @@ -227,6 +235,8 @@ public function testGetParamsOverride() 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); + assert($conn instanceof PoolingShardConnection); + self::assertEquals(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', @@ -267,6 +277,8 @@ public function testGetHostOverride() 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); + assert($conn instanceof PoolingShardConnection); + self::assertEquals('localhost', $conn->getHost()); $conn->connect(1); @@ -286,6 +298,8 @@ public function testGetPortOverride() 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); + assert($conn instanceof PoolingShardConnection); + self::assertEquals(3306, $conn->getPort()); $conn->connect(1); @@ -305,6 +319,8 @@ public function testGetUsernameOverride() 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); + assert($conn instanceof PoolingShardConnection); + self::assertEquals('foo', $conn->getUsername()); $conn->connect(1); @@ -324,6 +340,8 @@ public function testGetPasswordOverride() 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); + assert($conn instanceof PoolingShardConnection); + self::assertEquals('foo', $conn->getPassword()); $conn->connect(1); diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index fa22536f2d4..03835e2e4c2 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -2,26 +2,30 @@ namespace Doctrine\Tests\DBAL; +use Doctrine\DBAL\Configuration; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; use Doctrine\DBAL\Logging\SQLLogger; +use PDOStatement; +use PHPUnit\Framework\MockObject\MockObject; class StatementTest extends \Doctrine\Tests\DbalTestCase { /** * - * @var \Doctrine\DBAL\Connection + * @var Connection|MockObject */ private $conn; /** * - * @var \Doctrine\DBAL\Configuration + * @var Configuration|MockObject */ private $configuration; /** - * @var \PDOStatement + * @var PDOStatement|MockObject */ private $pdoStatement; diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index 164a609198a..5d2f49ae483 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -2,8 +2,10 @@ namespace Doctrine\Tests\DBAL\Tools\Console; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Doctrine\DBAL\Tools\Console\ConsoleRunner; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -15,7 +17,7 @@ class RunSqlCommandTest extends \PHPUnit\Framework\TestCase private $command; /** - * @var \Doctrine\DBAL\Connection + * @var Connection|MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index 7c60986240e..600d965b708 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -7,12 +7,13 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; use function get_class; class DateImmutableTypeTest extends \PHPUnit\Framework\TestCase { /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy + * @var AbstractPlatform|MockObject */ private $platform; @@ -24,7 +25,7 @@ class DateImmutableTypeTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->type = Type::getType('date_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->createMock(AbstractPlatform::class); } public function testFactoryCreatesCorrectType() @@ -44,46 +45,53 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->createMock(\DateTimeImmutable::class); - $this->platform->getDateFormatString()->willReturn('Y-m-d')->shouldBeCalled(); - $date->format('Y-m-d')->willReturn('2016-01-01')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateFormatString') + ->willReturn('Y-m-d'); + $date->expects($this->once()) + ->method('format') + ->with('Y-m-d') + ->willReturn('2016-01-01'); self::assertSame( '2016-01-01', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new \DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { $date = new \DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsDateStringToPHPValue() { - $this->platform->getDateFormatString()->willReturn('Y-m-d')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateFormatString') + ->willReturn('Y-m-d'); - $date = $this->type->convertToPHPValue('2016-01-01', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01', $this->platform); self::assertInstanceOf(\DateTimeImmutable::class, $date); self::assertSame('2016-01-01', $date->format('Y-m-d')); @@ -91,9 +99,11 @@ public function testConvertsDateStringToPHPValue() public function testResetTimeFractionsWhenConvertingToPHPValue() { - $this->platform->getDateFormatString()->willReturn('Y-m-d'); + $this->platform->expects($this->any()) + ->method('getDateFormatString') + ->willReturn('Y-m-d'); - $date = $this->type->convertToPHPValue('2016-01-01', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01', $this->platform); self::assertSame('2016-01-01 00:00:00.000000', $date->format('Y-m-d H:i:s.u')); } @@ -102,11 +112,11 @@ public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateStri { $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid date string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid date string', $this->platform); } public function testRequiresSQLCommentHint() { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 9cb1f9c6b72..0e069b34c7d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -7,12 +7,13 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; use function get_class; class DateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase { /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy + * @var AbstractPlatform|MockObject */ private $platform; @@ -24,7 +25,7 @@ class DateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->type = Type::getType('datetime_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); } public function testFactoryCreatesCorrectType() @@ -44,46 +45,53 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->getMockBuilder(\DateTimeImmutable::class)->getMock(); - $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); - $date->format('Y-m-d H:i:s')->willReturn('2016-01-01 15:58:59')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); + $date->expects($this->once()) + ->method('format') + ->with('Y-m-d H:i:s') + ->willReturn('2016-01-01 15:58:59'); self::assertSame( '2016-01-01 15:58:59', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new \DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { $date = new \DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsDateTimeStringToPHPValue() { - $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); - $date = $this->type->convertToPHPValue('2016-01-01 15:58:59', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01 15:58:59', $this->platform); self::assertInstanceOf(\DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59', $date->format('Y-m-d H:i:s')); @@ -94,9 +102,11 @@ public function testConvertsDateTimeStringToPHPValue() */ public function testConvertsDateTimeStringWithMicrosecondsToPHPValue() { - $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s'); + $this->platform->expects($this->any()) + ->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); - $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456', $this->platform); self::assertSame('2016-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } @@ -105,11 +115,11 @@ public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTime { $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid datetime string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid datetime string', $this->platform); } public function testRequiresSQLCommentHint() { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index 9563d968082..a0b2c25b183 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -7,12 +7,13 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeTzImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; use function get_class; class DateTimeTzImmutableTypeTest extends \PHPUnit\Framework\TestCase { /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy + * @var AbstractPlatform|MockObject */ private $platform; @@ -24,7 +25,7 @@ class DateTimeTzImmutableTypeTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->type = Type::getType('datetimetz_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->createMock(AbstractPlatform::class); } public function testFactoryCreatesCorrectType() @@ -44,46 +45,53 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->createMock(\DateTimeImmutable::class); - $this->platform->getDateTimeTzFormatString()->willReturn('Y-m-d H:i:s T')->shouldBeCalled(); - $date->format('Y-m-d H:i:s T')->willReturn('2016-01-01 15:58:59 UTC')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeTzFormatString') + ->willReturn('Y-m-d H:i:s T'); + $date->expects($this->once()) + ->method('format') + ->with('Y-m-d H:i:s T') + ->willReturn('2016-01-01 15:58:59 UTC'); self::assertSame( '2016-01-01 15:58:59 UTC', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new \DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { $date = new \DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsDateTimeWithTimezoneStringToPHPValue() { - $this->platform->getDateTimeTzFormatString()->willReturn('Y-m-d H:i:s T')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeTzFormatString') + ->willReturn('Y-m-d H:i:s T'); - $date = $this->type->convertToPHPValue('2016-01-01 15:58:59 UTC', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01 15:58:59 UTC', $this->platform); self::assertInstanceOf(\DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59 UTC', $date->format('Y-m-d H:i:s T')); @@ -93,11 +101,11 @@ public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTime { $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid datetime with timezone string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid datetime with timezone string', $this->platform); } public function testRequiresSQLCommentHint() { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index 78ae5917f77..951229c6a45 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -7,12 +7,13 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\TimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; use function get_class; class TimeImmutableTypeTest extends \PHPUnit\Framework\TestCase { /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy + * @var AbstractPlatform|MockObject */ private $platform; @@ -24,7 +25,7 @@ class TimeImmutableTypeTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->type = Type::getType('time_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); } public function testFactoryCreatesCorrectType() @@ -44,46 +45,53 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->getMockBuilder(\DateTimeImmutable::class)->getMock(); - $this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); - $date->format('H:i:s')->willReturn('15:58:59')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getTimeFormatString') + ->willReturn('H:i:s'); + $date->expects($this->once()) + ->method('format') + ->with('H:i:s') + ->willReturn('15:58:59'); self::assertSame( '15:58:59', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new \DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { $date = new \DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsTimeStringToPHPValue() { - $this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getTimeFormatString') + ->willReturn('H:i:s'); - $date = $this->type->convertToPHPValue('15:58:59', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('15:58:59', $this->platform); self::assertInstanceOf(\DateTimeImmutable::class, $date); self::assertSame('15:58:59', $date->format('H:i:s')); @@ -91,9 +99,11 @@ public function testConvertsTimeStringToPHPValue() public function testResetDateFractionsWhenConvertingToPHPValue() { - $this->platform->getTimeFormatString()->willReturn('H:i:s'); + $this->platform->expects($this->any()) + ->method('getTimeFormatString') + ->willReturn('H:i:s'); - $date = $this->type->convertToPHPValue('15:58:59', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('15:58:59', $this->platform); self::assertSame('1970-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } @@ -102,11 +112,11 @@ public function testThrowsExceptionDuringConversionToPHPValueWithInvalidTimeStri { $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid time string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid time string', $this->platform); } public function testRequiresSQLCommentHint() { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index ebf21284651..5ff1f27f95a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -7,11 +7,12 @@ use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\VarDateTimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\MockObject\MockObject; class VarDateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase { /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy + * @var AbstractPlatform|MockObject */ private $platform; @@ -27,7 +28,7 @@ protected function setUp() } $this->type = Type::getType('vardatetime_immutable'); - $this->platform = $this->prophesize(AbstractPlatform::class); + $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); } public function testReturnsName() @@ -42,46 +43,52 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->getMockBuilder(\DateTimeImmutable::class)->getMock(); - $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); - $date->format('Y-m-d H:i:s')->willReturn('2016-01-01 15:58:59')->shouldBeCalled(); + $this->platform->expects($this->once()) + ->method('getDateTimeFormatString') + ->willReturn('Y-m-d H:i:s'); + $date->expects($this->once()) + ->method('format') + ->with('Y-m-d H:i:s') + ->willReturn('2016-01-01 15:58:59'); self::assertSame( '2016-01-01 15:58:59', - $this->type->convertToDatabaseValue($date->reveal(), $this->platform->reveal()) + $this->type->convertToDatabaseValue($date, $this->platform) ); } public function testConvertsNullToDatabaseValue() { - self::assertNull($this->type->convertToDatabaseValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToDatabaseValue(null, $this->platform)); } public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new \DateTime(), $this->platform); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { $date = new \DateTimeImmutable(); - self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); + self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } public function testConvertsNullToPHPValue() { - self::assertNull($this->type->convertToPHPValue(null, $this->platform->reveal())); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertsDateishStringToPHPValue() { - $this->platform->getDateTimeFormatString()->shouldNotBeCalled(); + $this->platform->expects($this->never()) + ->method('getDateTimeFormatString'); - $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456 UTC', $this->platform->reveal()); + $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456 UTC', $this->platform); self::assertInstanceOf(\DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59.123456 UTC', $date->format('Y-m-d H:i:s.u T')); @@ -91,11 +98,11 @@ public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateishS { $this->expectException(ConversionException::class); - $this->type->convertToPHPValue('invalid date-ish string', $this->platform->reveal()); + $this->type->convertToPHPValue('invalid date-ish string', $this->platform); } public function testRequiresSQLCommentHint() { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform->reveal())); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); } } diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 17154eac9f6..80982ecbac8 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -1,6 +1,7 @@ close(); - self::$_sharedConn = null; + if (self::$_sharedConn === null) { + return; } + + self::$_sharedConn->close(); + self::$_sharedConn = null; } protected function setUp() diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php index 61b2d992aff..3b163e3d5b8 100644 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverMock.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\AbstractSchemaManager; class DriverMock implements \Doctrine\DBAL\Driver @@ -25,16 +26,12 @@ public function connect(array $params, $username = null, $password = null, array * Constructs the Sqlite PDO DSN. * * @return string The DSN. - * @override */ protected function _constructPdoDsn(array $params) { return ""; } - /** - * @override - */ public function getDatabasePlatform() { if ( ! $this->_platformMock) { @@ -43,10 +40,7 @@ public function getDatabasePlatform() return $this->_platformMock; } - /** - * @override - */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { if($this->_schemaManagerMock == null) { return new SchemaManagerMock($conn); @@ -55,14 +49,12 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn) return $this->_schemaManagerMock; } - /* MOCK API */ - - public function setDatabasePlatform(\Doctrine\DBAL\Platforms\AbstractPlatform $platform) + public function setDatabasePlatform(DatabasePlatformMock $platform) { $this->_platformMock = $platform; } - public function setSchemaManager(AbstractSchemaManager $sm) + public function setSchemaManager(SchemaManagerMock $sm) { $this->_schemaManagerMock = $sm; } @@ -72,7 +64,7 @@ public function getName() return 'mock'; } - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { return; }