Skip to content

Commit eee7f08

Browse files
author
Luca Degasperi
committed
First batch of tests
1 parent 8ca3645 commit eee7f08

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

phpunit.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@
2424
<directory suffix=".php">testing</directory>
2525
</blacklist>
2626
</filter>
27-
<logging>
28-
<log type="coverage-text" target="php://stdout" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="90"/>
29-
</logging>
3027
</phpunit>

src/LucaDegasperi/OAuth2Server/Filters/OAuthFilter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use ResourceServer;
44
use Response;
5+
use Config;
56

67
class OAuthFilter {
78

@@ -10,7 +11,7 @@ public function filter($route, $request, $scope = null)
1011
try {
1112
ResourceServer::isValid(Config::get('oauth2-server-laravel::oauth2.http_headers_only'));
1213
}
13-
catch (League\OAuth2\Server\Exception\InvalidAccessTokenException $e) {
14+
catch (\League\OAuth2\Server\Exception\InvalidAccessTokenException $e) {
1415
return Response::json(array(
1516
'status' => 403,
1617
'error' => 'forbidden',

tests/OAuthFilterTest.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
11
<?php
22

3-
use Mockery as m;
3+
use \Mockery as m;
44

55
class OAuthFilterTest extends TestCase {
66

7-
public function test_filter_with_no_scope()
7+
public function getFilter()
88
{
9-
$this->assertTrue(true);
9+
return new LucaDegasperi\OAuth2Server\Filters\OAuthFilter;
10+
}
11+
12+
public function test_valid_filter_with_no_scope()
13+
{
14+
ResourceServer::shouldReceive('isValid')->once()->andReturn(true);
15+
16+
$response = $this->getFilter()->filter('', '', null);
17+
$this->assertNull($response);
18+
}
19+
20+
public function test_invalid_filter_with_no_scope()
21+
{
22+
//$e = m::mock();
23+
//$exception->shouldReceive('getMessage')->once()->andReturn('foo error message');
24+
25+
ResourceServer::shouldReceive('isValid')->andThrow(new \League\OAuth2\Server\Exception\InvalidAccessTokenException('Access token is not valid'));
26+
27+
$response = $this->getFilter()->filter('', '', null);
28+
$this->assertTrue($response instanceof Illuminate\Http\JsonResponse);
29+
30+
// to check te status code and the json payload
31+
32+
}
33+
34+
public function tearDown() {
35+
m::close();
1036
}
1137

1238
}

0 commit comments

Comments
 (0)