| Total Complexity | 6 |
| Total Lines | 179 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class StatementTest extends \Doctrine\Tests\DbalTestCase |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * |
||
| 13 | * @var \Doctrine\DBAL\Connection |
||
| 14 | */ |
||
| 15 | private $conn; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * |
||
| 19 | * @var \Doctrine\DBAL\Configuration |
||
| 20 | */ |
||
| 21 | private $configuration; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var \PDOStatement |
||
| 25 | */ |
||
| 26 | private $pdoStatement; |
||
| 27 | |||
| 28 | protected function setUp() |
||
| 29 | { |
||
| 30 | $this->pdoStatement = $this->getMockBuilder('\PDOStatement') |
||
|
1 ignored issue
–
show
|
|||
| 31 | ->setMethods(array('execute', 'bindParam', 'bindValue')) |
||
| 32 | ->getMock(); |
||
| 33 | $platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform(); |
||
| 34 | $driverConnection = $this->createMock('\Doctrine\DBAL\Driver\Connection'); |
||
| 35 | $driverConnection->expects($this->any()) |
||
| 36 | ->method('prepare') |
||
| 37 | ->will($this->returnValue($this->pdoStatement)); |
||
| 38 | |||
| 39 | $driver = $this->createMock('\Doctrine\DBAL\Driver'); |
||
| 40 | $constructorArgs = array( |
||
| 41 | array( |
||
| 42 | 'platform' => $platform |
||
| 43 | ), |
||
| 44 | $driver |
||
| 45 | ); |
||
| 46 | $this->conn = $this->getMockBuilder('\Doctrine\DBAL\Connection') |
||
|
1 ignored issue
–
show
|
|||
| 47 | ->setConstructorArgs($constructorArgs) |
||
| 48 | ->getMock(); |
||
| 49 | $this->conn->expects($this->atLeastOnce()) |
||
| 50 | ->method('getWrappedConnection') |
||
| 51 | ->will($this->returnValue($driverConnection)); |
||
| 52 | |||
| 53 | $this->configuration = $this->createMock('\Doctrine\DBAL\Configuration'); |
||
|
1 ignored issue
–
show
|
|||
| 54 | $this->conn->expects($this->any()) |
||
| 55 | ->method('getConfiguration') |
||
| 56 | ->will($this->returnValue($this->configuration)); |
||
| 57 | |||
| 58 | $this->conn->expects($this->any()) |
||
| 59 | ->method('getDriver') |
||
| 60 | ->will($this->returnValue($driver)); |
||
| 61 | |||
| 62 | } |
||
| 63 | |||
| 64 | public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() |
||
| 65 | { |
||
| 66 | $name = 'foo'; |
||
| 67 | $var = 'bar'; |
||
| 68 | $type = ParameterType::STRING; |
||
| 69 | $values = [$name => $var]; |
||
| 70 | $types = [$name => $type]; |
||
| 71 | $sql = ''; |
||
| 72 | |||
| 73 | $logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger'); |
||
| 74 | $logger->expects($this->once()) |
||
| 75 | ->method('startQuery') |
||
| 76 | ->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types)); |
||
| 77 | |||
| 78 | $this->configuration->expects($this->once()) |
||
| 79 | ->method('getSQLLogger') |
||
| 80 | ->will($this->returnValue($logger)); |
||
| 81 | |||
| 82 | $statement = new Statement($sql, $this->conn); |
||
| 83 | $statement->bindValue($name, $var, $type); |
||
| 84 | $statement->execute(); |
||
| 85 | } |
||
| 86 | |||
| 87 | public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedToExecute() |
||
| 88 | { |
||
| 89 | $name = 'foo'; |
||
| 90 | $var = 'bar'; |
||
| 91 | $values = array($name => $var); |
||
| 92 | $types = array(); |
||
| 93 | $sql = ''; |
||
| 94 | |||
| 95 | $logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger'); |
||
| 96 | $logger->expects($this->once()) |
||
| 97 | ->method('startQuery') |
||
| 98 | ->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types)); |
||
| 99 | |||
| 100 | $this->configuration->expects($this->once()) |
||
| 101 | ->method('getSQLLogger') |
||
| 102 | ->will($this->returnValue($logger)); |
||
| 103 | |||
| 104 | $statement = new Statement($sql, $this->conn); |
||
| 105 | $statement->execute($values); |
||
| 106 | } |
||
| 107 | |||
| 108 | public function testExecuteCallsStartQueryWithTheParametersBoundViaBindParam() |
||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @expectedException \Doctrine\DBAL\DBALException |
||
| 132 | */ |
||
| 133 | public function testExecuteCallsLoggerStopQueryOnException() |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @expectedException \Doctrine\DBAL\DBALException |
||
| 162 | */ |
||
| 163 | public function testExecuteCallsLoggerExtendedFailsOnException() |
||
| 190 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..