|
|
|
|
@ -99,7 +99,7 @@ class QBMapperTest extends \Test\TestCase { |
|
|
|
|
$this->mapper = new QBTestMapper($this->db); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testInsertEntityParameterTypeMapping(): void { |
|
|
|
|
$datetime = new \DateTimeImmutable(); |
|
|
|
|
$entity = new QBTestEntity(); |
|
|
|
|
@ -117,31 +117,40 @@ class QBMapperTest extends \Test\TestCase { |
|
|
|
|
$booleanParam = $this->qb->createNamedParameter('boolean_prop', IQueryBuilder::PARAM_BOOL); |
|
|
|
|
$datetimeParam = $this->qb->createNamedParameter('datetime_prop', IQueryBuilder::PARAM_DATETIME_IMMUTABLE); |
|
|
|
|
|
|
|
|
|
$createNamedParameterCalls = [ |
|
|
|
|
[123, IQueryBuilder::PARAM_INT, null], |
|
|
|
|
[true, IQueryBuilder::PARAM_BOOL, null], |
|
|
|
|
['string', IQueryBuilder::PARAM_STR, null], |
|
|
|
|
[456, IQueryBuilder::PARAM_INT, null], |
|
|
|
|
[false, IQueryBuilder::PARAM_BOOL, null], |
|
|
|
|
[$datetime, IQueryBuilder::PARAM_DATETIME_IMMUTABLE, null], |
|
|
|
|
]; |
|
|
|
|
$this->qb->expects($this->exactly(6)) |
|
|
|
|
->method('createNamedParameter') |
|
|
|
|
->withConsecutive( |
|
|
|
|
[$this->equalTo(123), $this->equalTo(IQueryBuilder::PARAM_INT)], |
|
|
|
|
[$this->equalTo(true), $this->equalTo(IQueryBuilder::PARAM_BOOL)], |
|
|
|
|
[$this->equalTo('string'), $this->equalTo(IQueryBuilder::PARAM_STR)], |
|
|
|
|
[$this->equalTo(456), $this->equalTo(IQueryBuilder::PARAM_INT)], |
|
|
|
|
[$this->equalTo(false), $this->equalTo(IQueryBuilder::PARAM_BOOL)], |
|
|
|
|
[$this->equalTo($datetime), $this->equalTo(IQueryBuilder::PARAM_DATETIME_IMMUTABLE)], |
|
|
|
|
); |
|
|
|
|
->willReturnCallback(function() use (&$createNamedParameterCalls) { |
|
|
|
|
$expected = array_shift($createNamedParameterCalls); |
|
|
|
|
$this->assertEquals($expected, func_get_args()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$setValueCalls = [ |
|
|
|
|
['int_prop', $intParam], |
|
|
|
|
['bool_prop', $boolParam], |
|
|
|
|
['string_prop', $stringParam], |
|
|
|
|
['integer_prop', $integerParam], |
|
|
|
|
['boolean_prop', $booleanParam], |
|
|
|
|
['datetime_prop', $datetimeParam], |
|
|
|
|
]; |
|
|
|
|
$this->qb->expects($this->exactly(6)) |
|
|
|
|
->method('setValue') |
|
|
|
|
->withConsecutive( |
|
|
|
|
[$this->equalTo('int_prop'), $this->equalTo($intParam)], |
|
|
|
|
[$this->equalTo('bool_prop'), $this->equalTo($boolParam)], |
|
|
|
|
[$this->equalTo('string_prop'), $this->equalTo($stringParam)], |
|
|
|
|
[$this->equalTo('integer_prop'), $this->equalTo($integerParam)], |
|
|
|
|
[$this->equalTo('boolean_prop'), $this->equalTo($booleanParam)], |
|
|
|
|
[$this->equalTo('datetime_prop'), $this->equalTo($datetimeParam)], |
|
|
|
|
); |
|
|
|
|
->willReturnCallback(function() use (&$setValueCalls) { |
|
|
|
|
$expected = array_shift($setValueCalls); |
|
|
|
|
$this->assertEquals($expected, func_get_args()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$this->mapper->insert($entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateEntityParameterTypeMapping(): void { |
|
|
|
|
$datetime = new \DateTimeImmutable(); |
|
|
|
|
$entity = new QBTestEntity(); |
|
|
|
|
@ -163,30 +172,38 @@ class QBMapperTest extends \Test\TestCase { |
|
|
|
|
$jsonParam = $this->qb->createNamedParameter('json_prop', IQueryBuilder::PARAM_JSON); |
|
|
|
|
$datetimeParam = $this->qb->createNamedParameter('datetime_prop', IQueryBuilder::PARAM_DATETIME_IMMUTABLE); |
|
|
|
|
|
|
|
|
|
$createNamedParameterCalls = [ |
|
|
|
|
[123, IQueryBuilder::PARAM_INT, null], |
|
|
|
|
[true, IQueryBuilder::PARAM_BOOL, null], |
|
|
|
|
['string', IQueryBuilder::PARAM_STR, null], |
|
|
|
|
[456, IQueryBuilder::PARAM_INT, null], |
|
|
|
|
[false, IQueryBuilder::PARAM_BOOL, null], |
|
|
|
|
[['hello' => 'world'], IQueryBuilder::PARAM_JSON, null], |
|
|
|
|
[$datetime, IQueryBuilder::PARAM_DATETIME_IMMUTABLE, null], |
|
|
|
|
[789, IQueryBuilder::PARAM_INT, null], |
|
|
|
|
]; |
|
|
|
|
$this->qb->expects($this->exactly(8)) |
|
|
|
|
->method('createNamedParameter') |
|
|
|
|
->withConsecutive( |
|
|
|
|
[$this->equalTo(123), $this->equalTo(IQueryBuilder::PARAM_INT)], |
|
|
|
|
[$this->equalTo(true), $this->equalTo(IQueryBuilder::PARAM_BOOL)], |
|
|
|
|
[$this->equalTo('string'), $this->equalTo(IQueryBuilder::PARAM_STR)], |
|
|
|
|
[$this->equalTo(456), $this->equalTo(IQueryBuilder::PARAM_INT)], |
|
|
|
|
[$this->equalTo(false), $this->equalTo(IQueryBuilder::PARAM_BOOL)], |
|
|
|
|
[$this->equalTo(['hello' => 'world']), $this->equalTo(IQueryBuilder::PARAM_JSON)], |
|
|
|
|
[$this->equalTo($datetime), $this->equalTo(IQueryBuilder::PARAM_DATETIME_IMMUTABLE)], |
|
|
|
|
[$this->equalTo(789), $this->equalTo(IQueryBuilder::PARAM_INT)], |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
->willReturnCallback(function() use (&$createNamedParameterCalls) { |
|
|
|
|
$expected = array_shift($createNamedParameterCalls); |
|
|
|
|
$this->assertEquals($expected, func_get_args()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$setCalls = [ |
|
|
|
|
['int_prop', $intParam], |
|
|
|
|
['bool_prop', $boolParam], |
|
|
|
|
['string_prop', $stringParam], |
|
|
|
|
['integer_prop', $integerParam], |
|
|
|
|
['boolean_prop', $booleanParam], |
|
|
|
|
['json_prop', $datetimeParam], |
|
|
|
|
['datetime_prop', $datetimeParam], |
|
|
|
|
]; |
|
|
|
|
$this->qb->expects($this->exactly(7)) |
|
|
|
|
->method('set') |
|
|
|
|
->withConsecutive( |
|
|
|
|
[$this->equalTo('int_prop'), $this->equalTo($intParam)], |
|
|
|
|
[$this->equalTo('bool_prop'), $this->equalTo($boolParam)], |
|
|
|
|
[$this->equalTo('string_prop'), $this->equalTo($stringParam)], |
|
|
|
|
[$this->equalTo('integer_prop'), $this->equalTo($integerParam)], |
|
|
|
|
[$this->equalTo('boolean_prop'), $this->equalTo($booleanParam)], |
|
|
|
|
[$this->equalTo('json_prop'), $this->equalTo($jsonParam)], |
|
|
|
|
[$this->equalTo('datetime_prop'), $this->equalTo($datetimeParam)], |
|
|
|
|
); |
|
|
|
|
->willReturnCallback(function() use (&$setCalls) { |
|
|
|
|
$expected = array_shift($setCalls); |
|
|
|
|
$this->assertEquals($expected, func_get_args()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$this->expr->expects($this->once()) |
|
|
|
|
->method('eq') |
|
|
|
|
@ -196,7 +213,7 @@ class QBMapperTest extends \Test\TestCase { |
|
|
|
|
$this->mapper->update($entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetParameterTypeForProperty(): void { |
|
|
|
|
$entity = new QBTestEntity(); |
|
|
|
|
|
|
|
|
|
|