/** * Temporary method for db interaction * * @param Db $db * @return Response */ public function databaseAction(Db $db) { $db->query('CREATE TABLE users(name varchar(255));'); $db->query('INSERT INTO users VALUES (?)', ['matthew']); $results = $db->first("SELECT * FROM users WHERE name = ?", ['matthew']); /** Psr7 example */ $stream = new Stream('php://memory', 'wb+'); $stream->write(json_encode($results)); return (new Response())->withStatus(200)->withBody($stream)->withHeader('Content-Type', 'application/json'); }
public function testQueryFindsFirst() { $user = new StdClass(); $user->name = 'matthew'; $statement = Mockery::mock('\\PDOStatement'); $statement->shouldReceive('execute')->once()->with(['matthew'])->andReturn(true); $statement->shouldReceive('fetch')->once()->andReturn($user); $pdo = Mockery::mock('\\PDO'); $pdo->shouldReceive('prepare')->once()->with('SELECT * FROM users WHERE name = ?')->andReturn($statement); $conn = Mockery::mock('\\Fyuze\\Database\\Drivers\\ConnectionInterface'); $conn->shouldReceive('open')->once()->andReturn($pdo); $db = new Db($conn); $first = $db->first('SELECT * FROM users WHERE name = ?', ['matthew']); $this->assertEquals('matthew', $first->name); }