Skip to content

Commit

Permalink
Merge pull request #68 from WebFiori/dev
Browse files Browse the repository at this point in the history
Multiple Enhancements
  • Loading branch information
usernane authored Dec 9, 2024
2 parents 9fec0f7 + ab69a61 commit a98f0d7
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php70.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php71.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php72.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php73.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php74.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php80.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php81.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php82.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/php83.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand All @@ -45,7 +45,7 @@ jobs:


release_prod:
name: Publish Release
name: Prepare Release Branch / Publish Release
needs:
- "test"
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php84.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: composer install --prefer-source --no-interaction --no-dev

- name: Execute Tests
run: phpunit
run: phpunit --configuration tests/phpunit.xml

- name: CodeCov
uses: codecov/codecov-action@v4
Expand Down
29 changes: 0 additions & 29 deletions phpunit.xml

This file was deleted.

56 changes: 3 additions & 53 deletions tests/loader.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
<?php

/*
* The MIT License
*
* Copyright 2018 Ibrahim.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
Expand All @@ -41,32 +17,7 @@
}
define('ROOT', $rootDir);
fwrite($stderr,'Root Directory: \''.$rootDir.'\'.'."\n");
require_once $rootDir.'vendor'.$DS.'webfiori'.$DS.'jsonx'.$DS.'webfiori'.$DS.'json'.$DS.'JsonTypes.php';
require_once $rootDir.'vendor'.$DS.'webfiori'.$DS.'jsonx'.$DS.'webfiori'.$DS.'json'.$DS.'JsonI.php';
require_once $rootDir.'vendor'.$DS.'webfiori'.$DS.'jsonx'.$DS.'webfiori'.$DS.'json'.$DS.'Json.php';
require_once $rootDir.'vendor'.$DS.'webfiori'.$DS.'jsonx'.$DS.'webfiori'.$DS.'json'.$DS.'CaseConverter.php';
require_once $rootDir.'vendor'.$DS.'webfiori'.$DS.'jsonx'.$DS.'webfiori'.$DS.'json'.$DS.'Property.php';
require_once $rootDir.'vendor'.$DS.'webfiori'.$DS.'jsonx'.$DS.'webfiori'.$DS.'json'.$DS.'JsonConverter.php';
require_once $rootDir.'vendor'.$DS.'webfiori'.$DS.'jsonx'.$DS.'webfiori'.$DS.'json'.$DS.'JsonException.php';

require_once $rootDir.'webfiori'.$DS.'http'.$DS.'UriParameter.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'HttpHeader.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'HttpCookie.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'HeadersPool.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'ParamType.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'ParamOption.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'AbstractWebService.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'APIFilter.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'RequestParameter.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'WebServicesManager.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'ManagerInfoService.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'Uri.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'Request.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'Response.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'ObjectMapper.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'RequestMethod.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'ResponseMessage.php';
require_once $rootDir.'webfiori'.$DS.'http'.$DS.'APITestCase.php';
require_once __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php';

require_once $rootDir.'tests'.$DS.'webfiori'.$DS.'tests'.$DS.'http'.$DS.'testServices'.$DS.'TestServiceObj.php';
require_once $rootDir.'tests'.$DS.'webfiori'.$DS.'tests'.$DS.'http'.$DS.'testServices'.$DS.'SampleServicesManager.php';
Expand All @@ -78,5 +29,4 @@
require_once $rootDir.'tests'.$DS.'webfiori'.$DS.'tests'.$DS.'http'.$DS.'testServices'.$DS.'NotImplService.php';
require_once $rootDir.'tests'.$DS.'webfiori'.$DS.'tests'.$DS.'http'.$DS.'testServices'.$DS.'TestUserObj.php';
require_once $rootDir.'tests'.$DS.'webfiori'.$DS.'tests'.$DS.'http'.$DS.'testServices'.$DS.'CreateUserProfileService.php';
require_once $rootDir.'tests'.$DS.'webfiori'.$DS.'tests'.$DS.'http'.$DS.'testServices'.$DS.'MulNubmersService.php';
fwrite($stderr,"Classes Loaded.\n");
require_once $rootDir.'tests'.$DS.'webfiori'.$DS.'tests'.$DS.'http'.$DS.'testServices'.$DS.'MulNubmersService.php';
30 changes: 30 additions & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="loader.php">
<php>
</php>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<file>../webfiori/http/AbstractWebService.php</file>
<file>../webfiori/http/APIFilter.php</file>
<file>../webfiori/http/RequestParameter.php</file>
<file>../webfiori/http/WebServicesManager.php</file>
<file>../webfiori/http/Request.php</file>
<file>../webfiori/http/Response.php</file>
<file>../webfiori/http/Uri.php</file>
<file>../webfiori/http/HttpHeader.php</file>
<file>../webfiori/http/HttpCookie.php</file>
<file>../webfiori/http/HeadersPool.php</file>
<file>../webfiori/http/UriParameter.php</file>
<file>../webfiori/http/ObjectMapper.php</file>
<file>../webfiori/http/AuthHeader.php</file>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="clover.xml"/>
</logging>
<testsuites>
<testsuite name="Tests">
<directory>./webfiori/tests/http</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 8 additions & 0 deletions tests/webfiori/tests/http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,12 @@ public function testGetHeaders00() {
]
], Request::getHeadersAssoc());
}
/**
* @test
*/
public function testGetCookie00() {
$this->assertNull(Request::getCookieValue('not-exist'));
$_COOKIE['cool'] = 'cool_cookie';
$this->assertEquals('cool_cookie', Request::getCookieValue('cool'));
}
}
24 changes: 8 additions & 16 deletions tests/webfiori/tests/http/WebServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,29 @@ class WebServiceTest extends TestCase {
*/
public function testGetAuthHeaders00() {
$service = new TestServiceObj('Hello');
$this->assertEquals([
'scheme' => '',
'credentials' => ''
],$service->getAuthHeader());
$this->assertNull($service->getAuthHeader());
$this->assertNull($service->isAuthorized());
}
/**
*
*/
public function testGetAuthHeaders01() {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid authorization header structure.');
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic';
$service = new TestServiceObj('Hello');
$this->assertEquals([
'scheme' => '',
'credentials' => ''
],$service->getAuthHeader());
$this->assertNull($service->getAuthHeader());
}
/**
*
*/
public function testGetAuthHeaders02() {
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic XYZ';
$service = new TestServiceObj('Hello');
if (!function_exists('apache_request_headers')) {
$this->assertEquals([
'scheme' => 'basic',
'credentials' => 'XYZ'
],$service->getAuthHeader());
} else {
$this->assertTrue(true);
}
$header = $service->getAuthHeader();
$this->assertNotNull($header);
$this->assertEquals('basic', $header->getScheme());
$this->assertEquals('XYZ', $header->getCredentials());
}
/**
* @test
Expand Down
30 changes: 27 additions & 3 deletions webfiori/http/APITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,35 @@
/**
* A helper class which is used to implement test cases for API calls.
*
* This class will mimic the process of sending HTTP request to an endpoint and
* store the output temporarily on a file. At second stage, the developer
* can read the output and compare it to an expected output.
*
* @author Ibrahim
*/
class APITestCase extends TestCase {
const NL = "\r\n";
const OUTPUT_STREAM = __DIR__.DIRECTORY_SEPARATOR.'outputStream.txt';
const DEFAULT_OUTPUT_STREAM = __DIR__.DIRECTORY_SEPARATOR.'outputStream.txt';
private $outputStreamPath;
/**
* Sets the path to the file which is used to store API output temporarily.
*
* @param string $path The absolute path to the file.
*/
public function setOutputFile(string $path) {
$this->outputStreamPath = $path;
}
/**
* Returns the path to the file which is used to store API output temporarily.
*
* @return string
*/
public function getOutputFile() : string {
if ($this->outputStreamPath === null) {
$this->outputStreamPath = self::DEFAULT_OUTPUT_STREAM;
}
return $this->outputStreamPath;
}
/**
* Adds a file to the array $_FILES for testing API with upload.
*
Expand Down Expand Up @@ -77,7 +101,7 @@ public function addFile(string $fileIdx, string $filePath, bool $reset = false)
* @return string The method will return the output of the endpoint.
*/
public function callEndpoint(WebServicesManager $manager, string $requestMethod, string $apiEndpointName, array $parameters = [], array $httpHeaders = []) : string {
$manager->setOutputStream(fopen(self::OUTPUT_STREAM,'w'));
$manager->setOutputStream(fopen(self::DEFAULT_OUTPUT_STREAM,'w'));
$method = strtoupper($requestMethod);
putenv('REQUEST_METHOD='.$method);

Expand All @@ -104,7 +128,7 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,
}

$retVal = $manager->readOutputStream();
unlink(self::OUTPUT_STREAM);
unlink(self::DEFAULT_OUTPUT_STREAM);

try {
$json = Json::decode($retVal);
Expand Down
13 changes: 6 additions & 7 deletions webfiori/http/AbstractWebService.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,17 @@ public final function addResponseDescription(string $description) {
}
}
/**
* Returns an array that contains the value of the header 'authorization'.
* Returns an object that contains the value of the header 'authorization'.
*
*
* @return array The array will have two indices, the first one with
* name 'scheme' and the second one with name 'credentials'. The index 'scheme'
* @return AuthHeader|null The object will have two primary attributes, the first is
* the 'scheme' and the second one is 'credentials'. The 'scheme'
* will contain the name of the scheme which is used to authenticate
* ('Basic', 'Bearer', 'Digest', etc...). The index 'credentials' will contain
* ('basic', 'bearer', 'digest', etc...). The 'credentials' will contain
* the credentials which can be used to authenticate the client.
*
* @since 1.0.1
* @throws InvalidArgumentException
*/
public function getAuthHeader() : array {
public function getAuthHeader() {
return Request::getAuthHeader();
}
/**
Expand Down
Loading

0 comments on commit a98f0d7

Please sign in to comment.