magium/twitter

提供了一种机制,用于登录到Twitter以验证基于OAuth的测试

1.1.1 2017-01-27 23:16 UTC

This package is not auto-updated.

Last update: 2024-09-17 04:52:09 UTC


README

Scrutinizer Code Quality

magium/twitter

这是一个简单的库,用于帮助浏览器测试执行Twitter的OAuth登录。

安装方法

composer require magium/twitter

使用方法

use Magium\Twitter\Actions\AuthenticateTwitter;

class TwitterTest extends \Magium\AbstractTestCase
{

    public function testLogin()
    {
        // Do something that forwards the browser to the twitter OAuth page.

         $action = $this->getAction(AuthenticateTwitter::ACTION);
        /* @var $action AuthenticateTwitter */
        $action->execute();
    }

}

设置用户名和密码

设置用户名和密码有两种方式

在代码中

use Magium\Twitter\Identities\Twitter
use Magium\Twitter\Actions\AuthenticateTwitter;

class TwitterTest extends \Magium\AbstractTestCase
{

    public function testLogin()
    {

        $identity = $this->getIdentity(Twitter::IDENTITY);
        /* @var $identity Twitter */
        $identity->setUsername('username');
        $identity->setPassword('password');

        // Do something that forwards the browser to the twitter OAuth page.

         $action = $this->getAction(AuthenticateTwitter::ACTION);
        /* @var $action AuthenticateTwitter */
        $action->execute();
    }

}

在配置文件中

创建文件 /configuration/Magium/Twitter/Identities/Twitter.php 并输入以下内容

<?php

/* @var $this \Magium\Twitter\Identities\Twitter */
$this->username = 'username';
$this->password = 'password';

请注意,您需要熟悉AbstractConfigurableElements才能完成此操作

##通过Twitter登录

使用登录-with-Twitter功能


    public function testSignInWithTwitter()
    {
        
        $action = $this->getAction(SignInWithTwitter::ACTION);
        /* @var $action SignInWithTwitter */
        $action->execute();

    }

##登录到Twitter

要通过Twitter首页登录...


    public function testAuthenticate()
    {
        $this->getAction(AuthenticateTwitter::ACTION)->execute();
    }

##发布推文


    public function testTweet()
    {
        $text = 'This is text I would like to tweet';

        $this->getAction(AuthenticateTwitter::ACTION)->execute();
        $this->getAction(Tweet::ACTION)->tweet($text);
    }