From de28e24749a1af78a1db8b3f3329719a0b2de7cf Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 16 Jan 2025 10:32:14 -0600 Subject: [PATCH] little bit of cleanup, adding few basic client unit tests --- files/constants.php | 2 + template/core/class_autoloader.php | 3 +- template/core/class_constants.php | 3 +- template/core/class_response_parser.php | 3 +- template/core/class_version_config.php | 3 +- template/core/client/class_client.php | 7 +- template/core/client/class_config.php | 6 +- template/core/client/class_request.php | 3 +- template/core/client/class_response.php | 3 +- .../core/client/class_response_headers.php | 3 +- template/core/client/enum_http_method.php | 3 +- template/core/client/enum_response_format.php | 3 +- template/core/client/enum_sort_direction.php | 3 +- .../core/client/exception_abstract_client.php | 3 +- .../core/client/exception_client_error.php | 3 +- .../exception_unexpected_response_code.php | 3 +- template/core/client/interface_client.php | 3 +- .../core/encoding/class_serialize_config.php | 3 +- .../encoding/class_unserialize_config.php | 3 +- template/core/encoding/class_xml_writer.php | 3 +- template/core/encoding/enum_xml_location.php | 3 +- template/core/encoding/trait_xml_location.php | 3 +- template/core/enum_version.php | 3 +- template/core/interface_comment_container.php | 3 +- template/core/interface_contained_type.php | 3 +- template/core/interface_primitive_type.php | 3 +- template/core/interface_type.php | 3 +- template/core/interface_version.php | 3 +- template/core/interface_version_config.php | 3 +- template/core/interface_version_type_map.php | 3 +- .../core/tests/client/test_class_client.php | 59 +++++++++++++++ .../core/tests/client/test_class_config.php | 72 +++++++++++++++++++ .../test_class_unserialize_config.php | 3 +- .../tests/encoding/test_class_xml_writer.php | 3 +- template/core/trait_comment_container.php | 3 +- template/core/trait_source_xml_namespace.php | 3 +- template/core/validation/class_validator.php | 3 +- 37 files changed, 170 insertions(+), 72 deletions(-) create mode 100644 template/core/tests/client/test_class_client.php create mode 100644 template/core/tests/client/test_class_config.php diff --git a/files/constants.php b/files/constants.php index 33be7e65..8f6b2d8b 100644 --- a/files/constants.php +++ b/files/constants.php @@ -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'; diff --git a/template/core/class_autoloader.php b/template/core/class_autoloader.php index cb85ee14..edd1b5c9 100644 --- a/template/core/class_autoloader.php +++ b/template/core/class_autoloader.php @@ -28,8 +28,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> abstract class diff --git a/template/core/class_constants.php b/template/core/class_constants.php index 92e3b952..686fb070 100644 --- a/template/core/class_constants.php +++ b/template/core/class_constants.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> final class diff --git a/template/core/class_response_parser.php b/template/core/class_response_parser.php index 8a292f4a..3da7d239 100644 --- a/template/core/class_response_parser.php +++ b/template/core/class_response_parser.php @@ -29,8 +29,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> class diff --git a/template/core/class_version_config.php b/template/core/class_version_config.php index 4ef482a5..c9b3f550 100644 --- a/template/core/class_version_config.php +++ b/template/core/class_version_config.php @@ -37,8 +37,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> diff --git a/template/core/client/class_client.php b/template/core/client/class_client.php index 8462cc15..96e7e782 100644 --- a/template/core/client/class_client.php +++ b/template/core/client/class_client.php @@ -41,8 +41,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> @@ -75,7 +74,7 @@ class implements $config) { if (is_string($config)) { - $config = new ($config); + $config = new (address: $config); } $this->_config = $config; } @@ -115,7 +114,7 @@ public function exec( $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) { diff --git a/template/core/client/class_config.php b/template/core/client/class_config.php index da22757e..fee71369 100644 --- a/template/core/client/class_config.php +++ b/template/core/client/class_config.php @@ -28,8 +28,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> /** * Class @@ -64,7 +63,6 @@ class public function __construct(string $address, null| $defaultFormat = null, array $queryParams = [], - array $requestHeaders = [], array $curlOpts = [], bool $parseResponseHeaders = false) { @@ -112,7 +110,7 @@ public function getCurlOpts(): array /** * @return bool */ - public function getParseHeaders(): bool + public function getParseResponseHeaders(): bool { return $this->_parseResponseHeaders; } diff --git a/template/core/client/class_request.php b/template/core/client/class_request.php index f5876bf6..df7f8ac3 100644 --- a/template/core/client/class_request.php +++ b/template/core/client/class_request.php @@ -31,8 +31,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> class diff --git a/template/core/client/class_response.php b/template/core/client/class_response.php index 3bf475c0..c42e6cec 100644 --- a/template/core/client/class_response.php +++ b/template/core/client/class_response.php @@ -28,8 +28,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> class diff --git a/template/core/client/class_response_headers.php b/template/core/client/class_response_headers.php index fe2e5050..40bb8b48 100644 --- a/template/core/client/class_response_headers.php +++ b/template/core/client/class_response_headers.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> class implements \Countable { diff --git a/template/core/client/enum_http_method.php b/template/core/client/enum_http_method.php index 86ba5957..697803c5 100644 --- a/template/core/client/enum_http_method.php +++ b/template/core/client/enum_http_method.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> enum : string { diff --git a/template/core/client/enum_response_format.php b/template/core/client/enum_response_format.php index f36ee437..72f2b869 100644 --- a/template/core/client/enum_response_format.php +++ b/template/core/client/enum_response_format.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> enum : string { diff --git a/template/core/client/enum_sort_direction.php b/template/core/client/enum_sort_direction.php index 8d3b6aa0..a7645aef 100644 --- a/template/core/client/enum_sort_direction.php +++ b/template/core/client/enum_sort_direction.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> enum : string { diff --git a/template/core/client/exception_abstract_client.php b/template/core/client/exception_abstract_client.php index 8c7e7633..881adb1c 100644 --- a/template/core/client/exception_abstract_client.php +++ b/template/core/client/exception_abstract_client.php @@ -28,8 +28,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> abstract class extends \Exception { /** @var getFullyQualifiedName(true); ?> */ diff --git a/template/core/client/exception_client_error.php b/template/core/client/exception_client_error.php index 61fe0cf6..1e64be33 100644 --- a/template/core/client/exception_client_error.php +++ b/template/core/client/exception_client_error.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> class extends diff --git a/template/core/client/exception_unexpected_response_code.php b/template/core/client/exception_unexpected_response_code.php index f60b7fad..f672cc7d 100644 --- a/template/core/client/exception_unexpected_response_code.php +++ b/template/core/client/exception_unexpected_response_code.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> class extends diff --git a/template/core/client/interface_client.php b/template/core/client/interface_client.php index 77ef9735..9e06141d 100644 --- a/template/core/client/interface_client.php +++ b/template/core/client/interface_client.php @@ -29,8 +29,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> interface diff --git a/template/core/encoding/class_serialize_config.php b/template/core/encoding/class_serialize_config.php index b498f5dc..6437f92c 100644 --- a/template/core/encoding/class_serialize_config.php +++ b/template/core/encoding/class_serialize_config.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> class diff --git a/template/core/encoding/class_unserialize_config.php b/template/core/encoding/class_unserialize_config.php index ee33ebd0..2a868fd8 100644 --- a/template/core/encoding/class_unserialize_config.php +++ b/template/core/encoding/class_unserialize_config.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> class diff --git a/template/core/encoding/class_xml_writer.php b/template/core/encoding/class_xml_writer.php index fd4a0a51..df40c98a 100644 --- a/template/core/encoding/class_xml_writer.php +++ b/template/core/encoding/class_xml_writer.php @@ -28,8 +28,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> /** * PHP FHIR XMLWriter Class. diff --git a/template/core/encoding/enum_xml_location.php b/template/core/encoding/enum_xml_location.php index 49dac7a5..30d4c9de 100644 --- a/template/core/encoding/enum_xml_location.php +++ b/template/core/encoding/enum_xml_location.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> enum : string { diff --git a/template/core/encoding/trait_xml_location.php b/template/core/encoding/trait_xml_location.php index 4d4db38f..f0964bf2 100644 --- a/template/core/encoding/trait_xml_location.php +++ b/template/core/encoding/trait_xml_location.php @@ -30,8 +30,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> trait diff --git a/template/core/enum_version.php b/template/core/enum_version.php index 93cdd7c1..470be914 100644 --- a/template/core/enum_version.php +++ b/template/core/enum_version.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> getVersionsIterator() as $version) : ?> use getFullyQualifiedName(false, PHPFHIR_VERSION_CLASSNAME_VERSION); ?> as getEnumImportName(); ?>; diff --git a/template/core/interface_comment_container.php b/template/core/interface_comment_container.php index 4362f2ca..4891f6a4 100644 --- a/template/core/interface_comment_container.php +++ b/template/core/interface_comment_container.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> interface diff --git a/template/core/interface_contained_type.php b/template/core/interface_contained_type.php index 81db6405..412d5df5 100644 --- a/template/core/interface_contained_type.php +++ b/template/core/interface_contained_type.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> /** * Interface diff --git a/template/core/interface_primitive_type.php b/template/core/interface_primitive_type.php index 3ff4fe31..7b1189c3 100644 --- a/template/core/interface_primitive_type.php +++ b/template/core/interface_primitive_type.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> interface extends diff --git a/template/core/interface_type.php b/template/core/interface_type.php index 6de8ba7f..c0b8dc1b 100644 --- a/template/core/interface_type.php +++ b/template/core/interface_type.php @@ -41,8 +41,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> diff --git a/template/core/interface_version.php b/template/core/interface_version.php index fe77c041..227bb62e 100644 --- a/template/core/interface_version.php +++ b/template/core/interface_version.php @@ -38,8 +38,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> diff --git a/template/core/interface_version_config.php b/template/core/interface_version_config.php index 236fdf03..13c43f5e 100644 --- a/template/core/interface_version_config.php +++ b/template/core/interface_version_config.php @@ -37,8 +37,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> diff --git a/template/core/interface_version_type_map.php b/template/core/interface_version_type_map.php index 0a76e5a3..50100c01 100644 --- a/template/core/interface_version_type_map.php +++ b/template/core/interface_version_type_map.php @@ -28,8 +28,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> interface diff --git a/template/core/tests/client/test_class_client.php b/template/core/tests/client/test_class_client.php new file mode 100644 index 00000000..d90307b3 --- /dev/null +++ b/template/core/tests/client/test_class_client.php @@ -0,0 +1,59 @@ +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 " +namespace getFullyQualifiedNamespace(false); ?>; + +getBasePHPFHIRCopyrightComment(true); ?> + + +use PHPUnit\Framework\TestCase; + +class extends TestCase +{ + public function testCanConstructWithOnlyAddress() + { + $cl = new getEntityName(); ?>('http://example.com'); + $this->assertEquals('http://example.com', $cl->getConfig()->getAddress()); + } + + public function testCanConstructWithConfig() + { + $c = new getEntityName(); ?>('http://example.com'); + $cl = new getEntityName(); ?>($c); + $this->assertEquals('http://example.com', $cl->getConfig()->getAddress()); + } +} +getImports(); +$imports->addCoreFileImportsByName( + PHPFHIR_CLIENT_CLASSNAME_CONFIG, + PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT, +); + +$coreFiles = $config->getCoreFiles(); + +$clientConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_CONFIG); +$responseFormatEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT); + +ob_start(); +echo " +namespace getFullyQualifiedNamespace(false); ?>; + +getBasePHPFHIRCopyrightComment(true); ?> + + +use PHPUnit\Framework\TestCase; + +class extends TestCase +{ + public function testCanConstructWithOnlyAddress() + { + $c = new getEntityName(); ?>('http://example.com'); + $this->assertEquals('http://example.com', $c->getAddress()); + $this->assertNull($c->getDefaultFormat()); + $this->assertEmpty($c->getQueryParams()); + $this->assertEmpty($c->getCurlOpts()); + $this->assertFalse($c->getParseResponseHeaders()); + } + + public function testCanConstructWithAllParams() + { + $c = new getEntityName(); ?>( + address: 'http://example.com', + defaultFormat: getEntityName(); ?>::JSON, + queryParams: ['foo' => 'bar'], + curlOpts: ['bar' => 'baz'], + parseResponseHeaders: true + ); + $this->assertEquals('http://example.com', $c->getAddress()); + $this->assertEquals(getEntityName(); ?>::JSON, $c->getDefaultFormat()); + $this->assertEquals(['foo' => 'bar'], $c->getQueryParams()); + $this->assertEquals(['bar' => 'baz'], $c->getCurlOpts()); + $this->assertTrue($c->getParseResponseHeaders()); + } +} + namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> use PHPUnit\Framework\TestCase; diff --git a/template/core/tests/encoding/test_class_xml_writer.php b/template/core/tests/encoding/test_class_xml_writer.php index bd0470ab..6235f3e4 100644 --- a/template/core/tests/encoding/test_class_xml_writer.php +++ b/template/core/tests/encoding/test_class_xml_writer.php @@ -36,8 +36,7 @@ echo " namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> use PHPUnit\Framework\TestCase; diff --git a/template/core/trait_comment_container.php b/template/core/trait_comment_container.php index 06d7bee8..91c92eb4 100644 --- a/template/core/trait_comment_container.php +++ b/template/core/trait_comment_container.php @@ -24,8 +24,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> trait diff --git a/template/core/trait_source_xml_namespace.php b/template/core/trait_source_xml_namespace.php index c6aa2d17..0d16c39f 100644 --- a/template/core/trait_source_xml_namespace.php +++ b/template/core/trait_source_xml_namespace.php @@ -25,8 +25,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?> trait diff --git a/template/core/validation/class_validator.php b/template/core/validation/class_validator.php index af161d21..127d3f4f 100644 --- a/template/core/validation/class_validator.php +++ b/template/core/validation/class_validator.php @@ -38,8 +38,7 @@ namespace getFullyQualifiedNamespace(false); ?>; -getBasePHPFHIRCopyrightComment(false); ?> - +getBasePHPFHIRCopyrightComment(true); ?>