repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/integration/Platform/FixtureLoader.php
test/integration/Platform/FixtureLoader.php
<?php namespace LaminasIntegrationTest\Db\Platform; // phpcs:ignore WebimpressCodingStandard.NamingConventions.Interface.Suffix interface FixtureLoader { public function createDatabase(); public function dropDatabase(); }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/ConfigProviderTest.php
test/unit/ConfigProviderTest.php
<?php namespace LaminasTest\Db; use Laminas\Db\Adapter; use Laminas\Db\ConfigProvider; use PHPUnit\Framework\TestCase; use Zend\Db\Adapter\AdapterInterface; class ConfigProviderTest extends TestCase { /** @var array<string, array<array-key, string>> */ private $config = [ 'abstract_factories' => [ Adapter\AdapterAbstractServiceFactory::class, ], 'factories' => [ Adapter\AdapterInterface::class => Adapter\AdapterServiceFactory::class, ], 'aliases' => [ Adapter\Adapter::class => Adapter\AdapterInterface::class, AdapterInterface::class => Adapter\AdapterInterface::class, \Zend\Db\Adapter\Adapter::class => Adapter\Adapter::class, ], ]; public function testProvidesExpectedConfiguration(): ConfigProvider { $provider = new ConfigProvider(); self::assertEquals($this->config, $provider->getDependencyConfig()); return $provider; } /** * @depends testProvidesExpectedConfiguration */ public function testInvocationProvidesDependencyConfiguration(ConfigProvider $provider) { self::assertEquals(['dependencies' => $provider->getDependencyConfig()], $provider()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/DeprecatedAssertionsTrait.php
test/unit/DeprecatedAssertionsTrait.php
<?php namespace LaminasTest\Db; use PHPUnit\Framework\Assert; use ReflectionProperty; trait DeprecatedAssertionsTrait { /** * @param mixed $expected */ public static function assertAttributeEquals( $expected, string $attribute, object $instance, string $message = '' ): void { $r = new ReflectionProperty($instance, $attribute); $r->setAccessible(true); Assert::assertEquals($expected, $r->getValue($instance), $message); } /** * @return mixed */ public function readAttribute(object $instance, string $attribute) { $r = new ReflectionProperty($instance, $attribute); $r->setAccessible(true); return $r->getValue($instance); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Metadata/Source/OracleMetadataTest.php
test/unit/Metadata/Source/OracleMetadataTest.php
<?php namespace LaminasTest\Db\Metadata\Source; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\Oci8\Statement; use Laminas\Db\Metadata\Object\ConstraintObject; use Laminas\Db\Metadata\Source\OracleMetadata; use LaminasTest\Db\Adapter\Driver\Oci8\AbstractIntegrationTest; use PHPUnit\Framework\MockObject\MockObject; use function count; use function extension_loaded; /** * @requires extension oci8 */ class OracleMetadataTest extends AbstractIntegrationTest { /** @var OracleMetadata */ protected $metadata; /** @var Adapter */ protected $adapter; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { if (! extension_loaded('oci8')) { $this->markTestSkipped('I cannot test without the oci8 extension'); } parent::setUp(); $this->variables['driver'] = 'OCI8'; $this->adapter = new Adapter($this->variables); $this->metadata = new OracleMetadata($this->adapter); } /** * @dataProvider constraintDataProvider * @param array $constraintData */ public function testGetConstraints(array $constraintData) { $statement = $this->getMockBuilder(Statement::class) ->getMock(); $statement->expects($this->once()) ->method('execute') ->willReturn($constraintData); /** @var Adapter|MockObject $adapter */ $adapter = $this->getMockBuilder(Adapter::class) ->setConstructorArgs([$this->variables]) ->getMock(); $adapter->expects($this->once()) ->method('query') ->willReturn($statement); $this->metadata = new OracleMetadata($adapter); $constraints = $this->metadata->getConstraints(null, 'main'); self::assertCount(count($constraintData), $constraints); self::assertContainsOnlyInstancesOf( ConstraintObject::class, $constraints ); } /** * @return array */ public function constraintDataProvider() { return [ [ [ // no constraints ], ], [ [ [ 'OWNER' => 'SYS', 'CONSTRAINT_NAME' => 'SYS_C000001', 'CONSTRAINT_TYPE' => 'C', 'CHECK_CLAUSE' => '"COLUMN_1" IS NOT NULL', 'TABLE_NAME' => 'TABLE', 'DELETE_RULE' => null, 'COLUMN_NAME' => 'COLUMN_1', 'REF_TABLE' => null, 'REF_COLUMN' => null, 'REF_OWNER' => null, ], [ 'OWNER' => 'SYS', 'CONSTRAINT_NAME' => 'SYS_C000002', 'CONSTRAINT_TYPE' => 'C', 'CHECK_CLAUSE' => '"COLUMN_2" IS NOT NULL', 'TABLE_NAME' => 'TABLE', 'DELETE_RULE' => null, 'COLUMN_NAME' => 'COLUMN_2', 'REF_TABLE' => null, 'REF_COLUMN' => null, 'REF_OWNER' => null, ], ], ], ]; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Metadata/Source/FactoryTest.php
test/unit/Metadata/Source/FactoryTest.php
<?php namespace LaminasTest\Db\Metadata\Source; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Platform\PlatformInterface; use Laminas\Db\Metadata\MetadataInterface; use Laminas\Db\Metadata\Source\Factory; use Laminas\Db\Metadata\Source\MysqlMetadata; use Laminas\Db\Metadata\Source\OracleMetadata; use Laminas\Db\Metadata\Source\PostgresqlMetadata; use Laminas\Db\Metadata\Source\SqliteMetadata; use Laminas\Db\Metadata\Source\SqlServerMetadata; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class FactoryTest extends TestCase { /** * @dataProvider validAdapterProvider * @param string $expectedReturnClass */ public function testCreateSourceFromAdapter(Adapter $adapter, $expectedReturnClass) { $source = Factory::createSourceFromAdapter($adapter); self::assertInstanceOf(MetadataInterface::class, $source); self::assertInstanceOf($expectedReturnClass, $source); } /** @psalm-return array<string, array{0: Adapter&MockObject, 1: MetadataInterface}> */ public function validAdapterProvider(): array { /** @return Adapter&MockObject */ $createAdapterForPlatform = function (string $platformName) { $platform = $this->getMockBuilder(PlatformInterface::class)->getMock(); $platform ->expects($this->any()) ->method('getName') ->willReturn($platformName); $adapter = $this->getMockBuilder(Adapter::class) ->disableOriginalConstructor() ->getMock(); $adapter ->expects($this->any()) ->method('getPlatform') ->willReturn($platform); return $adapter; }; return [ // Description => [adapter, expected return class] 'MySQL' => [$createAdapterForPlatform('MySQL'), MysqlMetadata::class], 'SQLServer' => [$createAdapterForPlatform('SQLServer'), SqlServerMetadata::class], 'SQLite' => [$createAdapterForPlatform('SQLite'), SqliteMetadata::class], 'PostgreSQL' => [$createAdapterForPlatform('PostgreSQL'), PostgresqlMetadata::class], 'Oracle' => [$createAdapterForPlatform('Oracle'), OracleMetadata::class], ]; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Metadata/Source/AbstractSourceTest.php
test/unit/Metadata/Source/AbstractSourceTest.php
<?php namespace LaminasTest\Db\Metadata\Source; use Laminas\Db\Metadata\Object\ConstraintKeyObject; use Laminas\Db\Metadata\Source\AbstractSource; use PHPUnit\Framework\TestCase; use ReflectionProperty; class AbstractSourceTest extends TestCase { /** @var AbstractSource */ protected $abstractSourceMock; protected function setUp(): void { $this->abstractSourceMock = $this->getMockForAbstractClass( AbstractSource::class, [], '', false ); } public function testGetConstraintKeys() { $refProp = new ReflectionProperty($this->abstractSourceMock, 'data'); $refProp->setAccessible(true); // internal data $data = [ 'constraint_references' => [ 'foo_schema' => [ [ 'constraint_name' => 'bam_constraint', 'update_rule' => 'UP', 'delete_rule' => 'DOWN', 'referenced_table_name' => 'another_table', 'referenced_column_name' => 'another_column', ], ], ], 'constraint_keys' => [ 'foo_schema' => [ [ 'table_name' => 'bar_table', 'constraint_name' => 'bam_constraint', 'column_name' => 'a', 'ordinal_position' => 1, ], ], ], ]; $refProp->setValue($this->abstractSourceMock, $data); $constraints = $this->abstractSourceMock->getConstraintKeys('bam_constraint', 'bar_table', 'foo_schema'); self::assertCount(1, $constraints); /** * @var ConstraintKeyObject $constraintKeyObj */ $constraintKeyObj = $constraints[0]; self::assertInstanceOf(ConstraintKeyObject::class, $constraintKeyObj); // check value object is mapped correctly self::assertEquals('a', $constraintKeyObj->getColumnName()); self::assertEquals(1, $constraintKeyObj->getOrdinalPosition()); self::assertEquals('another_table', $constraintKeyObj->getReferencedTableName()); self::assertEquals('another_column', $constraintKeyObj->getReferencedColumnName()); self::assertEquals('UP', $constraintKeyObj->getForeignKeyUpdateRule()); self::assertEquals('DOWN', $constraintKeyObj->getForeignKeyDeleteRule()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Metadata/Source/SqliteMetadataTest.php
test/unit/Metadata/Source/SqliteMetadataTest.php
<?php namespace LaminasTest\Db\Metadata\Source; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Metadata\Object\ConstraintKeyObject; use Laminas\Db\Metadata\Object\ConstraintObject; use Laminas\Db\Metadata\Object\TriggerObject; use Laminas\Db\Metadata\Source\SqliteMetadata; use PHPUnit\Framework\TestCase; use function extension_loaded; /** * @requires extension pdo_sqlite */ class SqliteMetadataTest extends TestCase { /** @var SqliteMetadata */ protected $metadata; /** @var Adapter */ protected $adapter; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { if (! extension_loaded('pdo_sqlite')) { $this->markTestSkipped('I cannot test without the pdo_sqlite extension'); } $this->adapter = new Adapter([ 'driver' => 'Pdo', 'dsn' => 'sqlite::memory:', ]); $this->metadata = new SqliteMetadata($this->adapter); } public function testGetSchemas() { $schemas = $this->metadata->getSchemas(); self::assertContains('main', $schemas); self::assertCount(1, $schemas); } public function testGetTableNames() { $tables = $this->metadata->getTableNames('main'); self::assertCount(0, $tables); } public function testGetColumnNames() { $columns = $this->metadata->getColumnNames(null, 'main'); self::assertCount(0, $columns); } public function testGetConstraints() { $constraints = $this->metadata->getConstraints(null, 'main'); self::assertCount(0, $constraints); self::assertContainsOnlyInstancesOf( ConstraintObject::class, $constraints ); } /** * @group Laminas-3719 */ public function testGetConstraintKeys() { $keys = $this->metadata->getConstraintKeys( null, null, 'main' ); self::assertCount(0, $keys); self::assertContainsOnlyInstancesOf( ConstraintKeyObject::class, $keys ); } public function testGetTriggers() { $triggers = $this->metadata->getTriggers('main'); self::assertCount(0, $triggers); self::assertContainsOnlyInstancesOf( TriggerObject::class, $triggers ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/ResultSet/HydratingResultSetTest.php
test/unit/ResultSet/HydratingResultSetTest.php
<?php namespace LaminasTest\Db\ResultSet; use Laminas\Db\ResultSet\HydratingResultSet; use Laminas\Hydrator\ArraySerializable; use Laminas\Hydrator\ArraySerializableHydrator; use Laminas\Hydrator\ClassMethods; use Laminas\Hydrator\ClassMethodsHydrator; use PHPUnit\Framework\TestCase; use stdClass; use function class_exists; class HydratingResultSetTest extends TestCase { /** @var string */ private $arraySerializableHydratorClass; /** @var string */ private $classMethodsHydratorClass; protected function setUp(): void { $this->arraySerializableHydratorClass = class_exists(ArraySerializableHydrator::class) ? ArraySerializableHydrator::class : ArraySerializable::class; $this->classMethodsHydratorClass = class_exists(ClassMethodsHydrator::class) ? ClassMethodsHydrator::class : ClassMethods::class; } /** * @covers \Laminas\Db\ResultSet\HydratingResultSet::setObjectPrototype */ public function testSetObjectPrototype() { $prototype = new stdClass(); $hydratingRs = new HydratingResultSet(); self::assertSame($hydratingRs, $hydratingRs->setObjectPrototype($prototype)); } /** * @covers \Laminas\Db\ResultSet\HydratingResultSet::getObjectPrototype */ public function testGetObjectPrototype() { $hydratingRs = new HydratingResultSet(); self::assertInstanceOf('ArrayObject', $hydratingRs->getObjectPrototype()); } /** * @covers \Laminas\Db\ResultSet\HydratingResultSet::setHydrator */ public function testSetHydrator() { $hydratingRs = new HydratingResultSet(); $hydratorClass = $this->classMethodsHydratorClass; self::assertSame($hydratingRs, $hydratingRs->setHydrator(new $hydratorClass())); } /** * @covers \Laminas\Db\ResultSet\HydratingResultSet::getHydrator */ public function testGetHydrator() { $hydratingRs = new HydratingResultSet(); self::assertInstanceOf($this->arraySerializableHydratorClass, $hydratingRs->getHydrator()); } /** * @covers \Laminas\Db\ResultSet\HydratingResultSet::current */ public function testCurrentHasData() { $hydratingRs = new HydratingResultSet(); $hydratingRs->initialize([ ['id' => 1, 'name' => 'one'], ]); $obj = $hydratingRs->current(); self::assertInstanceOf('ArrayObject', $obj); } /** * @covers \Laminas\Db\ResultSet\HydratingResultSet::current */ public function testCurrentDoesnotHasData() { $hydratingRs = new HydratingResultSet(); $hydratingRs->initialize([]); $result = $hydratingRs->current(); self::assertNull($result); } /** * @covers \Laminas\Db\ResultSet\HydratingResultSet::toArray * @todo Implement testToArray(). */ public function testToArray() { $hydratingRs = new HydratingResultSet(); $hydratingRs->initialize([ ['id' => 1, 'name' => 'one'], ]); $obj = $hydratingRs->toArray(); self::assertIsArray($obj); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/ResultSet/ResultSetIntegrationTest.php
test/unit/ResultSet/ResultSetIntegrationTest.php
<?php namespace LaminasTest\Db\ResultSet; use ArrayIterator; use ArrayObject; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\ResultSet\Exception\InvalidArgumentException; use Laminas\Db\ResultSet\Exception\RuntimeException; use Laminas\Db\ResultSet\ResultSet; use PHPUnit\Framework\TestCase; use SplStack; use stdClass; use function is_array; use function rand; use function var_export; class ResultSetIntegrationTest extends TestCase { /** @var ResultSet */ protected $resultSet; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->resultSet = new ResultSet(); } public function testRowObjectPrototypeIsPopulatedByRowObjectByDefault() { $row = $this->resultSet->getArrayObjectPrototype(); self::assertInstanceOf('ArrayObject', $row); } public function testRowObjectPrototypeIsMutable() { $row = new ArrayObject(); $this->resultSet->setArrayObjectPrototype($row); self::assertSame($row, $this->resultSet->getArrayObjectPrototype()); } public function testRowObjectPrototypeMayBePassedToConstructor() { $row = new ArrayObject(); $resultSet = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, $row); self::assertSame($row, $resultSet->getArrayObjectPrototype()); } public function testReturnTypeIsObjectByDefault() { self::assertEquals(ResultSet::TYPE_ARRAYOBJECT, $this->resultSet->getReturnType()); } /** @psalm-return array<array-key, array{0: mixed}> */ public function invalidReturnTypes(): array { return [ [1], [1.0], [true], ['string'], [['foo']], [new stdClass()], ]; } /** * @dataProvider invalidReturnTypes * @param mixed $type */ public function testSettingInvalidReturnTypeRaisesException($type) { $this->expectException(InvalidArgumentException::class); new ResultSet(ResultSet::TYPE_ARRAYOBJECT, $type); } public function testDataSourceIsNullByDefault() { self::assertNull($this->resultSet->getDataSource()); } public function testCanProvideIteratorAsDataSource() { $it = new SplStack(); $this->resultSet->initialize($it); self::assertSame($it, $this->resultSet->getDataSource()); } public function testCanProvideArrayAsDataSource() { $dataSource = [['foo']]; $this->resultSet->initialize($dataSource); $this->assertEquals($dataSource[0], (array) $this->resultSet->current()); $returnType = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS); $dataSource = [$returnType]; $this->resultSet->setArrayObjectPrototype($returnType); $this->resultSet->initialize($dataSource); $this->assertEquals($dataSource[0], $this->resultSet->current()); $this->assertContains($dataSource[0], $this->resultSet); } public function testCanProvideIteratorAggregateAsDataSource() { $iteratorAggregate = $this->getMockBuilder('IteratorAggregate') ->setMethods(['getIterator']) ->getMock(); $iteratorAggregate->expects($this->any())->method('getIterator')->will($this->returnValue($iteratorAggregate)); $this->resultSet->initialize($iteratorAggregate); self::assertSame($iteratorAggregate->getIterator(), $this->resultSet->getDataSource()); } /** * @dataProvider invalidReturnTypes * @param mixed $dataSource */ public function testInvalidDataSourceRaisesException($dataSource) { if (is_array($dataSource)) { // this is valid return; } $this->expectException(InvalidArgumentException::class); $this->resultSet->initialize($dataSource); } public function testFieldCountIsZeroWithNoDataSourcePresent() { self::assertEquals(0, $this->resultSet->getFieldCount()); } public function getArrayDataSource(int $count): ArrayIterator { $array = []; for ($i = 0; $i < $count; $i++) { $array[] = [ 'id' => $i, 'title' => 'title ' . $i, ]; } return new ArrayIterator($array); } public function testFieldCountRepresentsNumberOfFieldsInARowOfData() { $resultSet = new ResultSet(ResultSet::TYPE_ARRAY); $dataSource = $this->getArrayDataSource(10); $resultSet->initialize($dataSource); self::assertEquals(2, $resultSet->getFieldCount()); } public function testWhenReturnTypeIsArrayThenIterationReturnsArrays() { $resultSet = new ResultSet(ResultSet::TYPE_ARRAY); $dataSource = $this->getArrayDataSource(10); $resultSet->initialize($dataSource); foreach ($resultSet as $index => $row) { self::assertEquals($dataSource[$index], $row); } } public function testWhenReturnTypeIsObjectThenIterationReturnsRowObjects() { $dataSource = $this->getArrayDataSource(10); $this->resultSet->initialize($dataSource); foreach ($this->resultSet as $index => $row) { self::assertInstanceOf('ArrayObject', $row); self::assertEquals($dataSource[$index], $row->getArrayCopy()); } } public function testCountReturnsCountOfRows() { $count = rand(3, 75); $dataSource = $this->getArrayDataSource($count); $this->resultSet->initialize($dataSource); self::assertEquals($count, $this->resultSet->count()); } public function testToArrayRaisesExceptionForRowsThatAreNotArraysOrArrayCastable() { $count = rand(3, 75); $dataSource = $this->getArrayDataSource($count); foreach ($dataSource as $index => $row) { $dataSource[$index] = (object) $row; } $this->resultSet->initialize($dataSource); $this->expectException(RuntimeException::class); $this->resultSet->toArray(); } public function testToArrayCreatesArrayOfArraysRepresentingRows() { $count = rand(3, 75); $dataSource = $this->getArrayDataSource($count); $this->resultSet->initialize($dataSource); $test = $this->resultSet->toArray(); self::assertEquals($dataSource->getArrayCopy(), $test, var_export($test, 1)); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::current * @covers \Laminas\Db\ResultSet\AbstractResultSet::buffer */ public function testCurrentWithBufferingCallsDataSourceCurrentOnce() { $mockResult = $this->getMockBuilder(ResultInterface::class)->getMock(); $mockResult->expects($this->once())->method('current')->will($this->returnValue(['foo' => 'bar'])); $this->resultSet->initialize($mockResult); $this->resultSet->buffer(); $this->resultSet->current(); // assertion above will fail if this calls datasource current $this->resultSet->current(); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::current * @covers \Laminas\Db\ResultSet\AbstractResultSet::buffer */ public function testBufferCalledAfterIterationThrowsException() { $this->resultSet->initialize($this->createMock(ResultInterface::class)); $this->resultSet->current(); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Buffering must be enabled before iteration is started'); $this->resultSet->buffer(); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::current */ public function testCurrentReturnsNullForNonExistingValues() { $mockResult = $this->createMock(ResultInterface::class); $mockResult->expects($this->once())->method('current')->will($this->returnValue("Not an Array")); $this->resultSet->initialize($mockResult); $this->resultSet->buffer(); self::assertNull($this->resultSet->current()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/ResultSet/AbstractResultSetTest.php
test/unit/ResultSet/AbstractResultSetTest.php
<?php namespace LaminasTest\Db\ResultSet; use ArrayIterator; use Laminas\Db\Adapter\Driver\Pdo\Result; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\ResultSet\AbstractResultSet; use Laminas\Db\ResultSet\Exception\InvalidArgumentException; use Laminas\Db\ResultSet\Exception\RuntimeException; use PDOStatement; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function assert; class AbstractResultSetTest extends TestCase { /** @var MockObject */ protected $resultSet; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::initialize */ public function testInitialize() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); self::assertSame($resultSet, $resultSet->initialize([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( 'DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate' ); $resultSet->initialize('foo'); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::initialize */ public function testInitializeDoesNotCallCount() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $result = $this->getMockForAbstractClass(ResultInterface::class); $result->expects($this->never())->method('count'); $resultSet->initialize($result); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::initialize */ public function testInitializeWithEmptyArray() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); self::assertSame($resultSet, $resultSet->initialize([])); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::buffer */ public function testBuffer() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); self::assertSame($resultSet, $resultSet->buffer()); $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); $resultSet->next(); // start iterator $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Buffering must be enabled before iteration is started'); $resultSet->buffer(); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::isBuffered */ public function testIsBuffered() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); self::assertFalse($resultSet->isBuffered()); $resultSet->buffer(); self::assertTrue($resultSet->isBuffered()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::getDataSource */ public function testGetDataSource() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); self::assertInstanceOf(ArrayIterator::class, $resultSet->getDataSource()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::getFieldCount */ public function testGetFieldCount() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ])); self::assertEquals(2, $resultSet->getFieldCount()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::next */ public function testNext() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); self::assertNull($resultSet->next()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::key */ public function testKey() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); $resultSet->next(); self::assertEquals(1, $resultSet->key()); $resultSet->next(); self::assertEquals(2, $resultSet->key()); $resultSet->next(); self::assertEquals(3, $resultSet->key()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::current */ public function testCurrent() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); self::assertEquals(['id' => 1, 'name' => 'one'], $resultSet->current()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::valid */ public function testValid() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); self::assertTrue($resultSet->valid()); $resultSet->next(); $resultSet->next(); $resultSet->next(); self::assertFalse($resultSet->valid()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::rewind */ public function testRewind() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); self::assertNull($resultSet->rewind()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::count */ public function testCount() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); self::assertEquals(3, $resultSet->count()); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::toArray */ public function testToArray() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); self::assertEquals( [ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ], $resultSet->toArray() ); } /** * Test multiple iterations with buffer * * @group issue-6845 */ public function testBufferIterations() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $resultSet->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ])); $resultSet->buffer(); $data = $resultSet->current(); self::assertEquals(1, $data['id']); $resultSet->next(); $data = $resultSet->current(); self::assertEquals(2, $data['id']); $resultSet->rewind(); $data = $resultSet->current(); self::assertEquals(1, $data['id']); $resultSet->next(); $data = $resultSet->current(); self::assertEquals(2, $data['id']); $resultSet->next(); $data = $resultSet->current(); self::assertEquals(3, $data['id']); } /** * Test multiple iterations with buffer with multiple rewind() calls * * @group issue-6845 */ public function testMultipleRewindBufferIterations() { $resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); $result = new Result(); $stub = $this->getMockBuilder(PDOStatement::class)->getMock(); $data = new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ['id' => 3, 'name' => 'three'], ]); assert($stub instanceof PDOStatement); // to suppress IDE type warnings $stub->expects($this->any()) ->method('fetch') ->will($this->returnCallback(function () use ($data) { $r = $data->current(); $data->next(); return $r; })); $result->initialize($stub, null); $result->rewind(); $result->rewind(); $resultSet->initialize($result); $resultSet->buffer(); $resultSet->rewind(); $resultSet->rewind(); $data = $resultSet->current(); self::assertEquals(1, $data['id']); $resultSet->next(); $data = $resultSet->current(); self::assertEquals(2, $data['id']); $resultSet->rewind(); $resultSet->rewind(); $data = $resultSet->current(); self::assertEquals(1, $data['id']); $resultSet->next(); $data = $resultSet->current(); self::assertEquals(2, $data['id']); $resultSet->next(); $data = $resultSet->current(); self::assertEquals(3, $data['id']); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/ResultSet/HydratingResultSetIntegrationTest.php
test/unit/ResultSet/HydratingResultSetIntegrationTest.php
<?php namespace LaminasTest\Db\ResultSet; use ArrayIterator; use Laminas\Db\ResultSet\HydratingResultSet; use PHPUnit\Framework\TestCase; class HydratingResultSetIntegrationTest extends TestCase { /** * @covers \Laminas\Db\ResultSet\HydratingResultSet::current */ public function testCurrentWillReturnBufferedRow() { $hydratingRs = new HydratingResultSet(); $hydratingRs->initialize(new ArrayIterator([ ['id' => 1, 'name' => 'one'], ['id' => 2, 'name' => 'two'], ])); $hydratingRs->buffer(); $obj1 = $hydratingRs->current(); $hydratingRs->rewind(); $obj2 = $hydratingRs->current(); self::assertSame($obj1, $obj2); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/ResultSet/AbstractResultSetIntegrationTest.php
test/unit/ResultSet/AbstractResultSetIntegrationTest.php
<?php namespace LaminasTest\Db\ResultSet; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\ResultSet\AbstractResultSet; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class AbstractResultSetIntegrationTest extends TestCase { /** @var AbstractResultSet|MockObject */ protected $resultSet; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->resultSet = $this->getMockForAbstractClass(AbstractResultSet::class); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::current */ public function testCurrentCallsDataSourceCurrentAsManyTimesWithoutBuffer() { $result = $this->getMockBuilder(ResultInterface::class)->getMock(); $this->resultSet->initialize($result); $result->expects($this->exactly(3))->method('current')->will($this->returnValue(['foo' => 'bar'])); $value1 = $this->resultSet->current(); $value2 = $this->resultSet->current(); $this->resultSet->current(); self::assertEquals($value1, $value2); } /** * @covers \Laminas\Db\ResultSet\AbstractResultSet::current */ public function testCurrentCallsDataSourceCurrentOnceWithBuffer() { $result = $this->getMockBuilder(ResultInterface::class)->getMock(); $this->resultSet->buffer(); $this->resultSet->initialize($result); $result->expects($this->once())->method('current')->will($this->returnValue(['foo' => 'bar'])); $value1 = $this->resultSet->current(); $value2 = $this->resultSet->current(); $this->resultSet->current(); self::assertEquals($value1, $value2); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TableGateway/TableGatewayTest.php
test/unit/TableGateway/TableGatewayTest.php
<?php namespace LaminasTest\Db\TableGateway; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\ConnectionInterface; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\ResultSet\ResultSet; use Laminas\Db\Sql\Delete; use Laminas\Db\Sql\Insert; use Laminas\Db\Sql\Sql; use Laminas\Db\Sql\TableIdentifier; use Laminas\Db\Sql\Update; use Laminas\Db\TableGateway\Exception\InvalidArgumentException; use Laminas\Db\TableGateway\Feature; use Laminas\Db\TableGateway\Feature\FeatureSet; use Laminas\Db\TableGateway\TableGateway; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class TableGatewayTest extends TestCase { /** @var Adapter&MockObject */ protected $mockAdapter; protected function setUp(): void { // mock the adapter, driver, and parts $mockResult = $this->getMockBuilder(ResultInterface::class)->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); $mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); // setup mock adapter $this->mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); } /** * Beside other tests checks for plain string table identifier */ public function testConstructor() { // constructor with only required args $table = new TableGateway( 'foo', $this->mockAdapter ); self::assertEquals('foo', $table->getTable()); self::assertSame($this->mockAdapter, $table->getAdapter()); self::assertInstanceOf(FeatureSet::class, $table->getFeatureSet()); self::assertInstanceOf(ResultSet::class, $table->getResultSetPrototype()); self::assertInstanceOf(Sql::class, $table->getSql()); // injecting all args $table = new TableGateway( 'foo', $this->mockAdapter, $featureSet = new Feature\FeatureSet(), $resultSet = new ResultSet(), $sql = new Sql($this->mockAdapter, 'foo') ); self::assertEquals('foo', $table->getTable()); self::assertSame($this->mockAdapter, $table->getAdapter()); self::assertSame($featureSet, $table->getFeatureSet()); self::assertSame($resultSet, $table->getResultSetPrototype()); self::assertSame($sql, $table->getSql()); // constructor expects exception $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Table name must be a string or an instance of Laminas\Db\Sql\TableIdentifier'); new TableGateway( null, $this->mockAdapter ); } /** * @group 6726 * @group 6740 */ public function testTableAsString() { $ti = 'fooTable.barSchema'; // constructor with only required args $table = new TableGateway( $ti, $this->mockAdapter ); self::assertEquals($ti, $table->getTable()); } /** * @group 6726 * @group 6740 */ public function testTableAsTableIdentifierObject() { $ti = new TableIdentifier('fooTable', 'barSchema'); // constructor with only required args $table = new TableGateway( $ti, $this->mockAdapter ); self::assertEquals($ti, $table->getTable()); } /** * @group 6726 * @group 6740 */ public function testTableAsAliasedTableIdentifierObject() { // phpcs:disable WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps $aliasedTI = ['foo' => new TableIdentifier('fooTable', 'barSchema')]; // constructor with only required args $table = new TableGateway( $aliasedTI, $this->mockAdapter ); self::assertEquals($aliasedTI, $table->getTable()); // phpcs:enable WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps } /** * @psalm-return array<string, array{ * 0: array<string, string|TableIdentifier>, * 1: string|TableIdentifier * }> */ public function aliasedTables(): array { $identifier = new TableIdentifier('Users'); return [ 'simple-alias' => [['U' => 'Users'], 'Users'], 'identifier-alias' => [['U' => $identifier], $identifier], ]; } /** * @group 7311 * @dataProvider aliasedTables * @param array<string, string|TableIdentifier> $tableValue * @param string|TableIdentifier $expected */ public function testInsertShouldResetTableToUnaliasedTable(array $tableValue, $expected) { $insert = new Insert(); $insert->into($tableValue); $result = $this->getMockBuilder(ResultInterface::class) ->getMock(); $result->expects($this->once()) ->method('getAffectedRows') ->will($this->returnValue(1)); $statement = $this->getMockBuilder(StatementInterface::class) ->getMock(); $statement->expects($this->once()) ->method('execute') ->will($this->returnValue($result)); $statementExpectation = function ($insert) use ($expected, $statement) { $state = $insert->getRawState(); self::assertSame($expected, $state['table']); return $statement; }; $sql = $this->getMockBuilder(Sql::class) ->disableOriginalConstructor() ->getMock(); $sql->expects($this->atLeastOnce()) ->method('getTable') ->will($this->returnValue($tableValue)); $sql->expects($this->once()) ->method('insert') ->will($this->returnValue($insert)); $sql->expects($this->once()) ->method('prepareStatementForSqlObject') ->with($this->equalTo($insert)) ->will($this->returnCallback($statementExpectation)); $table = new TableGateway( $tableValue, $this->mockAdapter, null, null, $sql ); $result = $table->insert([ 'foo' => 'FOO', ]); $state = $insert->getRawState(); self::assertIsArray($state['table']); self::assertEquals( $tableValue, $state['table'] ); } /** * @dataProvider aliasedTables * @param array<string, string|TableIdentifier> $tableValue * @param string|TableIdentifier $expected */ public function testUpdateShouldResetTableToUnaliasedTable(array $tableValue, $expected) { $update = new Update(); $update->table($tableValue); $result = $this->getMockBuilder(ResultInterface::class) ->getMock(); $result->expects($this->once()) ->method('getAffectedRows') ->will($this->returnValue(1)); $statement = $this->getMockBuilder(StatementInterface::class) ->getMock(); $statement->expects($this->once()) ->method('execute') ->will($this->returnValue($result)); $statementExpectation = function ($update) use ($expected, $statement) { $state = $update->getRawState(); self::assertSame($expected, $state['table']); return $statement; }; $sql = $this->getMockBuilder(Sql::class) ->disableOriginalConstructor() ->getMock(); $sql->expects($this->atLeastOnce()) ->method('getTable') ->will($this->returnValue($tableValue)); $sql->expects($this->once()) ->method('update') ->will($this->returnValue($update)); $sql->expects($this->once()) ->method('prepareStatementForSqlObject') ->with($this->equalTo($update)) ->will($this->returnCallback($statementExpectation)); $table = new TableGateway( $tableValue, $this->mockAdapter, null, null, $sql ); $result = $table->update([ 'foo' => 'FOO', ], [ 'bar' => 'BAR', ]); $state = $update->getRawState(); self::assertIsArray($state['table']); self::assertEquals( $tableValue, $state['table'] ); } /** * @dataProvider aliasedTables * @param array<string, string|TableIdentifier> $tableValue * @param string|TableIdentifier $expected */ public function testDeleteShouldResetTableToUnaliasedTable(array $tableValue, $expected) { $delete = new Delete(); $delete->from($tableValue); $result = $this->getMockBuilder(ResultInterface::class) ->getMock(); $result->expects($this->once()) ->method('getAffectedRows') ->will($this->returnValue(1)); $statement = $this->getMockBuilder(StatementInterface::class) ->getMock(); $statement->expects($this->once()) ->method('execute') ->will($this->returnValue($result)); $statementExpectation = function ($delete) use ($expected, $statement) { $state = $delete->getRawState(); self::assertSame($expected, $state['table']); return $statement; }; $sql = $this->getMockBuilder(Sql::class) ->disableOriginalConstructor() ->getMock(); $sql->expects($this->atLeastOnce()) ->method('getTable') ->will($this->returnValue($tableValue)); $sql->expects($this->once()) ->method('delete') ->will($this->returnValue($delete)); $sql->expects($this->once()) ->method('prepareStatementForSqlObject') ->with($this->equalTo($delete)) ->will($this->returnCallback($statementExpectation)); $table = new TableGateway( $tableValue, $this->mockAdapter, null, null, $sql ); $result = $table->delete([ 'foo' => 'FOO', ]); $state = $delete->getRawState(); self::assertIsArray($state['table']); self::assertEquals( $tableValue, $state['table'] ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TableGateway/AbstractTableGatewayTest.php
test/unit/TableGateway/AbstractTableGatewayTest.php
<?php namespace LaminasTest\Db\TableGateway; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\ConnectionInterface; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\ResultSet\ResultSet; use Laminas\Db\Sql; use Laminas\Db\Sql\Delete; use Laminas\Db\Sql\Insert; use Laminas\Db\Sql\Select; use Laminas\Db\Sql\Update; use Laminas\Db\TableGateway\AbstractTableGateway; use Laminas\Db\TableGateway\Feature\FeatureSet; use PHPUnit\Framework\MockObject\Generator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionClass; class AbstractTableGatewayTest extends TestCase { /** @var Generator */ protected $mockAdapter; /** @var Generator */ protected $mockSql; /** @var AbstractTableGateway */ protected $table; /** @var FeatureSet&MockObject */ protected $mockFeatureSet; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { // mock the adapter, driver, and parts $mockResult = $this->getMockBuilder(ResultInterface::class)->getMock(); $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(5)); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); $mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $mockConnection->expects($this->any())->method('getLastGeneratedValue')->will($this->returnValue(10)); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); $this->mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $this->mockSql = $this->getMockBuilder(\Laminas\Db\Sql\Sql::class) ->setMethods(['select', 'insert', 'update', 'delete']) ->setConstructorArgs([$this->mockAdapter, 'foo']) ->getMock(); $this->mockSql->expects($this->any())->method('select')->will($this->returnValue( $this->getMockBuilder(Select::class) ->setMethods(['where', 'getRawState']) ->setConstructorArgs(['foo']) ->getMock() )); $this->mockSql->expects($this->any())->method('insert')->will($this->returnValue( $this->getMockBuilder(Insert::class) ->setMethods(['prepareStatement', 'values']) ->setConstructorArgs(['foo']) ->getMock() )); $this->mockSql->expects($this->any())->method('update')->will($this->returnValue( $this->getMockBuilder(Update::class) ->setMethods(['where', 'join']) ->setConstructorArgs(['foo']) ->getMock() )); $this->mockSql->expects($this->any())->method('delete')->will($this->returnValue( $this->getMockBuilder(Delete::class) ->setMethods(['where']) ->setConstructorArgs(['foo']) ->getMock() )); $this->mockFeatureSet = $this->getMockBuilder(FeatureSet::class)->getMock(); $this->table = $this->getMockForAbstractClass( AbstractTableGateway::class //array('getTable') ); $tgReflection = new ReflectionClass(AbstractTableGateway::class); foreach ($tgReflection->getProperties() as $tgPropReflection) { $tgPropReflection->setAccessible(true); switch ($tgPropReflection->getName()) { case 'table': $tgPropReflection->setValue($this->table, 'foo'); break; case 'adapter': $tgPropReflection->setValue($this->table, $this->mockAdapter); break; case 'resultSetPrototype': $tgPropReflection->setValue($this->table, new ResultSet()); break; case 'sql': $tgPropReflection->setValue($this->table, $this->mockSql); break; case 'featureSet': $tgPropReflection->setValue($this->table, $this->mockFeatureSet); break; } } } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getTable */ public function testGetTable() { self::assertEquals('foo', $this->table->getTable()); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getAdapter */ public function testGetAdapter() { self::assertSame($this->mockAdapter, $this->table->getAdapter()); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getSql */ public function testGetSql() { self::assertInstanceOf(\Laminas\Db\Sql\Sql::class, $this->table->getSql()); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getResultSetPrototype */ public function testGetSelectResultPrototype() { self::assertInstanceOf(ResultSet::class, $this->table->getResultSetPrototype()); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::select * @covers \Laminas\Db\TableGateway\AbstractTableGateway::selectWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeSelect */ public function testSelectWithNoWhere() { $resultSet = $this->table->select(); // check return types self::assertInstanceOf(ResultSet::class, $resultSet); self::assertNotSame($this->table->getResultSetPrototype(), $resultSet); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::select * @covers \Laminas\Db\TableGateway\AbstractTableGateway::selectWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeSelect */ public function testSelectWithWhereString() { $mockSelect = $this->mockSql->select(); $mockSelect->expects($this->any()) ->method('getRawState') ->will($this->returnValue([ 'table' => $this->table->getTable(), 'columns' => [], ])); // assert select::from() is called $mockSelect->expects($this->once()) ->method('where') ->with($this->equalTo('foo')); $this->table->select('foo'); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::select * @covers \Laminas\Db\TableGateway\AbstractTableGateway::selectWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeSelect * * This is a test for the case when a valid $select is built using an aliased table name, then used * with AbstractTableGateway::selectWith (or AbstractTableGateway::select). * * $myTable = new MyTable(...); * $sql = new \Laminas\Db\Sql\Sql(...); * $select = $sql->select()->from(array('t' => 'mytable')); * * // Following fails, with Fatal error: Uncaught exception 'RuntimeException' with message * 'The table name of the provided select object must match that of the table' unless fix is provided. * $myTable->selectWith($select); */ public function testSelectWithArrayTable() { // Case 1 $select1 = $this->getMockBuilder(Select::class)->setMethods(['getRawState'])->getMock(); $select1->expects($this->once()) ->method('getRawState') ->will($this->returnValue([ 'table' => 'foo', // Standard table name format, valid according to Select::from() 'columns' => null, ])); $return = $this->table->selectWith($select1); self::assertNotNull($return); // Case 2 $select1 = $this->getMockBuilder(Select::class)->setMethods(['getRawState'])->getMock(); $select1->expects($this->once()) ->method('getRawState') ->will($this->returnValue([ 'table' => ['f' => 'foo'], // Alias table name format, valid according to Select::from() 'columns' => null, ])); $return = $this->table->selectWith($select1); self::assertNotNull($return); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::insert * @covers \Laminas\Db\TableGateway\AbstractTableGateway::insertWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeInsert */ public function testInsert() { $mockInsert = $this->mockSql->insert(); $mockInsert->expects($this->once()) ->method('prepareStatement') ->with($this->mockAdapter); $mockInsert->expects($this->once()) ->method('values') ->with($this->equalTo(['foo' => 'bar'])); $affectedRows = $this->table->insert(['foo' => 'bar']); self::assertEquals(5, $affectedRows); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::update * @covers \Laminas\Db\TableGateway\AbstractTableGateway::updateWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeUpdate */ public function testUpdate() { $mockUpdate = $this->mockSql->update(); // assert select::from() is called $mockUpdate->expects($this->once()) ->method('where') ->with($this->equalTo('id = 2')); $affectedRows = $this->table->update(['foo' => 'bar'], 'id = 2'); self::assertEquals(5, $affectedRows); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::update * @covers \Laminas\Db\TableGateway\AbstractTableGateway::updateWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeUpdate */ public function testUpdateWithJoin() { $mockUpdate = $this->mockSql->update(); $joins = [ [ 'name' => 'baz', 'on' => 'foo.fooId = baz.fooId', 'type' => Sql\Join::JOIN_LEFT, ], ]; // assert select::from() is called $mockUpdate->expects($this->once()) ->method('where') ->with($this->equalTo('id = 2')); $mockUpdate->expects($this->once()) ->method('join') ->with($joins[0]['name'], $joins[0]['on'], $joins[0]['type']); $affectedRows = $this->table->update(['foo.field' => 'bar'], 'id = 2', $joins); self::assertEquals(5, $affectedRows); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::update * @covers \Laminas\Db\TableGateway\AbstractTableGateway::updateWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeUpdate */ public function testUpdateWithJoinDefaultType() { $mockUpdate = $this->mockSql->update(); $joins = [ [ 'name' => 'baz', 'on' => 'foo.fooId = baz.fooId', ], ]; // assert select::from() is called $mockUpdate->expects($this->once()) ->method('where') ->with($this->equalTo('id = 2')); $mockUpdate->expects($this->once()) ->method('join') ->with($joins[0]['name'], $joins[0]['on'], Sql\Join::JOIN_INNER); $affectedRows = $this->table->update(['foo.field' => 'bar'], 'id = 2', $joins); self::assertEquals(5, $affectedRows); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::update * @covers \Laminas\Db\TableGateway\AbstractTableGateway::updateWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeUpdate */ public function testUpdateWithNoCriteria() { $mockUpdate = $this->mockSql->update(); $affectedRows = $this->table->update(['foo' => 'bar']); self::assertEquals(5, $affectedRows); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::delete * @covers \Laminas\Db\TableGateway\AbstractTableGateway::deleteWith * @covers \Laminas\Db\TableGateway\AbstractTableGateway::executeDelete */ public function testDelete() { $mockDelete = $this->mockSql->delete(); // assert select::from() is called $mockDelete->expects($this->once()) ->method('where') ->with($this->equalTo('foo')); $affectedRows = $this->table->delete('foo'); self::assertEquals(5, $affectedRows); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::getLastInsertValue */ public function testGetLastInsertValue() { $this->table->insert(['foo' => 'bar']); self::assertEquals(10, $this->table->getLastInsertValue()); } public function testInitializeBuildsAResultSet() { $stub = $this->getMockForAbstractClass(AbstractTableGateway::class); $tgReflection = new ReflectionClass(AbstractTableGateway::class); foreach ($tgReflection->getProperties() as $tgPropReflection) { $tgPropReflection->setAccessible(true); switch ($tgPropReflection->getName()) { case 'table': $tgPropReflection->setValue($stub, 'foo'); break; case 'adapter': $tgPropReflection->setValue($stub, $this->mockAdapter); break; case 'featureSet': $tgPropReflection->setValue($stub, $this->mockFeatureSet); break; } } $stub->initialize(); $this->assertInstanceOf(ResultSet::class, $stub->getResultSetPrototype()); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::__get */ // @codingStandardsIgnoreStart public function test__get() { // @codingStandardsIgnoreEnd $this->table->insert(['foo']); // trigger last insert id update self::assertEquals(10, $this->table->lastInsertValue); self::assertSame($this->mockAdapter, $this->table->adapter); //self::assertEquals('foo', $this->table->table); } /** * @covers \Laminas\Db\TableGateway\AbstractTableGateway::__clone */ // @codingStandardsIgnoreStart public function test__clone() { // @codingStandardsIgnoreEnd $cTable = clone $this->table; self::assertSame($this->mockAdapter, $cTable->getAdapter()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TableGateway/Feature/MetadataFeatureTest.php
test/unit/TableGateway/Feature/MetadataFeatureTest.php
<?php namespace LaminasTest\Db\TableGateway\Feature; use Laminas\Db\Metadata\MetadataInterface; use Laminas\Db\Metadata\Object\ConstraintObject; use Laminas\Db\Metadata\Object\TableObject; use Laminas\Db\Metadata\Object\ViewObject; use Laminas\Db\TableGateway\AbstractTableGateway; use Laminas\Db\TableGateway\Feature\MetadataFeature; use PHPUnit\Framework\TestCase; use ReflectionProperty; class MetadataFeatureTest extends TestCase { /** * @group integration-test */ public function testPostInitialize() { $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); $metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock(); $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); $constraintObject = new ConstraintObject('id_pk', 'table'); $constraintObject->setColumns(['id']); $constraintObject->setType('PRIMARY KEY'); $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject])); $feature = new MetadataFeature($metadataMock); $feature->setTableGateway($tableGatewayMock); $feature->postInitialize(); self::assertEquals(['id', 'name'], $tableGatewayMock->getColumns()); } public function testPostInitializeRecordsPrimaryKeyColumnToSharedMetadata() { /** @var AbstractTableGateway $tableGatewayMock */ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); $metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock(); $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); $metadataMock->expects($this->any()) ->method('getTable') ->will($this->returnValue(new TableObject('foo'))); $constraintObject = new ConstraintObject('id_pk', 'table'); $constraintObject->setColumns(['id']); $constraintObject->setType('PRIMARY KEY'); $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject])); $feature = new MetadataFeature($metadataMock); $feature->setTableGateway($tableGatewayMock); $feature->postInitialize(); $r = new ReflectionProperty(MetadataFeature::class, 'sharedData'); $r->setAccessible(true); $sharedData = $r->getValue($feature); self::assertTrue( isset($sharedData['metadata']['primaryKey']), 'Shared data must have metadata entry for primary key' ); self::assertSame($sharedData['metadata']['primaryKey'], 'id'); } public function testPostInitializeRecordsListOfColumnsInPrimaryKeyToSharedMetadata() { /** @var AbstractTableGateway $tableGatewayMock */ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); $metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock(); $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); $metadataMock->expects($this->any()) ->method('getTable') ->will($this->returnValue(new TableObject('foo'))); $constraintObject = new ConstraintObject('id_pk', 'table'); $constraintObject->setColumns(['composite', 'id']); $constraintObject->setType('PRIMARY KEY'); $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject])); $feature = new MetadataFeature($metadataMock); $feature->setTableGateway($tableGatewayMock); $feature->postInitialize(); $r = new ReflectionProperty(MetadataFeature::class, 'sharedData'); $r->setAccessible(true); $sharedData = $r->getValue($feature); self::assertTrue( isset($sharedData['metadata']['primaryKey']), 'Shared data must have metadata entry for primary key' ); self::assertEquals($sharedData['metadata']['primaryKey'], ['composite', 'id']); } public function testPostInitializeSkipsPrimaryKeyCheckIfNotTable() { /** @var AbstractTableGateway $tableGatewayMock */ $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); $metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock(); $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); $metadataMock->expects($this->any()) ->method('getTable') ->will($this->returnValue(new ViewObject('foo'))); $metadataMock->expects($this->never())->method('getConstraints'); $feature = new MetadataFeature($metadataMock); $feature->setTableGateway($tableGatewayMock); $feature->postInitialize(); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php
test/unit/TableGateway/Feature/MasterSlaveFeatureTest.php
<?php namespace LaminasTest\Db\TableGateway\Feature; use Laminas\Db\Adapter\AdapterInterface; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\Adapter\Platform\Sql92; use Laminas\Db\ResultSet\ResultSet; use Laminas\Db\TableGateway\Feature\MasterSlaveFeature; use Laminas\Db\TableGateway\TableGateway; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class MasterSlaveFeatureTest extends TestCase { /** @var AdapterInterface&MockObject */ protected $mockMasterAdapter; /** @var AdapterInterface&MockObject */ protected $mockSlaveAdapter; /** @var MasterSlaveFeature */ protected $feature; /** @var TableGateway&MockObject */ protected $table; protected function setUp(): void { $this->mockMasterAdapter = $this->getMockBuilder(AdapterInterface::class)->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue( $mockStatement )); $this->mockMasterAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); $this->mockMasterAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue( new Sql92() )); $this->mockSlaveAdapter = $this->getMockBuilder(AdapterInterface::class)->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue( $mockStatement )); $this->mockSlaveAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); $this->mockSlaveAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue( new Sql92() )); $this->feature = new MasterSlaveFeature($this->mockSlaveAdapter); } public function testPostInitialize() { $this->getMockForAbstractClass( TableGateway::class, ['foo', $this->mockMasterAdapter, $this->feature] ); // postInitialize is run self::assertSame($this->mockSlaveAdapter, $this->feature->getSlaveSql()->getAdapter()); } public function testPreSelect() { $table = $this->getMockForAbstractClass( TableGateway::class, ['foo', $this->mockMasterAdapter, $this->feature] ); $this->mockSlaveAdapter->getDriver()->createStatement() ->expects($this->once())->method('execute')->will($this->returnValue( $this->getMockBuilder(ResultSet::class)->getMock() )); $table->select('foo = bar'); } public function testPostSelect() { $table = $this->getMockForAbstractClass( TableGateway::class, ['foo', $this->mockMasterAdapter, $this->feature] ); $this->mockSlaveAdapter->getDriver()->createStatement() ->expects($this->once())->method('execute')->will($this->returnValue( $this->getMockBuilder(ResultSet::class)->getMock() )); $masterSql = $table->getSql(); $table->select('foo = bar'); // test that the sql object is restored self::assertSame($masterSql, $table->getSql()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TableGateway/Feature/SequenceFeatureTest.php
test/unit/TableGateway/Feature/SequenceFeatureTest.php
<?php namespace LaminasTest\Db\TableGateway\Feature; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\Adapter\Platform\PlatformInterface; use Laminas\Db\TableGateway\Feature\SequenceFeature; use Laminas\Db\TableGateway\TableGateway; use PHPUnit\Framework\TestCase; class SequenceFeatureTest extends TestCase { /** @var SequenceFeature */ protected $feature; /** @var TableGateway */ protected $tableGateway; /** @var string primary key name */ protected $primaryKeyField = 'id'; /** @var string sequence name */ protected $sequenceName = 'table_sequence'; protected function setUp(): void { $this->feature = new SequenceFeature($this->primaryKeyField, $this->sequenceName); } /** * @dataProvider nextSequenceIdProvider */ public function testNextSequenceId(string $platformName, string $statementSql) { $platform = $this->createMock(PlatformInterface::class); $platform->expects($this->any()) ->method('getName') ->will($this->returnValue($platformName)); $platform->expects($this->any()) ->method('quoteIdentifier') ->will($this->returnValue($this->sequenceName)); $adapter = $this->getMockBuilder(Adapter::class) ->setMethods(['getPlatform', 'createStatement']) ->disableOriginalConstructor() ->getMock(); $adapter->expects($this->any()) ->method('getPlatform') ->will($this->returnValue($platform)); $result = $this->createMock(ResultInterface::class); $result->expects($this->any()) ->method('current') ->will($this->returnValue(['nextval' => 2])); $statement = $this->createMock(StatementInterface::class); $statement->expects($this->any()) ->method('execute') ->will($this->returnValue($result)); $statement->expects($this->any()) ->method('prepare') ->with($statementSql); $adapter->expects($this->once()) ->method('createStatement') ->will($this->returnValue($statement)); $this->tableGateway = $this->getMockForAbstractClass( TableGateway::class, ['table', $adapter], '', true ); $this->feature->setTableGateway($this->tableGateway); $this->feature->nextSequenceId(); } /** @psalm-return array<array-key, array{0: string, 1: string}> */ public function nextSequenceIdProvider(): array { return [ ['PostgreSQL', 'SELECT NEXTVAL(\'"' . $this->sequenceName . '"\')'], ['Oracle', 'SELECT ' . $this->sequenceName . '.NEXTVAL as "nextval" FROM dual'], ]; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TableGateway/Feature/FeatureSetTest.php
test/unit/TableGateway/Feature/FeatureSetTest.php
<?php namespace LaminasTest\Db\TableGateway\Feature; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\AdapterInterface; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\Pgsql\Result; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\Adapter\Platform\Postgresql; use Laminas\Db\Adapter\Platform\Sql92; use Laminas\Db\Metadata\MetadataInterface; use Laminas\Db\Metadata\Object\ConstraintObject; use Laminas\Db\TableGateway\AbstractTableGateway; use Laminas\Db\TableGateway\Feature\FeatureSet; use Laminas\Db\TableGateway\Feature\MasterSlaveFeature; use Laminas\Db\TableGateway\Feature\MetadataFeature; use Laminas\Db\TableGateway\Feature\SequenceFeature; use PHPUnit\Framework\TestCase; use ReflectionClass; class FeatureSetTest extends TestCase { /** * @cover FeatureSet::addFeature * @group Laminas-4993 */ public function testAddFeatureThatFeatureDoesNotHaveTableGatewayButFeatureSetHas() { $mockMasterAdapter = $this->getMockBuilder(AdapterInterface::class)->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue( $mockStatement )); $mockMasterAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); $mockMasterAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue( new Sql92() )); $mockSlaveAdapter = $this->getMockBuilder(AdapterInterface::class)->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue( $mockStatement )); $mockSlaveAdapter->expects($this->any())->method('getDriver')->will($this->returnValue($mockDriver)); $mockSlaveAdapter->expects($this->any())->method('getPlatform')->will($this->returnValue( new Sql92() )); $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); //feature doesn't have tableGateway, but FeatureSet has $feature = new MasterSlaveFeature($mockSlaveAdapter); $featureSet = new FeatureSet(); $featureSet->setTableGateway($tableGatewayMock); self::assertInstanceOf(FeatureSet::class, $featureSet->addFeature($feature)); } /** * @cover FeatureSet::addFeature * @group Laminas-4993 */ public function testAddFeatureThatFeatureHasTableGatewayButFeatureSetDoesNotHave() { $tableGatewayMock = $this->getMockForAbstractClass(AbstractTableGateway::class); $metadataMock = $this->getMockBuilder(MetadataInterface::class)->getMock(); $metadataMock->expects($this->any())->method('getColumnNames')->will($this->returnValue(['id', 'name'])); $constraintObject = new ConstraintObject('id_pk', 'table'); $constraintObject->setColumns(['id']); $constraintObject->setType('PRIMARY KEY'); $metadataMock->expects($this->any())->method('getConstraints')->will($this->returnValue([$constraintObject])); //feature have tableGateway, but FeatureSet doesn't has $feature = new MetadataFeature($metadataMock); $feature->setTableGateway($tableGatewayMock); $featureSet = new FeatureSet(); self::assertInstanceOf(FeatureSet::class, $featureSet->addFeature($feature)); } /** * @covers \Laminas\Db\TableGateway\Feature\FeatureSet::canCallMagicCall */ public function testCanCallMagicCallReturnsTrueForAddedMethodOfAddedFeature() { $feature = new SequenceFeature('id', 'table_sequence'); $featureSet = new FeatureSet(); $featureSet->addFeature($feature); self::assertTrue( $featureSet->canCallMagicCall('lastSequenceId'), "Should have been able to call lastSequenceId from the Sequence Feature" ); } /** * @covers \Laminas\Db\TableGateway\Feature\FeatureSet::canCallMagicCall */ public function testCanCallMagicCallReturnsFalseForAddedMethodOfAddedFeature() { $feature = new SequenceFeature('id', 'table_sequence'); $featureSet = new FeatureSet(); $featureSet->addFeature($feature); self::assertFalse( $featureSet->canCallMagicCall('postInitialize'), "Should have been able to call postInitialize from the MetaData Feature" ); } /** * @covers \Laminas\Db\TableGateway\Feature\FeatureSet::canCallMagicCall */ public function testCanCallMagicCallReturnsFalseWhenNoFeaturesHaveBeenAdded() { $featureSet = new FeatureSet(); self::assertFalse( $featureSet->canCallMagicCall('lastSequenceId') ); } /** * @covers \Laminas\Db\TableGateway\Feature\FeatureSet::callMagicCall */ public function testCallMagicCallSucceedsForValidMethodOfAddedFeature() { $sequenceName = 'table_sequence'; $platformMock = $this->getMockBuilder(Postgresql::class)->getMock(); $platformMock->expects($this->any()) ->method('getName')->will($this->returnValue('PostgreSQL')); $resultMock = $this->getMockBuilder(Result::class)->getMock(); $resultMock->expects($this->any()) ->method('current') ->will($this->returnValue(['currval' => 1])); $statementMock = $this->getMockBuilder(StatementInterface::class)->getMock(); $statementMock->expects($this->any()) ->method('prepare') ->with('SELECT CURRVAL(\'' . $sequenceName . '\')'); $statementMock->expects($this->any()) ->method('execute') ->will($this->returnValue($resultMock)); $adapterMock = $this->getMockBuilder(Adapter::class) ->disableOriginalConstructor() ->getMock(); $adapterMock->expects($this->any()) ->method('getPlatform')->will($this->returnValue($platformMock)); $adapterMock->expects($this->any()) ->method('createStatement')->will($this->returnValue($statementMock)); $tableGatewayMock = $this->getMockBuilder(AbstractTableGateway::class) ->disableOriginalConstructor() ->getMock(); $reflectionClass = new ReflectionClass(AbstractTableGateway::class); $reflectionProperty = $reflectionClass->getProperty('adapter'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($tableGatewayMock, $adapterMock); $feature = new SequenceFeature('id', 'table_sequence'); $feature->setTableGateway($tableGatewayMock); $featureSet = new FeatureSet(); $featureSet->addFeature($feature); self::assertEquals(1, $featureSet->callMagicCall('lastSequenceId', null)); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TableGateway/Feature/EventFeatureTest.php
test/unit/TableGateway/Feature/EventFeatureTest.php
<?php namespace LaminasTest\Db\TableGateway\Feature; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\ResultSet\ResultSet; use Laminas\Db\Sql\Delete; use Laminas\Db\Sql\Insert; use Laminas\Db\Sql\Select; use Laminas\Db\Sql\Update; use Laminas\Db\TableGateway\Feature\EventFeature; use Laminas\Db\TableGateway\TableGateway; use Laminas\EventManager\EventManager; use PHPUnit\Framework\TestCase; class EventFeatureTest extends TestCase { /** @var EventManager */ protected $eventManager; /** @var EventFeature */ protected $feature; /** @var EventFeature\TableGatewayEvent */ protected $event; /** @var TableGateway */ protected $tableGateway; protected function setUp(): void { $this->eventManager = new EventManager(); $this->event = new EventFeature\TableGatewayEvent(); $this->feature = new EventFeature($this->eventManager, $this->event); $this->tableGateway = $this->getMockForAbstractClass(TableGateway::class, [], '', false); $this->feature->setTableGateway($this->tableGateway); // typically runs before everything else $this->feature->preInitialize(); } public function testGetEventManager() { self::assertSame($this->eventManager, $this->feature->getEventManager()); } public function testGetEvent() { self::assertSame($this->event, $this->feature->getEvent()); } public function testPreInitialize() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_PRE_INITIALIZE, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->preInitialize(); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_PRE_INITIALIZE, $event->getName()); } public function testPostInitialize() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_POST_INITIALIZE, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->postInitialize(); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_POST_INITIALIZE, $event->getName()); } public function testPreSelect() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_PRE_SELECT, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->preSelect($select = $this->getMockBuilder(Select::class)->getMock()); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_PRE_SELECT, $event->getName()); self::assertSame($select, $event->getParam('select')); } public function testPostSelect() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_POST_SELECT, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->postSelect( $stmt = $this->getMockBuilder(StatementInterface::class)->getMock(), $result = $this->getMockBuilder(ResultInterface::class)->getMock(), $resultset = $this->getMockBuilder(ResultSet::class)->getMock() ); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_POST_SELECT, $event->getName()); self::assertSame($stmt, $event->getParam('statement')); self::assertSame($result, $event->getParam('result')); self::assertSame($resultset, $event->getParam('result_set')); } public function testPreInsert() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_PRE_INSERT, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->preInsert($insert = $this->getMockBuilder(Insert::class)->getMock()); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_PRE_INSERT, $event->getName()); self::assertSame($insert, $event->getParam('insert')); } public function testPostInsert() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_POST_INSERT, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->postInsert( $stmt = $this->getMockBuilder(StatementInterface::class)->getMock(), $result = $this->getMockBuilder(ResultInterface::class)->getMock() ); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_POST_INSERT, $event->getName()); self::assertSame($stmt, $event->getParam('statement')); self::assertSame($result, $event->getParam('result')); } public function testPreUpdate() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_PRE_UPDATE, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->preUpdate($update = $this->getMockBuilder(Update::class)->getMock()); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_PRE_UPDATE, $event->getName()); self::assertSame($update, $event->getParam('update')); } public function testPostUpdate() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_POST_UPDATE, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->postUpdate( $stmt = $this->getMockBuilder(StatementInterface::class)->getMock(), $result = $this->getMockBuilder(ResultInterface::class)->getMock() ); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_POST_UPDATE, $event->getName()); self::assertSame($stmt, $event->getParam('statement')); self::assertSame($result, $event->getParam('result')); } public function testPreDelete() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_PRE_DELETE, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->preDelete($delete = $this->getMockBuilder(Delete::class)->getMock()); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_PRE_DELETE, $event->getName()); self::assertSame($delete, $event->getParam('delete')); } public function testPostDelete() { $closureHasRun = false; /** @var EventFeature\TableGatewayEvent $event */ $event = null; $this->eventManager->attach(EventFeature::EVENT_POST_DELETE, function ($e) use (&$closureHasRun, &$event) { $event = $e; $closureHasRun = true; }); $this->feature->postDelete( $stmt = $this->getMockBuilder(StatementInterface::class)->getMock(), $result = $this->getMockBuilder(ResultInterface::class)->getMock() ); self::assertTrue($closureHasRun); self::assertInstanceOf(TableGateway::class, $event->getTarget()); self::assertEquals(EventFeature::EVENT_POST_DELETE, $event->getName()); self::assertSame($stmt, $event->getParam('statement')); self::assertSame($result, $event->getParam('result')); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/InsertDecorator.php
test/unit/TestAsset/InsertDecorator.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Sql; class InsertDecorator extends Sql\Insert implements Sql\Platform\PlatformDecoratorInterface { /** @var null|object */ protected $subject; /** * @param null|object $subject * @return $this Provides a fluent interface */ public function setSubject($subject) { $this->subject = $subject; return $this; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/ConnectionWrapper.php
test/unit/TestAsset/ConnectionWrapper.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Adapter\Driver\Pdo\Connection; /** * Test asset class used only by {@see \LaminasTest\Db\Adapter\Driver\Pdo\ConnectionTransactionsTest} */ class ConnectionWrapper extends Connection { public function __construct() { $this->resource = new PdoStubDriver('foo', 'bar', 'baz'); } /** @return int */ public function getNestedTransactionsCount() { return $this->nestedTransactionsCount; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/TemporaryResultSet.php
test/unit/TestAsset/TemporaryResultSet.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\ResultSet\ResultSet; class TemporaryResultSet extends ResultSet { }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/UpdateIgnore.php
test/unit/TestAsset/UpdateIgnore.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\ParameterContainer; use Laminas\Db\Adapter\Platform\PlatformInterface; use Laminas\Db\Sql\Update; class UpdateIgnore extends Update { public const SPECIFICATION_UPDATE = 'updateIgnore'; /** @var array<string, string> */ protected $specifications = [ self::SPECIFICATION_UPDATE => 'UPDATE IGNORE %1$s', self::SPECIFICATION_SET => 'SET %1$s', self::SPECIFICATION_WHERE => 'WHERE %1$s', ]; /** @return string */ protected function processupdateIgnore( PlatformInterface $platform, ?DriverInterface $driver = null, ?ParameterContainer $parameterContainer = null ) { return parent::processUpdate($platform, $driver, $parameterContainer); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/Replace.php
test/unit/TestAsset/Replace.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\ParameterContainer; use Laminas\Db\Adapter\Platform\PlatformInterface; use Laminas\Db\Sql\Insert; class Replace extends Insert { public const SPECIFICATION_INSERT = 'replace'; /** @var array<string, string> */ protected $specifications = [ self::SPECIFICATION_INSERT => 'REPLACE INTO %1$s (%2$s) VALUES (%3$s)', self::SPECIFICATION_SELECT => 'REPLACE INTO %1$s %2$s %3$s', ]; /** @return null|string */ protected function processreplace( PlatformInterface $platform, ?DriverInterface $driver = null, ?ParameterContainer $parameterContainer = null ) { return parent::processInsert($platform, $driver, $parameterContainer); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/TrustingSqlServerPlatform.php
test/unit/TestAsset/TrustingSqlServerPlatform.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Adapter\Platform\SqlServer; class TrustingSqlServerPlatform extends SqlServer { /** * @param string $value * @return string */ public function quoteValue($value) { return $this->quoteTrustedValue($value); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/PdoStubDriver.php
test/unit/TestAsset/PdoStubDriver.php
<?php namespace LaminasTest\Db\TestAsset; use PDO; class PdoStubDriver extends PDO { public function beginTransaction(): bool { return true; } public function commit(): bool { return true; } /** * @param string $dsn * @param string $user * @param string $password */ public function __construct($dsn, $user, $password) { } public function rollBack(): bool { return true; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/UpdateDecorator.php
test/unit/TestAsset/UpdateDecorator.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Sql; class UpdateDecorator extends Sql\Update implements Sql\Platform\PlatformDecoratorInterface { /** @var null|object $subject */ protected $subject; /** * @param null|object $subject * @return $this Provides a fluent interface */ public function setSubject($subject) { $this->subject = $subject; return $this; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/TrustingSql92Platform.php
test/unit/TestAsset/TrustingSql92Platform.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Adapter\Platform\Sql92; class TrustingSql92Platform extends Sql92 { /** * {@inheritDoc} */ public function quoteValue($value) { return $this->quoteTrustedValue($value); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/TrustingOraclePlatform.php
test/unit/TestAsset/TrustingOraclePlatform.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Adapter\Platform\Oracle; class TrustingOraclePlatform extends Oracle { /** * @param string $value * @return string */ public function quoteValue($value) { return $this->quoteTrustedValue($value); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/DeleteDecorator.php
test/unit/TestAsset/DeleteDecorator.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Sql; class DeleteDecorator extends Sql\Delete implements Sql\Platform\PlatformDecoratorInterface { /** @var null|object */ protected $subject; /** * @param null|object $subject * @return $this Provides a fluent interface */ public function setSubject($subject) { $this->subject = $subject; return $this; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/SelectDecorator.php
test/unit/TestAsset/SelectDecorator.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Sql; class SelectDecorator extends Sql\Select implements Sql\Platform\PlatformDecoratorInterface { /** @var null|object */ protected $subject; /** * @param null|object $subject * @return $this Provides a fluent interface */ public function setSubject($subject) { $this->subject = $subject; return $this; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/DeleteIgnore.php
test/unit/TestAsset/DeleteIgnore.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\ParameterContainer; use Laminas\Db\Adapter\Platform\PlatformInterface; use Laminas\Db\Sql\Delete; class DeleteIgnore extends Delete { public const SPECIFICATION_DELETE = 'deleteIgnore'; /** @var array<string, string> */ protected $specifications = [ self::SPECIFICATION_DELETE => 'DELETE IGNORE FROM %1$s', self::SPECIFICATION_WHERE => 'WHERE %1$s', ]; /** @return string */ protected function processdeleteIgnore( PlatformInterface $platform, ?DriverInterface $driver = null, ?ParameterContainer $parameterContainer = null ) { return parent::processDelete($platform, $driver, $parameterContainer); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/TestAsset/TrustingMysqlPlatform.php
test/unit/TestAsset/TrustingMysqlPlatform.php
<?php namespace LaminasTest\Db\TestAsset; use Laminas\Db\Adapter\Platform\Mysql; class TrustingMysqlPlatform extends Mysql { /** * @param string $value * @return string */ public function quoteValue($value) { return $this->quoteTrustedValue($value); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/RowGateway/RowGatewayTest.php
test/unit/RowGateway/RowGatewayTest.php
<?php namespace LaminasTest\Db\RowGateway; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\ConnectionInterface; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\RowGateway\Exception\RuntimeException; use Laminas\Db\RowGateway\RowGateway; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class RowGatewayTest extends TestCase { /** @var Adapter&MockObject */ protected $mockAdapter; /** @var RowGateway */ protected $rowGateway; /** @var ResultInterface&MockObject */ protected $mockResult; protected function setUp(): void { // mock the adapter, driver, and parts $mockResult = $this->getMockBuilder(ResultInterface::class)->getMock(); $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(1)); $this->mockResult = $mockResult; $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); $mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); // setup mock adapter $this->mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); } public function testEmptyPrimaryKey() { $this->expectException(RuntimeException::class); $this->expectExceptionMessage('This row object does not have a primary key column set.'); $this->rowGateway = new RowGateway('', 'foo', $this->mockAdapter); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/RowGateway/AbstractRowGatewayTest.php
test/unit/RowGateway/AbstractRowGatewayTest.php
<?php namespace LaminasTest\Db\RowGateway; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\ConnectionInterface; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\RowGateway\AbstractRowGateway; use Laminas\Db\RowGateway\Exception\RuntimeException; use Laminas\Db\RowGateway\RowGateway; use Laminas\Db\Sql\Select; use Laminas\Db\Sql\Sql; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionObject; class AbstractRowGatewayTest extends TestCase { /** @var Adapter&MockObject */ protected $mockAdapter; /** @var RowGateway */ protected $rowGateway; /** @var ResultInterface&MockObject */ protected $mockResult; protected function setUp(): void { // mock the adapter, driver, and parts $mockResult = $this->getMockBuilder(ResultInterface::class)->getMock(); $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(1)); $this->mockResult = $mockResult; $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult)); $mockConnection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement)); $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); // setup mock adapter $this->mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $this->rowGateway = $this->getMockForAbstractClass(AbstractRowGateway::class); $rgPropertyValues = [ 'primaryKeyColumn' => 'id', 'table' => 'foo', 'sql' => new Sql($this->mockAdapter), ]; $this->setRowGatewayState($rgPropertyValues); } /** * @covers \Laminas\Db\RowGateway\RowGateway::offsetSet */ public function testOffsetSet() { // If we set with an index, both getters should retrieve the same value: $this->rowGateway['testColumn'] = 'test'; self::assertEquals('test', $this->rowGateway->testColumn); self::assertEquals('test', $this->rowGateway['testColumn']); } /** * @covers \Laminas\Db\RowGateway\RowGateway::__set */ // @codingStandardsIgnoreStart public function test__set() { // @codingStandardsIgnoreEnd // If we set with a property, both getters should retrieve the same value: $this->rowGateway->testColumn = 'test'; self::assertEquals('test', $this->rowGateway->testColumn); self::assertEquals('test', $this->rowGateway['testColumn']); } /** * @covers \Laminas\Db\RowGateway\RowGateway::__isset */ // @codingStandardsIgnoreStart public function test__isset() { // @codingStandardsIgnoreEnd // Test isset before and after assigning to a property: self::assertFalse(isset($this->rowGateway->foo)); $this->rowGateway->foo = 'bar'; self::assertTrue(isset($this->rowGateway->foo)); } /** * @covers \Laminas\Db\RowGateway\RowGateway::offsetExists */ public function testOffsetExists() { // Test isset before and after assigning to an index: self::assertFalse(isset($this->rowGateway['foo'])); $this->rowGateway['foo'] = 'bar'; self::assertTrue(isset($this->rowGateway['foo'])); } /** * @covers \Laminas\Db\RowGateway\RowGateway::__unset */ // @codingStandardsIgnoreStart public function test__unset() { // @codingStandardsIgnoreEnd $this->rowGateway->foo = 'bar'; self::assertEquals('bar', $this->rowGateway->foo); unset($this->rowGateway->foo); self::assertEmpty($this->rowGateway->foo); self::assertEmpty($this->rowGateway['foo']); } /** * @covers \Laminas\Db\RowGateway\RowGateway::offsetUnset */ public function testOffsetUnset() { $this->rowGateway['foo'] = 'bar'; self::assertEquals('bar', $this->rowGateway['foo']); unset($this->rowGateway['foo']); self::assertEmpty($this->rowGateway->foo); self::assertEmpty($this->rowGateway['foo']); } /** * @covers \Laminas\Db\RowGateway\RowGateway::offsetGet */ public function testOffsetGet() { // If we set with an index, both getters should retrieve the same value: $this->rowGateway['testColumn'] = 'test'; self::assertEquals('test', $this->rowGateway->testColumn); self::assertEquals('test', $this->rowGateway['testColumn']); } /** * @covers \Laminas\Db\RowGateway\RowGateway::__get */ // @codingStandardsIgnoreStart public function test__get() { // @codingStandardsIgnoreEnd // If we set with a property, both getters should retrieve the same value: $this->rowGateway->testColumn = 'test'; self::assertEquals('test', $this->rowGateway->testColumn); self::assertEquals('test', $this->rowGateway['testColumn']); } /** * @covers \Laminas\Db\RowGateway\RowGateway::save */ public function testSaveInsert() { // test insert $this->mockResult->expects($this->any())->method('current') ->will($this->returnValue(['id' => 5, 'name' => 'foo'])); $this->mockResult->expects($this->any())->method('getGeneratedValue')->will($this->returnValue(5)); $this->rowGateway->populate(['name' => 'foo']); $this->rowGateway->save(); self::assertEquals(5, $this->rowGateway->id); self::assertEquals(5, $this->rowGateway['id']); } /** * @covers \Laminas\Db\RowGateway\RowGateway::save */ public function testSaveInsertMultiKey() { $this->rowGateway = $this->getMockForAbstractClass(AbstractRowGateway::class); $mockSql = $this->getMockForAbstractClass(Sql::class, [$this->mockAdapter]); $rgPropertyValues = [ 'primaryKeyColumn' => ['one', 'two'], 'table' => 'foo', 'sql' => $mockSql, ]; $this->setRowGatewayState($rgPropertyValues); // test insert $this->mockResult->expects($this->any())->method('current') ->will($this->returnValue(['one' => 'foo', 'two' => 'bar'])); // @todo Need to assert that $where was filled in $refRowGateway = new ReflectionObject($this->rowGateway); $refRowGatewayProp = $refRowGateway->getProperty('primaryKeyData'); $refRowGatewayProp->setAccessible(true); $this->rowGateway->populate(['one' => 'foo', 'two' => 'bar']); self::assertNull($refRowGatewayProp->getValue($this->rowGateway)); // save should setup the primaryKeyData $this->rowGateway->save(); self::assertEquals(['one' => 'foo', 'two' => 'bar'], $refRowGatewayProp->getValue($this->rowGateway)); } /** * @covers \Laminas\Db\RowGateway\RowGateway::save */ public function testSaveUpdate() { // test update $this->mockResult->expects($this->any())->method('current') ->will($this->returnValue(['id' => 6, 'name' => 'foo'])); $this->rowGateway->populate(['id' => 6, 'name' => 'foo'], true); $this->rowGateway->save(); self::assertEquals(6, $this->rowGateway['id']); } /** * @covers \Laminas\Db\RowGateway\RowGateway::save */ public function testSaveUpdateChangingPrimaryKey() { // this mock is the select to be used to re-fresh the rowobject's data $selectMock = $this->getMockBuilder(Select::class) ->setMethods(['where']) ->getMock(); $selectMock->expects($this->once()) ->method('where') ->with($this->equalTo(['id' => 7])) ->will($this->returnValue($selectMock)); $sqlMock = $this->getMockBuilder(Sql::class) ->setMethods(['select']) ->setConstructorArgs([$this->mockAdapter]) ->getMock(); $sqlMock->expects($this->any()) ->method('select') ->will($this->returnValue($selectMock)); $this->setRowGatewayState(['sql' => $sqlMock]); // original mock returning updated data $this->mockResult->expects($this->any()) ->method('current') ->will($this->returnValue(['id' => 7, 'name' => 'fooUpdated'])); // populate forces an update in save(), seeds with original data (from db) $this->rowGateway->populate(['id' => 6, 'name' => 'foo'], true); $this->rowGateway->id = 7; $this->rowGateway->save(); self::assertEquals(['id' => 7, 'name' => 'fooUpdated'], $this->rowGateway->toArray()); } /** * @covers \Laminas\Db\RowGateway\RowGateway::delete */ public function testDelete() { $this->rowGateway->foo = 'bar'; $affectedRows = $this->rowGateway->delete(); self::assertFalse($this->rowGateway->rowExistsInDatabase()); self::assertEquals(1, $affectedRows); } /** * @covers \Laminas\Db\RowGateway\RowGateway::populate * @covers \Laminas\Db\RowGateway\RowGateway::rowExistsInDatabase */ public function testPopulate() { $this->rowGateway->populate(['id' => 5, 'name' => 'foo']); self::assertEquals(5, $this->rowGateway['id']); self::assertEquals('foo', $this->rowGateway['name']); self::assertFalse($this->rowGateway->rowExistsInDatabase()); $this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true); self::assertTrue($this->rowGateway->rowExistsInDatabase()); } /** * @covers \Laminas\Db\RowGateway\RowGateway::processPrimaryKeyData */ public function testProcessPrimaryKeyData() { $this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('a known key id was not found'); $this->rowGateway->populate(['boo' => 5, 'name' => 'foo'], true); } /** * @covers \Laminas\Db\RowGateway\RowGateway::count */ public function testCount() { $this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true); self::assertEquals(2, $this->rowGateway->count()); } /** * @covers \Laminas\Db\RowGateway\RowGateway::toArray */ public function testToArray() { $this->rowGateway->populate(['id' => 5, 'name' => 'foo'], true); self::assertEquals(['id' => 5, 'name' => 'foo'], $this->rowGateway->toArray()); } protected function setRowGatewayState(array $properties) { $refRowGateway = new ReflectionObject($this->rowGateway); foreach ($properties as $rgPropertyName => $rgPropertyValue) { $refRowGatewayProp = $refRowGateway->getProperty($rgPropertyName); $refRowGatewayProp->setAccessible(true); $refRowGatewayProp->setValue($this->rowGateway, $rgPropertyValue); } } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/AdapterAwareTraitTest.php
test/unit/Adapter/AdapterAwareTraitTest.php
<?php namespace LaminasTest\Db\Adapter; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\AdapterAwareTrait; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Platform\PlatformInterface; use LaminasTest\Db\DeprecatedAssertionsTrait; use PHPUnit\Framework\TestCase; class AdapterAwareTraitTest extends TestCase { use DeprecatedAssertionsTrait; public function testSetDbAdapter() { $object = $this->getObjectForTrait(AdapterAwareTrait::class); self::assertAttributeEquals(null, 'adapter', $object); $driver = $this->getMockBuilder(DriverInterface::class)->getMock(); $platform = $this->getMockBuilder(PlatformInterface::class)->getMock(); $adapter = new Adapter($driver, $platform); $object->setDbAdapter($adapter); self::assertAttributeEquals($adapter, 'adapter', $object); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/AdapterServiceFactoryTest.php
test/unit/Adapter/AdapterServiceFactoryTest.php
<?php namespace LaminasTest\Db\Adapter; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\AdapterServiceFactory; use Laminas\ServiceManager\ServiceLocatorInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function extension_loaded; class AdapterServiceFactoryTest extends TestCase { /** @var ServiceLocatorInterface&MockObject */ private $services; /** @var AdapterServiceFactory */ private $factory; protected function setUp(): void { if (! extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Adapter factory tests require pdo_sqlite'); } $this->services = $this->createMock(ServiceLocatorInterface::class); $this->factory = new AdapterServiceFactory(); } public function testV2FactoryReturnsAdapter() { $this->services ->method('get') ->with('config') ->willReturn([ 'db' => [ 'driver' => 'Pdo_Sqlite', 'database' => 'sqlite::memory:', ], ]); $adapter = $this->factory->createService($this->services); self::assertInstanceOf(Adapter::class, $adapter); } public function testV3FactoryReturnsAdapter() { $this->services ->method('get') ->with('config') ->willReturn([ 'db' => [ 'driver' => 'Pdo_Sqlite', 'database' => 'sqlite::memory:', ], ]); $adapter = $this->factory->__invoke($this->services, Adapter::class); self::assertInstanceOf(Adapter::class, $adapter); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/AdapterTest.php
test/unit/Adapter/AdapterTest.php
<?php namespace LaminasTest\Db\Adapter; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\ConnectionInterface; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\Mysqli\Mysqli; use Laminas\Db\Adapter\Driver\Pdo\Pdo; use Laminas\Db\Adapter\Driver\Pgsql\Pgsql; use Laminas\Db\Adapter\Driver\ResultInterface; use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\Adapter\ParameterContainer; use Laminas\Db\Adapter\Platform\IbmDb2; use Laminas\Db\Adapter\Platform\Mysql; use Laminas\Db\Adapter\Platform\Oracle; use Laminas\Db\Adapter\Platform\PlatformInterface; use Laminas\Db\Adapter\Platform\Postgresql; use Laminas\Db\Adapter\Platform\Sql92; use Laminas\Db\Adapter\Platform\Sqlite; use Laminas\Db\Adapter\Platform\SqlServer; use Laminas\Db\Adapter\Profiler; use Laminas\Db\ResultSet\ResultSet; use Laminas\Db\ResultSet\ResultSetInterface; use LaminasTest\Db\TestAsset\TemporaryResultSet; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function extension_loaded; class AdapterTest extends TestCase { /** @var MockObject&DriverInterface */ protected $mockDriver; /** @var MockObject&PlatformInterface */ protected $mockPlatform; /** @var MockObject&ConnectionInterface */ protected $mockConnection; /** @var MockObject&StatementInterface */ protected $mockStatement; /** @var Adapter */ protected $adapter; protected function setUp(): void { $this->mockDriver = $this->createMock(DriverInterface::class); $this->mockConnection = $this->createMock(ConnectionInterface::class); $this->mockDriver->method('checkEnvironment')->will($this->returnValue(true)); $this->mockDriver->method('getConnection') ->will($this->returnValue($this->mockConnection)); $this->mockPlatform = $this->createMock(PlatformInterface::class); $this->mockStatement = $this->createMock(StatementInterface::class); $this->mockDriver->method('createStatement') ->will($this->returnValue($this->mockStatement)); $this->adapter = new Adapter($this->mockDriver, $this->mockPlatform); } /** * @testdox unit test: Test setProfiler() will store profiler * @covers \Laminas\Db\Adapter\Adapter::setProfiler */ public function testSetProfiler() { $ret = $this->adapter->setProfiler(new Profiler\Profiler()); self::assertSame($this->adapter, $ret); } /** * @testdox unit test: Test getProfiler() will store profiler * @covers \Laminas\Db\Adapter\Adapter::getProfiler */ public function testGetProfiler() { $this->adapter->setProfiler($profiler = new Profiler\Profiler()); self::assertSame($profiler, $this->adapter->getProfiler()); $adapter = new Adapter(['driver' => $this->mockDriver, 'profiler' => true], $this->mockPlatform); self::assertInstanceOf(\Laminas\Db\Adapter\Profiler\Profiler::class, $adapter->getProfiler()); } /** * @testdox unit test: Test createDriverFromParameters() will create proper driver type * @covers \Laminas\Db\Adapter\Adapter::createDriver */ public function testCreateDriver() { if (extension_loaded('mysqli')) { $adapter = new Adapter(['driver' => 'mysqli'], $this->mockPlatform); self::assertInstanceOf(Mysqli::class, $adapter->driver); unset($adapter); } if (extension_loaded('pgsql')) { $adapter = new Adapter(['driver' => 'pgsql'], $this->mockPlatform); self::assertInstanceOf(Pgsql::class, $adapter->driver); unset($adapter); } if (extension_loaded('sqlsrv')) { $adapter = new Adapter(['driver' => 'sqlsrv'], $this->mockPlatform); self::assertInstanceOf(Sqlsrv::class, $adapter->driver); unset($adapter); } if (extension_loaded('pdo')) { $adapter = new Adapter(['driver' => 'pdo_sqlite'], $this->mockPlatform); self::assertInstanceOf(Pdo::class, $adapter->driver); unset($adapter); } } /** * @testdox unit test: Test createPlatformFromDriver() will create proper platform from driver * @covers \Laminas\Db\Adapter\Adapter::createPlatform */ public function testCreatePlatform() { $driver = clone $this->mockDriver; $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Mysql')); $adapter = new Adapter($driver); self::assertInstanceOf(Mysql::class, $adapter->platform); unset($adapter, $driver); $driver = clone $this->mockDriver; $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('SqlServer')); $adapter = new Adapter($driver); self::assertInstanceOf(SqlServer::class, $adapter->platform); unset($adapter, $driver); $driver = clone $this->mockDriver; $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Postgresql')); $adapter = new Adapter($driver); self::assertInstanceOf(Postgresql::class, $adapter->platform); unset($adapter, $driver); $driver = clone $this->mockDriver; $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Sqlite')); $adapter = new Adapter($driver); self::assertInstanceOf(Sqlite::class, $adapter->platform); unset($adapter, $driver); $driver = clone $this->mockDriver; $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('IbmDb2')); $adapter = new Adapter($driver); self::assertInstanceOf(IbmDb2::class, $adapter->platform); unset($adapter, $driver); $driver = clone $this->mockDriver; $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Oracle')); $adapter = new Adapter($driver); self::assertInstanceOf(Oracle::class, $adapter->platform); unset($adapter, $driver); $driver = clone $this->mockDriver; $driver->expects($this->any())->method('getDatabasePlatformName')->will($this->returnValue('Foo')); $adapter = new Adapter($driver); self::assertInstanceOf(Sql92::class, $adapter->platform); unset($adapter, $driver); // ensure platform can created via string, and also that it passed in options to platform object $driver = [ 'driver' => 'pdo_oci', 'platform' => 'Oracle', 'platform_options' => ['quote_identifiers' => false], ]; $adapter = new Adapter($driver); self::assertInstanceOf(Oracle::class, $adapter->platform); self::assertEquals('foo', $adapter->getPlatform()->quoteIdentifier('foo')); unset($adapter, $driver); } /** * @testdox unit test: Test getDriver() will return driver object * @covers \Laminas\Db\Adapter\Adapter::getDriver */ public function testGetDriver() { self::assertSame($this->mockDriver, $this->adapter->getDriver()); } /** * @testdox unit test: Test getPlatform() returns platform object * @covers \Laminas\Db\Adapter\Adapter::getPlatform */ public function testGetPlatform() { self::assertSame($this->mockPlatform, $this->adapter->getPlatform()); } /** * @testdox unit test: Test getPlatform() returns platform object * @covers \Laminas\Db\Adapter\Adapter::getQueryResultSetPrototype */ public function testGetQueryResultSetPrototype() { self::assertInstanceOf(ResultSetInterface::class, $this->adapter->getQueryResultSetPrototype()); } /** * @testdox unit test: Test getCurrentSchema() returns current schema from connection object * @covers \Laminas\Db\Adapter\Adapter::getCurrentSchema */ public function testGetCurrentSchema() { $this->mockConnection->expects($this->any())->method('getCurrentSchema')->will($this->returnValue('FooSchema')); self::assertEquals('FooSchema', $this->adapter->getCurrentSchema()); } /** * @testdox unit test: Test query() in prepare mode produces a statement object * @covers \Laminas\Db\Adapter\Adapter::query */ public function testQueryWhenPreparedProducesStatement() { $s = $this->adapter->query('SELECT foo'); self::assertSame($this->mockStatement, $s); } /** @group #210 */ public function testProducedResultSetPrototypeIsDifferentForEachQuery() { $statement = $this->createMock(StatementInterface::class); $result = $this->createMock(ResultInterface::class); $this->mockDriver->method('createStatement') ->willReturn($statement); $this->mockStatement->method('execute') ->willReturn($result); $result->method('isQueryResult') ->willReturn(true); self::assertNotSame( $this->adapter->query('SELECT foo', []), $this->adapter->query('SELECT foo', []) ); } /** * @testdox unit test: Test query() in prepare mode, with array of parameters, produces a result object * @covers \Laminas\Db\Adapter\Adapter::query */ public function testQueryWhenPreparedWithParameterArrayProducesResult() { $parray = ['bar' => 'foo']; $sql = 'SELECT foo, :bar'; $statement = $this->getMockBuilder(StatementInterface::class)->getMock(); $result = $this->getMockBuilder(ResultInterface::class)->getMock(); $this->mockDriver->expects($this->any())->method('createStatement') ->with($sql)->will($this->returnValue($statement)); $this->mockStatement->expects($this->any())->method('execute')->will($this->returnValue($result)); $r = $this->adapter->query($sql, $parray); self::assertSame($result, $r); } /** * @testdox unit test: Test query() in prepare mode, with ParameterContainer, produces a result object * @covers \Laminas\Db\Adapter\Adapter::query */ public function testQueryWhenPreparedWithParameterContainerProducesResult() { $sql = 'SELECT foo'; $parameterContainer = $this->getMockBuilder(ParameterContainer::class)->getMock(); $result = $this->getMockBuilder(ResultInterface::class)->getMock(); $this->mockDriver->expects($this->any())->method('createStatement') ->with($sql)->will($this->returnValue($this->mockStatement)); $this->mockStatement->expects($this->any())->method('execute')->will($this->returnValue($result)); $result->expects($this->any())->method('isQueryResult')->will($this->returnValue(true)); $r = $this->adapter->query($sql, $parameterContainer); self::assertInstanceOf(ResultSet::class, $r); } /** * @testdox unit test: Test query() in execute mode produces a driver result object * @covers \Laminas\Db\Adapter\Adapter::query */ public function testQueryWhenExecutedProducesAResult() { $sql = 'SELECT foo'; $result = $this->getMockBuilder(ResultInterface::class)->getMock(); $this->mockConnection->expects($this->any())->method('execute')->with($sql)->will($this->returnValue($result)); $r = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); self::assertSame($result, $r); } /** * @testdox unit test: Test query() in execute mode produces a resultset object * @covers \Laminas\Db\Adapter\Adapter::query */ public function testQueryWhenExecutedProducesAResultSetObjectWhenResultIsQuery() { $sql = 'SELECT foo'; $result = $this->getMockBuilder(ResultInterface::class)->getMock(); $this->mockConnection->expects($this->any())->method('execute')->with($sql)->will($this->returnValue($result)); $result->expects($this->any())->method('isQueryResult')->will($this->returnValue(true)); $r = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); self::assertInstanceOf(ResultSet::class, $r); $r = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE, new TemporaryResultSet()); self::assertInstanceOf(TemporaryResultSet::class, $r); } /** * @testdox unit test: Test createStatement() produces a statement object * @covers \Laminas\Db\Adapter\Adapter::createStatement */ public function testCreateStatement() { self::assertSame($this->mockStatement, $this->adapter->createStatement()); } /** * @testdox unit test: Test __get() works * @covers \Laminas\Db\Adapter\Adapter::__get */ // @codingStandardsIgnoreStart public function test__get() { // @codingStandardsIgnoreEnd self::assertSame($this->mockDriver, $this->adapter->driver); self::assertSame($this->mockDriver, $this->adapter->DrivER); self::assertSame($this->mockPlatform, $this->adapter->PlatForm); self::assertSame($this->mockPlatform, $this->adapter->platform); $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Invalid magic'); $this->adapter->foo; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/AdapterAbstractServiceFactoryTest.php
test/unit/Adapter/AdapterAbstractServiceFactoryTest.php
<?php namespace LaminasTest\Db\Adapter; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\AdapterAbstractServiceFactory; use Laminas\ServiceManager\Config; use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Laminas\ServiceManager\ServiceLocatorInterface; use Laminas\ServiceManager\ServiceManager; use PHPUnit\Framework\TestCase; class AdapterAbstractServiceFactoryTest extends TestCase { /** @var ServiceLocatorInterface */ private $serviceManager; protected function setUp(): void { $this->serviceManager = new ServiceManager(); $config = new Config([ 'abstract_factories' => [AdapterAbstractServiceFactory::class], ]); $config->configureServiceManager($this->serviceManager); $this->serviceManager->setService('config', [ 'db' => [ 'adapters' => [ 'Laminas\Db\Adapter\Writer' => [ 'driver' => 'mysqli', ], 'Laminas\Db\Adapter\Reader' => [ 'driver' => 'mysqli', ], ], ], ]); } /** * @return array */ public function providerValidService() { return [ ['Laminas\Db\Adapter\Writer'], ['Laminas\Db\Adapter\Reader'], ]; } /** * @return array */ public function providerInvalidService() { return [ ['Laminas\Db\Adapter\Unknown'], ]; } /** * @param string $service * @dataProvider providerValidService * @requires extension mysqli */ public function testValidService($service) { $actual = $this->serviceManager->get($service); self::assertInstanceOf(Adapter::class, $actual); } /** * @dataProvider providerInvalidService * @param string $service */ public function testInvalidService($service) { $this->expectException(ServiceNotFoundException::class); $this->serviceManager->get($service); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/AdapterServiceDelegatorTest.php
test/unit/Adapter/AdapterServiceDelegatorTest.php
<?php namespace LaminasTest\Db\Adapter; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\AdapterAwareInterface; use Laminas\Db\Adapter\AdapterInterface; use Laminas\Db\Adapter\AdapterServiceDelegator; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\ServiceManager\AbstractPluginManager; use Laminas\ServiceManager\ServiceManager; use LaminasTest\Db\Adapter\TestAsset\ConcreteAdapterAwareObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use stdClass; final class AdapterServiceDelegatorTest extends TestCase { public function testSetAdapterShouldBeCalledForExistingAdapter(): void { $container = $this->createMock(ContainerInterface::class); $container ->expects(self::once()) ->method('has') ->with(AdapterInterface::class) ->willReturn(true); $container ->expects(self::once()) ->method('get') ->with(AdapterInterface::class) ->willReturn($this->createMock(Adapter::class)); $callback = static function (): ConcreteAdapterAwareObject { return new ConcreteAdapterAwareObject(); }; /** @var ConcreteAdapterAwareObject $result */ $result = (new AdapterServiceDelegator())( $container, ConcreteAdapterAwareObject::class, $callback ); $this->assertInstanceOf( AdapterInterface::class, $result->getAdapter() ); } public function testSetAdapterShouldBeCalledForOnlyConcreteAdapter(): void { $container = $this ->createMock(ContainerInterface::class); $container ->expects(self::once()) ->method('has') ->with(AdapterInterface::class) ->willReturn(true); $container ->expects(self::once()) ->method('get') ->with(AdapterInterface::class) ->willReturn($this->createMock(AdapterInterface::class)); $callback = static function (): ConcreteAdapterAwareObject { return new ConcreteAdapterAwareObject(); }; /** @var ConcreteAdapterAwareObject $result */ $result = (new AdapterServiceDelegator())( $container, ConcreteAdapterAwareObject::class, $callback ); $this->assertNull($result->getAdapter()); } public function testSetAdapterShouldNotBeCalledForMissingAdapter(): void { $container = $this->createMock(ContainerInterface::class); $container ->expects(self::once()) ->method('has') ->with(AdapterInterface::class) ->willReturn(false); $container ->expects(self::never()) ->method('get'); $callback = static function (): ConcreteAdapterAwareObject { return new ConcreteAdapterAwareObject(); }; /** @var ConcreteAdapterAwareObject $result */ $result = (new AdapterServiceDelegator())( $container, ConcreteAdapterAwareObject::class, $callback ); $this->assertNull($result->getAdapter()); } public function testSetAdapterShouldNotBeCalledForWrongClassInstance(): void { $container = $this->createMock(ContainerInterface::class); $container ->expects(self::never()) ->method('has'); $callback = static function (): stdClass { return new stdClass(); }; $result = (new AdapterServiceDelegator())( $container, stdClass::class, $callback ); $this->assertNotInstanceOf(AdapterAwareInterface::class, $result); } public function testDelegatorWithServiceManager(): void { $databaseAdapter = new Adapter($this->createMock(DriverInterface::class)); $container = new ServiceManager([ 'invokables' => [ ConcreteAdapterAwareObject::class => ConcreteAdapterAwareObject::class, ], 'factories' => [ AdapterInterface::class => static function () use ( $databaseAdapter ) { return $databaseAdapter; }, ], 'delegators' => [ ConcreteAdapterAwareObject::class => [ AdapterServiceDelegator::class, ], ], ]); /** @var ConcreteAdapterAwareObject $result */ $result = $container->get(ConcreteAdapterAwareObject::class); $this->assertInstanceOf( AdapterInterface::class, $result->getAdapter() ); } public function testDelegatorWithServiceManagerAndCustomAdapterName() { $databaseAdapter = new Adapter($this->createMock(DriverInterface::class)); $container = new ServiceManager([ 'invokables' => [ ConcreteAdapterAwareObject::class => ConcreteAdapterAwareObject::class, ], 'factories' => [ 'alternate-database-adapter' => static function () use ( $databaseAdapter ) { return $databaseAdapter; }, ], 'delegators' => [ ConcreteAdapterAwareObject::class => [ new AdapterServiceDelegator('alternate-database-adapter'), ], ], ]); /** @var ConcreteAdapterAwareObject $result */ $result = $container->get(ConcreteAdapterAwareObject::class); $this->assertInstanceOf( AdapterInterface::class, $result->getAdapter() ); } public function testDelegatorWithPluginManager() { $databaseAdapter = new Adapter($this->createMock(DriverInterface::class)); $container = new ServiceManager([ 'factories' => [ AdapterInterface::class => static function () use ( $databaseAdapter ) { return $databaseAdapter; }, ], ]); $pluginManagerConfig = [ 'invokables' => [ ConcreteAdapterAwareObject::class => ConcreteAdapterAwareObject::class, ], 'delegators' => [ ConcreteAdapterAwareObject::class => [ AdapterServiceDelegator::class, ], ], ]; /** @var AbstractPluginManager $pluginManager */ $pluginManager = new class ($container, $pluginManagerConfig) extends AbstractPluginManager { }; $options = [ 'table' => 'foo', 'field' => 'bar', ]; /** @var ConcreteAdapterAwareObject $result */ $result = $pluginManager->get( ConcreteAdapterAwareObject::class, $options ); $this->assertInstanceOf( AdapterInterface::class, $result->getAdapter() ); $this->assertSame($options, $result->getOptions()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/ParameterContainerTest.php
test/unit/Adapter/ParameterContainerTest.php
<?php namespace LaminasTest\Db\Adapter; use Laminas\Db\Adapter\ParameterContainer; use PHPUnit\Framework\TestCase; class ParameterContainerTest extends TestCase { /** @var ParameterContainer */ protected $parameterContainer; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->parameterContainer = new ParameterContainer(['foo' => 'bar']); } /** * @testdox unit test: Test offsetExists() returns proper values via method call and isset() * @covers \Laminas\Db\Adapter\ParameterContainer::offsetExists */ public function testOffsetExists() { self::assertTrue($this->parameterContainer->offsetExists('foo')); self::assertTrue(isset($this->parameterContainer['foo'])); self::assertFalse($this->parameterContainer->offsetExists('bar')); self::assertFalse(isset($this->parameterContainer['bar'])); } /** * @testdox unit test: Test offsetGet() returns proper values via method call and array access * @covers \Laminas\Db\Adapter\ParameterContainer::offsetGet */ public function testOffsetGet() { self::assertEquals('bar', $this->parameterContainer->offsetGet('foo')); self::assertEquals('bar', $this->parameterContainer['foo']); self::assertNull($this->parameterContainer->offsetGet('bar')); // @todo determine what should come back here } /** * @testdox unit test: Test offsetSet() works via method call and array access * @covers \Laminas\Db\Adapter\ParameterContainer::offsetSet */ public function testOffsetSet() { $this->parameterContainer->offsetSet('boo', 'baz'); self::assertEquals('baz', $this->parameterContainer->offsetGet('boo')); $this->parameterContainer->offsetSet('1', 'book', ParameterContainer::TYPE_STRING, 4); self::assertEquals( ['foo' => 'bar', 'boo' => 'baz', '1' => 'book'], $this->parameterContainer->getNamedArray() ); self::assertEquals('string', $this->parameterContainer->offsetGetErrata('1')); self::assertEquals(4, $this->parameterContainer->offsetGetMaxLength('1')); // test that setting an index applies to correct named parameter $this->parameterContainer[0] = 'Zero'; $this->parameterContainer[1] = 'One'; self::assertEquals( ['foo' => 'Zero', 'boo' => 'One', '1' => 'book'], $this->parameterContainer->getNamedArray() ); self::assertEquals( [0 => 'Zero', 1 => 'One', 2 => 'book'], $this->parameterContainer->getPositionalArray() ); // test no-index applies $this->parameterContainer['buffer'] = 'A buffer Element'; $this->parameterContainer[] = 'Second To Last'; $this->parameterContainer[] = 'Last'; self::assertEquals( [ 'foo' => 'Zero', 'boo' => 'One', '1' => 'book', 'buffer' => 'A buffer Element', '4' => 'Second To Last', '5' => 'Last', ], $this->parameterContainer->getNamedArray() ); self::assertEquals( [0 => 'Zero', 1 => 'One', 2 => 'book', 3 => 'A buffer Element', 4 => 'Second To Last', 5 => 'Last'], $this->parameterContainer->getPositionalArray() ); } /** * @testdox unit test: Test offsetUnset() works via method call and array access * @covers \Laminas\Db\Adapter\ParameterContainer::offsetUnset */ public function testOffsetUnset() { $this->parameterContainer->offsetSet('boo', 'baz'); self::assertTrue($this->parameterContainer->offsetExists('boo')); $this->parameterContainer->offsetUnset('boo'); self::assertFalse($this->parameterContainer->offsetExists('boo')); } /** * @testdox unit test: Test setFromArray() will populate the container * @covers \Laminas\Db\Adapter\ParameterContainer::setFromArray */ public function testSetFromArray() { $this->parameterContainer->setFromArray(['bar' => 'baz']); self::assertEquals('baz', $this->parameterContainer['bar']); } /** * Handle statement parameters - https://github.com/laminas/laminas-db/issues/47 * * @see Insert::procesInsert as example * * @covers \Laminas\Db\Adapter\ParameterContainer::setFromArray */ public function testSetFromArrayNamed() { $this->parameterContainer->offsetSet('c_0', ':myparam'); $this->parameterContainer->setFromArray([':myparam' => 'baz']); self::assertEquals('baz', $this->parameterContainer['c_0']); self::assertEquals('baz', $this->parameterContainer[':myparam']); } /** * @testdox unit test: Test offsetSetMaxLength() will persist errata data * @covers \Laminas\Db\Adapter\ParameterContainer::offsetSetMaxLength * @testdox unit test: Test offsetGetMaxLength() return persisted errata data, if it exists * @covers \Laminas\Db\Adapter\ParameterContainer::offsetGetMaxLength */ public function testOffsetSetAndGetMaxLength() { $this->parameterContainer->offsetSetMaxLength('foo', 100); self::assertEquals(100, $this->parameterContainer->offsetGetMaxLength('foo')); } /** * @testdox unit test: Test offsetHasMaxLength() will check if errata exists for a particular key * @covers \Laminas\Db\Adapter\ParameterContainer::offsetHasMaxLength */ public function testOffsetHasMaxLength() { $this->parameterContainer->offsetSetMaxLength('foo', 100); self::assertTrue($this->parameterContainer->offsetHasMaxLength('foo')); } /** * @testdox unit test: Test offsetUnsetMaxLength() will unset data for a particular key * @covers \Laminas\Db\Adapter\ParameterContainer::offsetUnsetMaxLength */ public function testOffsetUnsetMaxLength() { $this->parameterContainer->offsetSetMaxLength('foo', 100); $this->parameterContainer->offsetUnsetMaxLength('foo'); self::assertNull($this->parameterContainer->offsetGetMaxLength('foo')); } /** * @testdox unit test: Test getMaxLengthIterator() will return an iterator for the errata data * @covers \Laminas\Db\Adapter\ParameterContainer::getMaxLengthIterator */ public function testGetMaxLengthIterator() { $this->parameterContainer->offsetSetMaxLength('foo', 100); $data = $this->parameterContainer->getMaxLengthIterator(); self::assertInstanceOf('ArrayIterator', $data); } /** * @testdox unit test: Test offsetSetErrata() will persist errata data * @covers \Laminas\Db\Adapter\ParameterContainer::offsetSetErrata */ public function testOffsetSetErrata() { $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); self::assertEquals(ParameterContainer::TYPE_INTEGER, $this->parameterContainer->offsetGetErrata('foo')); } /** * @testdox unit test: Test offsetGetErrata() return persisted errata data, if it exists * @covers \Laminas\Db\Adapter\ParameterContainer::offsetGetErrata */ public function testOffsetGetErrata() { $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); self::assertEquals(ParameterContainer::TYPE_INTEGER, $this->parameterContainer->offsetGetErrata('foo')); } /** * @testdox unit test: Test offsetHasErrata() will check if errata exists for a particular key * @covers \Laminas\Db\Adapter\ParameterContainer::offsetHasErrata */ public function testOffsetHasErrata() { $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); self::assertTrue($this->parameterContainer->offsetHasErrata('foo')); } /** * @testdox unit test: Test offsetUnsetErrata() will unset data for a particular key * @covers \Laminas\Db\Adapter\ParameterContainer::offsetUnsetErrata */ public function testOffsetUnsetErrata() { $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); $this->parameterContainer->offsetUnsetErrata('foo'); self::assertNull($this->parameterContainer->offsetGetErrata('foo')); } /** * @testdox unit test: Test getErrataIterator() will return an iterator for the errata data * @covers \Laminas\Db\Adapter\ParameterContainer::getErrataIterator */ public function testGetErrataIterator() { $this->parameterContainer->offsetSetErrata('foo', ParameterContainer::TYPE_INTEGER); $data = $this->parameterContainer->getErrataIterator(); self::assertInstanceOf('ArrayIterator', $data); } /** * @testdox unit test: Test getNamedArray() * @covers \Laminas\Db\Adapter\ParameterContainer::getNamedArray */ public function testGetNamedArray() { $data = $this->parameterContainer->getNamedArray(); self::assertEquals(['foo' => 'bar'], $data); } /** * @testdox unit test: Test count() returns the proper count * @covers \Laminas\Db\Adapter\ParameterContainer::count */ public function testCount() { self::assertEquals(1, $this->parameterContainer->count()); } /** * @testdox unit test: Test current() returns the current element when used as an iterator * @covers \Laminas\Db\Adapter\ParameterContainer::current */ public function testCurrent() { $value = $this->parameterContainer->current(); self::assertEquals('bar', $value); } /** * @testdox unit test: Test next() increases the pointer when used as an iterator * @covers \Laminas\Db\Adapter\ParameterContainer::next */ public function testNext() { $this->parameterContainer['bar'] = 'baz'; $this->parameterContainer->next(); self::assertEquals('baz', $this->parameterContainer->current()); } /** * @testdox unit test: Test key() returns the name of the current item's name * @covers \Laminas\Db\Adapter\ParameterContainer::key */ public function testKey() { self::assertEquals('foo', $this->parameterContainer->key()); } /** * @testdox unit test: Test valid() returns whether the iterators current position is valid * @covers \Laminas\Db\Adapter\ParameterContainer::valid */ public function testValid() { self::assertTrue($this->parameterContainer->valid()); $this->parameterContainer->next(); self::assertFalse($this->parameterContainer->valid()); } /** * @testdox unit test: Test rewind() resets the iterators pointer * @covers \Laminas\Db\Adapter\ParameterContainer::rewind */ public function testRewind() { $this->parameterContainer->offsetSet('bar', 'baz'); $this->parameterContainer->next(); self::assertEquals('bar', $this->parameterContainer->key()); $this->parameterContainer->rewind(); self::assertEquals('foo', $this->parameterContainer->key()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/TestAsset/PdoMock.php
test/unit/Adapter/Driver/TestAsset/PdoMock.php
<?php namespace LaminasTest\Db\Adapter\Driver\TestAsset; use PDO; use ReturnTypeWillChange; /** * Stub class */ class PdoMock extends PDO { public function __construct() { } public function beginTransaction(): bool { return true; } public function commit(): bool { return true; } /** * @param string $attribute * @return null */ #[ReturnTypeWillChange] public function getAttribute($attribute) { return null; } public function rollBack(): bool { return true; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php
test/unit/Adapter/Driver/Sqlsrv/SqlSrvIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Statement; use Laminas\Db\Adapter\Exception\InvalidArgumentException; use stdClass; /** * @group integration * @group integration-sqlserver */ class SqlSrvIntegrationTest extends AbstractIntegrationTest { /** @var Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv */ private $driver; /** @var resource SQL Server Connection */ private $resource; protected function setUp(): void { parent::setUp(); $this->resource = $this->adapters['sqlsrv']; $this->driver = new Sqlsrv($this->resource); } /** * @group integration-sqlserver * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::checkEnvironment */ public function testCheckEnvironment() { $sqlserver = new Sqlsrv([]); self::assertNull($sqlserver->checkEnvironment()); } public function testCreateStatement() { $stmt = $this->driver->createStatement('SELECT 1'); $this->assertInstanceOf(Statement::class, $stmt); $stmt = $this->driver->createStatement($this->resource); $this->assertInstanceOf(Statement::class, $stmt); $stmt = $this->driver->createStatement(); $this->assertInstanceOf(Statement::class, $stmt); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('only accepts an SQL string or a Sqlsrv resource'); $this->driver->createStatement(new stdClass()); } public function testParameterizedQuery() { $stmt = $this->driver->createStatement('SELECT ? as col_one'); $result = $stmt->execute(['a']); $row = $result->current(); $this->assertEquals('a', $row['col_one']); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTest.php
test/unit/Adapter/Driver/Sqlsrv/AbstractIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use PHPUnit\Framework\TestCase; use function extension_loaded; use function getenv; use function sqlsrv_connect; abstract class AbstractIntegrationTest extends TestCase { /** @var array<string, string> */ protected $variables = [ 'hostname' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME', 'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_USERNAME', 'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD', ]; /** @var array<string, resource> */ protected $adapters; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV')) { $this->markTestSkipped('SQLSRV tests are not enabled'); } foreach ($this->variables as $name => $value) { if (! getenv($value)) { $this->markTestSkipped( 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' ); } $this->variables[$name] = getenv($value); } $this->variables['options'] = ['TrustServerCertificate' => '1']; if (! extension_loaded('sqlsrv')) { $this->fail('The phpunit group integration-sqlsrv was enabled, but the extension is not loaded.'); } $this->adapters['sqlsrv'] = sqlsrv_connect( getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_HOSTNAME'), [ 'UID' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_USERNAME'), 'PWD' => getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD'), 'TrustServerCertificate' => 1, ] ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/StatementTest.php
test/unit/Adapter/Driver/Sqlsrv/StatementTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Statement; use Laminas\Db\Adapter\ParameterContainer; use PHPUnit\Framework\TestCase; class StatementTest extends TestCase { /** @var Statement */ protected $statement; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->statement = new Statement(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::setDriver */ public function testSetDriver() { self::assertEquals($this->statement, $this->statement->setDriver(new Sqlsrv([]))); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::setParameterContainer */ public function testSetParameterContainer() { self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer())); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::getParameterContainer */ public function testGetParameterContainer() { $container = new ParameterContainer(); $this->statement->setParameterContainer($container); self::assertSame($container, $this->statement->getParameterContainer()); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::getResource * @todo Implement testGetResource(). */ public function testGetResource() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::setSql * @todo Implement testSetSql(). */ public function testSetSql() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::getSql * @todo Implement testGetSql(). */ public function testGetSql() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::prepare * @todo Implement testPrepare(). */ public function testPrepare() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::isPrepared * @todo Implement testIsPrepared(). */ public function testIsPrepared() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::execute * @todo Implement testExecute(). */ public function testExecute() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php
test/unit/Adapter/Driver/Sqlsrv/ResultIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Result; use PHPUnit\Framework\TestCase; /** * @group integration * @group integration-sqlsrv */ class ResultIntegrationTest extends TestCase { /** @var Result */ protected $object; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->object = new Result(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::initialize * @todo Implement testInitialize(). */ public function testInitialize() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::buffer * @todo Implement testBuffer(). */ public function testBuffer() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::getResource * @todo Implement testGetResource(). */ public function testGetResource() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::current * @todo Implement testCurrent(). */ public function testCurrent() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::next * @todo Implement testNext(). */ public function testNext() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::key * @todo Implement testKey(). */ public function testKey() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::rewind * @todo Implement testRewind(). */ public function testRewind() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::valid * @todo Implement testValid(). */ public function testValid() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::count * @todo Implement testCount(). */ public function testCount() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::getFieldCount * @todo Implement testGetFieldCount(). */ public function testGetFieldCount() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::isQueryResult * @todo Implement testIsQueryResult(). */ public function testIsQueryResult() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::getAffectedRows * @todo Implement testGetAffectedRows(). */ public function testGetAffectedRows() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Result::getGeneratedValue * @todo Implement testGetGeneratedValue(). */ public function testGetGeneratedValue() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php
test/unit/Adapter/Driver/Sqlsrv/ConnectionTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Connection; use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv; use PHPUnit\Framework\TestCase; class ConnectionTest extends TestCase { /** @var Connection */ protected $connection; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->connection = new Connection([]); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::setDriver */ public function testSetDriver() { self::assertEquals($this->connection, $this->connection->setDriver(new Sqlsrv([]))); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::setConnectionParameters */ public function testSetConnectionParameters() { self::assertEquals($this->connection, $this->connection->setConnectionParameters([])); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::getConnectionParameters */ public function testGetConnectionParameters() { $this->connection->setConnectionParameters(['foo' => 'bar']); self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php
test/unit/Adapter/Driver/Sqlsrv/ConnectionIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Connection; use Laminas\Db\Adapter\Driver\Sqlsrv\Result; use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Statement; use function sqlsrv_connect; /** * @group integration * @group integration-sqlserver */ class ConnectionIntegrationTest extends AbstractIntegrationTest { /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::getCurrentSchema */ public function testGetCurrentSchema() { $connection = new Connection($this->variables); self::assertIsString($connection->getCurrentSchema()); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::setResource */ public function testSetResource() { $resource = sqlsrv_connect( $this->variables['hostname'], [ 'UID' => $this->variables['username'], 'PWD' => $this->variables['password'], 'TrustServerCertificate' => 1, ] ); $connection = new Connection([]); self::assertSame($connection, $connection->setResource($resource)); $connection->disconnect(); unset($connection); unset($resource); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::getResource */ public function testGetResource() { $connection = new Connection($this->variables); $connection->connect(); self::assertIsResource($connection->getResource()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::connect */ public function testConnect() { $connection = new Connection($this->variables); self::assertSame($connection, $connection->connect()); self::assertTrue($connection->isConnected()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::isConnected */ public function testIsConnected() { $connection = new Connection($this->variables); self::assertFalse($connection->isConnected()); self::assertSame($connection, $connection->connect()); self::assertTrue($connection->isConnected()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::disconnect */ public function testDisconnect() { $connection = new Connection($this->variables); $connection->connect(); self::assertTrue($connection->isConnected()); $connection->disconnect(); self::assertFalse($connection->isConnected()); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::beginTransaction * @todo Implement testBeginTransaction(). */ public function testBeginTransaction() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::commit * @todo Implement testCommit(). */ public function testCommit() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::rollback * @todo Implement testRollback(). */ public function testRollback() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::execute */ public function testExecute() { $sqlsrv = new Sqlsrv($this->variables); $connection = $sqlsrv->getConnection(); $result = $connection->execute('SELECT \'foo\''); self::assertInstanceOf(Result::class, $result); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::prepare */ public function testPrepare() { $sqlsrv = new Sqlsrv($this->variables); $connection = $sqlsrv->getConnection(); $statement = $connection->prepare('SELECT \'foo\''); self::assertInstanceOf(Statement::class, $statement); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Connection::getLastGeneratedValue */ public function testGetLastGeneratedValue() { $this->markTestIncomplete('Need to create a temporary sequence.'); $connection = new Connection($this->variables); $connection->getLastGeneratedValue(); } /** * @group laminas3469 */ public function testConnectReturnsConnectionWhenResourceSet() { $resource = sqlsrv_connect( $this->variables['hostname'], [ 'UID' => $this->variables['username'], 'PWD' => $this->variables['password'], 'TrustServerCertificate' => 1, ] ); $connection = new Connection([]); $connection->setResource($resource); self::assertSame($connection, $connection->connect()); $connection->disconnect(); unset($connection); unset($resource); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php
test/unit/Adapter/Driver/Sqlsrv/PdoSqlSrvIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use Laminas\Db\Adapter\Driver\Pdo\Pdo; /** * @group integration * @group integration-sqlserver */ class PdoSqlSrvIntegrationTest extends AbstractIntegrationTest { public function testParameterizedQuery() { if (! isset($this->adapters['pdo_sqlsrv'])) { $this->markTestSkipped('pdo_sqlsrv adapter is not found'); } $driver = new Pdo($this->adapters['pdo_sqlsrv']); $stmt = $driver->createStatement('SELECT ? as col_one'); $result = $stmt->execute(['a']); $row = $result->current(); $this->assertEquals('a', $row['col_one']); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php
test/unit/Adapter/Driver/Sqlsrv/SqlsrvTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Connection; use Laminas\Db\Adapter\Driver\Sqlsrv\Result; use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Statement; use PHPUnit\Framework\TestCase; class SqlsrvTest extends TestCase { /** @var Sqlsrv */ protected $sqlsrv; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->sqlsrv = new Sqlsrv([]); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerConnection */ public function testRegisterConnection() { $mockConnection = $this->getMockForAbstractClass( Connection::class, [[]], '', true, true, true, ['setDriver'] ); $mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->sqlsrv)); self::assertSame($this->sqlsrv, $this->sqlsrv->registerConnection($mockConnection)); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerStatementPrototype */ public function testRegisterStatementPrototype() { $this->sqlsrv = new Sqlsrv([]); $mockStatement = $this->getMockForAbstractClass( Statement::class, [], '', true, true, true, ['setDriver'] ); $mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->sqlsrv)); self::assertSame($this->sqlsrv, $this->sqlsrv->registerStatementPrototype($mockStatement)); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::registerResultPrototype */ public function testRegisterResultPrototype() { $this->sqlsrv = new Sqlsrv([]); $mockStatement = $this->getMockForAbstractClass( Result::class, [], '', true, true, true, ['setDriver'] ); self::assertSame($this->sqlsrv, $this->sqlsrv->registerResultPrototype($mockStatement)); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getDatabasePlatformName */ public function testGetDatabasePlatformName() { $this->sqlsrv = new Sqlsrv([]); self::assertEquals('SqlServer', $this->sqlsrv->getDatabasePlatformName()); self::assertEquals('SQLServer', $this->sqlsrv->getDatabasePlatformName(Sqlsrv::NAME_FORMAT_NATURAL)); } /** * @depends testRegisterConnection * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getConnection */ public function testGetConnection() { $conn = new Connection([]); $this->sqlsrv->registerConnection($conn); self::assertSame($conn, $this->sqlsrv->getConnection()); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::createStatement * @todo Implement testGetPrepareType(). */ public function testCreateStatement() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::createResult * @todo Implement testGetPrepareType(). */ public function testCreateResult() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getPrepareType * @todo Implement testGetPrepareType(). */ public function testGetPrepareType() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::formatParameterName * @todo Implement testFormatParameterName(). */ public function testFormatParameterName() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getLastGeneratedValue * @todo Implement testGetLastGeneratedValue(). */ public function testGetLastGeneratedValue() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getResultPrototype */ public function testGetResultPrototype() { $resultPrototype = $this->sqlsrv->getResultPrototype(); self::assertInstanceOf(Result::class, $resultPrototype); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php
test/unit/Adapter/Driver/Sqlsrv/StatementIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Result; use Laminas\Db\Adapter\Driver\Sqlsrv\Sqlsrv; use Laminas\Db\Adapter\Driver\Sqlsrv\Statement; use function get_resource_type; use function sqlsrv_connect; /** * @group integration * @group integration-sqlserver */ class StatementIntegrationTest extends AbstractIntegrationTest { /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::initialize */ public function testInitialize() { $sqlsrvResource = sqlsrv_connect( $this->variables['hostname'], [ 'UID' => $this->variables['username'], 'PWD' => $this->variables['password'], 'TrustServerCertificate' => 1, ] ); $statement = new Statement(); self::assertSame($statement, $statement->initialize($sqlsrvResource)); unset($stmtResource, $sqlsrvResource); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::getResource */ public function testGetResource() { $sqlsrvResource = sqlsrv_connect( $this->variables['hostname'], [ 'UID' => $this->variables['username'], 'PWD' => $this->variables['password'], 'TrustServerCertificate' => 1, ] ); $statement = new Statement(); $statement->initialize($sqlsrvResource); $statement->prepare("SELECT 'foo'"); $resource = $statement->getResource(); self::assertEquals('SQL Server Statement', get_resource_type($resource)); unset($resource, $sqlsrvResource); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::prepare * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::isPrepared */ public function testPrepare() { $sqlsrvResource = sqlsrv_connect( $this->variables['hostname'], [ 'UID' => $this->variables['username'], 'PWD' => $this->variables['password'], 'TrustServerCertificate' => 1, ] ); $statement = new Statement(); $statement->initialize($sqlsrvResource); self::assertFalse($statement->isPrepared()); self::assertSame($statement, $statement->prepare("SELECT 'foo'")); self::assertTrue($statement->isPrepared()); unset($resource, $sqlsrvResource); } /** * @covers \Laminas\Db\Adapter\Driver\Sqlsrv\Statement::execute */ public function testExecute() { $sqlsrv = new Sqlsrv($this->variables); $statement = $sqlsrv->createStatement("SELECT 'foo'"); self::assertSame($statement, $statement->prepare()); $result = $statement->execute(); self::assertInstanceOf(Result::class, $result); unset($resource, $sqlsrvResource); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/ResultTest.php
test/unit/Adapter/Driver/Oci8/ResultTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Result; use PHPUnit\Framework\TestCase; /** * @group result-oci8 */ class ResultTest extends TestCase { /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getResource */ public function testGetResource() { $result = new Result(); self::assertNull($result->getResource()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::buffer */ public function testBuffer() { $result = new Result(); self::assertNull($result->buffer()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::isBuffered */ public function testIsBuffered() { $result = new Result(); self::assertFalse($result->isBuffered()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getGeneratedValue */ public function testGetGeneratedValue() { $result = new Result(); self::assertNull($result->getGeneratedValue()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::key */ public function testKey() { $result = new Result(); self::assertEquals(0, $result->key()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::next */ public function testNext() { $mockResult = $this->getMockBuilder(Result::class) ->setMethods(['loadData']) ->getMock(); $mockResult->expects($this->any()) ->method('loadData') ->willReturn(null); self::assertNull($mockResult->next()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::rewind */ public function testRewind() { $result = new Result(); self::assertNull($result->rewind()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php
test/unit/Adapter/Driver/Oci8/AbstractIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use PHPUnit\Framework\TestCase; use function extension_loaded; use function getenv; abstract class AbstractIntegrationTest extends TestCase { /** @var array<string, string> */ protected $variables = [ 'hostname' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_HOSTNAME', 'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_USERNAME', 'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_PASSWORD', ]; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { foreach ($this->variables as $name => $value) { if (! getenv($value)) { $this->markTestSkipped( 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' ); } $this->variables[$name] = getenv($value); } if (! extension_loaded('oci8')) { $this->fail('The phpunit group integration-oci8 was enabled, but the extension is not loaded.'); } } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/StatementTest.php
test/unit/Adapter/Driver/Oci8/StatementTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Statement; use Laminas\Db\Adapter\ParameterContainer; use Laminas\Db\Adapter\Profiler\Profiler; use PHPUnit\Framework\TestCase; /** * @group integrationOracle */ class StatementTest extends TestCase { /** @var Statement */ protected $statement; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->statement = new Statement(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::setDriver */ public function testSetDriver() { self::assertEquals($this->statement, $this->statement->setDriver(new Oci8([]))); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::setProfiler */ public function testSetProfiler() { self::assertEquals($this->statement, $this->statement->setProfiler(new Profiler())); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getProfiler */ public function testGetProfiler() { $profiler = new Profiler(); $this->statement->setProfiler($profiler); self::assertEquals($profiler, $this->statement->getProfiler()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::initialize */ public function testInitialize() { $oci8 = new Oci8([]); self::assertEquals($this->statement, $this->statement->initialize($oci8)); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::setSql */ public function testSetSql() { self::assertEquals($this->statement, $this->statement->setSql('select * from table')); self::assertEquals('select * from table', $this->statement->getSql()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::setParameterContainer */ public function testSetParameterContainer() { self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer())); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getParameterContainer * @todo Implement testGetParameterContainer(). */ public function testGetParameterContainer() { $container = new ParameterContainer(); $this->statement->setParameterContainer($container); self::assertSame($container, $this->statement->getParameterContainer()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getResource * @todo Implement testGetResource(). */ public function testGetResource() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getSql * @todo Implement testGetSql(). */ public function testGetSql() { self::assertEquals($this->statement, $this->statement->setSql('select * from table')); self::assertEquals('select * from table', $this->statement->getSql()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::prepare * @todo Implement testPrepare(). */ public function testPrepare() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::isPrepared */ public function testIsPrepared() { self::assertFalse($this->statement->isPrepared()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::execute * @todo Implement testExecute(). */ public function testExecute() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php
test/unit/Adapter/Driver/Oci8/ResultIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Result; use PHPUnit\Framework\TestCase; /** * @group integration * @group integration-oracle */ class ResultIntegrationTest extends TestCase { /** @var Result */ protected $object; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->object = new Result(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::initialize * @todo Implement testInitialize(). */ public function testInitialize() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::buffer * @todo Implement testBuffer(). */ public function testBuffer() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getResource * @todo Implement testGetResource(). */ public function testGetResource() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::current * @todo Implement testCurrent(). */ public function testCurrent() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::next * @todo Implement testNext(). */ public function testNext() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::key * @todo Implement testKey(). */ public function testKey() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::rewind * @todo Implement testRewind(). */ public function testRewind() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::valid * @todo Implement testValid(). */ public function testValid() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::count * @todo Implement testCount(). */ public function testCount() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getFieldCount * @todo Implement testGetFieldCount(). */ public function testGetFieldCount() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::isQueryResult * @todo Implement testIsQueryResult(). */ public function testIsQueryResult() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getAffectedRows * @todo Implement testGetAffectedRows(). */ public function testGetAffectedRows() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Result::getGeneratedValue * @todo Implement testGetGeneratedValue(). */ public function testGetGeneratedValue() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/ConnectionTest.php
test/unit/Adapter/Driver/Oci8/ConnectionTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Connection; use Laminas\Db\Adapter\Driver\Oci8\Oci8; use PHPUnit\Framework\TestCase; class ConnectionTest extends TestCase { /** @var Connection */ protected $connection; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->connection = new Connection([]); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::setDriver */ public function testSetDriver() { self::assertEquals($this->connection, $this->connection->setDriver(new Oci8([]))); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::setConnectionParameters */ public function testSetConnectionParameters() { self::assertEquals($this->connection, $this->connection->setConnectionParameters([])); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::getConnectionParameters */ public function testGetConnectionParameters() { $this->connection->setConnectionParameters(['foo' => 'bar']); self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php
test/unit/Adapter/Driver/Oci8/ConnectionIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Connection; use Laminas\Db\Adapter\Driver\Oci8\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Result; /** * @group integration * @group integration-oracle */ class ConnectionIntegrationTest extends AbstractIntegrationTest { /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::getCurrentSchema */ public function testGetCurrentSchema() { $connection = new Connection($this->variables); self::assertInternalType('string', $connection->getCurrentSchema()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::setResource */ public function testSetResource() { $this->markTestIncomplete('edit this'); $resource = oci_connect( $this->variables['username'], $this->variables['password'], $this->variables['hostname'] ); $connection = new Connection([]); self::assertSame($connection, $connection->setResource($resource)); $connection->disconnect(); unset($connection); unset($resource); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::getResource */ public function testGetResource() { $connection = new Connection($this->variables); $connection->connect(); self::assertInternalType('resource', $connection->getResource()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::connect */ public function testConnect() { $connection = new Connection($this->variables); self::assertSame($connection, $connection->connect()); self::assertTrue($connection->isConnected()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::isConnected */ public function testIsConnected() { $connection = new Connection($this->variables); self::assertFalse($connection->isConnected()); self::assertSame($connection, $connection->connect()); self::assertTrue($connection->isConnected()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::disconnect */ public function testDisconnect() { $connection = new Connection($this->variables); $connection->connect(); self::assertTrue($connection->isConnected()); $connection->disconnect(); self::assertFalse($connection->isConnected()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::beginTransaction * @todo Implement testBeginTransaction(). */ public function testBeginTransaction() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::commit * @todo Implement testCommit(). */ public function testCommit() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::rollback * @todo Implement testRollback(). */ public function testRollback() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::execute */ public function testExecute() { $oci8 = new Oci8($this->variables); $connection = $oci8->getConnection(); $result = $connection->execute('SELECT \'foo\' FROM DUAL'); self::assertInstanceOf(Result::class, $result); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Connection::getLastGeneratedValue */ public function testGetLastGeneratedValue() { $this->markTestIncomplete('Need to create a temporary sequence.'); $connection = new Connection($this->variables); $connection->getLastGeneratedValue(); } /** * @group laminas3469 */ public function testConnectReturnsConnectionWhenResourceSet() { $this->markTestIncomplete('edit this'); $resource = oci_connect( $this->variables['username'], $this->variables['password'], $this->variables['hostname'] ); $connection = new Connection([]); $connection->setResource($resource); self::assertSame($connection, $connection->connect()); $connection->disconnect(); unset($connection); unset($resource); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/Oci8Test.php
test/unit/Adapter/Driver/Oci8/Oci8Test.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Connection; use Laminas\Db\Adapter\Driver\Oci8\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Result; use Laminas\Db\Adapter\Driver\Oci8\Statement; use PHPUnit\Framework\TestCase; class Oci8Test extends TestCase { /** @var Oci8 */ protected $oci8; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->oci8 = new Oci8([]); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::registerConnection */ public function testRegisterConnection() { $mockConnection = $this->getMockForAbstractClass( Connection::class, [[]], '', true, true, true, ['setDriver'] ); $mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->oci8)); self::assertSame($this->oci8, $this->oci8->registerConnection($mockConnection)); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::registerStatementPrototype */ public function testRegisterStatementPrototype() { $this->oci8 = new Oci8([]); $mockStatement = $this->getMockForAbstractClass( Statement::class, [], '', true, true, true, ['setDriver'] ); $mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->oci8)); self::assertSame($this->oci8, $this->oci8->registerStatementPrototype($mockStatement)); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::registerResultPrototype */ public function testRegisterResultPrototype() { $this->oci8 = new Oci8([]); $mockStatement = $this->getMockForAbstractClass( Result::class, [], '', true, true, true, ['setDriver'] ); self::assertSame($this->oci8, $this->oci8->registerResultPrototype($mockStatement)); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::getDatabasePlatformName */ public function testGetDatabasePlatformName() { $this->oci8 = new Oci8([]); self::assertEquals('Oracle', $this->oci8->getDatabasePlatformName()); self::assertEquals('Oracle', $this->oci8->getDatabasePlatformName(Oci8::NAME_FORMAT_NATURAL)); } /** * @depends testRegisterConnection * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::getConnection */ public function testGetConnection() { $conn = new Connection([]); $this->oci8->registerConnection($conn); self::assertSame($conn, $this->oci8->getConnection()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::createStatement * @todo Implement testGetPrepareType(). */ public function testCreateStatement() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::createResult * @todo Implement testGetPrepareType(). */ public function testCreateResult() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::getPrepareType * @todo Implement testGetPrepareType(). */ public function testGetPrepareType() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::formatParameterName * @todo Implement testFormatParameterName(). */ public function testFormatParameterName() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::getLastGeneratedValue * @todo Implement testGetLastGeneratedValue(). */ public function testGetLastGeneratedValue() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php
test/unit/Adapter/Driver/Oci8/Oci8IntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Statement; use Laminas\Db\Adapter\Exception\InvalidArgumentException; use stdClass; /** * @group integration * @group integration-oracle */ class Oci8IntegrationTest extends AbstractIntegrationTest { /** * @group integration-oci8 * @covers \Laminas\Db\Adapter\Driver\Oci8\Oci8::checkEnvironment */ public function testCheckEnvironment() { $sqlserver = new Oci8([]); self::assertNull($sqlserver->checkEnvironment()); } public function testCreateStatement() { $driver = new Oci8([]); $resource = oci_connect( $this->variables['username'], $this->variables['password'], $this->variables['hostname'] ); $driver->getConnection()->setResource($resource); $stmt = $driver->createStatement('SELECT * FROM DUAL'); self::assertInstanceOf(Statement::class, $stmt); $stmt = $driver->createStatement(); self::assertInstanceOf(Statement::class, $stmt); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('only accepts an SQL string or an oci8 resource'); $driver->createStatement(new stdClass()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php
test/unit/Adapter/Driver/Oci8/StatementIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Result; use Laminas\Db\Adapter\Driver\Oci8\Statement; use PHPUnit\Framework\TestCase; use function extension_loaded; use function get_resource_type; use function getenv; /** * @group integration * @group integration-oracle */ class StatementIntegrationTest extends TestCase { /** @var array<string, string> */ protected $variables = [ 'hostname' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_HOSTNAME', 'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_USERNAME', 'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_OCI8_PASSWORD', ]; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { foreach ($this->variables as $name => $value) { if (! getenv($value)) { $this->markTestSkipped( 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' ); } $this->variables[$name] = getenv($value); } if (! extension_loaded('oci8')) { $this->fail('The phpunit group integration-oracle was enabled, but the extension is not loaded.'); } } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::initialize */ public function testInitialize() { $ociResource = oci_connect( $this->variables['username'], $this->variables['password'], $this->variables['hostname'] ); $statement = new Statement(); self::assertSame($statement, $statement->initialize($ociResource)); unset($stmtResource, $ociResource); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::getResource */ public function testGetResource() { $ociResource = oci_connect( $this->variables['username'], $this->variables['password'], $this->variables['hostname'] ); $statement = new Statement(); $statement->initialize($ociResource); $statement->prepare('SELECT * FROM DUAL'); $resource = $statement->getResource(); self::assertEquals('oci8 statement', get_resource_type($resource)); unset($resource, $ociResource); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::prepare * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::isPrepared */ public function testPrepare() { $ociResource = oci_connect( $this->variables['username'], $this->variables['password'], $this->variables['hostname'] ); $statement = new Statement(); $statement->initialize($ociResource); self::assertFalse($statement->isPrepared()); self::assertSame($statement, $statement->prepare('SELECT * FROM DUAL')); self::assertTrue($statement->isPrepared()); unset($resource, $ociResource); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Statement::execute */ public function testExecute() { $oci8 = new Oci8($this->variables); $statement = $oci8->createStatement('SELECT * FROM DUAL'); self::assertSame($statement, $statement->prepare()); $result = $statement->execute(); self::assertInstanceOf(Result::class, $result); unset($resource, $oci8); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php
test/unit/Adapter/Driver/Oci8/Feature/RowCounterTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Oci8\Feature; use Closure; use Laminas\Db\Adapter\Driver\ConnectionInterface; use Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter; use Laminas\Db\Adapter\Driver\Oci8\Oci8; use Laminas\Db\Adapter\Driver\Oci8\Statement; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class RowCounterTest extends TestCase { /** @var RowCounter */ protected $rowCounter; protected function setUp(): void { $this->rowCounter = new RowCounter(); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter::getName */ public function testGetName() { self::assertEquals('RowCounter', $this->rowCounter->getName()); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter::getCountForStatement */ public function testGetCountForStatement() { $statement = $this->getMockStatement('SELECT XXX', 5); $statement->expects($this->once()) ->method('prepare') ->with($this->equalTo('SELECT COUNT(*) as "count" FROM (SELECT XXX)')); $count = $this->rowCounter->getCountForStatement($statement); self::assertEquals(5, $count); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter::getCountForSql */ public function testGetCountForSql() { $this->rowCounter->setDriver($this->getMockDriver(5)); $count = $this->rowCounter->getCountForSql('SELECT XXX'); self::assertEquals(5, $count); } /** * @covers \Laminas\Db\Adapter\Driver\Oci8\Feature\RowCounter::getRowCountClosure */ public function testGetRowCountClosure() { $stmt = $this->getMockStatement('SELECT XXX', 5); /** @var Closure $closure */ $closure = $this->rowCounter->getRowCountClosure($stmt); self::assertInstanceOf('Closure', $closure); self::assertEquals(5, $closure()); } /** * @param string $sql * @param mixed $returnValue * @return Statement&MockObject */ protected function getMockStatement($sql, $returnValue) { $statement = $this->getMockBuilder(Statement::class) ->setMethods(['prepare', 'execute']) ->disableOriginalConstructor() ->getMock(); // mock the result $result = $this->getMockBuilder('stdClass') ->setMethods(['current']) ->getMock(); $result->expects($this->once()) ->method('current') ->will($this->returnValue(['count' => $returnValue])); $statement->setSql($sql); $statement->expects($this->once()) ->method('execute') ->will($this->returnValue($result)); return $statement; } /** * @param mixed $returnValue * @return Oci8&MockObject */ protected function getMockDriver($returnValue) { $oci8Statement = $this->getMockBuilder('stdClass') ->setMethods(['current']) ->disableOriginalConstructor() ->getMock(); // stdClass can be used here $oci8Statement->expects($this->once()) ->method('current') ->will($this->returnValue(['count' => $returnValue])); $connection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $connection->expects($this->once()) ->method('execute') ->will($this->returnValue($oci8Statement)); $driver = $this->getMockBuilder(Oci8::class) ->setMethods(['getConnection']) ->disableOriginalConstructor() ->getMock(); $driver->expects($this->once()) ->method('getConnection') ->will($this->returnValue($connection)); return $driver; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/ResultTest.php
test/unit/Adapter/Driver/Pdo/ResultTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Result; use Laminas\Db\Adapter\Exception\InvalidArgumentException; use PDO; use PDOStatement; use PHPUnit\Framework\TestCase; use stdClass; use function assert; use function uniqid; /** * @group result-pdo */ class ResultTest extends TestCase { /** * Tests current method returns same data on consecutive calls. * * @covers \Laminas\Db\Adapter\Driver\Pdo\Result::current */ public function testCurrent() { $stub = $this->getMockBuilder('PDOStatement')->getMock(); $stub->expects($this->any()) ->method('fetch') ->will($this->returnCallback(function () { return uniqid(); })); $result = new Result(); $result->initialize($stub, null); self::assertEquals($result->current(), $result->current()); } public function testFetchModeException() { $result = new Result(); $this->expectException(InvalidArgumentException::class); $result->setFetchMode(13); } /** * Tests whether the fetch mode was set properly and */ public function testFetchModeAnonymousObject() { $stub = $this->getMockBuilder('PDOStatement')->getMock(); $stub->expects($this->any()) ->method('fetch') ->will($this->returnCallback(function () { return new stdClass(); })); $result = new Result(); $result->initialize($stub, null); $result->setFetchMode(PDO::FETCH_OBJ); self::assertEquals(5, $result->getFetchMode()); self::assertInstanceOf('stdClass', $result->current()); } /** * Tests whether the fetch mode has a broader range */ public function testFetchModeRange() { $stub = $this->getMockBuilder('PDOStatement')->getMock(); $stub->expects($this->any()) ->method('fetch') ->will($this->returnCallback(function () { return new stdClass(); })); $result = new Result(); $result->initialize($stub, null); $result->setFetchMode(PDO::FETCH_NAMED); self::assertEquals(11, $result->getFetchMode()); self::assertInstanceOf('stdClass', $result->current()); } public function testMultipleRewind() { $data = [ ['test' => 1], ['test' => 2], ]; $position = 0; $stub = $this->getMockBuilder('PDOStatement')->getMock(); assert($stub instanceof PDOStatement); // to suppress IDE type warnings $stub->expects($this->any()) ->method('fetch') ->will($this->returnCallback(function () use ($data, &$position) { return $data[$position++]; })); $result = new Result(); $result->initialize($stub, null); $result->rewind(); $result->rewind(); $this->assertEquals(0, $result->key()); $this->assertEquals(1, $position); $this->assertEquals($data[0], $result->current()); $result->next(); $this->assertEquals(1, $result->key()); $this->assertEquals(2, $position); $this->assertEquals($data[1], $result->current()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/StatementTest.php
test/unit/Adapter/Driver/Pdo/StatementTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Connection; use Laminas\Db\Adapter\Driver\Pdo\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Result; use Laminas\Db\Adapter\Driver\Pdo\Statement; use Laminas\Db\Adapter\ParameterContainer; use PHPUnit\Framework\TestCase; class StatementTest extends TestCase { /** @var Statement */ protected $statement; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->statement = new Statement(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::setDriver */ public function testSetDriver() { self::assertEquals($this->statement, $this->statement->setDriver(new Pdo([]))); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::setParameterContainer */ public function testSetParameterContainer() { self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer())); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::getParameterContainer * @todo Implement testGetParameterContainer(). */ public function testGetParameterContainer() { $container = new ParameterContainer(); $this->statement->setParameterContainer($container); self::assertSame($container, $this->statement->getParameterContainer()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::getResource */ public function testGetResource() { $pdo = new TestAsset\SqliteMemoryPdo(); $stmt = $pdo->prepare('SELECT 1'); $this->statement->setResource($stmt); self::assertSame($stmt, $this->statement->getResource()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::setSql */ public function testSetSql() { $this->statement->setSql('SELECT 1'); self::assertEquals('SELECT 1', $this->statement->getSql()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::getSql */ public function testGetSql() { $this->statement->setSql('SELECT 1'); self::assertEquals('SELECT 1', $this->statement->getSql()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::prepare * @todo Implement testPrepare(). */ public function testPrepare() { $this->statement->initialize(new TestAsset\SqliteMemoryPdo()); self::assertNull($this->statement->prepare('SELECT 1')); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::isPrepared */ public function testIsPrepared() { self::assertFalse($this->statement->isPrepared()); $this->statement->initialize(new TestAsset\SqliteMemoryPdo()); $this->statement->prepare('SELECT 1'); self::assertTrue($this->statement->isPrepared()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Statement::execute */ public function testExecute() { $this->statement->setDriver(new Pdo(new Connection($pdo = new TestAsset\SqliteMemoryPdo()))); $this->statement->initialize($pdo); $this->statement->prepare('SELECT 1'); self::assertInstanceOf(Result::class, $this->statement->execute()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/ConnectionTest.php
test/unit/Adapter/Driver/Pdo/ConnectionTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo; use Exception; use Laminas\Db\Adapter\Driver\Pdo\Connection; use Laminas\Db\Adapter\Exception\InvalidConnectionParametersException; use PHPUnit\Framework\TestCase; class ConnectionTest extends TestCase { /** @var Connection */ protected $connection; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->connection = new Connection(); } /** * Test getResource method tries to connect to the database, it should never return null * * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getResource */ public function testResource() { $this->expectException(InvalidConnectionParametersException::class); $this->connection->getResource(); } /** * Test getConnectedDsn returns a DSN string if it has been set * * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getDsn */ public function testGetDsn() { $dsn = "sqlite::memory:"; $this->connection->setConnectionParameters(['dsn' => $dsn]); try { $this->connection->connect(); } catch (Exception $e) { } $responseString = $this->connection->getDsn(); self::assertEquals($dsn, $responseString); } /** * @group 2622 */ public function testArrayOfConnectionParametersCreatesCorrectDsn() { $this->connection->setConnectionParameters([ 'driver' => 'pdo_mysql', 'charset' => 'utf8', 'dbname' => 'foo', 'port' => '3306', 'unix_socket' => '/var/run/mysqld/mysqld.sock', ]); try { $this->connection->connect(); } catch (Exception $e) { } $responseString = $this->connection->getDsn(); self::assertStringStartsWith('mysql:', $responseString); self::assertStringContainsString('charset=utf8', $responseString); self::assertStringContainsString('dbname=foo', $responseString); self::assertStringContainsString('port=3306', $responseString); self::assertStringContainsString('unix_socket=/var/run/mysqld/mysqld.sock', $responseString); } public function testHostnameAndUnixSocketThrowsInvalidConnectionParametersException() { $this->expectException(InvalidConnectionParametersException::class); $this->expectExceptionMessage( 'Ambiguous connection parameters, both hostname and unix_socket parameters were set' ); $this->connection->setConnectionParameters([ 'driver' => 'pdo_mysql', 'host' => '127.0.0.1', 'dbname' => 'foo', 'port' => '3306', 'unix_socket' => '/var/run/mysqld/mysqld.sock', ]); $this->connection->connect(); } public function testDblibArrayOfConnectionParametersCreatesCorrectDsn() { $this->connection->setConnectionParameters([ 'driver' => 'pdo_dblib', 'charset' => 'UTF-8', 'dbname' => 'foo', 'port' => '1433', 'version' => '7.3', ]); try { $this->connection->connect(); } catch (Exception $e) { } $responseString = $this->connection->getDsn(); $this->assertStringStartsWith('dblib:', $responseString); $this->assertStringContainsString('charset=UTF-8', $responseString); $this->assertStringContainsString('dbname=foo', $responseString); $this->assertStringContainsString('port=1433', $responseString); $this->assertStringContainsString('version=7.3', $responseString); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php
test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Connection; use Laminas\Db\Adapter\Driver\Pdo\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Result; use Laminas\Db\Adapter\Driver\Pdo\Statement; use PHPUnit\Framework\TestCase; /** * @group integration * @group integration-pdo */ class ConnectionIntegrationTest extends TestCase { /** @var array<string, string> */ protected $variables = ['pdodriver' => 'sqlite', 'database' => ':memory:']; /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getCurrentSchema */ public function testGetCurrentSchema() { $connection = new Connection($this->variables); self::assertIsString($connection->getCurrentSchema()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::setResource */ public function testSetResource() { $resource = new TestAsset\SqliteMemoryPdo(); $connection = new Connection([]); self::assertSame($connection, $connection->setResource($resource)); $connection->disconnect(); unset($connection); unset($resource); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getResource */ public function testGetResource() { $connection = new Connection($this->variables); $connection->connect(); self::assertInstanceOf('PDO', $connection->getResource()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::connect */ public function testConnect() { $connection = new Connection($this->variables); self::assertSame($connection, $connection->connect()); self::assertTrue($connection->isConnected()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::isConnected */ public function testIsConnected() { $connection = new Connection($this->variables); self::assertFalse($connection->isConnected()); self::assertSame($connection, $connection->connect()); self::assertTrue($connection->isConnected()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::disconnect */ public function testDisconnect() { $connection = new Connection($this->variables); $connection->connect(); self::assertTrue($connection->isConnected()); $connection->disconnect(); self::assertFalse($connection->isConnected()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction * @todo Implement testBeginTransaction(). */ public function testBeginTransaction() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit * @todo Implement testCommit(). */ public function testCommit() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback * @todo Implement testRollback(). */ public function testRollback() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::execute */ public function testExecute() { $sqlsrv = new Pdo($this->variables); $connection = $sqlsrv->getConnection(); $result = $connection->execute('SELECT \'foo\''); self::assertInstanceOf(Result::class, $result); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::prepare */ public function testPrepare() { $sqlsrv = new Pdo($this->variables); $connection = $sqlsrv->getConnection(); $statement = $connection->prepare('SELECT \'foo\''); self::assertInstanceOf(Statement::class, $statement); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::getLastGeneratedValue */ public function testGetLastGeneratedValue() { $this->markTestIncomplete('Need to create a temporary sequence.'); $connection = new Connection($this->variables); $connection->getLastGeneratedValue(); } /** * @group laminas3469 */ public function testConnectReturnsConnectionWhenResourceSet() { $resource = new TestAsset\SqliteMemoryPdo(); $connection = new Connection([]); $connection->setResource($resource); self::assertSame($connection, $connection->connect()); $connection->disconnect(); unset($connection); unset($resource); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/PdoTest.php
test/unit/Adapter/Driver/Pdo/PdoTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\Pdo\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Result; use Laminas\Db\Exception\RuntimeException; use PHPUnit\Framework\TestCase; class PdoTest extends TestCase { /** @var Pdo */ protected $pdo; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->pdo = new Pdo([]); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Pdo::getDatabasePlatformName */ public function testGetDatabasePlatformName() { // Test platform name for SqlServer $this->pdo->getConnection()->setConnectionParameters(['pdodriver' => 'sqlsrv']); self::assertEquals('SqlServer', $this->pdo->getDatabasePlatformName()); self::assertEquals('SQLServer', $this->pdo->getDatabasePlatformName(DriverInterface::NAME_FORMAT_NATURAL)); } /** @psalm-return array<array-key, array{0: int|string, 1: null|string, 2: string}> */ public function getParamsAndType(): array { return [ ['foo', null, ':foo'], ['foo_bar', null, ':foo_bar'], ['123foo', null, ':123foo'], [1, null, '?'], ['1', null, '?'], ['foo', Pdo::PARAMETERIZATION_NAMED, ':foo'], ['foo_bar', Pdo::PARAMETERIZATION_NAMED, ':foo_bar'], ['123foo', Pdo::PARAMETERIZATION_NAMED, ':123foo'], [1, Pdo::PARAMETERIZATION_NAMED, ':1'], ['1', Pdo::PARAMETERIZATION_NAMED, ':1'], [':foo', null, ':foo'], ]; } /** * @dataProvider getParamsAndType * @param int|string $name */ public function testFormatParameterName($name, ?string $type, string $expected) { $result = $this->pdo->formatParameterName($name, $type); $this->assertEquals($expected, $result); } /** @psalm-return array<array-key, array{0: string}> */ public function getInvalidParamName(): array { return [ ['foo%'], ['foo-'], ['foo$'], ['foo0!'], ]; } /** * @dataProvider getInvalidParamName */ public function testFormatParameterNameWithInvalidCharacters(string $name) { $this->expectException(RuntimeException::class); $this->pdo->formatParameterName($name); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Pdo::getResultPrototype */ public function testGetResultPrototype() { $resultPrototype = $this->pdo->getResultPrototype(); self::assertInstanceOf(Result::class, $resultPrototype); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php
test/unit/Adapter/Driver/Pdo/ConnectionTransactionsTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Connection; use Laminas\Db\Adapter\Exception\RuntimeException; use LaminasTest\Db\TestAsset\ConnectionWrapper; use PHPUnit\Framework\TestCase; /** * Tests for {@see \Laminas\Db\Adapter\Driver\Pdo\Connection} transaction support * * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection * @covers \Laminas\Db\Adapter\Driver\AbstractConnection */ class ConnectionTransactionsTest extends TestCase { /** @var Wrapper */ protected $wrapper; /** * {@inheritDoc} */ protected function setUp(): void { $this->wrapper = new ConnectionWrapper(); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction() */ public function testBeginTransactionReturnsInstanceOfConnection() { self::assertInstanceOf(Connection::class, $this->wrapper->beginTransaction()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction() * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction() */ public function testBeginTransactionSetsInTransactionAtTrue() { $this->wrapper->beginTransaction(); self::assertTrue($this->wrapper->inTransaction()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit() */ public function testCommitReturnsInstanceOfConnection() { $this->wrapper->beginTransaction(); self::assertInstanceOf(Connection::class, $this->wrapper->commit()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit() * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction() */ public function testCommitSetsInTransactionAtFalse() { $this->wrapper->beginTransaction(); $this->wrapper->commit(); self::assertFalse($this->wrapper->inTransaction()); } /** * Standalone commit after a SET autocommit=0; * * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit() */ public function testCommitWithoutBeginReturnsInstanceOfConnection() { self::assertInstanceOf(Connection::class, $this->wrapper->commit()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction() * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction() * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit() */ public function testNestedTransactionsCommit() { $nested = 0; self::assertFalse($this->wrapper->inTransaction()); // 1st transaction $this->wrapper->beginTransaction(); self::assertTrue($this->wrapper->inTransaction()); self::assertSame(++$nested, $this->wrapper->getNestedTransactionsCount()); // 2nd transaction $this->wrapper->beginTransaction(); self::assertTrue($this->wrapper->inTransaction()); self::assertSame(++$nested, $this->wrapper->getNestedTransactionsCount()); // 1st commit $this->wrapper->commit(); self::assertTrue($this->wrapper->inTransaction()); self::assertSame(--$nested, $this->wrapper->getNestedTransactionsCount()); // 2nd commit $this->wrapper->commit(); self::assertFalse($this->wrapper->inTransaction()); self::assertSame(--$nested, $this->wrapper->getNestedTransactionsCount()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction() * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::beginTransaction() * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback() */ public function testNestedTransactionsRollback() { $nested = 0; self::assertFalse($this->wrapper->inTransaction()); // 1st transaction $this->wrapper->beginTransaction(); self::assertTrue($this->wrapper->inTransaction()); self::assertSame(++$nested, $this->wrapper->getNestedTransactionsCount()); // 2nd transaction $this->wrapper->beginTransaction(); self::assertTrue($this->wrapper->inTransaction()); self::assertSame(++$nested, $this->wrapper->getNestedTransactionsCount()); // Rollback $this->wrapper->rollback(); self::assertFalse($this->wrapper->inTransaction()); self::assertSame(0, $this->wrapper->getNestedTransactionsCount()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback() */ public function testRollbackDisconnectedThrowsException() { $this->wrapper->disconnect(); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Must be connected before you can rollback'); $this->wrapper->rollback(); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback() */ public function testRollbackReturnsInstanceOfConnection() { $this->wrapper->beginTransaction(); self::assertInstanceOf(Connection::class, $this->wrapper->rollback()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback() * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction() */ public function testRollbackSetsInTransactionAtFalse() { $this->wrapper->beginTransaction(); $this->wrapper->rollback(); self::assertFalse($this->wrapper->inTransaction()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::rollback() */ public function testRollbackWithoutBeginThrowsException() { $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Must call beginTransaction() before you can rollback'); $this->wrapper->rollback(); } /** * Standalone commit after a SET autocommit=0; * * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::inTransaction() * @covers \Laminas\Db\Adapter\Driver\Pdo\Connection::commit() */ public function testStandaloneCommit() { self::assertFalse($this->wrapper->inTransaction()); self::assertSame(0, $this->wrapper->getNestedTransactionsCount()); $this->wrapper->commit(); self::assertFalse($this->wrapper->inTransaction()); self::assertSame(0, $this->wrapper->getNestedTransactionsCount()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php
test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Statement; use PDO; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class StatementIntegrationTest extends TestCase { /** @var Statement */ protected $statement; /** @var MockObject */ protected $pdoStatementMock; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $driver = $this->getMockBuilder(\Laminas\Db\Adapter\Driver\Pdo\Pdo::class) ->setMethods(['createResult']) ->disableOriginalConstructor() ->getMock(); $this->statement = new Statement(); $this->statement->setDriver($driver); $this->statement->initialize(new TestAsset\CtorlessPdo( $this->pdoStatementMock = $this->getMockBuilder('PDOStatement') ->setMethods(['execute', 'bindParam']) ->getMock() )); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } public function testStatementExecuteWillConvertPhpBoolToPdoBoolWhenBinding() { $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( $this->equalTo(':foo'), $this->equalTo(false), $this->equalTo(PDO::PARAM_BOOL) ); $this->statement->execute(['foo' => false]); } public function testStatementExecuteWillUsePdoStrByDefaultWhenBinding() { $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( $this->equalTo(':foo'), $this->equalTo('bar'), $this->equalTo(PDO::PARAM_STR) ); $this->statement->execute(['foo' => 'bar']); } public function testStatementExecuteWillUsePdoStrForStringIntegerWhenBinding() { $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( $this->equalTo(':foo'), $this->equalTo('123'), $this->equalTo(PDO::PARAM_STR) ); $this->statement->execute(['foo' => '123']); } public function testStatementExecuteWillUsePdoIntForIntWhenBinding() { $this->pdoStatementMock->expects($this->any())->method('bindParam')->with( $this->equalTo(':foo'), $this->equalTo(123), $this->equalTo(PDO::PARAM_INT) ); $this->statement->execute(['foo' => 123]); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php
test/unit/Adapter/Driver/Pdo/TestAsset/SqliteMemoryPdo.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo\TestAsset; use Exception; use PDO; use PDOStatement; use PHPUnit\Framework\MockObject\MockObject; use function implode; use function sprintf; class SqliteMemoryPdo extends PDO { /** @var PDOStatement&MockObject */ protected $mockStatement; /** @param null|string $sql */ public function __construct($sql = null) { parent::__construct('sqlite::memory:'); if (empty($sql)) { return; } if (false === $this->exec($sql)) { throw new Exception(sprintf( "Error: %s, %s", $this->errorCode(), implode(",", $this->errorInfo()) )); } } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php
test/unit/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo\TestAsset; use PDO; use PDOStatement; use PHPUnit\Framework\MockObject\MockObject; // phpcs:ignore SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse use ReturnTypeWillChange; class CtorlessPdo extends PDO { /** * @var PDOStatement * @psalm-var PDOStatement&MockObject */ protected $mockStatement; /** * @param PDOStatement $mockStatement * @psalm-param PDOStatement&MockObject $mockStatement */ public function __construct($mockStatement) { $this->mockStatement = $mockStatement; } /** * @param string $sql * @param null|array $options * @return PDOStatement|false */ #[ReturnTypeWillChange] public function prepare($sql, $options = null): PDOStatement { return $this->mockStatement; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php
test/unit/Adapter/Driver/Pdo/Feature/SqliteRowCounterTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo\Feature; use Closure; use Laminas\Db\Adapter\Driver\ConnectionInterface; use Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter; use Laminas\Db\Adapter\Driver\Pdo\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Statement; use Laminas\Db\Adapter\Driver\ResultInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class SqliteRowCounterTest extends TestCase { /** @var SqliteRowCounter */ protected $rowCounter; protected function setUp(): void { $this->rowCounter = new SqliteRowCounter(); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getName */ public function testGetName() { self::assertEquals('SqliteRowCounter', $this->rowCounter->getName()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getCountForStatement */ public function testGetCountForStatement() { $statement = $this->getMockStatement('SELECT XXX', 5); $statement->expects($this->once())->method('prepare') ->with($this->equalTo('SELECT COUNT(*) as "count" FROM (SELECT XXX)')); $count = $this->rowCounter->getCountForStatement($statement); self::assertEquals(5, $count); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getCountForSql */ public function testGetCountForSql() { $this->rowCounter->setDriver($this->getMockDriver(5)); $count = $this->rowCounter->getCountForSql('SELECT XXX'); self::assertEquals(5, $count); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\SqliteRowCounter::getRowCountClosure */ public function testGetRowCountClosure() { $stmt = $this->getMockStatement('SELECT XXX', 5); /** @var Closure $closure */ $closure = $this->rowCounter->getRowCountClosure($stmt); self::assertInstanceOf('Closure', $closure); self::assertEquals(5, $closure()); } /** * @param string $sql * @param mixed $returnValue * @return Statement&MockObject */ protected function getMockStatement($sql, $returnValue) { /** @var Statement|MockObject $statement */ $statement = $this->getMockBuilder(Statement::class) ->setMethods(['prepare', 'execute']) ->disableOriginalConstructor() ->getMock(); // mock PDOStatement with stdClass $resource = $this->getMockBuilder('stdClass') ->setMethods(['fetch']) ->getMock(); $resource->expects($this->once()) ->method('fetch') ->will($this->returnValue(['count' => $returnValue])); // mock the result $result = $this->getMockBuilder(ResultInterface::class)->getMock(); $result->expects($this->once()) ->method('getResource') ->will($this->returnValue($resource)); $statement->setSql($sql); $statement->expects($this->once()) ->method('execute') ->will($this->returnValue($result)); return $statement; } /** * @param mixed $returnValue * @return Pdo&MockObject */ protected function getMockDriver($returnValue) { $pdoStatement = $this->getMockBuilder('stdClass') ->setMethods(['fetch']) ->disableOriginalConstructor() ->getMock(); // stdClass can be used here $pdoStatement->expects($this->once()) ->method('fetch') ->will($this->returnValue(['count' => $returnValue])); $pdoConnection = $this->getMockBuilder('stdClass') ->setMethods(['query']) ->getMock(); $pdoConnection->expects($this->once()) ->method('query') ->will($this->returnValue($pdoStatement)); $connection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $connection->expects($this->once()) ->method('getResource') ->will($this->returnValue($pdoConnection)); $driver = $this->getMockBuilder(Pdo::class) ->setMethods(['getConnection']) ->disableOriginalConstructor() ->getMock(); $driver->expects($this->once()) ->method('getConnection') ->will($this->returnValue($connection)); return $driver; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php
test/unit/Adapter/Driver/Pdo/Feature/OracleRowCounterTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pdo\Feature; use Closure; use Laminas\Db\Adapter\Driver\ConnectionInterface; use Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter; use Laminas\Db\Adapter\Driver\Pdo\Pdo; use Laminas\Db\Adapter\Driver\Pdo\Statement; use Laminas\Db\Adapter\Driver\ResultInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class OracleRowCounterTest extends TestCase { /** @var OracleRowCounter */ protected $rowCounter; protected function setUp(): void { $this->rowCounter = new OracleRowCounter(); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getName */ public function testGetName() { self::assertEquals('OracleRowCounter', $this->rowCounter->getName()); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getCountForStatement */ public function testGetCountForStatement() { $statement = $this->getMockStatement('SELECT XXX', 5); $statement->expects($this->once())->method('prepare') ->with($this->equalTo('SELECT COUNT(*) as "count" FROM (SELECT XXX)')); $count = $this->rowCounter->getCountForStatement($statement); self::assertEquals(5, $count); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getCountForSql */ public function testGetCountForSql() { $this->rowCounter->setDriver($this->getMockDriver(5)); $count = $this->rowCounter->getCountForSql('SELECT XXX'); self::assertEquals(5, $count); } /** * @covers \Laminas\Db\Adapter\Driver\Pdo\Feature\OracleRowCounter::getRowCountClosure */ public function testGetRowCountClosure() { $stmt = $this->getMockStatement('SELECT XXX', 5); /** @var Closure $closure */ $closure = $this->rowCounter->getRowCountClosure($stmt); self::assertInstanceOf('Closure', $closure); self::assertEquals(5, $closure()); } /** * @param mixed $returnValue * @return Statement&MockObject */ protected function getMockStatement(string $sql, $returnValue) { /** @var Statement|MockObject $statement */ $statement = $this->getMockBuilder(Statement::class) ->setMethods(['prepare', 'execute']) ->disableOriginalConstructor() ->getMock(); // mock PDOStatement with stdClass $resource = $this->getMockBuilder('stdClass') ->setMethods(['fetch']) ->getMock(); $resource->expects($this->once()) ->method('fetch') ->will($this->returnValue(['count' => $returnValue])); // mock the result $result = $this->getMockBuilder(ResultInterface::class)->getMock(); $result->expects($this->once()) ->method('getResource') ->will($this->returnValue($resource)); $statement->setSql($sql); $statement->expects($this->once()) ->method('execute') ->will($this->returnValue($result)); return $statement; } /** * @param mixed $returnValue * @return Pdo&MockObject */ protected function getMockDriver($returnValue) { $pdoStatement = $this->getMockBuilder('stdClass') ->setMethods(['fetch']) ->disableOriginalConstructor() ->getMock(); // stdClass can be used here $pdoStatement->expects($this->once()) ->method('fetch') ->will($this->returnValue(['count' => $returnValue])); $pdoConnection = $this->getMockBuilder('stdClass') ->setMethods(['query']) ->getMock(); $pdoConnection->expects($this->once()) ->method('query') ->will($this->returnValue($pdoStatement)); $connection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $connection->expects($this->once()) ->method('getResource') ->will($this->returnValue($pdoConnection)); $driver = $this->getMockBuilder(Pdo::class) ->setMethods(['getConnection']) ->disableOriginalConstructor() ->getMock(); $driver->expects($this->once()) ->method('getConnection') ->will($this->returnValue($connection)); return $driver; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php
test/unit/Adapter/Driver/IbmDb2/AbstractIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\IbmDb2; use PHPUnit\Framework\TestCase; use function extension_loaded; use function getenv; abstract class AbstractIntegrationTest extends TestCase { /** @var array */ protected $variables = [ 'database' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_DATABASE', 'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_USERNAME', 'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_PASSWORD', ]; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { foreach ($this->variables as $name => $value) { if (! getenv($value)) { $this->markTestSkipped( 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' ); } $this->variables[$name] = getenv($value); } if (! extension_loaded('ibm_db2')) { $this->fail('The phpunit group integration-ibm_db2 was enabled, but the extension is not loaded.'); } } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/StatementTest.php
test/unit/Adapter/Driver/IbmDb2/StatementTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Statement; use Laminas\Db\Adapter\Exception\RuntimeException; use Laminas\Db\Adapter\ParameterContainer; use PHPUnit\Framework\TestCase; use function error_reporting; include __DIR__ . '/TestAsset/Db2Functions.php'; class StatementTest extends TestCase { /** @var Statement */ protected $statement; /** @var int */ protected $currentErrorReporting; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { // store current error_reporting value as we may change it // in a test $this->currentErrorReporting = error_reporting(); $this->statement = new Statement(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { // ensure error_reporting is set back to correct value error_reporting($this->currentErrorReporting); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setDriver */ public function testSetDriver() { self::assertEquals($this->statement, $this->statement->setDriver(new IbmDb2([]))); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setParameterContainer */ public function testSetParameterContainer() { self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer())); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::getParameterContainer * @todo Implement testGetParameterContainer(). */ public function testGetParameterContainer() { $container = new ParameterContainer(); $this->statement->setParameterContainer($container); self::assertSame($container, $this->statement->getParameterContainer()); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::getResource * @todo Implement testGetResource(). */ public function testGetResource() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setSql * @todo Implement testSetSql(). */ public function testSetSql() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::getSql * @todo Implement testGetSql(). */ public function testGetSql() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::isPrepared */ public function testPrepare() { $sql = "SELECT 'foo' FROM SYSIBM.SYSDUMMY1"; $this->statement->prepare($sql); $this->assertTrue($this->statement->isPrepared()); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::isPrepared */ public function testPreparingTwiceErrors() { $sql = "SELECT 'foo' FROM SYSIBM.SYSDUMMY1"; $this->statement->prepare($sql); $this->assertTrue($this->statement->isPrepared()); $this->expectException( RuntimeException::class, 'This statement has been prepared already' ); $this->statement->prepare($sql); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setSql */ public function testPrepareThrowsRuntimeExceptionOnInvalidSql() { $sql = "INVALID SQL"; $this->statement->setSql($sql); $this->expectException( RuntimeException::class, 'SQL is invalid. Error message' ); $this->statement->prepare(); } /** * If error_reporting() is turned off, then the error handler will not * be called, but a RuntimeException will still be generated as the * resource is false * * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::setSql */ public function testPrepareThrowsRuntimeExceptionOnInvalidSqlWithErrorReportingDisabled() { error_reporting(0); $sql = "INVALID SQL"; $this->statement->setSql($sql); $this->expectException( RuntimeException::class, 'Error message' ); $this->statement->prepare(); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::execute * @todo Implement testExecute(). */ public function testExecute() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php
test/unit/Adapter/Driver/IbmDb2/ResultIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Result; use PHPUnit\Framework\TestCase; /** * @group integration * @group integration-ibm_db2 */ class ResultIntegrationTest extends TestCase { /** @var Result */ protected $object; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->object = new Result(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::initialize * @todo Implement testInitialize(). */ public function testInitialize() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::buffer * @todo Implement testBuffer(). */ public function testBuffer() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::getResource * @todo Implement testGetResource(). */ public function testGetResource() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::current * @todo Implement testCurrent(). */ public function testCurrent() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::next * @todo Implement testNext(). */ public function testNext() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::key * @todo Implement testKey(). */ public function testKey() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::rewind * @todo Implement testRewind(). */ public function testRewind() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::valid * @todo Implement testValid(). */ public function testValid() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::count * @todo Implement testCount(). */ public function testCount() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::getFieldCount * @todo Implement testGetFieldCount(). */ public function testGetFieldCount() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::isQueryResult * @todo Implement testIsQueryResult(). */ public function testIsQueryResult() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::getAffectedRows * @todo Implement testGetAffectedRows(). */ public function testGetAffectedRows() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Result::getGeneratedValue * @todo Implement testGetGeneratedValue(). */ public function testGetGeneratedValue() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php
test/unit/Adapter/Driver/IbmDb2/ConnectionTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Connection; use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2; use PHPUnit\Framework\TestCase; class ConnectionTest extends TestCase { /** @var Connection */ protected $connection; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->connection = new Connection([]); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::setDriver */ public function testSetDriver() { self::assertEquals($this->connection, $this->connection->setDriver(new IbmDb2([]))); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::setConnectionParameters */ public function testSetConnectionParameters() { self::assertEquals($this->connection, $this->connection->setConnectionParameters([])); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::getConnectionParameters */ public function testGetConnectionParameters() { $this->connection->setConnectionParameters(['foo' => 'bar']); self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php
test/unit/Adapter/Driver/IbmDb2/ConnectionIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Connection; use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Result; use function ini_get; use function php_uname; /** * @group integration * @group integration-ibm_db2 */ class ConnectionIntegrationTest extends AbstractIntegrationTest { /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::getCurrentSchema */ public function testGetCurrentSchema() { $connection = new Connection($this->variables); self::assertInternalType('string', $connection->getCurrentSchema()); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::setResource */ public function testSetResource() { $resource = db2_connect( $this->variables['database'], $this->variables['username'], $this->variables['password'] ); $connection = new Connection([]); self::assertSame($connection, $connection->setResource($resource)); $connection->disconnect(); unset($connection); unset($resource); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::getResource */ public function testGetResource() { $connection = new Connection($this->variables); $connection->connect(); self::assertInternalType('resource', $connection->getResource()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::connect */ public function testConnect() { $connection = new Connection($this->variables); self::assertSame($connection, $connection->connect()); self::assertTrue($connection->isConnected()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::isConnected */ public function testIsConnected() { $connection = new Connection($this->variables); self::assertFalse($connection->isConnected()); self::assertSame($connection, $connection->connect()); self::assertTrue($connection->isConnected()); $connection->disconnect(); unset($connection); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::disconnect */ public function testDisconnect() { $connection = new Connection($this->variables); $connection->connect(); self::assertTrue($connection->isConnected()); $connection->disconnect(); self::assertFalse($connection->isConnected()); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::beginTransaction */ public function testBeginTransaction() { if (! $this->isTransactionEnabled()) { $this->markTestIncomplete( 'I cannot test without the DB2 transactions enabled' ); } $connection = new Connection($this->variables); $connection->beginTransaction(); self::assertTrue($connection->inTransaction()); self::assertEquals(0, db2_autocommit($connection->getResource())); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::commit */ public function testCommit() { if (! $this->isTransactionEnabled()) { $this->markTestIncomplete( 'I cannot test without the DB2 transactions enabled' ); } $connection = new Connection($this->variables); $connection->beginTransaction(); $oldValue = db2_autocommit($connection->getResource()); $connection->beginTransaction(); self::assertTrue($connection->inTransaction()); $connection->commit(); self::assertFalse($connection->inTransaction()); self::assertEquals($oldValue, db2_autocommit($connection->getResource())); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::rollback */ public function testRollback() { if (! $this->isTransactionEnabled()) { $this->markTestIncomplete( 'I cannot test without the DB2 transactions enabled' ); } $connection = new Connection($this->variables); $connection->beginTransaction(); $oldValue = db2_autocommit($connection->getResource()); $connection->beginTransaction(); self::assertTrue($connection->inTransaction()); $connection->rollback(); self::assertFalse($connection->inTransaction()); self::assertEquals($oldValue, db2_autocommit($connection->getResource())); } /** * Return true if the transaction is enabled for DB2 * * @return bool */ protected function isTransactionEnabled() { $os = php_uname('s') === 'OS400'; if ($os) { return ini_get('ibm_db2.i5_allow_commit') === 1; } return true; } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::execute */ public function testExecute() { $ibmdb2 = new IbmDb2($this->variables); $connection = $ibmdb2->getConnection(); $result = $connection->execute('SELECT \'foo\' FROM SYSIBM.SYSDUMMY1'); self::assertInstanceOf(Result::class, $result); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Connection::getLastGeneratedValue */ public function testGetLastGeneratedValue() { $this->markTestIncomplete('Need to create a temporary sequence.'); $connection = new Connection($this->variables); $connection->getLastGeneratedValue(); } /** * @group laminas3469 */ public function testConnectReturnsConnectionWhenResourceSet() { $resource = db2_connect( $this->variables['database'], $this->variables['username'], $this->variables['password'] ); $connection = new Connection([]); $connection->setResource($resource); self::assertSame($connection, $connection->connect()); $connection->disconnect(); unset($connection); unset($resource); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php
test/unit/Adapter/Driver/IbmDb2/IbmDb2Test.php
<?php namespace LaminasTest\Db\Adapter\Driver\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Connection; use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Result; use Laminas\Db\Adapter\Driver\IbmDb2\Statement; use PHPUnit\Framework\TestCase; class IbmDb2Test extends TestCase { /** @var IbmDb2 */ protected $ibmdb2; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->ibmdb2 = new IbmDb2([]); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::registerConnection */ public function testRegisterConnection() { $mockConnection = $this->getMockForAbstractClass( Connection::class, [[]], '', true, true, true, ['setDriver'] ); $mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->ibmdb2)); self::assertSame($this->ibmdb2, $this->ibmdb2->registerConnection($mockConnection)); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::registerStatementPrototype */ public function testRegisterStatementPrototype() { $this->ibmdb2 = new IbmDb2([]); $mockStatement = $this->getMockForAbstractClass( Statement::class, [], '', true, true, true, ['setDriver'] ); $mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->ibmdb2)); self::assertSame($this->ibmdb2, $this->ibmdb2->registerStatementPrototype($mockStatement)); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::registerResultPrototype */ public function testRegisterResultPrototype() { $this->ibmdb2 = new IbmDb2([]); $mockStatement = $this->getMockForAbstractClass( Result::class, [], '', true, true, true, ['setDriver'] ); self::assertSame($this->ibmdb2, $this->ibmdb2->registerResultPrototype($mockStatement)); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getDatabasePlatformName */ public function testGetDatabasePlatformName() { $this->ibmdb2 = new IbmDb2([]); self::assertEquals('IbmDb2', $this->ibmdb2->getDatabasePlatformName()); self::assertEquals('IBM DB2', $this->ibmdb2->getDatabasePlatformName(IbmDb2::NAME_FORMAT_NATURAL)); } /** * @depends testRegisterConnection * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getConnection */ public function testGetConnection() { $conn = new Connection([]); $this->ibmdb2->registerConnection($conn); self::assertSame($conn, $this->ibmdb2->getConnection()); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::createStatement * @todo Implement testGetPrepareType(). */ public function testCreateStatement() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::createResult * @todo Implement testGetPrepareType(). */ public function testCreateResult() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getPrepareType * @todo Implement testGetPrepareType(). */ public function testGetPrepareType() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::formatParameterName * @todo Implement testFormatParameterName(). */ public function testFormatParameterName() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getLastGeneratedValue * @todo Implement testGetLastGeneratedValue(). */ public function testGetLastGeneratedValue() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::getResultPrototype */ public function testGetResultPrototype() { $resultPrototype = $this->ibmdb2->getResultPrototype(); self::assertInstanceOf(Result::class, $resultPrototype); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php
test/unit/Adapter/Driver/IbmDb2/IbmDb2IntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Statement; use Laminas\Db\Adapter\Exception\InvalidArgumentException; use stdClass; /** * @group integration * @group integration-ibm_db2 */ class IbmDb2IntegrationTest extends AbstractIntegrationTest { /** * @group integration-ibm_db2 * @covers \Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2::checkEnvironment */ public function testCheckEnvironment() { $ibmdb2 = new IbmDb2([]); self::assertNull($ibmdb2->checkEnvironment()); } public function testCreateStatement() { $driver = new IbmDb2([]); $resource = db2_connect( $this->variables['database'], $this->variables['username'], $this->variables['password'] ); $stmtResource = db2_prepare($resource, 'SELECT 1 FROM SYSIBM.SYSDUMMY1'); $driver->getConnection()->setResource($resource); $stmt = $driver->createStatement('SELECT 1 FROM SYSIBM.SYSDUMMY1'); self::assertInstanceOf(Statement::class, $stmt); $stmt = $driver->createStatement($stmtResource); self::assertInstanceOf(Statement::class, $stmt); $stmt = $driver->createStatement(); self::assertInstanceOf(Statement::class, $stmt); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('only accepts an SQL string or an ibm_db2 resource'); $driver->createStatement(new stdClass()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php
test/unit/Adapter/Driver/IbmDb2/StatementIntegrationTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\IbmDb2; use Laminas\Db\Adapter\Driver\IbmDb2\Result; use Laminas\Db\Adapter\Driver\IbmDb2\Statement; use Laminas\Db\Adapter\Exception\RuntimeException; use PHPUnit\Framework\TestCase; use function extension_loaded; use function get_resource_type; use function getenv; /** * @group integration * @group integration-ibm_db2 */ class StatementIntegrationTest extends TestCase { /** @var array<string, string> */ protected $variables = [ 'database' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_DATABASE', 'username' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_USERNAME', 'password' => 'TESTS_LAMINAS_DB_ADAPTER_DRIVER_IBMDB2_PASSWORD', ]; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { foreach ($this->variables as $name => $value) { if (! getenv($value)) { $this->markTestSkipped( 'Missing required variable ' . $value . ' from phpunit.xml for this integration test' ); } $this->variables[$name] = getenv($value); } if (! extension_loaded('ibm_db2')) { $this->fail('The phpunit group integration-ibm_db2 was enabled, but the extension is not loaded.'); } } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::initialize */ public function testInitialize() { $db2Resource = db2_connect( $this->variables['database'], $this->variables['username'], $this->variables['password'] ); $statement = new Statement(); self::assertSame($statement, $statement->initialize($db2Resource)); unset($stmtResource, $db2Resource); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::getResource */ public function testGetResource() { $db2Resource = db2_connect( $this->variables['database'], $this->variables['username'], $this->variables['password'] ); $statement = new Statement(); $statement->initialize($db2Resource); $statement->prepare("SELECT 'foo' FROM sysibm.sysdummy1"); $resource = $statement->getResource(); self::assertEquals('DB2 Statement', get_resource_type($resource)); unset($resource, $db2Resource); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::isPrepared */ public function testPrepare() { $db2Resource = db2_connect( $this->variables['database'], $this->variables['username'], $this->variables['password'] ); $statement = new Statement(); $statement->initialize($db2Resource); self::assertFalse($statement->isPrepared()); self::assertSame($statement, $statement->prepare("SELECT 'foo' FROM SYSIBM.SYSDUMMY1")); self::assertTrue($statement->isPrepared()); unset($resource, $db2Resource); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::prepare */ public function testPrepareThrowsAnExceptionOnFailure() { $db2Resource = db2_connect( $this->variables['database'], $this->variables['username'], $this->variables['password'] ); $statement = new Statement(); $statement->initialize($db2Resource); $this->expectException(RuntimeException::class); $statement->prepare("SELECT"); } /** * @covers \Laminas\Db\Adapter\Driver\IbmDb2\Statement::execute */ public function testExecute() { $ibmdb2 = new IbmDb2($this->variables); $statement = $ibmdb2->createStatement("SELECT 'foo' FROM SYSIBM.SYSDUMMY1"); self::assertSame($statement, $statement->prepare()); $result = $statement->execute(); self::assertInstanceOf(Result::class, $result); unset($resource, $ibmdb2); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php
test/unit/Adapter/Driver/IbmDb2/TestAsset/Db2Functions.php
<?php namespace Laminas\Db\Adapter\Driver\IbmDb2; use function is_string; use function trigger_error; use const E_USER_WARNING; /** * Mock db2_prepare by placing in same namespace as Statement * * Return false if $sql is "invalid sql", otherwise return true * * @param resource $connection * @param string $sql * @param array $options * @return bool */ function db2_prepare($connection, $sql, $options = []) { if ($sql === 'INVALID SQL') { // db2_prepare issues a warning with invalid SQL trigger_error("SQL is invalid", E_USER_WARNING); return false; } return true; } /** * Mock db2_stmt_errormsg * * If you pass a string to $stmt, it will be returned to you * * @param mixed $stmt * @return string */ function db2_stmt_errormsg($stmt = null) { if (is_string($stmt)) { return $stmt; } return 'Error message'; } /** * Mock db2_stmt_error * * If you pass a string to $stmt, it will be returned to you * * @param mixed $stmt * @return string */ function db2_stmt_error($stmt = null) { if (is_string($stmt)) { return $stmt; } return '1'; }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Mysqli/ConnectionTest.php
test/unit/Adapter/Driver/Mysqli/ConnectionTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Mysqli; use Laminas\Db\Adapter\Driver\Mysqli\Connection; use Laminas\Db\Adapter\Driver\Mysqli\Mysqli; use Laminas\Db\Adapter\Exception\RuntimeException; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function getenv; use const MYSQLI_CLIENT_SSL; use const MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT; class ConnectionTest extends TestCase { /** @var Connection */ protected $connection; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { if (! getenv('TESTS_LAMINAS_DB_ADAPTER_DRIVER_MYSQL')) { $this->markTestSkipped('Mysqli test disabled'); } $this->connection = new Connection([]); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Adapter\Driver\Mysqli\Connection::setDriver */ public function testSetDriver() { self::assertEquals($this->connection, $this->connection->setDriver(new Mysqli([]))); } /** * @covers \Laminas\Db\Adapter\Driver\Mysqli\Connection::setConnectionParameters */ public function testSetConnectionParameters() { self::assertEquals($this->connection, $this->connection->setConnectionParameters([])); } /** * @covers \Laminas\Db\Adapter\Driver\Mysqli\Connection::getConnectionParameters */ public function testGetConnectionParameters() { $this->connection->setConnectionParameters(['foo' => 'bar']); self::assertEquals(['foo' => 'bar'], $this->connection->getConnectionParameters()); } public function testNonSecureConnection() { $mysqli = $this->createMockMysqli(0); $connection = $this->createMockConnection( $mysqli, [ 'hostname' => 'localhost', 'username' => 'superuser', 'password' => '1234', 'database' => 'main', 'port' => 123, ] ); $connection->connect(); } public function testSslConnection() { $mysqli = $this->createMockMysqli(MYSQLI_CLIENT_SSL); $connection = $this->createMockConnection( $mysqli, [ 'hostname' => 'localhost', 'username' => 'superuser', 'password' => '1234', 'database' => 'main', 'port' => 123, 'use_ssl' => true, ] ); $connection->connect(); } public function testSslConnectionNoVerify() { $mysqli = $this->createMockMysqli(MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT); $connection = $this->createMockConnection( $mysqli, [ 'hostname' => 'localhost', 'username' => 'superuser', 'password' => '1234', 'database' => 'main', 'port' => 123, 'use_ssl' => true, 'driver_options' => [ MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT => true, ], ] ); $connection->connect(); } public function testConnectionFails() { $connection = new Connection([]); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Connection error'); $connection->connect(); } /** * Create a mock mysqli * * @param int $flags Expected flags to real_connect * @return MockObject */ protected function createMockMysqli($flags) { $mysqli = $this->getMockBuilder(\mysqli::class)->getMock(); $mysqli->expects($flags ? $this->once() : $this->never()) ->method('ssl_set') ->with( $this->equalTo(''), $this->equalTo(''), $this->equalTo(''), $this->equalTo(''), $this->equalTo('') ); if ($flags === 0) { // Do not pass $flags argument if invalid flags provided $mysqli->expects($this->once()) ->method('real_connect') ->with( $this->equalTo('localhost'), $this->equalTo('superuser'), $this->equalTo('1234'), $this->equalTo('main'), $this->equalTo(123), $this->equalTo('') ) ->willReturn(true); return $mysqli; } $mysqli->expects($this->once()) ->method('real_connect') ->with( $this->equalTo('localhost'), $this->equalTo('superuser'), $this->equalTo('1234'), $this->equalTo('main'), $this->equalTo(123), $this->equalTo(''), $this->equalTo($flags) ) ->willReturn(true); return $mysqli; } /** * Create a mock connection * * @param MockObject $mysqli Mock mysqli object * @param array $params Connection params * @return MockObject */ protected function createMockConnection($mysqli, $params) { $connection = $this->getMockBuilder(Connection::class) ->setMethods(['createResource']) ->setConstructorArgs([$params]) ->getMock(); $connection->expects($this->once()) ->method('createResource') ->willReturn($mysqli); return $connection; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pgsql/ConnectionTest.php
test/unit/Adapter/Driver/Pgsql/ConnectionTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pgsql; use Laminas\Db\Adapter\Driver\Pgsql\Connection; use Laminas\Db\Adapter\Exception as AdapterException; use Laminas\Db\Adapter\Exception\InvalidArgumentException; use Laminas\Db\Adapter\Exception\RuntimeException; use LaminasTest\Db\DeprecatedAssertionsTrait; use PHPUnit\Framework\TestCase; use ReflectionMethod; use function extension_loaded; use function pg_client_encoding; use const PGSQL_CONNECT_FORCE_NEW; class ConnectionTest extends TestCase { use DeprecatedAssertionsTrait; /** @var Connection */ protected $connection; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->connection = new Connection(); } /** * Test getResource method if it tries to connect to the database. * * @covers \Laminas\Db\Adapter\Driver\Pgsql\Connection::getResource */ public function testResourceInvalid() { if (! extension_loaded('pgsql')) { $this->markTestSkipped('pgsql extension not loaded'); } // invalid port should lead to the custom error handler throwing $conn = new Connection(['socket' => '127.0.0.1', 'port' => 65112]); try { $resource = $conn->getResource(); $this->fail('should throw'); } catch (AdapterException\RuntimeException $exc) { $this->assertSame( 'Laminas\Db\Adapter\Driver\Pgsql\Connection::connect: Unable to connect to database', $exc->getMessage() ); } } /** * Test getResource method if it tries to connect to the database. * * @covers \Laminas\Db\Adapter\Driver\Pgsql\Connection::getResource */ public function testResource() { if (! extension_loaded('pgsql')) { $this->markTestSkipped('pgsql extension not loaded'); } try { $resource = $this->connection->getResource(); // connected with empty string self::assertIsResource($resource); } catch (AdapterException\RuntimeException $exc) { // If it throws an exception it has failed to connect $this->expectException(RuntimeException::class); throw $exc; } } /** * Test disconnect method to return instance of ConnectionInterface */ public function testDisconnect() { include_once 'pgsqlMockFunctions.php'; self::assertSame($this->connection, $this->connection->disconnect()); } /** * @group 6760 * @group 6787 */ public function testGetConnectionStringEncodeSpecialSymbol() { $connectionParameters = [ 'driver' => 'pgsql', 'host' => 'localhost', 'post' => '5432', 'dbname' => 'test', 'username' => 'test', 'password' => 'test123!', ]; $this->connection->setConnectionParameters($connectionParameters); $getConnectionString = new ReflectionMethod( Connection::class, 'getConnectionString' ); $getConnectionString->setAccessible(true); self::assertEquals( 'host=localhost user=test password=test123! dbname=test', $getConnectionString->invoke($this->connection) ); } public function testSetConnectionTypeException() { if (! extension_loaded('pgsql')) { $this->markTestSkipped('pgsql extension not loaded'); } $this->expectException(InvalidArgumentException::class); $this->connection->setType(3); } /** * Test the connection type setter */ public function testSetConnectionType() { if (! extension_loaded('pgsql')) { $this->markTestSkipped('pgsql extension not loaded'); } $type = PGSQL_CONNECT_FORCE_NEW; $this->connection->setType($type); self::assertEquals($type, self::readAttribute($this->connection, 'type')); } /** * @runInSeparateProcess */ public function testSetCharset() { if (! extension_loaded('pgsql')) { $this->markTestSkipped('pgsql extension not loaded'); } $this->connection->setConnectionParameters([ 'driver' => 'pgsql', 'host' => 'localhost', 'post' => '5432', 'dbname' => 'laminasdb_test', 'username' => 'postgres', 'password' => 'postgres', 'charset' => 'SQL_ASCII', ]); try { $this->connection->connect(); } catch (AdapterException\RuntimeException $e) { $this->markTestSkipped('Skipping pgsql charset test due to inability to connecto to database'); } self::assertEquals('SQL_ASCII', pg_client_encoding($this->connection->getResource())); } /** * @runInSeparateProcess */ public function testSetInvalidCharset() { if (! extension_loaded('pgsql')) { $this->markTestSkipped('pgsql extension not loaded'); } $this->expectException(RuntimeException::class); $this->connection->setConnectionParameters([ 'driver' => 'pgsql', 'host' => 'localhost', 'post' => '5432', 'dbname' => 'laminasdb_test', 'username' => 'postgres', 'password' => 'postgres', 'charset' => 'FOOBAR', ]); $this->connection->connect(); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php
test/unit/Adapter/Driver/Pgsql/pgsqlMockFunctions.php
<?php namespace Laminas\Db\Adapter\Driver\Pgsql; /** * Closes a PostgreSQL connection * * @see http://php.net/manual/en/function.pg-close.php * * @param resource $connection * @return bool */ function pg_close($connection = null) { return true; }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Driver/Pgsql/PgsqlTest.php
test/unit/Adapter/Driver/Pgsql/PgsqlTest.php
<?php namespace LaminasTest\Db\Adapter\Driver\Pgsql; use Laminas\Db\Adapter\Driver\Pgsql\Connection; use Laminas\Db\Adapter\Driver\Pgsql\Pgsql; use Laminas\Db\Adapter\Driver\Pgsql\Result; use Laminas\Db\Adapter\Driver\Pgsql\Statement; use Laminas\Db\Adapter\Exception\RuntimeException; use PHPUnit\Framework\TestCase; use function extension_loaded; class PgsqlTest extends TestCase { /** @var Pgsql */ protected $pgsql; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->pgsql = new Pgsql([]); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::checkEnvironment */ public function testCheckEnvironment() { if (! extension_loaded('pgsql')) { $this->expectException(RuntimeException::class); } $this->pgsql->checkEnvironment(); self::assertTrue(true, 'No exception was thrown'); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::registerConnection */ public function testRegisterConnection() { $mockConnection = $this->getMockForAbstractClass( Connection::class, [[]], '', true, true, true, ['setDriver'] ); $mockConnection->expects($this->once())->method('setDriver')->with($this->equalTo($this->pgsql)); self::assertSame($this->pgsql, $this->pgsql->registerConnection($mockConnection)); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::registerStatementPrototype */ public function testRegisterStatementPrototype() { $this->pgsql = new Pgsql([]); $mockStatement = $this->getMockForAbstractClass( Statement::class, [], '', true, true, true, ['setDriver'] ); $mockStatement->expects($this->once())->method('setDriver')->with($this->equalTo($this->pgsql)); self::assertSame($this->pgsql, $this->pgsql->registerStatementPrototype($mockStatement)); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::registerResultPrototype */ public function testRegisterResultPrototype() { $this->pgsql = new Pgsql([]); $mockStatement = $this->getMockForAbstractClass( Result::class, [], '', true, true, true, ['setDriver'] ); self::assertSame($this->pgsql, $this->pgsql->registerResultPrototype($mockStatement)); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getDatabasePlatformName */ public function testGetDatabasePlatformName() { $this->pgsql = new Pgsql([]); self::assertEquals('Postgresql', $this->pgsql->getDatabasePlatformName()); self::assertEquals('PostgreSQL', $this->pgsql->getDatabasePlatformName(Pgsql::NAME_FORMAT_NATURAL)); } /** * @depends testRegisterConnection * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getConnection */ public function testGetConnection() { $conn = new Connection([]); $this->pgsql->registerConnection($conn); self::assertSame($conn, $this->pgsql->getConnection()); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::createStatement * @todo Implement testGetPrepareType(). */ public function testCreateStatement() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::createResult * @todo Implement testGetPrepareType(). */ public function testCreateResult() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getPrepareType * @todo Implement testGetPrepareType(). */ public function testGetPrepareType() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::formatParameterName * @todo Implement testFormatParameterName(). */ public function testFormatParameterName() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getLastGeneratedValue * @todo Implement testGetLastGeneratedValue(). */ public function testGetLastGeneratedValue() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } /** * @covers \Laminas\Db\Adapter\Driver\Pgsql\Pgsql::getResultPrototype */ public function testGetResultPrototype() { $resultPrototype = $this->pgsql->getResultPrototype(); self::assertInstanceOf(Result::class, $resultPrototype); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Profiler/ProfilerTest.php
test/unit/Adapter/Profiler/ProfilerTest.php
<?php namespace LaminasTest\Db\Adapter\Profiler; use Laminas\Db\Adapter\Exception\InvalidArgumentException; use Laminas\Db\Adapter\Exception\RuntimeException; use Laminas\Db\Adapter\Profiler\Profiler; use Laminas\Db\Adapter\StatementContainer; use PHPUnit\Framework\TestCase; class ProfilerTest extends TestCase { /** @var Profiler */ protected $profiler; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->profiler = new Profiler(); } /** * @covers \Laminas\Db\Adapter\Profiler\Profiler::profilerStart */ public function testProfilerStart() { $ret = $this->profiler->profilerStart('SELECT * FROM FOO'); self::assertSame($this->profiler, $ret); $ret = $this->profiler->profilerStart(new StatementContainer()); self::assertSame($this->profiler, $ret); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('profilerStart takes either a StatementContainer or a string'); $this->profiler->profilerStart(5); } /** * @covers \Laminas\Db\Adapter\Profiler\Profiler::profilerFinish */ public function testProfilerFinish() { $this->profiler->profilerStart('SELECT * FROM FOO'); $ret = $this->profiler->profilerFinish(); self::assertSame($this->profiler, $ret); $profiler = new Profiler(); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('A profile must be started before profilerFinish can be called'); $profiler->profilerFinish(); } /** * @covers \Laminas\Db\Adapter\Profiler\Profiler::getLastProfile */ public function testGetLastProfile() { $this->profiler->profilerStart('SELECT * FROM FOO'); $this->profiler->profilerFinish(); $profile = $this->profiler->getLastProfile(); self::assertEquals('SELECT * FROM FOO', $profile['sql']); self::assertNull($profile['parameters']); self::assertIsFloat($profile['start']); self::assertIsFloat($profile['end']); self::assertIsFloat($profile['elapse']); } /** * @covers \Laminas\Db\Adapter\Profiler\Profiler::getProfiles */ public function testGetProfiles() { $this->profiler->profilerStart('SELECT * FROM FOO1'); $this->profiler->profilerFinish(); $this->profiler->profilerStart('SELECT * FROM FOO2'); $this->profiler->profilerFinish(); self::assertCount(2, $this->profiler->getProfiles()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/TestAsset/ConcreteAdapterAwareObject.php
test/unit/Adapter/TestAsset/ConcreteAdapterAwareObject.php
<?php namespace LaminasTest\Db\Adapter\TestAsset; use Laminas\Db\Adapter\AdapterAwareInterface; use Laminas\Db\Adapter\AdapterAwareTrait; use Laminas\Db\Adapter\AdapterInterface; class ConcreteAdapterAwareObject implements AdapterAwareInterface { use AdapterAwareTrait; /** @var array */ private $options; public function __construct(array $options = []) { $this->options = $options; } public function getAdapter(): ?AdapterInterface { return $this->adapter; } public function getOptions(): array { return $this->options; } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Platform/Sql92Test.php
test/unit/Adapter/Platform/Sql92Test.php
<?php namespace LaminasTest\Db\Adapter\Platform; use Laminas\Db\Adapter\Platform\Sql92; use PHPUnit\Framework\TestCase; class Sql92Test extends TestCase { /** @var Sql92 */ protected $platform; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->platform = new Sql92(); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::getName */ public function testGetName() { self::assertEquals('SQL92', $this->platform->getName()); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::getQuoteIdentifierSymbol */ public function testGetQuoteIdentifierSymbol() { self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteIdentifier */ public function testQuoteIdentifier() { self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteIdentifierChain */ public function testQuoteIdentifierChain() { self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::getQuoteValueSymbol */ public function testGetQuoteValueSymbol() { self::assertEquals("'", $this->platform->getQuoteValueSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteValue */ public function testQuoteValueRaisesNoticeWithoutPlatformSupport() { $this->expectNotice(); $this->expectNoticeMessage( 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities ' . 'in a production environment.' ); $this->platform->quoteValue('value'); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteValue */ public function testQuoteValue() { self::assertEquals("'value'", @$this->platform->quoteValue('value')); self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar")); self::assertEquals( '\'\\\'; DELETE FROM some_table; -- \'', @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') ); self::assertEquals( "'\\\\\\'; DELETE FROM some_table; -- '", @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteTrustedValue */ public function testQuoteTrustedValue() { self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); self::assertEquals( '\'\\\'; DELETE FROM some_table; -- \'', $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') ); // '\\\'; DELETE FROM some_table; -- ' <- actual below self::assertEquals( "'\\\\\\'; DELETE FROM some_table; -- '", $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteValueList */ public function testQuoteValueList() { $this->expectError(); $this->expectErrorMessage( 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities ' . 'in a production environment.' ); self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::getIdentifierSeparator */ public function testGetIdentifierSeparator() { self::assertEquals('.', $this->platform->getIdentifierSeparator()); } /** * @covers \Laminas\Db\Adapter\Platform\Sql92::quoteIdentifierInFragment */ public function testQuoteIdentifierInFragment() { self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); // single char words self::assertEquals( '("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) ); // case insensitive safe words self::assertEquals( '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and'] ) ); // case insensitive safe words in field self::assertEquals( '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and', 'bAz'] ) ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Platform/SqliteTest.php
test/unit/Adapter/Platform/SqliteTest.php
<?php namespace LaminasTest\Db\Adapter\Platform; use Laminas\Db\Adapter\Driver\Pdo\Pdo; use Laminas\Db\Adapter\Platform\Sqlite; use PHPUnit\Framework\TestCase; use function file_exists; use function realpath; use function touch; use function unlink; class SqliteTest extends TestCase { /** @var Sqlite */ protected $platform; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->platform = new Sqlite(); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::getName */ public function testGetName() { self::assertEquals('SQLite', $this->platform->getName()); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::getQuoteIdentifierSymbol */ public function testGetQuoteIdentifierSymbol() { self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteIdentifier */ public function testQuoteIdentifier() { self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteIdentifierChain */ public function testQuoteIdentifierChain() { self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::getQuoteValueSymbol */ public function testGetQuoteValueSymbol() { self::assertEquals("'", $this->platform->getQuoteValueSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteValue */ public function testQuoteValueRaisesNoticeWithoutPlatformSupport() { $this->expectNotice(); $this->expectNoticeMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Sqlite without extension/driver support can ' . 'introduce security vulnerabilities in a production environment' ); $this->platform->quoteValue('value'); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteValue */ public function testQuoteValue() { self::assertEquals("'value'", @$this->platform->quoteValue('value')); self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar")); self::assertEquals( '\'\\\'; DELETE FROM some_table; -- \'', @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') ); self::assertEquals( "'\\\\\\'; DELETE FROM some_table; -- '", @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteTrustedValue */ public function testQuoteTrustedValue() { self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); self::assertEquals( '\'\\\'; DELETE FROM some_table; -- \'', $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') ); // '\\\'; DELETE FROM some_table; -- ' <- actual below self::assertEquals( "'\\\\\\'; DELETE FROM some_table; -- '", $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteValueList */ public function testQuoteValueList() { $this->expectError(); $this->expectErrorMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Sqlite without extension/driver support can ' . 'introduce security vulnerabilities in a production environment' ); self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::getIdentifierSeparator */ public function testGetIdentifierSeparator() { self::assertEquals('.', $this->platform->getIdentifierSeparator()); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteIdentifierInFragment */ public function testQuoteIdentifierInFragment() { self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); // single char words self::assertEquals( '("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) ); // case insensitive safe words self::assertEquals( '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and'] ) ); // case insensitive safe words in field self::assertEquals( '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and', 'bAz'] ) ); } /** * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteValue * @covers \Laminas\Db\Adapter\Platform\Sqlite::quoteTrustedValue */ public function testCanCloseConnectionAfterQuoteValue() { // Creating the SQLite database file $filePath = realpath(__DIR__) . "/_files/sqlite.db"; if (! file_exists($filePath)) { touch($filePath); } $driver = new Pdo([ 'driver' => 'Pdo_Sqlite', 'database' => $filePath, ]); $this->platform->setDriver($driver); $this->platform->quoteValue("some; random]/ value"); $this->platform->quoteTrustedValue("some; random]/ value"); // Closing the connection so we can delete the file $driver->getConnection()->disconnect(); @unlink($filePath); self::assertFileDoesNotExist($filePath); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Platform/MysqlTest.php
test/unit/Adapter/Platform/MysqlTest.php
<?php namespace LaminasTest\Db\Adapter\Platform; use Laminas\Db\Adapter\Platform\Mysql; use PHPUnit\Framework\TestCase; class MysqlTest extends TestCase { /** @var Mysql */ protected $platform; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->platform = new Mysql(); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::getName */ public function testGetName() { self::assertEquals('MySQL', $this->platform->getName()); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::getQuoteIdentifierSymbol */ public function testGetQuoteIdentifierSymbol() { self::assertEquals('`', $this->platform->getQuoteIdentifierSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteIdentifier */ public function testQuoteIdentifier() { self::assertEquals('`identifier`', $this->platform->quoteIdentifier('identifier')); self::assertEquals('`ident``ifier`', $this->platform->quoteIdentifier('ident`ifier')); self::assertEquals('`namespace:$identifier`', $this->platform->quoteIdentifier('namespace:$identifier')); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteIdentifierChain */ public function testQuoteIdentifierChain() { self::assertEquals('`identifier`', $this->platform->quoteIdentifierChain('identifier')); self::assertEquals('`identifier`', $this->platform->quoteIdentifierChain(['identifier'])); self::assertEquals('`schema`.`identifier`', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); self::assertEquals('`ident``ifier`', $this->platform->quoteIdentifierChain('ident`ifier')); self::assertEquals('`ident``ifier`', $this->platform->quoteIdentifierChain(['ident`ifier'])); self::assertEquals( '`schema`.`ident``ifier`', $this->platform->quoteIdentifierChain(['schema', 'ident`ifier']) ); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::getQuoteValueSymbol */ public function testGetQuoteValueSymbol() { self::assertEquals("'", $this->platform->getQuoteValueSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteValue */ public function testQuoteValueRaisesNoticeWithoutPlatformSupport() { $this->expectNotice(); $this->expectNoticeMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Mysql without extension/driver support can ' . 'introduce security vulnerabilities in a production environment' ); $this->platform->quoteValue('value'); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteValue */ public function testQuoteValue() { self::assertEquals("'value'", @$this->platform->quoteValue('value')); self::assertEquals("'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar")); self::assertEquals( '\'\\\'; DELETE FROM some_table; -- \'', @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') ); self::assertEquals( "'\\\\\\'; DELETE FROM some_table; -- '", @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteTrustedValue */ public function testQuoteTrustedValue() { self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); self::assertEquals( '\'\\\'; DELETE FROM some_table; -- \'', $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') ); // '\\\'; DELETE FROM some_table; -- ' <- actual below self::assertEquals( "'\\\\\\'; DELETE FROM some_table; -- '", $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteValueList */ public function testQuoteValueList() { $this->expectError(); $this->expectErrorMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Mysql without extension/driver support can ' . 'introduce security vulnerabilities in a production environment' ); self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::getIdentifierSeparator */ public function testGetIdentifierSeparator() { self::assertEquals('.', $this->platform->getIdentifierSeparator()); } /** * @covers \Laminas\Db\Adapter\Platform\Mysql::quoteIdentifierInFragment */ public function testQuoteIdentifierInFragment() { self::assertEquals('`foo`.`bar`', $this->platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('`foo` as `bar`', $this->platform->quoteIdentifierInFragment('foo as bar')); self::assertEquals('`$TableName`.`bar`', $this->platform->quoteIdentifierInFragment('$TableName.bar')); self::assertEquals( '`cmis:$TableName` as `cmis:TableAlias`', $this->platform->quoteIdentifierInFragment('cmis:$TableName as cmis:TableAlias') ); $this->assertEquals( '`foo-bar`.`bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar.bar-foo') ); $this->assertEquals( '`foo-bar` as `bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar as bar-foo') ); $this->assertEquals( '`$TableName-$ColumnName`.`bar-foo`', $this->platform->quoteIdentifierInFragment('$TableName-$ColumnName.bar-foo') ); $this->assertEquals( '`cmis:$TableName-$ColumnName` as `cmis:TableAlias-ColumnAlias`', $this->platform->quoteIdentifierInFragment('cmis:$TableName-$ColumnName as cmis:TableAlias-ColumnAlias') ); // single char words self::assertEquals( '(`foo`.`bar` = `boo`.`baz`)', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) ); self::assertEquals( '(`foo`.`bar`=`boo`.`baz`)', $this->platform->quoteIdentifierInFragment('(foo.bar=boo.baz)', ['(', ')', '=']) ); self::assertEquals('`foo`=`bar`', $this->platform->quoteIdentifierInFragment('foo=bar', ['='])); $this->assertEquals( '(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`)', $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo = boo-baz.baz-boo)', ['(', ')', '=']) ); $this->assertEquals( '(`foo-bar`.`bar-foo`=`boo-baz`.`baz-boo`)', $this->platform->quoteIdentifierInFragment('(foo-bar.bar-foo=boo-baz.baz-boo)', ['(', ')', '=']) ); $this->assertEquals( '`foo-bar`=`bar-foo`', $this->platform->quoteIdentifierInFragment('foo-bar=bar-foo', ['=']) ); // case insensitive safe words self::assertEquals( '(`foo`.`bar` = `boo`.`baz`) AND (`foo`.`baz` = `boo`.`baz`)', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and'] ) ); $this->assertEquals( '(`foo-bar`.`bar-foo` = `boo-baz`.`baz-boo`) AND (`foo-baz`.`baz-foo` = `boo-baz`.`baz-boo`)', $this->platform->quoteIdentifierInFragment( '(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', ['(', ')', '=', 'and'] ) ); // case insensitive safe words in field self::assertEquals( '(`foo`.`bar` = `boo`.baz) AND (`foo`.baz = `boo`.baz)', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and', 'bAz'] ) ); // case insensitive safe words in field $this->assertEquals( '(`foo-bar`.`bar-foo` = `boo-baz`.baz-boo) AND (`foo-baz`.`baz-foo` = `boo-baz`.baz-boo)', $this->platform->quoteIdentifierInFragment( '(foo-bar.bar-foo = boo-baz.baz-boo) AND (foo-baz.baz-foo = boo-baz.baz-boo)', ['(', ')', '=', 'and', 'bAz-BOo'] ) ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Platform/OracleTest.php
test/unit/Adapter/Platform/OracleTest.php
<?php namespace LaminasTest\Db\Adapter\Platform; use Laminas\Db\Adapter\Driver\Oci8\Oci8; use Laminas\Db\Adapter\Exception\InvalidArgumentException; use Laminas\Db\Adapter\Platform\Oracle; use PHPUnit\Framework\TestCase; class OracleTest extends TestCase { /** @var Oracle */ protected $platform; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->platform = new Oracle(); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::__construct */ public function testContructWithOptions() { self::assertEquals('"\'test\'.\'test\'"', $this->platform->quoteIdentifier('"test"."test"')); $plataform1 = new Oracle(['quote_identifiers' => false]); self::assertEquals('"test"."test"', $plataform1->quoteIdentifier('"test"."test"')); $plataform2 = new Oracle(['quote_identifiers' => 'false']); self::assertEquals('"test"."test"', $plataform2->quoteIdentifier('"test"."test"')); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::__construct */ public function testContructWithDriver() { $mockDriver = $this->getMockForAbstractClass( Oci8::class, [[]], '', true, true, true, [] ); $platform = new Oracle([], $mockDriver); self::assertEquals($mockDriver, $platform->getDriver()); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::setDriver */ public function testSetDriver() { $mockDriver = $this->getMockForAbstractClass( Oci8::class, [[]], '', true, true, true, [] ); $platform = $this->platform->setDriver($mockDriver); self::assertEquals($mockDriver, $platform->getDriver()); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::setDriver */ public function testSetDriverInvalid() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( '$driver must be a Oci8 or Oracle PDO Laminas\Db\Adapter\Driver, Oci8 instance, or Oci PDO instance' ); $this->platform->setDriver(null); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::getDriver */ public function testGetDriver() { self::assertNull($this->platform->getDriver()); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::getName */ public function testGetName() { self::assertEquals('Oracle', $this->platform->getName()); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::getQuoteIdentifierSymbol */ public function testGetQuoteIdentifierSymbol() { self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteIdentifier */ public function testQuoteIdentifier() { self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); $platform = new Oracle(['quote_identifiers' => false]); self::assertEquals('identifier', $platform->quoteIdentifier('identifier')); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteIdentifierChain */ public function testQuoteIdentifierChain() { self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); $platform = new Oracle(['quote_identifiers' => false]); self::assertEquals('identifier', $platform->quoteIdentifierChain('identifier')); self::assertEquals('identifier', $platform->quoteIdentifierChain(['identifier'])); self::assertEquals('schema.identifier', $platform->quoteIdentifierChain(['schema', 'identifier'])); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::getQuoteValueSymbol */ public function testGetQuoteValueSymbol() { self::assertEquals("'", $this->platform->getQuoteValueSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteValue */ public function testQuoteValueRaisesNoticeWithoutPlatformSupport() { $this->expectNotice(); $this->expectNoticeMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Oracle without ' . 'extension/driver support can introduce security vulnerabilities in a production environment' ); $this->platform->quoteValue('value'); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteValue */ public function testQuoteValue() { self::assertEquals("'value'", @$this->platform->quoteValue('value')); self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar")); self::assertEquals( '\'\'\'; DELETE FROM some_table; -- \'', @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') ); self::assertEquals( "'\\''; DELETE FROM some_table; -- '", @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteTrustedValue */ public function testQuoteTrustedValue() { self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); self::assertEquals( '\'\'\'; DELETE FROM some_table; -- \'', $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') ); // '\\\'; DELETE FROM some_table; -- ' <- actual below self::assertEquals( "'\\''; DELETE FROM some_table; -- '", $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteValueList */ public function testQuoteValueList() { $this->expectError(); $this->expectErrorMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Oracle without ' . 'extension/driver support can introduce security vulnerabilities in a production environment' ); self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar")); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::getIdentifierSeparator */ public function testGetIdentifierSeparator() { self::assertEquals('.', $this->platform->getIdentifierSeparator()); } /** * @covers \Laminas\Db\Adapter\Platform\Oracle::quoteIdentifierInFragment */ public function testQuoteIdentifierInFragment() { self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); $platform = new Oracle(['quote_identifiers' => false]); self::assertEquals('foo.bar', $platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('foo as bar', $platform->quoteIdentifierInFragment('foo as bar')); // single char words self::assertEquals( '("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) ); // case insensitive safe words self::assertEquals( '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and'] ) ); // case insensitive safe words in field self::assertEquals( '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and', 'bAz'] ) ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Platform/SqlServerTest.php
test/unit/Adapter/Platform/SqlServerTest.php
<?php namespace LaminasTest\Db\Adapter\Platform; use Laminas\Db\Adapter\Driver\Pdo\Pdo; use Laminas\Db\Adapter\Platform\SqlServer; use PHPUnit\Framework\TestCase; use function restore_error_handler; use function set_error_handler; class SqlServerTest extends TestCase { /** @var SqlServer */ protected $platform; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->platform = new SqlServer(); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::getName */ public function testGetName() { self::assertEquals('SQLServer', $this->platform->getName()); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::getQuoteIdentifierSymbol */ public function testGetQuoteIdentifierSymbol() { self::assertEquals(['[', ']'], $this->platform->getQuoteIdentifierSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteIdentifier */ public function testQuoteIdentifier() { self::assertEquals('[identifier]', $this->platform->quoteIdentifier('identifier')); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteIdentifierChain */ public function testQuoteIdentifierChain() { self::assertEquals('[identifier]', $this->platform->quoteIdentifierChain('identifier')); self::assertEquals('[identifier]', $this->platform->quoteIdentifierChain(['identifier'])); self::assertEquals('[schema].[identifier]', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::getQuoteValueSymbol */ public function testGetQuoteValueSymbol() { self::assertEquals("'", $this->platform->getQuoteValueSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteValue */ public function testQuoteValueRaisesNoticeWithoutPlatformSupport() { $this->expectNotice(); $this->expectNoticeMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\SqlServer without extension/driver support can ' . 'introduce security vulnerabilities in a production environment' ); $this->platform->quoteValue('value'); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteValue */ public function testQuoteValue() { self::assertEquals("'value'", @$this->platform->quoteValue('value')); self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar")); self::assertEquals( "'''; DELETE FROM some_table; -- '", @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') ); self::assertEquals( "'\\''; DELETE FROM some_table; -- '", @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteTrustedValue */ public function testQuoteTrustedValue() { self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); self::assertEquals( "'''; DELETE FROM some_table; -- '", $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') ); self::assertEquals( "'\\''; DELETE FROM some_table; -- '", $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteValueList */ public function testQuoteValueList() { $this->expectError(); $this->expectErrorMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\SqlServer without extension/driver support can ' . 'introduce security vulnerabilities in a production environment' ); self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar")); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::getIdentifierSeparator */ public function testGetIdentifierSeparator() { self::assertEquals('.', $this->platform->getIdentifierSeparator()); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::quoteIdentifierInFragment */ public function testQuoteIdentifierInFragment() { self::assertEquals('[foo].[bar]', $this->platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('[foo] as [bar]', $this->platform->quoteIdentifierInFragment('foo as bar')); // single char words self::assertEquals( '([foo].[bar] = [boo].[baz])', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) ); // case insensitive safe words self::assertEquals( '([foo].[bar] = [boo].[baz]) AND ([foo].[baz] = [boo].[baz])', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and'] ) ); // case insensitive safe words in field self::assertEquals( '([foo].[bar] = [boo].baz) AND ([foo].baz = [boo].baz)', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and', 'bAz'] ) ); } /** * @covers \Laminas\Db\Adapter\Platform\SqlServer::setDriver */ public function testSetDriver() { $driver = new Pdo(['pdodriver' => 'sqlsrv']); $this->platform->setDriver($driver); } public function testPlatformQuotesNullByteCharacter() { set_error_handler(function () { }); $string = "1\0"; $value = $this->platform->quoteValue($string); restore_error_handler(); self::assertEquals("'1\\000'", $value); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Platform/IbmDb2Test.php
test/unit/Adapter/Platform/IbmDb2Test.php
<?php namespace LaminasTest\Db\Adapter\Platform; use Laminas\Db\Adapter\Platform\IbmDb2; use PHPUnit\Framework\TestCase; use function function_exists; class IbmDb2Test extends TestCase { /** @var IbmDb2 */ protected $platform; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->platform = new IbmDb2(); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::getName */ public function testGetName() { self::assertEquals('IBM DB2', $this->platform->getName()); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::getQuoteIdentifierSymbol */ public function testGetQuoteIdentifierSymbol() { self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteIdentifier */ public function testQuoteIdentifier() { self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); $platform = new IbmDb2(['quote_identifiers' => false]); self::assertEquals('identifier', $platform->quoteIdentifier('identifier')); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteIdentifierChain */ public function testQuoteIdentifierChain() { self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); $platform = new IbmDb2(['quote_identifiers' => false]); self::assertEquals('identifier', $platform->quoteIdentifierChain('identifier')); self::assertEquals('identifier', $platform->quoteIdentifierChain(['identifier'])); self::assertEquals('schema.identifier', $platform->quoteIdentifierChain(['schema', 'identifier'])); $platform = new IbmDb2(['identifier_separator' => '\\']); self::assertEquals('"schema"\"identifier"', $platform->quoteIdentifierChain(['schema', 'identifier'])); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::getQuoteValueSymbol */ public function testGetQuoteValueSymbol() { self::assertEquals("'", $this->platform->getQuoteValueSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteValue */ public function testQuoteValueRaisesNoticeWithoutPlatformSupport() { if (! function_exists('db2_escape_string')) { $this->expectNotice(); $this->expectNoticeMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\IbmDb2 without extension/driver' . ' support can introduce security vulnerabilities in a production environment' ); } $this->platform->quoteValue('value'); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteValue */ public function testQuoteValue() { self::assertEquals("'value'", @$this->platform->quoteValue('value')); self::assertEquals("'Foo O''Bar'", @$this->platform->quoteValue("Foo O'Bar")); self::assertEquals( "'''; DELETE FROM some_table; -- '", @$this->platform->quoteValue("'; DELETE FROM some_table; -- ") ); self::assertEquals( "'\\''; \nDELETE FROM some_table; -- '", @$this->platform->quoteValue("\\'; \nDELETE FROM some_table; -- ") ); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteTrustedValue */ public function testQuoteTrustedValue() { self::assertEquals("'value'", $this->platform->quoteTrustedValue('value')); self::assertEquals("'Foo O''Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); self::assertEquals( "'''; DELETE FROM some_table; -- '", $this->platform->quoteTrustedValue("'; DELETE FROM some_table; -- ") ); self::assertEquals( "'\\''; \nDELETE FROM some_table; -- '", $this->platform->quoteTrustedValue("\\'; \nDELETE FROM some_table; -- ") ); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteValueList */ public function testQuoteValueList() { if (! function_exists('db2_escape_string')) { $this->expectError(); $this->expectErrorMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\IbmDb2 without extension/driver' . ' support can introduce security vulnerabilities in a production environment' ); } self::assertEquals("'Foo O''Bar'", $this->platform->quoteValueList("Foo O'Bar")); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::getIdentifierSeparator */ public function testGetIdentifierSeparator() { self::assertEquals('.', $this->platform->getIdentifierSeparator()); $platform = new IbmDb2(['identifier_separator' => '\\']); self::assertEquals('\\', $platform->getIdentifierSeparator()); } /** * @covers \Laminas\Db\Adapter\Platform\IbmDb2::quoteIdentifierInFragment */ public function testQuoteIdentifierInFragment() { self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); $platform = new IbmDb2(['quote_identifiers' => false]); self::assertEquals('foo.bar', $platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('foo as bar', $platform->quoteIdentifierInFragment('foo as bar')); // single char words self::assertEquals( '("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) ); // case insensitive safe words self::assertEquals( '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and'] ) ); // case insensitive safe words in field self::assertEquals( '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and', 'bAz'] ) ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Adapter/Platform/PostgresqlTest.php
test/unit/Adapter/Platform/PostgresqlTest.php
<?php namespace LaminasTest\Db\Adapter\Platform; use Laminas\Db\Adapter\Platform\Postgresql; use PHPUnit\Framework\TestCase; class PostgresqlTest extends TestCase { /** @var Postgresql */ protected $platform; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->platform = new Postgresql(); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::getName */ public function testGetName() { self::assertEquals('PostgreSQL', $this->platform->getName()); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::getQuoteIdentifierSymbol */ public function testGetQuoteIdentifierSymbol() { self::assertEquals('"', $this->platform->getQuoteIdentifierSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteIdentifier */ public function testQuoteIdentifier() { self::assertEquals('"identifier"', $this->platform->quoteIdentifier('identifier')); self::assertEquals( '"identifier ""with"" double-quotes"', $this->platform->quoteIdentifier('identifier "with" double-quotes') ); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteIdentifierChain */ public function testQuoteIdentifierChain() { self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain('identifier')); self::assertEquals('"identifier"', $this->platform->quoteIdentifierChain(['identifier'])); self::assertEquals('"schema"."identifier"', $this->platform->quoteIdentifierChain(['schema', 'identifier'])); self::assertEquals( '"schema"."identifier ""with"" double-quotes"', $this->platform->quoteIdentifierChain(['schema', 'identifier "with" double-quotes']) ); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::getQuoteValueSymbol */ public function testGetQuoteValueSymbol() { self::assertEquals("'", $this->platform->getQuoteValueSymbol()); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteValue */ public function testQuoteValueRaisesNoticeWithoutPlatformSupport() { $this->expectNotice(); $this->expectNoticeMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Postgresql without extension/driver' . ' support can introduce security vulnerabilities in a production environment' ); $this->platform->quoteValue('value'); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteValue */ public function testQuoteValue() { self::assertEquals("E'value'", @$this->platform->quoteValue('value')); self::assertEquals("E'Foo O\\'Bar'", @$this->platform->quoteValue("Foo O'Bar")); self::assertEquals( 'E\'\\\'; DELETE FROM some_table; -- \'', @$this->platform->quoteValue('\'; DELETE FROM some_table; -- ') ); self::assertEquals( "E'\\\\\\'; DELETE FROM some_table; -- '", @$this->platform->quoteValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteTrustedValue */ public function testQuoteTrustedValue() { self::assertEquals("E'value'", $this->platform->quoteTrustedValue('value')); self::assertEquals("E'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar")); self::assertEquals( 'E\'\\\'; DELETE FROM some_table; -- \'', $this->platform->quoteTrustedValue('\'; DELETE FROM some_table; -- ') ); // '\\\'; DELETE FROM some_table; -- ' <- actual below self::assertEquals( "E'\\\\\\'; DELETE FROM some_table; -- '", $this->platform->quoteTrustedValue('\\\'; DELETE FROM some_table; -- ') ); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteValueList */ public function testQuoteValueList() { $this->expectError(); $this->expectErrorMessage( 'Attempting to quote a value in Laminas\Db\Adapter\Platform\Postgresql without extension/driver' . ' support can introduce security vulnerabilities in a production environment' ); self::assertEquals("'Foo O\'\'Bar'", $this->platform->quoteValueList("Foo O'Bar")); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::getIdentifierSeparator */ public function testGetIdentifierSeparator() { self::assertEquals('.', $this->platform->getIdentifierSeparator()); } /** * @covers \Laminas\Db\Adapter\Platform\Postgresql::quoteIdentifierInFragment */ public function testQuoteIdentifierInFragment() { self::assertEquals('"foo"."bar"', $this->platform->quoteIdentifierInFragment('foo.bar')); self::assertEquals('"foo" as "bar"', $this->platform->quoteIdentifierInFragment('foo as bar')); // single char words self::assertEquals( '("foo"."bar" = "boo"."baz")', $this->platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']) ); // case insensitive safe words self::assertEquals( '("foo"."bar" = "boo"."baz") AND ("foo"."baz" = "boo"."baz")', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and'] ) ); // case insensitive safe words in field self::assertEquals( '("foo"."bar" = "boo".baz) AND ("foo".baz = "boo".baz)', $this->platform->quoteIdentifierInFragment( '(foo.bar = boo.baz) AND (foo.baz = boo.baz)', ['(', ')', '=', 'and', 'bAz'] ) ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Sql/UpdateTest.php
test/unit/Sql/UpdateTest.php
<?php namespace LaminasTest\Db\Sql; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\Adapter\ParameterContainer; use Laminas\Db\Sql\Exception\InvalidArgumentException; use Laminas\Db\Sql\Expression; use Laminas\Db\Sql\Join; use Laminas\Db\Sql\Predicate\In; use Laminas\Db\Sql\Predicate\IsNotNull; use Laminas\Db\Sql\Predicate\IsNull; use Laminas\Db\Sql\Predicate\Literal; use Laminas\Db\Sql\Predicate\Operator; use Laminas\Db\Sql\TableIdentifier; use Laminas\Db\Sql\Update; use Laminas\Db\Sql\Where; use LaminasTest\Db\DeprecatedAssertionsTrait; use LaminasTest\Db\TestAsset\TrustingSql92Platform; use LaminasTest\Db\TestAsset\UpdateIgnore; use PHPUnit\Framework\TestCase; class UpdateTest extends TestCase { use DeprecatedAssertionsTrait; /** @var Update */ protected $update; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->update = new Update(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Sql\Update::table */ public function testTable() { $this->update->table('foo', 'bar'); self::assertEquals('foo', $this->readAttribute($this->update, 'table')); $tableIdentifier = new TableIdentifier('foo', 'bar'); $this->update->table($tableIdentifier); self::assertEquals($tableIdentifier, $this->readAttribute($this->update, 'table')); } /** * @covers \Laminas\Db\Sql\Update::__construct */ public function testConstruct() { $update = new Update('foo'); self::assertEquals('foo', $this->readAttribute($update, 'table')); } /** * @covers \Laminas\Db\Sql\Update::set */ public function testSet() { $this->update->set(['foo' => 'bar']); self::assertEquals(['foo' => 'bar'], $this->update->getRawState('set')); } /** * @covers \Laminas\Db\Sql\Update::set */ public function testSortableSet() { $this->update->set([ 'two' => 'с_two', 'three' => 'с_three', ]); $this->update->set(['one' => 'с_one'], 10); self::assertEquals( [ 'one' => 'с_one', 'two' => 'с_two', 'three' => 'с_three', ], $this->update->getRawState('set') ); } /** * @covers \Laminas\Db\Sql\Update::where */ public function testWhere() { $this->update->where('x = y'); $this->update->where(['foo > ?' => 5]); $this->update->where(['id' => 2]); $this->update->where(['a = b'], Where::OP_OR); $this->update->where(['c1' => null]); $this->update->where(['c2' => [1, 2, 3]]); $this->update->where([new IsNotNull('c3')]); $where = $this->update->where; $predicates = $this->readAttribute($where, 'predicates'); self::assertEquals('AND', $predicates[0][0]); self::assertInstanceOf(Literal::class, $predicates[0][1]); self::assertEquals('AND', $predicates[1][0]); self::assertInstanceOf(\Laminas\Db\Sql\Predicate\Expression::class, $predicates[1][1]); self::assertEquals('AND', $predicates[2][0]); self::assertInstanceOf(Operator::class, $predicates[2][1]); self::assertEquals('OR', $predicates[3][0]); self::assertInstanceOf(Literal::class, $predicates[3][1]); self::assertEquals('AND', $predicates[4][0]); self::assertInstanceOf(IsNull::class, $predicates[4][1]); self::assertEquals('AND', $predicates[5][0]); self::assertInstanceOf(In::class, $predicates[5][1]); self::assertEquals('AND', $predicates[6][0]); self::assertInstanceOf(IsNotNull::class, $predicates[6][1]); $where = new Where(); $this->update->where($where); self::assertSame($where, $this->update->where); $this->update->where(function ($what) use ($where) { self::assertSame($where, $what); }); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Predicate cannot be null'); $this->update->where(null); } /** * @group Laminas-240 * @covers \Laminas\Db\Sql\Update::where */ public function testPassingMultipleKeyValueInWhereClause() { $update = clone $this->update; $update->table('table'); $update->set(['fld1' => 'val1']); $update->where(['id1' => 'val1', 'id2' => 'val2']); self::assertEquals( 'UPDATE "table" SET "fld1" = \'val1\' WHERE "id1" = \'val1\' AND "id2" = \'val2\'', $update->getSqlString(new TrustingSql92Platform()) ); } /** * @covers \Laminas\Db\Sql\Update::getRawState */ public function testGetRawState() { $this->update->table('foo') ->set(['bar' => 'baz']) ->where('x = y'); self::assertEquals('foo', $this->update->getRawState('table')); self::assertEquals(true, $this->update->getRawState('emptyWhereProtection')); self::assertEquals(['bar' => 'baz'], $this->update->getRawState('set')); self::assertInstanceOf(Where::class, $this->update->getRawState('where')); } /** * @covers \Laminas\Db\Sql\Update::prepareStatement */ public function testPrepareStatement() { $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); $mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $pContainer = new ParameterContainer([]); $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); $mockStatement->expects($this->at(1)) ->method('setSql') ->with($this->equalTo('UPDATE "foo" SET "bar" = ?, "boo" = NOW() WHERE x = y')); $this->update->table('foo') ->set(['bar' => 'baz', 'boo' => new Expression('NOW()')]) ->where('x = y'); $this->update->prepareStatement($mockAdapter, $mockStatement); // with TableIdentifier $this->update = new Update(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); $mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $pContainer = new ParameterContainer([]); $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); $mockStatement->expects($this->at(1)) ->method('setSql') ->with($this->equalTo('UPDATE "sch"."foo" SET "bar" = ?, "boo" = NOW() WHERE x = y')); $this->update->table(new TableIdentifier('foo', 'sch')) ->set(['bar' => 'baz', 'boo' => new Expression('NOW()')]) ->where('x = y'); $this->update->prepareStatement($mockAdapter, $mockStatement); } /** * @covers \Laminas\Db\Sql\Update::getSqlString */ public function testGetSqlString() { $this->update->table('foo') ->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]) ->where('x = y'); self::assertEquals( 'UPDATE "foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform()) ); // with TableIdentifier $this->update = new Update(); $this->update->table(new TableIdentifier('foo', 'sch')) ->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]) ->where('x = y'); self::assertEquals( 'UPDATE "sch"."foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform()) ); } /** * @group 6768 * @group 6773 */ public function testGetSqlStringForFalseUpdateValueParameter() { $this->update = new Update(); $this->update->table(new TableIdentifier('foo', 'sch')) ->set(['bar' => false, 'boo' => 'test', 'bam' => true]) ->where('x = y'); self::assertEquals( 'UPDATE "sch"."foo" SET "bar" = \'\', "boo" = \'test\', "bam" = \'1\' WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform()) ); } /** * @covers \Laminas\Db\Sql\Update::__get */ public function testGetUpdate() { $getWhere = $this->update->__get('where'); self::assertInstanceOf(Where::class, $getWhere); } /** * @covers \Laminas\Db\Sql\Update::__get */ public function testGetUpdateFails() { $getWhat = $this->update->__get('what'); self::assertNull($getWhat); } /** * @covers \Laminas\Db\Sql\Update::__clone */ public function testCloneUpdate() { $update1 = clone $this->update; $update1->table('foo') ->set(['bar' => 'baz']) ->where('x = y'); $update2 = clone $this->update; $update2->table('foo') ->set(['bar' => 'baz']) ->where([ 'id = ?' => 1, ]); self::assertEquals( 'UPDATE "foo" SET "bar" = \'baz\' WHERE id = \'1\'', $update2->getSqlString(new TrustingSql92Platform()) ); } /** * @coversNothing */ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement() { $updateIgnore = new UpdateIgnore(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional')); $mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?')); $mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $pContainer = new ParameterContainer([]); $mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer)); $mockStatement->expects($this->at(1)) ->method('setSql') ->with($this->equalTo('UPDATE IGNORE "foo" SET "bar" = ?, "boo" = NOW() WHERE x = y')); $updateIgnore->table('foo') ->set(['bar' => 'baz', 'boo' => new Expression('NOW()')]) ->where('x = y'); $updateIgnore->prepareStatement($mockAdapter, $mockStatement); } /** * @coversNothing */ public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString() { $this->update = new UpdateIgnore(); $this->update->table('foo') ->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]) ->where('x = y'); self::assertEquals( 'UPDATE IGNORE "foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform()) ); // with TableIdentifier $this->update = new UpdateIgnore(); $this->update->table(new TableIdentifier('foo', 'sch')) ->set(['bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null]) ->where('x = y'); self::assertEquals( 'UPDATE IGNORE "sch"."foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform()) ); } /** * @covers \Laminas\Db\Sql\Update::where */ public function testJoin() { $this->update->table('Document'); $this->update->set(['x' => 'y']) ->join( 'User', // table name 'User.UserId = Document.UserId' // expression to join on // default JOIN INNER ) ->join( 'Category', 'Category.CategoryId = Document.CategoryId', Join::JOIN_LEFT // (optional), one of inner, outer, left, right ); self::assertEquals( 'UPDATE "Document" INNER JOIN "User" ON "User"."UserId" = "Document"."UserId" ' . 'LEFT JOIN "Category" ON "Category"."CategoryId" = "Document"."CategoryId" SET "x" = \'y\'', $this->update->getSqlString(new TrustingSql92Platform()) ); } /** * Here test if we want update fields from specific table. * Important when we're updating fields that are existing in several tables in one query. * The same test as above but here we will specify table in update params */ public function testJoinMultiUpdate() { $this->update->table('Document'); $this->update->set(['Documents.x' => 'y']) ->join( 'User', 'User.UserId = Document.UserId' ) ->join( 'Category', 'Category.CategoryId = Document.CategoryId', Join::JOIN_LEFT ); self::assertEquals( 'UPDATE "Document" INNER JOIN "User" ON "User"."UserId" = "Document"."UserId" ' . 'LEFT JOIN "Category" ON "Category"."CategoryId" = "Document"."CategoryId" SET "Documents"."x" = \'y\'', $this->update->getSqlString(new TrustingSql92Platform()) ); } /** * @testdox unit test: Test join() returns Update object (is chainable) * @covers \Laminas\Db\Sql\Update::join */ public function testJoinChainable() { $return = $this->update->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT); self::assertSame($this->update, $return); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Sql/AbstractSqlTest.php
test/unit/Sql/AbstractSqlTest.php
<?php namespace LaminasTest\Db\Sql; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\ParameterContainer; use Laminas\Db\Adapter\StatementContainer; use Laminas\Db\Sql\AbstractSql; use Laminas\Db\Sql\Expression; use Laminas\Db\Sql\ExpressionInterface; use Laminas\Db\Sql\Predicate; use Laminas\Db\Sql\Select; use LaminasTest\Db\TestAsset\TrustingSql92Platform; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionMethod; use function current; use function key; use function next; use function preg_match; use function uniqid; class AbstractSqlTest extends TestCase { /** @var AbstractSql&MockObject */ protected $abstractSql; /** @var DriverInterface&MockObject */ protected $mockDriver; protected function setUp(): void { $this->abstractSql = $this->getMockForAbstractClass(AbstractSql::class); $this->mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $this->mockDriver ->expects($this->any()) ->method('getPrepareType') ->will($this->returnValue(DriverInterface::PARAMETERIZATION_NAMED)); $this->mockDriver ->expects($this->any()) ->method('formatParameterName') ->will($this->returnCallback(function ($x) { return ':' . $x; })); } /** * @covers \Laminas\Db\Sql\AbstractSql::processExpression */ public function testProcessExpressionWithoutParameterContainer() { $expression = new Expression('? > ? AND y < ?', ['x', 5, 10], [Expression::TYPE_IDENTIFIER]); $sqlAndParams = $this->invokeProcessExpressionMethod($expression); self::assertEquals("\"x\" > '5' AND y < '10'", $sqlAndParams); } /** * @covers \Laminas\Db\Sql\AbstractSql::processExpression */ public function testProcessExpressionWithParameterContainerAndParameterizationTypeNamed() { $parameterContainer = new ParameterContainer(); $expression = new Expression('? > ? AND y < ?', ['x', 5, 10], [Expression::TYPE_IDENTIFIER]); $sqlAndParams = $this->invokeProcessExpressionMethod($expression, $parameterContainer); $parameters = $parameterContainer->getNamedArray(); self::assertMatchesRegularExpression('#"x" > :expr\d\d\d\dParam1 AND y < :expr\d\d\d\dParam2#', $sqlAndParams); // test keys and values preg_match('#expr(\d\d\d\d)Param1#', key($parameters), $matches); $expressionNumber = $matches[1]; self::assertMatchesRegularExpression('#expr\d\d\d\dParam1#', key($parameters)); self::assertEquals(5, current($parameters)); next($parameters); self::assertMatchesRegularExpression('#expr\d\d\d\dParam2#', key($parameters)); self::assertEquals(10, current($parameters)); // ensure next invocation increases number by 1 $parameterContainer = new ParameterContainer(); $sqlAndParamsNext = $this->invokeProcessExpressionMethod($expression, $parameterContainer); $parameters = $parameterContainer->getNamedArray(); preg_match('#expr(\d\d\d\d)Param1#', key($parameters), $matches); $expressionNumberNext = $matches[1]; self::assertEquals(1, (int) $expressionNumberNext - (int) $expressionNumber); } /** * @covers \Laminas\Db\Sql\AbstractSql::processExpression */ public function testProcessExpressionWorksWithExpressionContainingStringParts() { $expression = new Predicate\Expression('x = ?', 5); $predicateSet = new Predicate\PredicateSet([new Predicate\PredicateSet([$expression])]); $sqlAndParams = $this->invokeProcessExpressionMethod($predicateSet); self::assertEquals("(x = '5')", $sqlAndParams); } /** * @covers \Laminas\Db\Sql\AbstractSql::processExpression */ public function testProcessExpressionWorksWithExpressionContainingSelectObject() { $select = new Select(); $select->from('x')->where->like('bar', 'Foo%'); $expression = new Predicate\In('x', $select); $predicateSet = new Predicate\PredicateSet([new Predicate\PredicateSet([$expression])]); $sqlAndParams = $this->invokeProcessExpressionMethod($predicateSet); self::assertEquals('("x" IN (SELECT "x".* FROM "x" WHERE "bar" LIKE \'Foo%\'))', $sqlAndParams); } public function testProcessExpressionWorksWithExpressionContainingExpressionObject() { $expression = new Predicate\Operator( 'release_date', '=', new Expression('FROM_UNIXTIME(?)', 100000000) ); $sqlAndParams = $this->invokeProcessExpressionMethod($expression); self::assertEquals('"release_date" = FROM_UNIXTIME(\'100000000\')', $sqlAndParams); } /** * @group 7407 */ public function testProcessExpressionWorksWithExpressionObjectWithPercentageSigns() { $expressionString = 'FROM_UNIXTIME(date, "%Y-%m")'; $expression = new Expression($expressionString); $sqlString = $this->invokeProcessExpressionMethod($expression); self::assertSame($expressionString, $sqlString); } public function testProcessExpressionWorksWithNamedParameterPrefix() { $parameterContainer = new ParameterContainer(); $namedParameterPrefix = uniqid(); $expression = new Expression('FROM_UNIXTIME(?)', [10000000]); $this->invokeProcessExpressionMethod($expression, $parameterContainer, $namedParameterPrefix); self::assertSame($namedParameterPrefix . '1', key($parameterContainer->getNamedArray())); } public function testProcessExpressionWorksWithNamedParameterPrefixContainingWhitespace() { $parameterContainer = new ParameterContainer(); $namedParameterPrefix = "string\ncontaining white space"; $expression = new Expression('FROM_UNIXTIME(?)', [10000000]); $this->invokeProcessExpressionMethod($expression, $parameterContainer, $namedParameterPrefix); self::assertSame('string__containing__white__space1', key($parameterContainer->getNamedArray())); } /** * @param ParameterContainer $parameterContainer * @param string $namedParameterPrefix * @return StatementContainer|string */ protected function invokeProcessExpressionMethod( ExpressionInterface $expression, $parameterContainer = null, $namedParameterPrefix = null ) { $method = new ReflectionMethod($this->abstractSql, 'processExpression'); $method->setAccessible(true); return $method->invoke( $this->abstractSql, $expression, new TrustingSql92Platform(), $this->mockDriver, $parameterContainer, $namedParameterPrefix ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Sql/DeleteTest.php
test/unit/Sql/DeleteTest.php
<?php namespace LaminasTest\Db\Sql; use Laminas\Db\Adapter\Adapter; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Adapter\Driver\StatementInterface; use Laminas\Db\Sql\Delete; use Laminas\Db\Sql\Predicate\Expression; use Laminas\Db\Sql\Predicate\In; use Laminas\Db\Sql\Predicate\IsNotNull; use Laminas\Db\Sql\Predicate\IsNull; use Laminas\Db\Sql\Predicate\Literal; use Laminas\Db\Sql\Predicate\Operator; use Laminas\Db\Sql\TableIdentifier; use Laminas\Db\Sql\Where; use LaminasTest\Db\DeprecatedAssertionsTrait; use LaminasTest\Db\TestAsset\DeleteIgnore; use PHPUnit\Framework\TestCase; class DeleteTest extends TestCase { use DeprecatedAssertionsTrait; /** @var Delete */ protected $delete; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp(): void { $this->delete = new Delete(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown(): void { } /** * @covers \Laminas\Db\Sql\Delete::from */ public function testFrom() { $this->delete->from('foo', 'bar'); self::assertEquals('foo', $this->readAttribute($this->delete, 'table')); $tableIdentifier = new TableIdentifier('foo', 'bar'); $this->delete->from($tableIdentifier); self::assertEquals($tableIdentifier, $this->readAttribute($this->delete, 'table')); } /** * @covers \Laminas\Db\Sql\Delete::where * @todo REMOVE THIS IN 3.x */ public function testWhere() { $this->delete->where('x = y'); $this->delete->where(['foo > ?' => 5]); $this->delete->where(['id' => 2]); $this->delete->where(['a = b'], Where::OP_OR); $this->delete->where(['c1' => null]); $this->delete->where(['c2' => [1, 2, 3]]); $this->delete->where([new IsNotNull('c3')]); $this->delete->where(['one' => 1, 'two' => 2]); $where = $this->delete->where; $predicates = $this->readAttribute($where, 'predicates'); self::assertEquals('AND', $predicates[0][0]); self::assertInstanceOf(Literal::class, $predicates[0][1]); self::assertEquals('AND', $predicates[1][0]); self::assertInstanceOf(Expression::class, $predicates[1][1]); self::assertEquals('AND', $predicates[2][0]); self::assertInstanceOf(Operator::class, $predicates[2][1]); self::assertEquals('OR', $predicates[3][0]); self::assertInstanceOf(Literal::class, $predicates[3][1]); self::assertEquals('AND', $predicates[4][0]); self::assertInstanceOf(IsNull::class, $predicates[4][1]); self::assertEquals('AND', $predicates[5][0]); self::assertInstanceOf(In::class, $predicates[5][1]); self::assertEquals('AND', $predicates[6][0]); self::assertInstanceOf(IsNotNull::class, $predicates[6][1]); self::assertEquals('AND', $predicates[7][0]); self::assertInstanceOf(Operator::class, $predicates[7][1]); self::assertEquals('AND', $predicates[8][0]); self::assertInstanceOf(Operator::class, $predicates[8][1]); $where = new Where(); $this->delete->where($where); self::assertSame($where, $this->delete->where); $this->delete->where(function ($what) use ($where) { self::assertSame($where, $what); }); } /** * @covers \Laminas\Db\Sql\Delete::prepareStatement */ public function testPrepareStatement() { $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockStatement->expects($this->at(2)) ->method('setSql') ->with($this->equalTo('DELETE FROM "foo" WHERE x = y')); $this->delete->from('foo') ->where('x = y'); $this->delete->prepareStatement($mockAdapter, $mockStatement); // with TableIdentifier $this->delete = new Delete(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockStatement->expects($this->at(2)) ->method('setSql') ->with($this->equalTo('DELETE FROM "sch"."foo" WHERE x = y')); $this->delete->from(new TableIdentifier('foo', 'sch')) ->where('x = y'); $this->delete->prepareStatement($mockAdapter, $mockStatement); } /** * @covers \Laminas\Db\Sql\Delete::getSqlString */ public function testGetSqlString() { $this->delete->from('foo') ->where('x = y'); self::assertEquals('DELETE FROM "foo" WHERE x = y', $this->delete->getSqlString()); // with TableIdentifier $this->delete = new Delete(); $this->delete->from(new TableIdentifier('foo', 'sch')) ->where('x = y'); self::assertEquals('DELETE FROM "sch"."foo" WHERE x = y', $this->delete->getSqlString()); } /** * @coversNothing */ public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement() { $deleteIgnore = new DeleteIgnore(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockStatement->expects($this->at(2)) ->method('setSql') ->with($this->equalTo('DELETE IGNORE FROM "foo" WHERE x = y')); $deleteIgnore->from('foo') ->where('x = y'); $deleteIgnore->prepareStatement($mockAdapter, $mockStatement); // with TableIdentifier $deleteIgnore = new DeleteIgnore(); $mockDriver = $this->getMockBuilder(DriverInterface::class)->getMock(); $mockAdapter = $this->getMockBuilder(Adapter::class) ->setMethods() ->setConstructorArgs([$mockDriver]) ->getMock(); $mockStatement = $this->getMockBuilder(StatementInterface::class)->getMock(); $mockStatement->expects($this->at(2)) ->method('setSql') ->with($this->equalTo('DELETE IGNORE FROM "sch"."foo" WHERE x = y')); $deleteIgnore->from(new TableIdentifier('foo', 'sch')) ->where('x = y'); $deleteIgnore->prepareStatement($mockAdapter, $mockStatement); } /** * @coversNothing */ public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString() { $deleteIgnore = new DeleteIgnore(); $deleteIgnore->from('foo') ->where('x = y'); self::assertEquals('DELETE IGNORE FROM "foo" WHERE x = y', $deleteIgnore->getSqlString()); // with TableIdentifier $deleteIgnore = new DeleteIgnore(); $deleteIgnore->from(new TableIdentifier('foo', 'sch')) ->where('x = y'); self::assertEquals('DELETE IGNORE FROM "sch"."foo" WHERE x = y', $deleteIgnore->getSqlString()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Sql/LiteralTest.php
test/unit/Sql/LiteralTest.php
<?php namespace LaminasTest\Db\Sql; use Laminas\Db\Sql\Literal; use PHPUnit\Framework\TestCase; class LiteralTest extends TestCase { public function testSetLiteral() { $literal = new Literal('bar'); self::assertSame($literal, $literal->setLiteral('foo')); } public function testGetLiteral() { $literal = new Literal('bar'); self::assertEquals('bar', $literal->getLiteral()); } public function testGetExpressionData() { $literal = new Literal('bar'); self::assertEquals([['bar', [], []]], $literal->getExpressionData()); } public function testGetExpressionDataWillEscapePercent() { $expression = new Literal('X LIKE "foo%"'); self::assertEquals( [ [ 'X LIKE "foo%%"', [], [], ], ], $expression->getExpressionData() ); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Sql/JoinTest.php
test/unit/Sql/JoinTest.php
<?php namespace LaminasTest\Db\Sql; use InvalidArgumentException; use Laminas\Db\Sql\Join; use Laminas\Db\Sql\Select; use LaminasTest\Db\DeprecatedAssertionsTrait; use PHPUnit\Framework\TestCase; class JoinTest extends TestCase { use DeprecatedAssertionsTrait; public function testInitialPositionIsZero() { $join = new Join(); self::assertAttributeEquals(0, 'position', $join); } public function testNextIncrementsThePosition() { $join = new Join(); $join->next(); self::assertAttributeEquals(1, 'position', $join); } public function testRewindResetsPositionToZero() { $join = new Join(); $join->next(); $join->next(); self::assertAttributeEquals(2, 'position', $join); $join->rewind(); self::assertAttributeEquals(0, 'position', $join); } public function testKeyReturnsTheCurrentPosition() { $join = new Join(); $join->next(); $join->next(); $join->next(); self::assertEquals(3, $join->key()); } public function testCurrentReturnsTheCurrentJoinSpecification() { $name = 'baz'; $on = 'foo.id = baz.id'; $join = new Join(); $join->join($name, $on); $expectedSpecification = [ 'name' => $name, 'on' => $on, 'columns' => [Select::SQL_STAR], 'type' => Join::JOIN_INNER, ]; self::assertEquals($expectedSpecification, $join->current()); } public function testValidReturnsTrueIfTheIteratorIsAtAValidPositionAndFalseIfNot() { $join = new Join(); $join->join('baz', 'foo.id = baz.id'); self::assertTrue($join->valid()); $join->next(); self::assertFalse($join->valid()); } /** * @testdox unit test: Test join() returns Join object (is chainable) * @covers \Laminas\Db\Sql\Join::join */ public function testJoin() { $join = new Join(); $return = $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT); self::assertSame($join, $return); } public function testJoinFullOuter() { $join = new Join(); $return = $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_FULL_OUTER); self::assertSame($join, $return); } public function testJoinWillThrowAnExceptionIfNameIsNoValid() { $join = new Join(); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("join() expects '' as a single element associative array"); $join->join([], false); } /** * @testdox unit test: Test count() returns correct count * @covers \Laminas\Db\Sql\Join::count * @covers \Laminas\Db\Sql\Join::join */ public function testCount() { $join = new Join(); $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT); $join->join('bar', 'foo.fooId = bar.fooId', Join::JOIN_LEFT); self::assertEquals(2, $join->count()); self::assertCount($join->count(), $join->getJoins()); } /** * @testdox unit test: Test reset() resets the joins * @covers \Laminas\Db\Sql\Join::count * @covers \Laminas\Db\Sql\Join::join * @covers \Laminas\Db\Sql\Join::reset */ public function testReset() { $join = new Join(); $join->join('baz', 'foo.fooId = baz.fooId', Join::JOIN_LEFT); $join->join('bar', 'foo.fooId = bar.fooId', Join::JOIN_LEFT); $join->reset(); self::assertEquals(0, $join->count()); } }
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
false
laminas/laminas-db
https://github.com/laminas/laminas-db/blob/1395efe76f7a20c322e78d1885efe103e5e291ff/test/unit/Sql/SqlFunctionalTest.php
test/unit/Sql/SqlFunctionalTest.php
<?php namespace LaminasTest\Db\Sql; use Laminas\Db\Adapter; use Laminas\Db\Adapter\Driver\DriverInterface; use Laminas\Db\Sql; use Laminas\Db\Sql\AbstractSql; use Laminas\Db\Sql\Ddl\Column\Column; use Laminas\Db\Sql\Ddl\CreateTable; use Laminas\Db\Sql\Delete; use Laminas\Db\Sql\Expression; use Laminas\Db\Sql\Insert; use Laminas\Db\Sql\Platform\PlatformDecoratorInterface; use Laminas\Db\Sql\Select; use Laminas\Db\Sql\Update; use LaminasTest\Db\TestAsset; use PHPUnit\Framework\TestCase; use function array_merge; use function is_array; use function is_string; /** * @method Select select(null|string $table) * @method Update update(null|string $table) * @method Delete delete(null|string $table) * @method Insert insert(null|string $table) * @method CreateTable createTable(null|string $table) * @method Column createColumn(null|string $name) */ class SqlFunctionalTest extends TestCase { /** * @psalm-return array<string, array{ * sqlObject: AbstractSql, * expected: array{ * sql92: { * string: string, * prepare: string, * parameters: array<string, mixed> * }, * MySql: { * string: string, * prepare: string, * parameters: array<string, mixed> * }, * Oracle: { * string: string, * prepare: string, * parameters: array<string, mixed> * }, * SqlServer: { * string: string, * prepare: string, * parameters: array<string, mixed> * } * } * }> */ protected function dataProviderCommonProcessMethods(): array { // phpcs:disable Generic.Files.LineLength.TooLong return [ 'Select::processOffset()' => [ 'sqlObject' => $this->select('foo')->offset(10), 'expected' => [ 'sql92' => [ 'string' => 'SELECT "foo".* FROM "foo" OFFSET \'10\'', 'prepare' => 'SELECT "foo".* FROM "foo" OFFSET ?', 'parameters' => ['offset' => 10], ], 'MySql' => [ 'string' => 'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET 10', 'prepare' => 'SELECT `foo`.* FROM `foo` LIMIT 18446744073709551615 OFFSET ?', 'parameters' => ['offset' => 10], ], 'Oracle' => [ 'string' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b ) WHERE b_rownum > (10)', 'prepare' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b ) WHERE b_rownum > (:offset)', 'parameters' => ['offset' => 10], ], 'SqlServer' => [ 'string' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__LAMINAS_ROW_NUMBER] FROM [foo] ) AS [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__LAMINAS_ROW_NUMBER] BETWEEN 10+1 AND 0+10', 'prepare' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__LAMINAS_ROW_NUMBER] FROM [foo] ) AS [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__LAMINAS_ROW_NUMBER] BETWEEN ?+1 AND ?+?', 'parameters' => ['offset' => 10, 'limit' => null, 'offsetForSum' => 10], ], ], ], 'Select::processLimit()' => [ 'sqlObject' => $this->select('foo')->limit(10), 'expected' => [ 'sql92' => [ 'string' => 'SELECT "foo".* FROM "foo" LIMIT \'10\'', 'prepare' => 'SELECT "foo".* FROM "foo" LIMIT ?', 'parameters' => ['limit' => 10], ], 'MySql' => [ 'string' => 'SELECT `foo`.* FROM `foo` LIMIT 10', 'prepare' => 'SELECT `foo`.* FROM `foo` LIMIT ?', 'parameters' => ['limit' => 10], ], 'Oracle' => [ 'string' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b WHERE rownum <= (0+10)) WHERE b_rownum >= (0 + 1)', 'prepare' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b WHERE rownum <= (:offset+:limit)) WHERE b_rownum >= (:offset + 1)', 'parameters' => ['offset' => 0, 'limit' => 10], ], 'SqlServer' => [ 'string' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__LAMINAS_ROW_NUMBER] FROM [foo] ) AS [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__LAMINAS_ROW_NUMBER] BETWEEN 0+1 AND 10+0', 'prepare' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__LAMINAS_ROW_NUMBER] FROM [foo] ) AS [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__LAMINAS_ROW_NUMBER] BETWEEN ?+1 AND ?+?', 'parameters' => ['offset' => null, 'limit' => 10, 'offsetForSum' => null], ], ], ], 'Select::processLimitOffset()' => [ 'sqlObject' => $this->select('foo')->limit(10)->offset(5), 'expected' => [ 'sql92' => [ 'string' => 'SELECT "foo".* FROM "foo" LIMIT \'10\' OFFSET \'5\'', 'prepare' => 'SELECT "foo".* FROM "foo" LIMIT ? OFFSET ?', 'parameters' => ['limit' => 10, 'offset' => 5], ], 'MySql' => [ 'string' => 'SELECT `foo`.* FROM `foo` LIMIT 10 OFFSET 5', 'prepare' => 'SELECT `foo`.* FROM `foo` LIMIT ? OFFSET ?', 'parameters' => ['limit' => 10, 'offset' => 5], ], 'Oracle' => [ 'string' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b WHERE rownum <= (5+10)) WHERE b_rownum >= (5 + 1)', 'prepare' => 'SELECT * FROM (SELECT b.*, rownum b_rownum FROM ( SELECT "foo".* FROM "foo" ) b WHERE rownum <= (:offset+:limit)) WHERE b_rownum >= (:offset + 1)', 'parameters' => ['offset' => 5, 'limit' => 10], ], 'SqlServer' => [ 'string' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__LAMINAS_ROW_NUMBER] FROM [foo] ) AS [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__LAMINAS_ROW_NUMBER] BETWEEN 5+1 AND 10+5', 'prepare' => 'SELECT * FROM ( SELECT [foo].*, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [__LAMINAS_ROW_NUMBER] FROM [foo] ) AS [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [LAMINAS_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__LAMINAS_ROW_NUMBER] BETWEEN ?+1 AND ?+?', 'parameters' => ['offset' => 5, 'limit' => 10, 'offsetForSum' => 5], ], ], ], // Github issue https://github.com/zendframework/zend-db/issues/98 'Select::processJoinNoJoinedColumns()' => [ 'sqlObject' => $this->select('my_table') ->join( 'joined_table2', 'my_table.id = joined_table2.id', $columns = [] ) ->join( 'joined_table3', 'my_table.id = joined_table3.id', [Select::SQL_STAR] ) ->columns([ 'my_table_column', 'aliased_column' => new Expression('NOW()'), ]), 'expected' => [ 'sql92' => [ 'string' => 'SELECT "my_table"."my_table_column" AS "my_table_column", NOW() AS "aliased_column", "joined_table3".* FROM "my_table" INNER JOIN "joined_table2" ON "my_table"."id" = "joined_table2"."id" INNER JOIN "joined_table3" ON "my_table"."id" = "joined_table3"."id"', ], 'MySql' => [ 'string' => 'SELECT `my_table`.`my_table_column` AS `my_table_column`, NOW() AS `aliased_column`, `joined_table3`.* FROM `my_table` INNER JOIN `joined_table2` ON `my_table`.`id` = `joined_table2`.`id` INNER JOIN `joined_table3` ON `my_table`.`id` = `joined_table3`.`id`', ], 'Oracle' => [ 'string' => 'SELECT "my_table"."my_table_column" AS "my_table_column", NOW() AS "aliased_column", "joined_table3".* FROM "my_table" INNER JOIN "joined_table2" ON "my_table"."id" = "joined_table2"."id" INNER JOIN "joined_table3" ON "my_table"."id" = "joined_table3"."id"', ], 'SqlServer' => [ 'string' => 'SELECT [my_table].[my_table_column] AS [my_table_column], NOW() AS [aliased_column], [joined_table3].* FROM [my_table] INNER JOIN [joined_table2] ON [my_table].[id] = [joined_table2].[id] INNER JOIN [joined_table3] ON [my_table].[id] = [joined_table3].[id]', ], ], ], 'Select::processJoin()' => [ 'sqlObject' => $this->select('a') ->join(['b' => $this->select('c')->where(['cc' => 10])], 'd=e')->where(['x' => 20]), 'expected' => [ 'sql92' => [ 'string' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = \'10\') AS "b" ON "d"="e" WHERE "x" = \'20\'', 'prepare' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = ?) AS "b" ON "d"="e" WHERE "x" = ?', 'parameters' => ['subselect1where1' => 10, 'where1' => 20], ], 'MySql' => [ 'string' => 'SELECT `a`.*, `b`.* FROM `a` INNER JOIN (SELECT `c`.* FROM `c` WHERE `cc` = \'10\') AS `b` ON `d`=`e` WHERE `x` = \'20\'', 'prepare' => 'SELECT `a`.*, `b`.* FROM `a` INNER JOIN (SELECT `c`.* FROM `c` WHERE `cc` = ?) AS `b` ON `d`=`e` WHERE `x` = ?', 'parameters' => ['subselect2where1' => 10, 'where2' => 20], ], 'Oracle' => [ 'string' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = \'10\') "b" ON "d"="e" WHERE "x" = \'20\'', 'prepare' => 'SELECT "a".*, "b".* FROM "a" INNER JOIN (SELECT "c".* FROM "c" WHERE "cc" = ?) "b" ON "d"="e" WHERE "x" = ?', 'parameters' => ['subselect2where1' => 10, 'where2' => 20], ], 'SqlServer' => [ 'string' => 'SELECT [a].*, [b].* FROM [a] INNER JOIN (SELECT [c].* FROM [c] WHERE [cc] = \'10\') AS [b] ON [d]=[e] WHERE [x] = \'20\'', 'prepare' => 'SELECT [a].*, [b].* FROM [a] INNER JOIN (SELECT [c].* FROM [c] WHERE [cc] = ?) AS [b] ON [d]=[e] WHERE [x] = ?', 'parameters' => ['subselect2where1' => 10, 'where2' => 20], ], ], ], 'Ddl::CreateTable::processColumns()' => [ 'sqlObject' => $this->createTable('foo') ->addColumn($this->createColumn('col1') ->setOption('identity', true) ->setOption('comment', 'Comment1')) ->addColumn($this->createColumn('col2') ->setOption('identity', true) ->setOption('comment', 'Comment2')), 'expected' => [ 'sql92' => "CREATE TABLE \"foo\" ( \n \"col1\" INTEGER NOT NULL,\n \"col2\" INTEGER NOT NULL \n)", 'MySql' => "CREATE TABLE `foo` ( \n `col1` INTEGER NOT NULL AUTO_INCREMENT COMMENT 'Comment1',\n `col2` INTEGER NOT NULL AUTO_INCREMENT COMMENT 'Comment2' \n)", 'Oracle' => "CREATE TABLE \"foo\" ( \n \"col1\" INTEGER NOT NULL,\n \"col2\" INTEGER NOT NULL \n)", 'SqlServer' => "CREATE TABLE [foo] ( \n [col1] INTEGER NOT NULL,\n [col2] INTEGER NOT NULL \n)", ], ], 'Ddl::CreateTable::processTable()' => [ 'sqlObject' => $this->createTable('foo')->setTemporary(true), 'expected' => [ 'sql92' => "CREATE TEMPORARY TABLE \"foo\" ( \n)", 'MySql' => "CREATE TEMPORARY TABLE `foo` ( \n)", 'Oracle' => "CREATE TEMPORARY TABLE \"foo\" ( \n)", 'SqlServer' => "CREATE TABLE [#foo] ( \n)", ], ], 'Select::processSubSelect()' => [ 'sqlObject' => $this ->select([ 'a' => $this ->select([ 'b' => $this->select('c')->where(['cc' => 'CC']), ]) ->where(['bb' => 'BB']), ]) ->where(['aa' => 'AA']), 'expected' => [ 'sql92' => [ 'string' => 'SELECT "a".* FROM (SELECT "b".* FROM (SELECT "c".* FROM "c" WHERE "cc" = \'CC\') AS "b" WHERE "bb" = \'BB\') AS "a" WHERE "aa" = \'AA\'', 'prepare' => 'SELECT "a".* FROM (SELECT "b".* FROM (SELECT "c".* FROM "c" WHERE "cc" = ?) AS "b" WHERE "bb" = ?) AS "a" WHERE "aa" = ?', 'parameters' => ['subselect2where1' => 'CC', 'subselect1where1' => 'BB', 'where1' => 'AA'], ], 'MySql' => [ 'string' => 'SELECT `a`.* FROM (SELECT `b`.* FROM (SELECT `c`.* FROM `c` WHERE `cc` = \'CC\') AS `b` WHERE `bb` = \'BB\') AS `a` WHERE `aa` = \'AA\'', 'prepare' => 'SELECT `a`.* FROM (SELECT `b`.* FROM (SELECT `c`.* FROM `c` WHERE `cc` = ?) AS `b` WHERE `bb` = ?) AS `a` WHERE `aa` = ?', 'parameters' => ['subselect4where1' => 'CC', 'subselect3where1' => 'BB', 'where2' => 'AA'], ], 'Oracle' => [ 'string' => 'SELECT "a".* FROM (SELECT "b".* FROM (SELECT "c".* FROM "c" WHERE "cc" = \'CC\') "b" WHERE "bb" = \'BB\') "a" WHERE "aa" = \'AA\'', 'prepare' => 'SELECT "a".* FROM (SELECT "b".* FROM (SELECT "c".* FROM "c" WHERE "cc" = ?) "b" WHERE "bb" = ?) "a" WHERE "aa" = ?', 'parameters' => ['subselect4where1' => 'CC', 'subselect3where1' => 'BB', 'where2' => 'AA'], ], 'SqlServer' => [ 'string' => 'SELECT [a].* FROM (SELECT [b].* FROM (SELECT [c].* FROM [c] WHERE [cc] = \'CC\') AS [b] WHERE [bb] = \'BB\') AS [a] WHERE [aa] = \'AA\'', 'prepare' => 'SELECT [a].* FROM (SELECT [b].* FROM (SELECT [c].* FROM [c] WHERE [cc] = ?) AS [b] WHERE [bb] = ?) AS [a] WHERE [aa] = ?', 'parameters' => ['subselect4where1' => 'CC', 'subselect3where1' => 'BB', 'where2' => 'AA'], ], ], ], 'Delete::processSubSelect()' => [ 'sqlObject' => $this->delete('foo')->where(['x' => $this->select('foo')->where(['x' => 'y'])]), 'expected' => [ 'sql92' => [ 'string' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')', 'prepare' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = ?)', 'parameters' => ['subselect1where1' => 'y'], ], 'MySql' => [ 'string' => 'DELETE FROM `foo` WHERE `x` = (SELECT `foo`.* FROM `foo` WHERE `x` = \'y\')', 'prepare' => 'DELETE FROM `foo` WHERE `x` = (SELECT `foo`.* FROM `foo` WHERE `x` = ?)', 'parameters' => ['subselect2where1' => 'y'], ], 'Oracle' => [ 'string' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')', 'prepare' => 'DELETE FROM "foo" WHERE "x" = (SELECT "foo".* FROM "foo" WHERE "x" = ?)', 'parameters' => ['subselect3where1' => 'y'], ], 'SqlServer' => [ 'string' => 'DELETE FROM [foo] WHERE [x] = (SELECT [foo].* FROM [foo] WHERE [x] = \'y\')', 'prepare' => 'DELETE FROM [foo] WHERE [x] = (SELECT [foo].* FROM [foo] WHERE [x] = ?)', 'parameters' => ['subselect4where1' => 'y'], ], ], ], 'Update::processSubSelect()' => [ 'sqlObject' => $this->update('foo')->set(['x' => $this->select('foo')]), 'expected' => [ 'sql92' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo")', 'MySql' => 'UPDATE `foo` SET `x` = (SELECT `foo`.* FROM `foo`)', 'Oracle' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo")', 'SqlServer' => 'UPDATE [foo] SET [x] = (SELECT [foo].* FROM [foo])', ], ], 'Insert::processSubSelect()' => [ 'sqlObject' => $this->insert('foo')->select($this->select('foo')->where(['x' => 'y'])), 'expected' => [ 'sql92' => [ 'string' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = \'y\'', 'prepare' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = ?', 'parameters' => ['subselect1where1' => 'y'], ], 'MySql' => [ 'string' => 'INSERT INTO `foo` SELECT `foo`.* FROM `foo` WHERE `x` = \'y\'', 'prepare' => 'INSERT INTO `foo` SELECT `foo`.* FROM `foo` WHERE `x` = ?', 'parameters' => ['subselect2where1' => 'y'], ], 'Oracle' => [ 'string' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = \'y\'', 'prepare' => 'INSERT INTO "foo" SELECT "foo".* FROM "foo" WHERE "x" = ?', 'parameters' => ['subselect3where1' => 'y'], ], 'SqlServer' => [ 'string' => 'INSERT INTO [foo] SELECT [foo].* FROM [foo] WHERE [x] = \'y\'', 'prepare' => 'INSERT INTO [foo] SELECT [foo].* FROM [foo] WHERE [x] = ?', 'parameters' => ['subselect4where1' => 'y'], ], ], ], 'Update::processExpression()' => [ 'sqlObject' => $this->update('foo')->set( ['x' => new Sql\Expression('?', [$this->select('foo')->where(['x' => 'y'])])] ), 'expected' => [ 'sql92' => [ 'string' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')', 'prepare' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo" WHERE "x" = ?)', 'parameters' => ['subselect1where1' => 'y'], ], 'MySql' => [ 'string' => 'UPDATE `foo` SET `x` = (SELECT `foo`.* FROM `foo` WHERE `x` = \'y\')', 'prepare' => 'UPDATE `foo` SET `x` = (SELECT `foo`.* FROM `foo` WHERE `x` = ?)', 'parameters' => ['subselect2where1' => 'y'], ], 'Oracle' => [ 'string' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo" WHERE "x" = \'y\')', 'prepare' => 'UPDATE "foo" SET "x" = (SELECT "foo".* FROM "foo" WHERE "x" = ?)', 'parameters' => ['subselect3where1' => 'y'], ], 'SqlServer' => [ 'string' => 'UPDATE [foo] SET [x] = (SELECT [foo].* FROM [foo] WHERE [x] = \'y\')', 'prepare' => 'UPDATE [foo] SET [x] = (SELECT [foo].* FROM [foo] WHERE [x] = ?)', 'parameters' => ['subselect4where1' => 'y'], ], ], ], 'Update::processJoins()' => [ 'sqlObject' => $this->update('foo')->set(['x' => 'y'])->where(['xx' => 'yy'])->join( 'bar', 'bar.barId = foo.barId' ), 'expected' => [ 'sql92' => [ 'string' => 'UPDATE "foo" INNER JOIN "bar" ON "bar"."barId" = "foo"."barId" SET "x" = \'y\' WHERE "xx" = \'yy\'', ], 'MySql' => [ 'string' => 'UPDATE `foo` INNER JOIN `bar` ON `bar`.`barId` = `foo`.`barId` SET `x` = \'y\' WHERE `xx` = \'yy\'', ], 'Oracle' => [ 'string' => 'UPDATE "foo" INNER JOIN "bar" ON "bar"."barId" = "foo"."barId" SET "x" = \'y\' WHERE "xx" = \'yy\'', ], 'SqlServer' => [ 'string' => 'UPDATE [foo] INNER JOIN [bar] ON [bar].[barId] = [foo].[barId] SET [x] = \'y\' WHERE [xx] = \'yy\'', ], ], ], ]; // phpcs:enable Generic.Files.LineLength.TooLong } /** * @psalm-return array<string, array{ * sqlObject: AbstractSql, * expected: array{ * sql92: array{ * decorators: array<class-string, PlatformDecoratorInterface>, * string: string * }, * MySql: array{ * decorators: array<class-string, PlatformDecoratorInterface>, * string: string * }, * Oracle: array{ * decorators: array<class-string, PlatformDecoratorInterface>, * string: string * }, * SqlServer: array{ * decorators: array<class-string, PlatformDecoratorInterface>, * string: string * } * } * }> */ protected function dataProviderDecorators(): array { return [ 'RootDecorators::Select' => [ 'sqlObject' => $this->select('foo')->where(['x' => $this->select('bar')]), 'expected' => [ 'sql92' => [ 'decorators' => [ Select::class => new TestAsset\SelectDecorator(), ], 'string' => 'SELECT "foo".* FROM "foo" WHERE "x" = (SELECT "bar".* FROM "bar")', ], 'MySql' => [ 'decorators' => [ Select::class => new TestAsset\SelectDecorator(), ], 'string' => 'SELECT `foo`.* FROM `foo` WHERE `x` = (SELECT `bar`.* FROM `bar`)', ], 'Oracle' => [ 'decorators' => [ Select::class => new TestAsset\SelectDecorator(), ], 'string' => 'SELECT "foo".* FROM "foo" WHERE "x" = (SELECT "bar".* FROM "bar")', ], 'SqlServer' => [ 'decorators' => [ Select::class => new TestAsset\SelectDecorator(), ], 'string' => 'SELECT [foo].* FROM [foo] WHERE [x] = (SELECT [bar].* FROM [bar])', ], ], ], // phpcs:disable Generic.Files.LineLength.TooLong /* TODO - should be implemented 'RootDecorators::Insert' => array( 'sqlObject' => $this->insert('foo')->select($this->select()), 'expected' => array( 'sql92' => array( 'decorators' => array( 'Laminas\Db\Sql\Insert' => new TestAsset\InsertDecorator, // Decorator for root sqlObject 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_Sql92=}') ), 'string' => 'INSERT INTO "foo" {=SELECT_Sql92=}', ), 'MySql' => array( 'decorators' => array( 'Laminas\Db\Sql\Insert' => new TestAsset\InsertDecorator, // Decorator for root sqlObject 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_MySql=}') ), 'string' => 'INSERT INTO `foo` {=SELECT_MySql=}', ), 'Oracle' => array( 'decorators' => array( 'Laminas\Db\Sql\Insert' => new TestAsset\InsertDecorator, // Decorator for root sqlObject 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Oracle\SelectDecorator', '{=SELECT_Oracle=}') ), 'string' => 'INSERT INTO "foo" {=SELECT_Oracle=}', ), 'SqlServer' => array( 'decorators' => array( 'Laminas\Db\Sql\Insert' => new TestAsset\InsertDecorator, // Decorator for root sqlObject 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\SqlServer\SelectDecorator', '{=SELECT_SqlServer=}') ), 'string' => 'INSERT INTO [foo] {=SELECT_SqlServer=}', ), ), ), 'RootDecorators::Delete' => array( 'sqlObject' => $this->delete('foo')->where(array('x'=>$this->select('foo'))), 'expected' => array( 'sql92' => array( 'decorators' => array( 'Laminas\Db\Sql\Delete' => new TestAsset\DeleteDecorator, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_Sql92=}') ), 'string' => 'DELETE FROM "foo" WHERE "x" = ({=SELECT_Sql92=})', ), 'MySql' => array( 'decorators' => array( 'Laminas\Db\Sql\Delete' => new TestAsset\DeleteDecorator, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_MySql=}') ), 'string' => 'DELETE FROM `foo` WHERE `x` = ({=SELECT_MySql=})', ), 'Oracle' => array( 'decorators' => array( 'Laminas\Db\Sql\Delete' => new TestAsset\DeleteDecorator, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Oracle\SelectDecorator', '{=SELECT_Oracle=}') ), 'string' => 'DELETE FROM "foo" WHERE "x" = ({=SELECT_Oracle=})', ), 'SqlServer' => array( 'decorators' => array( 'Laminas\Db\Sql\Delete' => new TestAsset\DeleteDecorator, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\SqlServer\SelectDecorator', '{=SELECT_SqlServer=}') ), 'string' => 'DELETE FROM [foo] WHERE [x] = ({=SELECT_SqlServer=})', ), ), ), 'RootDecorators::Update' => array( 'sqlObject' => $this->update('foo')->where(array('x'=>$this->select('foo'))), 'expected' => array( 'sql92' => array( 'decorators' => array( 'Laminas\Db\Sql\Update' => new TestAsset\UpdateDecorator, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_Sql92=}') ), 'string' => 'UPDATE "foo" SET WHERE "x" = ({=SELECT_Sql92=})', ), 'MySql' => array( 'decorators' => array( 'Laminas\Db\Sql\Update' => new TestAsset\UpdateDecorator, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_MySql=}') ), 'string' => 'UPDATE `foo` SET WHERE `x` = ({=SELECT_MySql=})', ), 'Oracle' => array( 'decorators' => array( 'Laminas\Db\Sql\Update' => new TestAsset\UpdateDecorator, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Oracle\SelectDecorator', '{=SELECT_Oracle=}') ), 'string' => 'UPDATE "foo" SET WHERE "x" = ({=SELECT_Oracle=})', ), 'SqlServer' => array( 'decorators' => array( 'Laminas\Db\Sql\Update' => new TestAsset\UpdateDecorator, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\SqlServer\SelectDecorator', '{=SELECT_SqlServer=}') ), 'string' => 'UPDATE [foo] SET WHERE [x] = ({=SELECT_SqlServer=})', ), ), ), 'DecorableExpression()' => array( 'sqlObject' => $this->update('foo')->where(array('x'=>new Sql\Expression('?', array($this->select('foo'))))), 'expected' => array( 'sql92' => array( 'decorators' => array( 'Laminas\Db\Sql\Expression' => new TestAsset\DecorableExpression, 'Laminas\Db\Sql\Select' => array('Laminas\Db\Sql\Platform\Mysql\SelectDecorator', '{=SELECT_Sql92=}') ), 'string' => 'UPDATE "foo" SET WHERE "x" = {decorate-({=SELECT_Sql92=})-decorate}', ), 'MySql' => array( 'decorators' => array( 'Laminas\Db\Sql\Expression' => new TestAsset\DecorableExpression,
php
BSD-3-Clause
1395efe76f7a20c322e78d1885efe103e5e291ff
2026-01-05T05:03:07.882669Z
true