Skip to content

Commit

Permalink
little bit of cleanup, adding few basic client unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 16, 2025
1 parent 983583e commit de28e24
Show file tree
Hide file tree
Showing 37 changed files with 170 additions and 72 deletions.
2 changes: 2 additions & 0 deletions files/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
const PHPFHIR_TEST_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG = PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG . 'Test';
const PHPFHIR_TEST_ENCODING_CLASSNAME_SERIALIZE_CONFIG = PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG . 'Test';
const PHPFHIR_TEST_ENCODING_CLASSSNAME_XML_WRITER = PHPFHIR_ENCODING_CLASSNAME_XML_WRITER . 'Test';
const PHPFHIR_TEST_CLIENT_CLASSNAME_CONFIG = PHPFHIR_CLIENT_CLASSNAME_CONFIG . 'Test';
const PHPFHIR_TEST_CLIENT_CLASSNAME_CLIENT = PHPFHIR_CLIENT_CLASSNAME_CLIENT . 'Test';

// Test constant names
const PHPFHIR_TEST_CONSTANT_INTEGRATION_ENDPOINT = 'PHPFHIR_TEST_INTEGRATION_ENDPOINT';
Expand Down
3 changes: 1 addition & 2 deletions template/core/class_autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

abstract class <?php echo PHPFHIR_CLASSNAME_AUTOLOADER; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/class_constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

final class <?php echo PHPFHIR_CLASSNAME_CONSTANTS; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/class_response_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

class <?php echo PHPFHIR_CLASSNAME_RESPONSE_PARSER; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/class_version_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

<?php echo ImportUtils::compileImportStatements($imports); ?>

Expand Down
7 changes: 3 additions & 4 deletions template/core/client/class_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

<?php echo ImportUtils::compileImportStatements($imports); ?>

Expand Down Expand Up @@ -75,7 +74,7 @@ class <?php echo PHPFHIR_CLIENT_CLASSNAME_CLIENT; ?> implements <?php echo PHPFH
public function __construct(string|<?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?> $config)
{
if (is_string($config)) {
$config = new <?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?>($config);
$config = new <?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?>(address: $config);
}
$this->_config = $config;
}
Expand Down Expand Up @@ -115,7 +114,7 @@ public function exec(<?php echo PHPFHIR_CLIENT_CLASSNAME_REQUEST; ?> $request):
+ [CURLOPT_CUSTOMREQUEST => $request->method]
+ array_merge($this->_config->getCurlOpts(), $request->options ?? []);

$parseResponseHeaders = ($this->_config->getParseHeaders() && (!isset($req->parseResponseHeaders) || $req->parseResponseHeaders))
$parseResponseHeaders = ($this->_config->getParseResponseHeaders() && (!isset($req->parseResponseHeaders) || $req->parseResponseHeaders))
|| (isset($req->parseResponseHeaders) && $req->parseResponseHeaders);

