Skip to content

Commit

Permalink
Fixed array offset error in Server::collectRoutes; updated test refer…
Browse files Browse the repository at this point in the history
…ences to InternalClient
  • Loading branch information
d-miles committed Aug 9, 2024
1 parent d655aff commit bccfee5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PHP REST Service is a simple and fast PHP class for RESTful JSON APIs.


## Requirements
* PHP 7.4+ (Tested on PHP 7.4 - 8.2)
* PHP 8.0+ (Tested on PHP 7.4 - 8.2)
## Installation
`php composer require cdgco/php-rest-service`

Expand Down
2 changes: 1 addition & 1 deletion RestService/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ public function collectRoutes() {
$this->routes[$phpDocs['url']][$httpMethod] = $method;
} else {
foreach($phpDocs['url'] as $urlAnnotation) {
$this->routes[$urlAnnotation['url']][$httpMethod] = $method;
$this->routes[$urlAnnotation][$httpMethod] = $method;
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions Test/Basic/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Test\Synthetic;

use RestService\Server;
use RestService\{Server, InternalClient};
use Test\Controller\MyRoutes;

class BasicTest extends \PHPUnit\Framework\TestCase
{
public function testCustomUrl()
{
$restService = Server::create('/', new MyRoutes)
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->collectRoutes();

$response = $restService->simulateCall('/test/test', 'get');
Expand Down
4 changes: 2 additions & 2 deletions Test/Synthetic/CollectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Test\Synthetic;

use RestService\Server;
use RestService\{Server, InternalClient};
use Test\Controller\MyRoutes;

class CollectTest extends \PHPUnit\Framework\TestCase
Expand All @@ -15,7 +15,7 @@ class CollectTest extends \PHPUnit\Framework\TestCase
public function setUp() : void
{
$this->restService = Server::create('/', new MyRoutes)
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->collectRoutes();
}
public function testNonPhpDocMethod()
Expand Down
14 changes: 7 additions & 7 deletions Test/Synthetic/CustomRoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Test\Synthetic;

use RestService\Server;
use RestService\{Server, InternalClient};
use Test\Controller\MyRoutes;

class CustomRoutesTest extends \PHPUnit\Framework\TestCase
Expand All @@ -11,7 +11,7 @@ class CustomRoutesTest extends \PHPUnit\Framework\TestCase
public function testOwnController()
{
$restService = Server::create('/', new MyRoutes)
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->addPostRoute('login', 'postLogin');

$response = $restService->simulateCall('/#?', 'post');
Expand Down Expand Up @@ -50,7 +50,7 @@ public function testOwnController()
public function testOwnControllerWithDifferentPrefix()
{
$restService = Server::create('/v1', new MyRoutes)
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->addPostRoute('login', 'postLogin');

$response = $restService->simulateCall('/v1/#?username=peter&password=pwd', 'post');
Expand All @@ -61,7 +61,7 @@ public function testOwnControllerWithDifferentPrefix()
}', $response);

$restService = Server::create('/v1/', new MyRoutes)
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->addPostRoute('login', 'postLogin');

$response = $restService->simulateCall('/v1/#?username=peter&password=pwd', 'post');
Expand All @@ -72,7 +72,7 @@ public function testOwnControllerWithDifferentPrefix()
}', $response);

$restService = Server::create('v1', new MyRoutes)
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->addPostRoute('login', 'postLogin');

$response = $restService->simulateCall('/v1/#?username=peter&password=pwd', 'post');
Expand All @@ -87,7 +87,7 @@ public function testOwnControllerWithDifferentPrefix()
public function testSubController()
{
$restService = Server::create('v1', new MyRoutes)
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->addPostRoute('login', 'postLogin')
->addSubController('sub', new MyRoutes())
->addPostRoute('login', 'postLogin')
Expand All @@ -106,7 +106,7 @@ public function testSubController()
public function testSubControllerWithSlashRootParent()
{
$restService = Server::create('/', new MyRoutes)
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->addSubController('sub', new MyRoutes())
->addPostRoute('login', 'postLogin')
->done()
Expand Down
4 changes: 2 additions & 2 deletions Test/Synthetic/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Test\Synthetic;

use RestService\Server;
use RestService\{Server, InternalClient};

class RouteTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -11,7 +11,7 @@ public function testAllRoutesClosures()
{

$restService = Server::create('/')
->setClient('RestService\\InternalClient')
->setClient(InternalClient::class)
->addGetRoute('test', function(){
return 'getTest';
})
Expand Down

0 comments on commit bccfee5

Please # to comment.