From affb0bf68411a2aae05df05904d647e9f2335ddc Mon Sep 17 00:00:00 2001 From: Ilija Studen Date: Fri, 19 Aug 2016 11:26:52 +0200 Subject: [PATCH 1/2] Extract port from mysqli host --- src/ConnectionFactory.php | 34 ++++++++++++++++++++++++------ test/src/ConnectionFactoryTest.php | 22 ++++++++++++++++++- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/ConnectionFactory.php b/src/ConnectionFactory.php index 771f458..41b9c47 100644 --- a/src/ConnectionFactory.php +++ b/src/ConnectionFactory.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection; use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; @@ -30,7 +39,17 @@ public function __construct(LoggerInterface &$log = null) */ public function mysqli($host, $user, $pass, $select_database = '', $set_connection_encoding = null, $set_connection_encoding_with_query = false) { - $link = $this->mysqliConnectFromParams($host, $user, $pass); + if (strpos($host, ':') !== false) { + $host_bits = explode(':', $host); + + if (empty($host_bits[1])) { + $host_bits[1] = 3306; + } + + $link = $this->mysqliConnectFromParams($host_bits[0], (int) $host_bits[1], $user, $pass); + } else { + $link = $this->mysqliConnectFromParams($host, 3306, $user, $pass); + } if ($set_connection_encoding && !$set_connection_encoding_with_query) { $link->set_charset($set_connection_encoding); @@ -50,16 +69,17 @@ public function mysqli($host, $user, $pass, $select_database = '', $set_connecti } /** - * @param string $host - * @param string $user - * @param string $pass - * @param string $select_database + * @param string $host + * @param int $port + * @param string $user + * @param string $pass + * @param string $select_database * @return MysqliLink * @throws ConnectionException */ - private function mysqliConnectFromParams($host, $user, $pass, $select_database = '') + private function mysqliConnectFromParams($host, $port, $user, $pass, $select_database = '') { - $link = new MysqliLink($host, $user, $pass); + $link = new MysqliLink($host, $user, $pass, '', $port); if ($link->connect_error) { throw new ConnectionException('Failed to connect to database. MySQL said: ' . $link->connect_error); diff --git a/test/src/ConnectionFactoryTest.php b/test/src/ConnectionFactoryTest.php index 6a1e171..85e27ff 100644 --- a/test/src/ConnectionFactoryTest.php +++ b/test/src/ConnectionFactoryTest.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; @@ -11,7 +20,7 @@ class ConnectionFactoryTest extends TestCase { /** - * Test mysqli connection + * Test mysqli connection. */ public function testMysqli() { @@ -20,4 +29,15 @@ public function testMysqli() $this->assertInstanceOf(MysqliConnection::class, $connection); $connection->disconnect(); } + + /** + * Test MySQLi connection with port added to hostname. + */ + public function testMysqliWithPortInHostname() + { + $connection = (new ConnectionFactory())->mysqli('localhost:3306', 'root', '', 'activecollab_database_connection_test'); + + $this->assertInstanceOf(MysqliConnection::class, $connection); + $connection->disconnect(); + } } From 56219ad318eb6b09a3c3ffca6f2ccbc34848d3f5 Mon Sep 17 00:00:00 2001 From: Ilija Studen Date: Fri, 19 Aug 2016 11:33:44 +0200 Subject: [PATCH 2/2] Fix code style --- .php_cs.php | 2 +- src/BatchInsert/BatchInsert.php | 53 ++++++++++++-------- src/BatchInsert/BatchInsertInterface.php | 23 ++++++--- src/Connection.php | 9 ++++ src/ConnectionFactoryInterface.php | 13 ++++- src/Exception/ConnectionException.php | 9 ++++ src/Exception/ExceptionInterface.php | 9 ++++ src/Exception/QueryException.php | 9 ++++ src/Record/LoadFromRow.php | 9 ++++ src/Result/Result.php | 23 ++++++--- src/Result/ResultIterator.php | 9 ++++ test/bootstrap.php | 9 ++++ test/src/BatchInsertTest.php | 39 ++++++++------ test/src/ContainerPropagatesToObjectTest.php | 11 +++- test/src/CountTest.php | 24 ++++++--- test/src/DatabasesTest.php | 15 ++++-- test/src/DeleteTest.php | 29 +++++++---- test/src/EscapeTest.php | 11 +++- test/src/ExecuteLoadObjectTest.php | 15 ++++-- test/src/ExecuteTest.php | 24 ++++++--- test/src/Fixture/Container.php | 12 ++++- test/src/Fixture/Writer.php | 9 ++++ test/src/Fixture/WriterWithContainer.php | 9 ++++ test/src/InsertTest.php | 26 +++++++--- test/src/QueryLoggingTest.php | 9 ++++ test/src/TablesTest.php | 21 +++++--- test/src/TestCase.php | 9 ++++ test/src/TransactionsTest.php | 9 ++++ test/src/UsersTest.php | 15 ++++-- 29 files changed, 360 insertions(+), 104 deletions(-) diff --git a/.php_cs.php b/.php_cs.php index dcc827f..d7a97a4 100644 --- a/.php_cs.php +++ b/.php_cs.php @@ -43,7 +43,7 @@ 'standardize_not_equal', 'ternary_spaces', 'trim_array_spaces', - 'unused_use ', + 'unused_use', 'whitespacy_lines', 'ordered_use', 'short_array_syntax', diff --git a/src/BatchInsert/BatchInsert.php b/src/BatchInsert/BatchInsert.php index 24bc043..0c12eb5 100644 --- a/src/BatchInsert/BatchInsert.php +++ b/src/BatchInsert/BatchInsert.php @@ -1,10 +1,19 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\BatchInsert; use ActiveCollab\DatabaseConnection\ConnectionInterface; -use InvalidArgumentException; use BadMethodCallException; +use InvalidArgumentException; use RuntimeException; /** @@ -28,49 +37,49 @@ class BatchInsert implements BatchInsertInterface private $fields; /** - * Cached SQL query foundation + * Cached SQL query foundation. * * @var string */ private $sql_foundation; /** - * String that's used to prepare statements + * String that's used to prepare statements. * * @var string */ private $row_prepare_pattern; /** - * Number of fields that are being inserted + * Number of fields that are being inserted. * - * @var integer + * @var int */ private $fields_num; /** - * Numbe of rows that are inserted per single INSERT query + * Numbe of rows that are inserted per single INSERT query. * - * @var integer + * @var int */ private $rows_per_batch; /** - * Insert or replace mode + * Insert or replace mode. * * @var string */ private $mode; /** - * Array of rows that will need to be inserted into the database + * Array of rows that will need to be inserted into the database. * * @var array */ private $rows = []; /** - * Total number of rows inserted + * Total number of rows inserted. * * @var int */ @@ -127,7 +136,7 @@ public function __construct(ConnectionInterface $connection, $table_name, array } /** - * Return table name + * Return table name. * * @return string */ @@ -137,7 +146,7 @@ public function getTableName() } /** - * Return the list of files + * Return the list of files. * * @return array */ @@ -155,7 +164,7 @@ public function getRowsPerBatch() } /** - * Return insert or replace mode (default is insert) + * Return insert or replace mode (default is insert). * * @return string */ @@ -165,14 +174,14 @@ public function getMode() } /** - * Insert a row with the given field values + * Insert a row with the given field values. * * @param mixed ...$field_values */ public function insert(...$field_values) { if ($this->is_done) { - throw new RuntimeException("This batch insert is already done"); + throw new RuntimeException('This batch insert is already done'); } if (count($field_values) == $this->fields_num) { @@ -187,14 +196,14 @@ public function insert(...$field_values) } /** - * Insert array of already escaped values + * Insert array of already escaped values. * * @param mixed ...$field_values */ public function insertEscaped(...$field_values) { if ($this->is_done) { - throw new RuntimeException("This batch insert is already done"); + throw new RuntimeException('This batch insert is already done'); } if (count($field_values) == $this->fields_num) { @@ -207,12 +216,12 @@ public function insertEscaped(...$field_values) } /** - * Insert rows that are already loaded + * Insert rows that are already loaded. */ public function flush() { if ($this->is_done) { - throw new RuntimeException("This batch insert is already done"); + throw new RuntimeException('This batch insert is already done'); } $count_rows = count($this->rows); @@ -226,12 +235,12 @@ public function flush() } /** - * Finish with the batch + * Finish with the batch. */ public function done() { if ($this->is_done) { - throw new RuntimeException("This batch insert is already done"); + throw new RuntimeException('This batch insert is already done'); } $this->flush(); @@ -241,7 +250,7 @@ public function done() } /** - * Check whether we should insert rows and insert them if we do + * Check whether we should insert rows and insert them if we do. */ private function checkAndInsert() { diff --git a/src/BatchInsert/BatchInsertInterface.php b/src/BatchInsert/BatchInsertInterface.php index 42ae377..a9724ec 100644 --- a/src/BatchInsert/BatchInsertInterface.php +++ b/src/BatchInsert/BatchInsertInterface.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\BatchInsert; /** @@ -8,14 +17,14 @@ interface BatchInsertInterface { /** - * Return table name + * Return table name. * * @return string */ public function getTableName(); /** - * Return the list of files + * Return the list of files. * * @return array */ @@ -27,33 +36,33 @@ public function getFields(); public function getRowsPerBatch(); /** - * Return insert or replace mode (default is insert) + * Return insert or replace mode (default is insert). * * @return string */ public function getMode(); /** - * Insert a row with the given field values + * Insert a row with the given field values. * * @param mixed ...$field_values */ public function insert(...$field_values); /** - * Insert array of already escaped values + * Insert array of already escaped values. * * @param mixed ...$field_values */ public function insertEscaped(...$field_values); /** - * Insert rows that are already loaded + * Insert rows that are already loaded. */ public function flush(); /** - * Finish with the batch + * Finish with the batch. */ public function done(); } diff --git a/src/Connection.php b/src/Connection.php index 5e3f546..e34dee5 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection; use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; diff --git a/src/ConnectionFactoryInterface.php b/src/ConnectionFactoryInterface.php index b9466fc..351c1e3 100644 --- a/src/ConnectionFactoryInterface.php +++ b/src/ConnectionFactoryInterface.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection; use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; @@ -10,14 +19,14 @@ interface ConnectionFactoryInterface { /** - * Connect to MySQL using mysqli extension + * Connect to MySQL using mysqli extension. * * @param string $host * @param string $user * @param string $pass * @param string $select_database * @param string|null $set_connection_encoding - * @param boolean $set_connection_encoding_with_query + * @param bool $set_connection_encoding_with_query * @return MysqliConnection */ public function mysqli($host, $user, $pass, $select_database = '', $set_connection_encoding = null, $set_connection_encoding_with_query = false); diff --git a/src/Exception/ConnectionException.php b/src/Exception/ConnectionException.php index c60595d..9221f8f 100644 --- a/src/Exception/ConnectionException.php +++ b/src/Exception/ConnectionException.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Exception; use Exception; diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 2841494..c6c6e0d 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Exception; /** diff --git a/src/Exception/QueryException.php b/src/Exception/QueryException.php index cf7cb56..fb5e04d 100644 --- a/src/Exception/QueryException.php +++ b/src/Exception/QueryException.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Exception; use Exception; diff --git a/src/Record/LoadFromRow.php b/src/Record/LoadFromRow.php index e9a7701..67e5c6f 100644 --- a/src/Record/LoadFromRow.php +++ b/src/Record/LoadFromRow.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Record; /** diff --git a/src/Result/Result.php b/src/Result/Result.php index c9816d6..995d03a 100644 --- a/src/Result/Result.php +++ b/src/Result/Result.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Result; use ActiveCollab\ContainerAccess\ContainerAccessInterface; @@ -56,7 +65,7 @@ class Result implements ResultInterface private $return_class_or_field; /** - * Constructor arguments (when objects are constructed from rows) + * Constructor arguments (when objects are constructed from rows). * * @var array|null */ @@ -75,10 +84,10 @@ class Result implements ResultInterface /** * Construct a new result object from resource. * - * @param mysqli_result $resource - * @param int $return_mode - * @param string $return_class_or_field - * @param array|null $constructor_arguments + * @param mysqli_result $resource + * @param int $return_mode + * @param string $return_class_or_field + * @param array|null $constructor_arguments * @param ContainerInterface|null $container */ public function __construct($resource, $return_mode = ConnectionInterface::RETURN_ARRAY, $return_class_or_field = null, array $constructor_arguments = null, ContainerInterface &$container = null) @@ -121,8 +130,8 @@ public function getResource() /** * Set cursor to a given position in the record set. * - * @param integer $num - * @return boolean + * @param int $num + * @return bool */ public function seek($num) { diff --git a/src/Result/ResultIterator.php b/src/Result/ResultIterator.php index 2bebced..6aa456d 100644 --- a/src/Result/ResultIterator.php +++ b/src/Result/ResultIterator.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Result; use Iterator; diff --git a/test/bootstrap.php b/test/bootstrap.php index 9daede0..88bd9de 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + date_default_timezone_set('GMT'); require dirname(__DIR__) . '/vendor/autoload.php'; diff --git a/test/src/BatchInsertTest.php b/test/src/BatchInsertTest.php index bf2c6ef..900c218 100644 --- a/test/src/BatchInsertTest.php +++ b/test/src/BatchInsertTest.php @@ -1,11 +1,20 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; -use ActiveCollab\DatabaseConnection\ConnectionInterface; -use ActiveCollab\DatabaseConnection\Connection; -use ActiveCollab\DatabaseConnection\BatchInsert\BatchInsertInterface; use ActiveCollab\DatabaseConnection\BatchInsert\BatchInsert; +use ActiveCollab\DatabaseConnection\BatchInsert\BatchInsertInterface; +use ActiveCollab\DatabaseConnection\Connection; +use ActiveCollab\DatabaseConnection\ConnectionInterface; use DateTime; /** @@ -19,7 +28,7 @@ class BatchInsertTest extends TestCase private $connection; /** - * Set up test environment + * Set up test environment. */ public function setUp() { @@ -38,7 +47,7 @@ public function setUp() } /** - * Tear down the test environment + * Tear down the test environment. */ public function tearDown() { @@ -48,7 +57,7 @@ public function tearDown() } /** - * Test if connection is properly creating batch insert instance + * Test if connection is properly creating batch insert instance. */ public function testConnectionPropertyCreatesBatchInsertObject() { @@ -63,7 +72,7 @@ public function testConnectionPropertyCreatesBatchInsertObject() } /** - * Test if rows per batch and insert mode can be changed + * Test if rows per batch and insert mode can be changed. */ public function testRowsPerBatchAndModeCanBeChanged() { @@ -78,7 +87,7 @@ public function testRowsPerBatchAndModeCanBeChanged() } /** - * Test if insert SQL foundation is properly prepared + * Test if insert SQL foundation is properly prepared. */ public function testInsertSqlIsProperlyPrepared() { @@ -93,7 +102,7 @@ public function testInsertSqlIsProperlyPrepared() } /** - * Test if replace SQL foundation is properly prepared + * Test if replace SQL foundation is properly prepared. */ public function testReplaceSqlIsProperlyPrepared() { @@ -108,7 +117,7 @@ public function testReplaceSqlIsProperlyPrepared() } /** - * Test if row prepare pattern is proeprly prepared + * Test if row prepare pattern is proeprly prepared. */ public function testRowPreparePattern() { @@ -123,7 +132,7 @@ public function testRowPreparePattern() } /** - * Test batch insert + * Test batch insert. */ public function testBatchInsert() { @@ -147,7 +156,7 @@ public function testBatchInsert() } /** - * Test batch replace + * Test batch replace. */ public function testBatchReplace() { @@ -177,7 +186,7 @@ public function testBatchReplace() } /** - * Test flush + * Test flush. */ public function testFlush() { @@ -194,7 +203,7 @@ public function testFlush() } /** - * Test if rows can't be inserted once batch is done + * Test if rows can't be inserted once batch is done. * * @expectedException \RuntimeException */ @@ -215,7 +224,7 @@ public function testRowsCantBeInsertedOnceDone() } /** - * Test if rows can't be inserted escaped once batch is done + * Test if rows can't be inserted escaped once batch is done. * * @expectedException \RuntimeException */ diff --git a/test/src/ContainerPropagatesToObjectTest.php b/test/src/ContainerPropagatesToObjectTest.php index 59aa00a..cea15c8 100644 --- a/test/src/ContainerPropagatesToObjectTest.php +++ b/test/src/ContainerPropagatesToObjectTest.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; @@ -47,7 +56,7 @@ public function setUp() $this->connection->execute('INSERT INTO `writers` (`name`, `birthday`) VALUES (?, ?), (?, ?), (?, ?)', 'Leo Tolstoy', new DateTime('1828-09-09'), 'Alexander Pushkin', new DateTime('1799-06-06'), 'Fyodor Dostoyevsky', new DateTime('1821-11-11')); $this->container = new Container([ - 'dependency' => 'it works!' + 'dependency' => 'it works!', ]); } diff --git a/test/src/CountTest.php b/test/src/CountTest.php index 23b4dc7..710ca96 100644 --- a/test/src/CountTest.php +++ b/test/src/CountTest.php @@ -1,4 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; @@ -15,7 +25,7 @@ class CountTest extends TestCase private $connection; /** - * Set up test environment + * Set up test environment. */ public function setUp() { @@ -36,7 +46,7 @@ public function setUp() } /** - * Tear down the test environment + * Tear down the test environment. */ public function tearDown() { @@ -46,7 +56,7 @@ public function tearDown() } /** - * Test cound all records in the table + * Test cound all records in the table. */ public function testCountAll() { @@ -54,7 +64,7 @@ public function testCountAll() } /** - * Test cound with conditions provided as string + * Test cound with conditions provided as string. */ public function testCountWithStringConditions() { @@ -62,7 +72,7 @@ public function testCountWithStringConditions() } /** - * Test count with conditions that need to be prepared first + * Test count with conditions that need to be prepared first. */ public function testCountWithConditionsThatNeedToBePrepared() { @@ -70,7 +80,7 @@ public function testCountWithConditionsThatNeedToBePrepared() } /** - * Test count(*) + * Test count(*). */ public function testCountAsterisk() { @@ -78,7 +88,7 @@ public function testCountAsterisk() } /** - * Test count by field + * Test count by field. */ public function testCountField() { diff --git a/test/src/DatabasesTest.php b/test/src/DatabasesTest.php index 73bd581..7492147 100644 --- a/test/src/DatabasesTest.php +++ b/test/src/DatabasesTest.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; @@ -15,7 +24,7 @@ class DatabasesTest extends TestCase private $connection; /** - * Set up test environment + * Set up test environment. */ public function setUp() { @@ -25,7 +34,7 @@ public function setUp() } /** - * Test database exists call + * Test database exists call. */ public function testDatabaseExists() { @@ -34,7 +43,7 @@ public function testDatabaseExists() } /** - * Test drop database + * Test drop database. */ public function testDropDatabase() { diff --git a/test/src/DeleteTest.php b/test/src/DeleteTest.php index 7c15d16..e6de20c 100644 --- a/test/src/DeleteTest.php +++ b/test/src/DeleteTest.php @@ -1,8 +1,17 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; -use ActiveCollab\DatabaseConnection\Record\ValueCaster; use DateTime; /** @@ -16,7 +25,7 @@ class DeleteTest extends TestCase private $connection; /** - * Set up test environment + * Set up test environment. */ public function setUp() { @@ -41,7 +50,7 @@ public function setUp() } /** - * Tear down the test environment + * Tear down the test environment. */ public function tearDown() { @@ -51,7 +60,7 @@ public function tearDown() } /** - * Test delete all records + * Test delete all records. */ public function testDelete() { @@ -62,7 +71,7 @@ public function testDelete() } /** - * Test delete with prepared conditions + * Test delete with prepared conditions. */ public function testDeleteWithPreparedConditions() { @@ -74,11 +83,11 @@ public function testDeleteWithPreparedConditions() } /** - * Test delete prepared conditions, as array + * Test delete prepared conditions, as array. */ public function testDeleteWithPreparedConditionsAsOnlyElement() { - $affected_rows = $this->connection->delete('writers', [ "`name` = 'Leo Tolstoy'" ]); + $affected_rows = $this->connection->delete('writers', ["`name` = 'Leo Tolstoy'"]); $this->assertEquals(1, $affected_rows); $this->assertEquals(2, $this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `writers`')); @@ -86,11 +95,11 @@ public function testDeleteWithPreparedConditionsAsOnlyElement() } /** - * Test delete where conditions are an array that needs to be prepared + * Test delete where conditions are an array that needs to be prepared. */ public function testDeleteWithConditionsThatNeedToBePrepared() { - $affected_rows = $this->connection->delete('writers', [ '`name` = ?', 'Leo Tolstoy' ]); + $affected_rows = $this->connection->delete('writers', ['`name` = ?', 'Leo Tolstoy']); $this->assertEquals(1, $affected_rows); $this->assertEquals(2, $this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `writers`')); @@ -112,4 +121,4 @@ public function testExceptionDueToInvalidConditions() { $this->connection->delete('writers', 123); } -} \ No newline at end of file +} diff --git a/test/src/EscapeTest.php b/test/src/EscapeTest.php index 97517b0..b6748a7 100644 --- a/test/src/EscapeTest.php +++ b/test/src/EscapeTest.php @@ -1,10 +1,19 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; -use ActiveCollab\DateValue\DateValue; use ActiveCollab\DateValue\DateTimeValue; +use ActiveCollab\DateValue\DateValue; use DateTime; use DateTimeZone; diff --git a/test/src/ExecuteLoadObjectTest.php b/test/src/ExecuteLoadObjectTest.php index 271b607..24d3cac 100644 --- a/test/src/ExecuteLoadObjectTest.php +++ b/test/src/ExecuteLoadObjectTest.php @@ -1,10 +1,19 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; -use ActiveCollab\DatabaseConnection\ConnectionInterface; use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; +use ActiveCollab\DatabaseConnection\ConnectionInterface; use ActiveCollab\DatabaseConnection\Result\Result; use ActiveCollab\DatabaseConnection\Test\Fixture\Writer; use DateTime; @@ -106,7 +115,7 @@ public function testExecuteLoadObjectFromClassName() } /** - * Test if constructor arguments are properly set to instances when provided + * Test if constructor arguments are properly set to instances when provided. */ public function testExecuteLoadObjectWithConstructorArguments() { @@ -122,7 +131,7 @@ public function testExecuteLoadObjectWithConstructorArguments() $this->assertNull($writer->constructor_argument_2); } - $result = $this->connection->advancedExecute('SELECT * FROM `writers` ORDER BY `id`', null, ConnectionInterface::LOAD_ALL_ROWS, ConnectionInterface::RETURN_OBJECT_BY_CLASS, '\ActiveCollab\DatabaseConnection\Test\Fixture\Writer', [12,34]); + $result = $this->connection->advancedExecute('SELECT * FROM `writers` ORDER BY `id`', null, ConnectionInterface::LOAD_ALL_ROWS, ConnectionInterface::RETURN_OBJECT_BY_CLASS, '\ActiveCollab\DatabaseConnection\Test\Fixture\Writer', [12, 34]); $this->assertInstanceOf('\ActiveCollab\DatabaseConnection\Result\Result', $result); $this->assertCount(3, $result); diff --git a/test/src/ExecuteTest.php b/test/src/ExecuteTest.php index 8deb91b..5f900dc 100644 --- a/test/src/ExecuteTest.php +++ b/test/src/ExecuteTest.php @@ -1,4 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; @@ -16,7 +26,7 @@ class ExecuteTest extends TestCase private $connection; /** - * Set up test environment + * Set up test environment. */ public function setUp() { @@ -37,7 +47,7 @@ public function setUp() } /** - * Tear down the test environment + * Tear down the test environment. */ public function tearDown() { @@ -55,7 +65,7 @@ public function testExceptionOnInvalidQuery() } /** - * Test execute + * Test execute. */ public function testExecute() { @@ -92,7 +102,7 @@ public function testExecute() } /** - * Test execute + * Test execute. */ public function testExecuteWithCustomCaster() { @@ -130,7 +140,7 @@ public function testExecuteWithCustomCaster() } /** - * Execute first cell + * Execute first cell. */ public function testExecuteFirstCell() { @@ -144,7 +154,7 @@ public function testExecuteFirstCell() } /** - * Test execute first row + * Test execute first row. */ public function testExecuteFirstRow() { @@ -156,7 +166,7 @@ public function testExecuteFirstRow() } /** - * Test execute first column + * Test execute first column. */ public function testExecuteFirstColumn() { diff --git a/test/src/Fixture/Container.php b/test/src/Fixture/Container.php index 74b3780..a419438 100644 --- a/test/src/Fixture/Container.php +++ b/test/src/Fixture/Container.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test\Fixture; use Interop\Container\ContainerInterface; @@ -24,6 +33,7 @@ public function get($id) if (!$this->offsetExists($id)) { throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id)); } + return $this->offsetGet($id); } @@ -33,7 +43,7 @@ public function get($id) * * @param string $id Identifier of the entry to look for. * - * @return boolean + * @return bool */ public function has($id) { diff --git a/test/src/Fixture/Writer.php b/test/src/Fixture/Writer.php index 6f09b18..74f0343 100644 --- a/test/src/Fixture/Writer.php +++ b/test/src/Fixture/Writer.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test\Fixture; use ActiveCollab\DatabaseConnection\Record\LoadFromRow; diff --git a/test/src/Fixture/WriterWithContainer.php b/test/src/Fixture/WriterWithContainer.php index 30ffc5f..946ddb4 100644 --- a/test/src/Fixture/WriterWithContainer.php +++ b/test/src/Fixture/WriterWithContainer.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test\Fixture; use ActiveCollab\ContainerAccess\ContainerAccessInterface; diff --git a/test/src/InsertTest.php b/test/src/InsertTest.php index 429a334..dbce9f6 100644 --- a/test/src/InsertTest.php +++ b/test/src/InsertTest.php @@ -1,4 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; @@ -16,7 +26,7 @@ class InsertTest extends TestCase private $connection; /** - * Set up test environment + * Set up test environment. */ public function setUp() { @@ -41,7 +51,7 @@ public function setUp() } /** - * Tear down the test environment + * Tear down the test environment. */ public function tearDown() { @@ -51,7 +61,7 @@ public function tearDown() } /** - * Test if last insert ID returns correct value + * Test if last insert ID returns correct value. */ public function testInsertId() { @@ -60,7 +70,7 @@ public function testInsertId() } /** - * Test insert + * Test insert. */ public function testInsert() { @@ -75,12 +85,12 @@ public function testInsert() $this->assertEquals([ 'id' => 4, 'name' => 'Anton Chekhov', - 'birthday' => '1860-01-29' + 'birthday' => '1860-01-29', ], $this->connection->executeFirstRow('SELECT * FROM `writers` WHERE `id` = ?', $last_insert_id)); } /** - * Test replace mode + * Test replace mode. */ public function testReplace() { @@ -96,7 +106,7 @@ public function testReplace() $this->assertEquals([ 'id' => 1, 'name' => 'Anton Chekhov', - 'birthday' => '1860-01-29' + 'birthday' => '1860-01-29', ], $this->connection->executeFirstRow('SELECT * FROM `writers` WHERE `id` = ?', $last_insert_id)); } -} \ No newline at end of file +} diff --git a/test/src/QueryLoggingTest.php b/test/src/QueryLoggingTest.php index 2c25ad9..f773308 100644 --- a/test/src/QueryLoggingTest.php +++ b/test/src/QueryLoggingTest.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; diff --git a/test/src/TablesTest.php b/test/src/TablesTest.php index a4291ad..82a9be8 100644 --- a/test/src/TablesTest.php +++ b/test/src/TablesTest.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; @@ -15,7 +24,7 @@ class TablesTest extends TestCase private $connection; /** - * Set up test environment + * Set up test environment. */ public function setUp() { @@ -49,7 +58,7 @@ public function setUp() } /** - * Tear down the test environment + * Tear down the test environment. */ public function tearDown() { @@ -61,7 +70,7 @@ public function tearDown() } /** - * Test list all database tables + * Test list all database tables. */ public function testListTables() { @@ -69,7 +78,7 @@ public function testListTables() } /** - * Test list tables from a specified database (user needs to have proper permissions over that database) + * Test list tables from a specified database (user needs to have proper permissions over that database). */ public function testListTablesFromAnotherDatabase() { @@ -89,7 +98,7 @@ public function testListTablesFromAnotherDatabase() } /** - * Test if we can check if table exists or not + * Test if we can check if table exists or not. */ public function testTableExists() { @@ -98,7 +107,7 @@ public function testTableExists() } /** - * Test drop table command + * Test drop table command. */ public function testDropTable() { diff --git a/test/src/TestCase.php b/test/src/TestCase.php index 17065b0..1c95562 100644 --- a/test/src/TestCase.php +++ b/test/src/TestCase.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use mysqli; diff --git a/test/src/TransactionsTest.php b/test/src/TransactionsTest.php index ab2348f..50d3e1b 100644 --- a/test/src/TransactionsTest.php +++ b/test/src/TransactionsTest.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection; diff --git a/test/src/UsersTest.php b/test/src/UsersTest.php index 75a9678..06c5cca 100644 --- a/test/src/UsersTest.php +++ b/test/src/UsersTest.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace ActiveCollab\DatabaseConnection\Test; use ActiveCollab\DatabaseConnection\Connection\MysqliConnection; @@ -15,7 +24,7 @@ class UsersTest extends TestCase private $connection; /** - * Set up test environment + * Set up test environment. */ public function setUp() { @@ -25,7 +34,7 @@ public function setUp() } /** - * Test user exists call + * Test user exists call. */ public function testUserExists() { @@ -34,7 +43,7 @@ public function testUserExists() } /** - * Test drop user account + * Test drop user account. */ public function testDropUser() {