public function testGeneratePDOStatementWithFail()
 {
     $mockPdoStatement = Mockery::mock(\PDOStatement::class);
     $mockPdoStatement->shouldReceive('execute')->with([':id' => 'blabla'])->andReturn(false);
     // fail
     $mockPdoStatement->shouldReceive('errorInfo')->andReturn([0, 1, 'blabla']);
     $mockPdo = Mockery::mock(\PDO::class);
     $mockPdo->shouldReceive('prepare')->with('SELECT * FROM `test` WHERE `id`=:id')->andReturn($mockPdoStatement);
     $connector = new Connection($mockPdo);
     try {
         $connector->generatePDOStatement('SELECT * FROM `test` WHERE `id`=:id', [':id' => 'blabla']);
         $this->fail();
     } catch (RuntimeException $e) {
         $this->assertEquals('DB Error, blabla. Query is "SELECT * FROM `test` WHERE `id`=:id"', $e->getMessage());
     }
 }
 public function register(ContainerInterface $app)
 {
     $app->singleton(Connection::class, function ($app) {
         return Connection::factory($app['config']['database']);
     });
     $app->alias('connection', Connection::class);
 }
Exemple #3
0
 /**
  * @param Model $model
  * @return self
  */
 public function store(Model $model)
 {
     $this->insert($model->toArray());
     $model->offsetSet($model->getPrimaryKey(), $this->connection->getLastInsertId());
     return $this;
 }