Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the tests directory to PSR-4 autoloading #332

Merged
merged 2 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CAS.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

require_once __DIR__.'/source/CAS.php';
require_once __DIR__.'/source/CAS.php';

trigger_error('Including CAS.php is deprecated. Install phpCAS using composer instead.', E_USER_DEPRECATED);
phy25 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"source/"
]
},
"autoload-dev": {
"psr-4": {
"PhpCas\\": "test/CAS/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
Expand Down
10 changes: 5 additions & 5 deletions source/CAS/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function CAS_autoload($class)
}
// Setup the include path if it's not already set from a previous call
if (empty($include_path)) {
$include_path = array(dirname(__DIR__), dirname(__DIR__) . '/../test/' );
$include_path = array(dirname(__DIR__));
phy25 marked this conversation as resolved.
Show resolved Hide resolved
}

// Declare local variable to store the expected full path to the file
Expand Down Expand Up @@ -73,10 +73,10 @@ function CAS_autoload($class)
die ((string) $e);
}

// set up __autoload
if (!(spl_autoload_functions())
|| !in_array('CAS_autoload', spl_autoload_functions())
) {
// Set up autoload if not already configured by composer.
if (!class_exists('CAS_Client'))
{
trigger_error('phpCAS autoloader is deprecated. Install phpCAS using composer instead.', E_USER_DEPRECATED);
spl_autoload_register('CAS_autoload');
if (function_exists('__autoload')
&& !in_array('__autoload', spl_autoload_functions())
Expand Down
12 changes: 8 additions & 4 deletions test/CAS/TestHarness/BasicResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

namespace PhpCas\TestHarness;

use PhpCas\TestHarness\ResponseInterface;

/**
* The BasicResponse allows tests to dynamically create a response that can be used
* in unit tests.
*
* @class CAS_TestHarness_BasicResponse
* @class BasicResponse
* @category Authentication
* @package PhpCAS
* @author Adam Franco <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

class CAS_TestHarness_BasicResponse implements CAS_TestHarness_ResponseInterface
class BasicResponse implements ResponseInterface
{
protected $scheme = 'http';
protected $host = null;
Expand Down Expand Up @@ -304,7 +308,7 @@ public function getResponseHeaders()
public function getResponseStatusCode()
{
if (!$this->sent) {
throw new CAS_OutOfSequenceException(
throw new \CAS_OutOfSequenceException(
'Request has not been sent yet. Cannot ' . __METHOD__
);
}
Expand All @@ -313,7 +317,7 @@ public function getResponseStatusCode()
$this->responseHeaders[0], $matches
)
) {
throw new CAS_Request_Exception(
throw new \CAS_Request_Exception(
"Bad response, no status code was found in the first line."
);
}
Expand Down
26 changes: 15 additions & 11 deletions test/CAS/TestHarness/DummyMultiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

namespace PhpCas\TestHarness;

use PhpCas\TestHarness\DummyRequest;

/**
* This interface defines a class library for performing multiple web requests
* in batches. Implementations of this interface may perform requests serially
* or in parallel.
*
* @class CAS_TestHarness_DummyMultiRequest
* @class DummyMultiRequest
* @category Authentication
* @package PhpCAS
* @author Adam Franco <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

class CAS_TestHarness_DummyMultiRequest implements
CAS_Request_MultiRequestInterface
class DummyMultiRequest implements
\CAS_Request_MultiRequestInterface
{
private $_requests = array();
private $_sent = false;
Expand All @@ -63,16 +67,16 @@ class CAS_TestHarness_DummyMultiRequest implements
* @throws CAS_InvalidArgumentException If passed a Request of the wrong
* implmentation.
*/
public function addRequest(CAS_Request_RequestInterface $request)
public function addRequest(\CAS_Request_RequestInterface $request)
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
throw new \CAS_OutOfSequenceException(
'Request has already been sent cannot ' . __METHOD__
);
}
if (!$request instanceof CAS_TestHarness_DummyRequest) {
throw new CAS_InvalidArgumentException(
'As a CAS_TestHarness_DummyMultiRequest, I can only work with CAS_TestHarness_DummyRequest objects.'
if (!$request instanceof DummyRequest) {
throw new \CAS_InvalidArgumentException(
'As a DummyMultiRequest, I can only work with DummyRequest objects.'
);
}

Expand All @@ -94,12 +98,12 @@ public function addRequest(CAS_Request_RequestInterface $request)
public function send()
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
throw new \CAS_OutOfSequenceException(
'Request has already been sent cannot send again.'
);
}
if (!count($this->_requests)) {
throw new CAS_OutOfSequenceException(
throw new \CAS_OutOfSequenceException(
'At least one request must be added via addRequest() before the multi-request can be sent.'
);
}
Expand All @@ -119,7 +123,7 @@ public function send()
public function getNumRequests()
{
if ($this->_sent) {
throw new CAS_OutOfSequenceException(
throw new \CAS_OutOfSequenceException(
'Request has already been sent cannot ' . __METHOD__
);
}
Expand Down
14 changes: 9 additions & 5 deletions test/CAS/TestHarness/DummyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,34 @@
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

namespace PhpCas\TestHarness;

use PhpCas\TestHarness\ResponseInterface;

/**
* Provides support for performing dummy web-requests
*
* @class CAS_TestHarness_DummyRequest
* @class DummyRequest
* @category Authentication
* @package PhpCAS
* @author Adam Franco <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
class CAS_TestHarness_DummyRequest extends CAS_Request_AbstractRequest
implements CAS_Request_RequestInterface
class DummyRequest extends \CAS_Request_AbstractRequest
implements \CAS_Request_RequestInterface
{
private static $_responses = array();

/**
* Configure a URL/Response that the test harness will respond to.
*
* @param CAS_TestHarness_ResponseInterface $response response interface
* @param ResponseInterface $response response interface
*
* @return void
*/
public static function addResponse(
CAS_TestHarness_ResponseInterface $response
ResponseInterface $response
) {
self::$_responses[] = $response;
}
Expand Down
6 changes: 4 additions & 2 deletions test/CAS/TestHarness/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

namespace PhpCas\TestHarness;

/**
* Implementations of this interface can validate a request and provide response
* headers and body, allowing the spoofing of responses to web requests for testing
* purposes.
*
* @class CAS_TestHarness_ResponseInterface
* @class ResponseInterface
* @category Authentication
* @package PhpCAS
* @author Adam Franco <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
interface CAS_TestHarness_ResponseInterface
interface ResponseInterface
{

/**
Expand Down
22 changes: 13 additions & 9 deletions test/CAS/Tests/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

namespace PhpCas\Tests;

use PhpCas\TestHarness\BasicResponse;
use PhpCas\TestHarness\DummyRequest;
use PHPUnit\Framework\TestCase;

/**
* Test class for verifying the operation of service tickets.
*
* @class CAS_Tests_AuthenticationTest
* @class AuthenticationTest
* @category Authentication
* @package PhpCAS
* @author Adam Franco <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
class CAS_Tests_AuthenticationTest extends TestCase
class AuthenticationTest extends TestCase
{
/**
* @var CAS_Client
Expand All @@ -57,7 +61,7 @@ protected function setUp()
// phpCAS::setDebug(dirname(__FILE__).'/../test.log');
// error_reporting(E_ALL);

CAS_GracefullTerminationException::throwInsteadOfExiting();
\CAS_GracefullTerminationException::throwInsteadOfExiting();

$_SERVER['SERVER_NAME'] = 'www.clientapp.com';
$_SERVER['SERVER_PORT'] = '80';
Expand All @@ -68,7 +72,7 @@ protected function setUp()
$_SERVER['PHP_SELF'] = '/index.php';
$_SESSION = array();

$this->object = new CAS_Client(
$this->object = new \CAS_Client(
phy25 marked this conversation as resolved.
Show resolved Hide resolved
CAS_VERSION_2_0, // Server Version
true, // Proxy
'cas.example.edu', // Server Hostname
Expand All @@ -77,15 +81,15 @@ protected function setUp()
false // Start Session
);

$this->object->setRequestImplementation('CAS_TestHarness_DummyRequest');
$this->object->setRequestImplementation('PhpCas\TestHarness\DummyRequest');
$this->object->setCasServerCACert(__FILE__, true);

/*********************************************************
* Enumerate our responses
*********************************************************/

// Set up our response.
$response = new CAS_TestHarness_BasicResponse(
$response = new BasicResponse(
'https', 'cas.example.edu', '/cas/serviceValidate'
);
$response->setResponseHeaders(
Expand All @@ -107,7 +111,7 @@ protected function setUp()
</cas:serviceResponse>
"
);
CAS_TestHarness_DummyRequest::addResponse($response);
DummyRequest::addResponse($response);

}

Expand All @@ -119,7 +123,7 @@ protected function setUp()
*/
protected function tearDown()
{
CAS_TestHarness_DummyRequest::clearResponses();
DummyRequest::clearResponses();
$_SESSION = array();
}

Expand All @@ -135,7 +139,7 @@ public function testRedirect()
ob_start();
try {
$this->object->forceAuthentication();
} catch (Exception $e) {
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
Expand Down
Loading