if ($parseResponseHeaders) {
Expand Down
6 changes: 2 additions & 4 deletions template/core/client/class_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

/**
* Class <?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?>
Expand Down Expand Up @@ -64,7 +63,6 @@ class <?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?>
public function __construct(string $address,
null|<?php echo PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT; ?> $defaultFormat = null,
array $queryParams = [],
array $requestHeaders = [],
array $curlOpts = [],
bool $parseResponseHeaders = false)
{
Expand Down Expand Up @@ -112,7 +110,7 @@ public function getCurlOpts(): array
/**
* @return bool
*/
public function getParseHeaders(): bool
public function getParseResponseHeaders(): bool
{
return $this->_parseResponseHeaders;
}
Expand Down
3 changes: 1 addition & 2 deletions template/core/client/class_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

class <?php echo PHPFHIR_CLIENT_CLASSNAME_REQUEST; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/client/class_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

class <?php echo PHPFHIR_CLIENT_CLASSNAME_RESPONSE; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/client/class_response_headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

class <?php echo PHPFHIR_CLIENT_CLASSNAME_RESPONSE_HEADERS; ?> implements \Countable
{
Expand Down
3 changes: 1 addition & 2 deletions template/core/client/enum_http_method.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

enum <?php echo PHPFHIR_CLIENT_ENUM_HTTP_METHOD; ?> : string
{
Expand Down
3 changes: 1 addition & 2 deletions template/core/client/enum_response_format.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

enum <?php echo PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT; ?> : string
{
Expand Down
3 changes: 1 addition & 2 deletions template/core/client/enum_sort_direction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

enum <?php echo PHPFHIR_CLIENT_ENUM_SORT_DIRECTION; ?> : string
{
Expand Down
3 changes: 1 addition & 2 deletions template/core/client/exception_abstract_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>
abstract class <?php echo PHPFHIR_EXCEPTION_CLIENT_ABSTRACT_CLIENT; ?> extends \Exception
{
/** @var <?php echo $respClass->getFullyQualifiedName(true); ?> */
Expand Down
3 changes: 1 addition & 2 deletions template/core/client/exception_client_error.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

class <?php echo PHPFHIR_EXCEPTION_CLIENT_ERROR; ?> extends <?php echo PHPFHIR_EXCEPTION_CLIENT_ABSTRACT_CLIENT; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/client/exception_unexpected_response_code.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

class <?php echo PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE; ?> extends <?php echo PHPFHIR_EXCEPTION_CLIENT_ABSTRACT_CLIENT; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/client/interface_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

interface <?php echo PHPFHIR_CLIENT_INTERFACE_CLIENT; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/encoding/class_serialize_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

class <?php echo PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/encoding/class_unserialize_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

class <?php echo PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/encoding/class_xml_writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

/**
* PHP FHIR XMLWriter Class.
Expand Down
3 changes: 1 addition & 2 deletions template/core/encoding/enum_xml_location.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

enum <?php echo PHPFHIR_ENCODING_ENUM_XML_LOCATION; ?> : string
{
Expand Down
3 changes: 1 addition & 2 deletions template/core/encoding/trait_xml_location.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

trait <?php echo PHPFHIR_ENCODING_TRAIT_XML_LOCATION; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/enum_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

<?php foreach($config->getVersionsIterator() as $version) : ?>
use <?php echo $version->getFullyQualifiedName(false, PHPFHIR_VERSION_CLASSNAME_VERSION); ?> as <?php echo $version->getEnumImportName(); ?>;
Expand Down
3 changes: 1 addition & 2 deletions template/core/interface_comment_container.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

interface <?php echo PHPFHIR_INTERFACE_COMMENT_CONTAINER; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/interface_contained_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

/**
* Interface <?php echo PHPFHIR_INTERFACE_CONTAINED_TYPE; ?>
Expand Down
3 changes: 1 addition & 2 deletions template/core/interface_primitive_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

interface <?php echo PHPFHIR_INTERFACE_PRIMITIVE_TYPE; ?> extends <?php echo PHPFHIR_INTERFACE_TYPE; ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/interface_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

<?php echo ImportUtils::compileImportStatements($imports); ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/interface_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

<?php echo ImportUtils::compileImportStatements($imports); ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/interface_version_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

<?php echo ImportUtils::compileImportStatements($imports); ?>

Expand Down
3 changes: 1 addition & 2 deletions template/core/interface_version_type_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

interface <?php echo PHPFHIR_INTERFACE_VERSION_TYPE_MAP; ?>

Expand Down
59 changes: 59 additions & 0 deletions template/core/tests/client/test_class_client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types=1);

/*
* Copyright 2025 Daniel Carbone ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use DCarbone\PHPFHIR\Utilities\ImportUtils;

/** @var \DCarbone\PHPFHIR\Config $config */
/** @var \DCarbone\PHPFHIR\CoreFile $coreFile */

$imports = $coreFile->getImports();
$imports->addCoreFileImportsByName(
PHPFHIR_CLIENT_CLASSNAME_CONFIG,
PHPFHIR_CLIENT_CLASSNAME_CLIENT,
);

$coreFiles = $config->getCoreFiles();

$clientClientClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_CLIENT);
$clientConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_CONFIG);

ob_start();
echo "<?php\n\n";?>
namespace <?php echo $coreFile->getFullyQualifiedNamespace(false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(true); ?>

<?php echo ImportUtils::compileImportStatements($imports); ?>
use PHPUnit\Framework\TestCase;

class <?php echo PHPFHIR_TEST_CLIENT_CLASSNAME_CLIENT; ?> extends TestCase
{
public function testCanConstructWithOnlyAddress()
{
$cl = new <?php echo $clientClientClass->getEntityName(); ?>('http://example.com');
$this->assertEquals('http://example.com', $cl->getConfig()->getAddress());
}

public function testCanConstructWithConfig()
{
$c = new <?php echo $clientConfigClass->getEntityName(); ?>('http://example.com');
$cl = new <?php echo $clientClientClass->getEntityName(); ?>($c);
$this->assertEquals('http://example.com', $cl->getConfig()->getAddress());
}
}
<?php return ob_get_clean();
Loading

0 comments on commit de28e24

Please sign in to comment.