/** * test the insert method * * @return void */ public function testInsert() { $fixture = new ArticlesFixture(); $db = $this->getMock('Cake\\Database\\Connection', [], [], '', false); $query = $this->getMock('Cake\\Database\\Query', [], [$db]); $db->expects($this->once())->method('newQuery')->will($this->returnValue($query)); $query->expects($this->once())->method('insert')->with(['name', 'created'], ['name' => 'string', 'created' => 'datetime'])->will($this->returnSelf()); $query->expects($this->once())->method('into')->with('articles')->will($this->returnSelf()); $expected = [['name' => 'Gandalf', 'created' => '2009-04-28 19:20:00'], ['name' => 'Captain Picard', 'created' => '2009-04-28 19:20:00'], ['name' => 'Chewbacca', 'created' => '2009-04-28 19:20:00']]; $query->expects($this->at(2))->method('values')->with($expected[0])->will($this->returnSelf()); $query->expects($this->at(3))->method('values')->with($expected[1])->will($this->returnSelf()); $query->expects($this->at(4))->method('values')->with($expected[2])->will($this->returnSelf()); $statement = $this->getMock('\\PDOStatement', ['closeCursor']); $statement->expects($this->once())->method('closeCursor'); $query->expects($this->once())->method('execute')->will($this->returnValue($statement)); $this->assertSame($statement, $fixture->insert($db)); }