dazz / oauth2-server-httpfoundation-webtest
A bridge for webtesting oauth2-server-php with bshaffer/oauth2-server-httpfoundation-bridge and silex
Installs: 4 270
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 2
Open Issues: 1
Requires
- php: >=5.3.0
- bshaffer/oauth2-server-httpfoundation-bridge: dev-develop
Requires (Dev)
- symfony/browser-kit: >=2.3,<2.4-dev
- symfony/css-selector: >=2.3,<2.4-dev
- symfony/dom-crawler: >=2.3,<2.4-dev
- symfony/http-foundation: >=2.3,<2.4-dev
Suggests
- bshaffer/oauth2-server-php: dev-develop
- silex/silex: 1.1.*@dev
This package is not auto-updated.
Last update: 2024-11-04 12:03:10 UTC
README
A webtesting bridge for oauth2-server-php with bshaffer/oauth2-server-httpfoundation-bridge.
Silex, Symfony and other frameworks depending on symfony/http-kernel offer a WebTestCase class for testing controller/actions. In order to write webtests for actions that are secured by the bshaffer/oauth2-server-php the request instance needs to implement \OAuth2_RequestInterface.
To achieve a valid request object the WebTestCase classes need to extend the WebTestCase class provided here.
Install
add to composer.json
{ "minimum-stability": "dev", "require-dev": { "dazz/oauth2-server-httpfoundation-webtest":"dev-master" } }
Run composer.phar update --dev
to install the development dependencies.
Example for Silex
namespace Company\Test\SomeBundle\Controller use OAuth2\HttpFoundationWebTest\Silex\WebTestCase; class UserControllerTest extends WebTestCase { public function testGetUser() { // create user, oauth2-client and access_token in the test-storage $accessToken = 'abc'; // this creates the browsing client, not to mix up with the oauth2-client $client = $this->createClient(); $client->request('GET', '/user/', array('access_token' => $accessToken)); $this->assertTrue($client->getResponse()->isSuccessful()); } public function testProjects() { $accessToken = 'abc'; $client = $this->createClient(); $content = json_encode(array( 'name' => 'My Project', )); // the content of $server['HTTP_AUTHORIZATION'] will be copied to the header $server = array( 'HTTP_AUTHORIZATION'=> sprintf('Bearer %s', $accessToken), ); $client->request('PUT', '/projects/theId', array(), array(), $server, $content); // all sorts of assertions on response string $this->assertTrue($client->getResponse()->isSuccessful()); } }