Ejemplo n.º 1
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->db_file = tempnam(sys_get_temp_dir(), 'test.sqlite');
     file_put_contents($this->db_file, '');
     $db = new PDO('sqlite:' . $this->db_file);
     $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $db->exec("CREATE TABLE fairies(id INT PRIMARY_KEY,name VARCHAR(255),fb_id VARCHAR(255))");
     $db->exec("INSERT INTO fairies(id,name,fb_id) VALUES(1,'Trixie','12345')");
     $db = null;
     $pixie = $this->pixie = new \PHPixie\Pixie();
     $this->pixie->app_namespace = 'FacebookTest\\';
     $pixie->db = new \PHPixie\DB($pixie);
     $pixie->orm = new \PHPixie\ORM($pixie);
     $this->pixie->auth = new \PHPixie\Auth($pixie);
     $pixie->config->set('db.default.connection', 'sqlite:' . $this->db_file);
     $pixie->config->set('db.default.driver', 'pdo');
     $pixie->config->set('auth.default.model', 'Fairy');
     $pixie->config->set('auth.default.login.facebook.app_id', '111');
     $pixie->config->set('auth.default.login.facebook.app_secret', '222');
     $pixie->config->set('auth.default.login.facebook.permissions', array('user_about_me'));
     $pixie->config->set('auth.default.login.facebook.fbid_field', 'fb_id');
     $this->session_array = array();
     $pixie->session = new \AuthStub\Session($this->session_array);
     $this->object = $this->getMock('\\PHPixie\\Auth\\Login\\Facebook', array('request'), array($pixie, $pixie->auth->service(), 'default'));
     $this->object->expects($this->any())->method('request')->will($this->returnCallback(function ($url) use($pixie) {
         $data = array();
         switch ($url) {
             case "https://graph.facebook.com/oauth/access_token?" . "client_id=111" . "&redirect_uri=2" . "&client_secret=222" . "&code=1":
                 return "test=test2";
             case "https://graph.facebook.com/me?access_token=login_test":
                 return json_encode(array('id' => 12345));
             default:
                 return json_encode(array());
         }
     }));
 }