Skip to content

Commit

Permalink
Merge pull request #1329 from thephpleague/fix-deprecation-notices-php-8
Browse files Browse the repository at this point in the history
Fixes for Deprecation Notices in Test Suite
  • Loading branch information
Sephster authored Mar 22, 2023
2 parents 539f434 + f4b65ec commit 8c3ba48
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/backwards-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
uses: "actions/checkout@v2"
with:
fetch-depth: 0

- name: Fix git safe.directory in container
run: mkdir -p /home/runner/work/_temp/_github_home && printf "[safe]\n\tdirectory = /github/workspace" > /home/runner/work/_temp/_github_home/.gitconfig
- name: "Backwards Compatibility Check"
uses: docker://nyholm/roave-bc-check-ga
with:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix deprecation notices for PHP 8.x (PR #1329)

## [8.4.0] - released 2023-02-15
### Added
Expand Down
4 changes: 0 additions & 4 deletions examples/public/client_credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,16 @@
]);

$app->post('/access_token', function (ServerRequestInterface $request, ResponseInterface $response) use ($app) {

/* @var \League\OAuth2\Server\AuthorizationServer $server */
$server = $app->getContainer()->get(AuthorizationServer::class);

try {

// Try to respond to the request
return $server->respondToAccessTokenRequest($request, $response);
} catch (OAuthServerException $exception) {

// All instances of OAuthServerException can be formatted into a HTTP response
return $exception->generateHttpResponse($response);
} catch (\Exception $exception) {

// Unknown exception
$body = new Stream('php://temp', 'r+');
$body->write($exception->getMessage());
Expand Down
5 changes: 0 additions & 5 deletions examples/public/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
$app = new App([
// Add the authorization server to the DI container
AuthorizationServer::class => function () {

// Setup the authorization server
$server = new AuthorizationServer(
new ClientRepository(), // instance of ClientRepositoryInterface
Expand Down Expand Up @@ -46,20 +45,16 @@
$app->post(
'/access_token',
function (ServerRequestInterface $request, ResponseInterface $response) use ($app) {

/* @var \League\OAuth2\Server\AuthorizationServer $server */
$server = $app->getContainer()->get(AuthorizationServer::class);

try {

// Try to respond to the access token request
return $server->respondToAccessTokenRequest($request, $response);
} catch (OAuthServerException $exception) {

// All instances of OAuthServerException can be converted to a PSR-7 response
return $exception->generateHttpResponse($response);
} catch (\Exception $exception) {

// Catch unexpected exceptions
$body = $response->getBody();
$body->write($exception->getMessage());
Expand Down
13 changes: 11 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="true"
stopOnFailure="true" stopOnIncomplete="false" stopOnSkipped="false" bootstrap="tests/Bootstrap.php">
<phpunit
colors="true"
convertDeprecationsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="true"
stopOnFailure="true"
stopOnIncomplete="false"
stopOnSkipped="false"
bootstrap="tests/Bootstrap.php"
>
<testsuites>
<testsuite name="Tests">
<directory>./tests/</directory>
Expand Down
1 change: 1 addition & 0 deletions src/Entities/Traits/ClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trait ClientTrait
* Get the client's name.
*
* @return string
*
* @codeCoverageIgnore
*/
public function getName()
Expand Down
1 change: 1 addition & 0 deletions src/Entities/Traits/ScopeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ trait ScopeTrait
*
* @return string
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->getIdentifier();
Expand Down
1 change: 1 addition & 0 deletions src/RequestAccessTokenEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct($name, ServerRequestInterface $request, AccessTokenE

/**
* @return AccessTokenEntityInterface
*
* @codeCoverageIgnore
*/
public function getAccessToken()
Expand Down
1 change: 1 addition & 0 deletions src/RequestEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __construct($name, ServerRequestInterface $request)

/**
* @return ServerRequestInterface
*
* @codeCoverageIgnore
*/
public function getRequest()
Expand Down
1 change: 1 addition & 0 deletions src/RequestRefreshTokenEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct($name, ServerRequestInterface $request, RefreshToken

/**
* @return RefreshTokenEntityInterface
*
* @codeCoverageIgnore
*/
public function getRefreshToken()
Expand Down
10 changes: 7 additions & 3 deletions tests/AuthorizationServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class AuthorizationServerTest extends TestCase
{
const DEFAULT_SCOPE = 'basic';
const REDIRECT_URI = 'https://foo/bar';

public function setUp(): void
{
Expand Down Expand Up @@ -86,7 +87,7 @@ public function testRespondToRequest()
$client = new ClientEntity();

$client->setConfidential();
$client->setRedirectUri('http://foo/bar');
$client->setRedirectUri(self::REDIRECT_URI);

$clientRepository = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
$clientRepository->method('getClientEntity')->willReturn($client);
Expand Down Expand Up @@ -245,9 +246,12 @@ public function testCompleteAuthorizationRequest()

$server->enableGrantType($grant);

$client = new ClientEntity();
$client->setRedirectUri(self::REDIRECT_URI);

$authRequest = new AuthorizationRequest();
$authRequest->setAuthorizationApproved(true);
$authRequest->setClient(new ClientEntity());
$authRequest->setClient($client);
$authRequest->setGrantTypeId('authorization_code');
$authRequest->setUser(new UserEntity());

Expand All @@ -260,7 +264,7 @@ public function testCompleteAuthorizationRequest()
public function testValidateAuthorizationRequest()
{
$client = new ClientEntity();
$client->setRedirectUri('http://foo/bar');
$client->setRedirectUri(self::REDIRECT_URI);
$client->setConfidential();
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
$clientRepositoryMock->method('getClientEntity')->willReturn($client);
Expand Down
2 changes: 2 additions & 0 deletions tests/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

\error_reporting(E_ALL);

if (!@include_once __DIR__ . '/../vendor/autoload.php') {
$message = <<<MSG
You must set up the project dependencies, run the following commands:
Expand Down
Loading

0 comments on commit 8c3ba48

Please sign in to comment.