diff --git a/CHANGELOG.md b/CHANGELOG.md index 16de8dca..ac311ece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,21 +5,44 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com) and this project adheres to [Semantic Versioning](https://semver.org). -## [Unreleased] +## Unreleased - TBD ### Added - Implemented Page Order for Xlsx and Xls Readers, and provided Page Settings (Orientation, Scale, Horizontal/Vertical Centering, Page Order, Margins) support for Ods, Gnumeric and Xls Readers [#1559](https://github.com/PHPOffice/PhpSpreadsheet/pull/1559) +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + ### Fixed +- Nothing. + +## 1.14.1 - 2020-07-19 + +### Added + - nothing +### Fixed + +- WEBSERVICE is HTTP client agnostic and must be configured via `Settings::setHttpClient()` [#1562](https://github.com/PHPOffice/PhpSpreadsheet/issues/1562) +- Borders were not complete on rowspanned columns using HTML reader [#1473](https://github.com/PHPOffice/PhpSpreadsheet/pull/1473) + ### Changed - nothing -## [1.14.0] - 2020-06-29 +## 1.14.0 - 2020-06-29 ### Added @@ -43,7 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Xls Writer - Correct Timestamp Bug [#1493](https://github.com/PHPOffice/PhpSpreadsheet/pull/1493) - Don't ouput row and columns without any cells in HTML writer [#1235](https://github.com/PHPOffice/PhpSpreadsheet/issues/1235) -## [1.13.0] - 2020-05-31 +## 1.13.0 - 2020-05-31 ### Added @@ -69,7 +92,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Drop partial migration tool in favor of complete migration via RectorPHP [#1445](https://github.com/PHPOffice/PhpSpreadsheet/issues/1445) - Limit composer package to `src/` [#1424](https://github.com/PHPOffice/PhpSpreadsheet/pull/1424) -## [1.12.0] - 2020-04-27 +## 1.12.0 - 2020-04-27 ### Added @@ -85,7 +108,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - MATCH with a static array should return the position of the found value based on the values submitted [#1332](https://github.com/PHPOffice/PhpSpreadsheet/pull/1332) - Fix Xlsx Reader's handling of undefined fill color [#1353](https://github.com/PHPOffice/PhpSpreadsheet/pull/1353) -## [1.11.0] - 2020-03-02 +## 1.11.0 - 2020-03-02 ### Added @@ -104,7 +127,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix XLSX file loading with autofilter containing '$' [#1326](https://github.com/PHPOffice/PhpSpreadsheet/pull/1326) - PHPDoc - Use `@return $this` for fluent methods [#1362](https://github.com/PHPOffice/PhpSpreadsheet/pull/1362) -## [1.10.1] - 2019-12-02 +## 1.10.1 - 2019-12-02 ### Changed @@ -119,7 +142,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - ODS writer prevent invalid numeric value if locale decimal separator is comma [#1268](https://github.com/PHPOffice/PhpSpreadsheet/pull/1268) - Xlsx writer actually writes plotVisOnly and dispBlanksAs from chart properties [#1266](https://github.com/PHPOffice/PhpSpreadsheet/pull/1266) -## [1.10.0] - 2019-11-18 +## 1.10.0 - 2019-11-18 ### Changed @@ -144,7 +167,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Validate XIRR inputs and return correct error values [#1120](https://github.com/PHPOffice/PhpSpreadsheet/issues/1120) - Allow to read xlsx files with exotic workbook names like "workbook2.xml" [#1183](https://github.com/PHPOffice/PhpSpreadsheet/pull/1183) -## [1.9.0] - 2019-08-17 +## 1.9.0 - 2019-08-17 ### Changed @@ -175,20 +198,20 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix `getCalculatedValue()` error with more than two INDIRECT [#1115](https://github.com/PHPOffice/PhpSpreadsheet/pull/1115) - Writer\Html did not hide columns [#985](https://github.com/PHPOffice/PhpSpreadsheet/pull/985) -## [1.8.2] - 2019-07-08 +## 1.8.2 - 2019-07-08 ### Fixed - Uncaught error when opening ods file and properties aren't defined [#1047](https://github.com/PHPOffice/PhpSpreadsheet/issues/1047) - Xlsx Reader Cell datavalidations bug [#1052](https://github.com/PHPOffice/PhpSpreadsheet/pull/1052) -## [1.8.1] - 2019-07-02 +## 1.8.1 - 2019-07-02 ### Fixed - Allow nullable theme for Xlsx Style Reader class [#1043](https://github.com/PHPOffice/PhpSpreadsheet/issues/1043) -## [1.8.0] - 2019-07-01 +## 1.8.0 - 2019-07-01 ### Security Fix (CVE-2019-12331) @@ -211,7 +234,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix a SUMIF warning with some versions of PHP when having different length of arrays provided as input [#873](https://github.com/PHPOffice/PhpSpreadsheet/pull/873) - Fix incorrectly handled backslash-escaped space characters in number format -## [1.7.0] - 2019-05-26 +## 1.7.0 - 2019-05-26 - Added support for inline styles in Html reader (borders, alignment, width, height) - QuotedText cells no longer treated as formulae if the content begins with a `=` @@ -225,7 +248,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix VLOOKUP - Fix return type hint -## [1.6.0] - 2019-01-02 +## 1.6.0 - 2019-01-02 ### Added @@ -253,13 +276,13 @@ and this project adheres to [Semantic Versioning](https://semver.org). - `master` is the new default branch, `develop` does not exist anymore -## [1.5.2] - 2018-11-25 +## 1.5.2 - 2018-11-25 ### Security - Improvements to the design of the XML Security Scanner [#771](https://github.com/PHPOffice/PhpSpreadsheet/issues/771) -## [1.5.1] - 2018-11-20 +## 1.5.1 - 2018-11-20 ### Security @@ -279,7 +302,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Mpdf export can exceed pcre.backtrack_limit [#637](https://github.com/PHPOffice/PhpSpreadsheet/issues/637) - Fix index overflow on data values array [#748](https://github.com/PHPOffice/PhpSpreadsheet/pull/748) -## [1.5.0] - 2018-10-21 +## 1.5.0 - 2018-10-21 ### Added @@ -294,7 +317,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - OFFSET should allow omitted height and width [#561](https://github.com/PHPOffice/PhpSpreadsheet/issues/561) - Correctly determine delimiter when CSV contains line breaks inside enclosures [#716](https://github.com/PHPOffice/PhpSpreadsheet/issues/716) -## [1.4.1] - 2018-09-30 +## 1.4.1 - 2018-09-30 ### Fixed @@ -303,7 +326,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix warning when reading xlsx without styles [#631](https://github.com/PHPOffice/PhpSpreadsheet/pull/631) - Fix broken sample links on windows due to $baseDir having backslash [#653](https://github.com/PHPOffice/PhpSpreadsheet/pull/653) -## [1.4.0] - 2018-08-06 +## 1.4.0 - 2018-08-06 ### Added @@ -367,13 +390,13 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Migration tool keep variables containing $PHPExcel untouched [#598](https://github.com/PHPOffice/PhpSpreadsheet/issues/598) - Rowspans/colspans were incorrect when adding worksheet using loadIntoExisting [#619](https://github.com/PHPOffice/PhpSpreadsheet/issues/619) -## [1.3.1] - 2018-06-12 +## 1.3.1 - 2018-06-12 ### Fixed - Ranges across Z and AA columns incorrectly threw an exception [#545](https://github.com/PHPOffice/PhpSpreadsheet/issues/545) -## [1.3.0] - 2018-06-10 +## 1.3.0 - 2018-06-10 ### Added @@ -392,13 +415,13 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fixed parsing of conditionals in COUNTIF functions [#526](https://github.com/PHPOffice/PhpSpreadsheet/issues/526) - Corruption errors for saved Xlsx docs with frozen panes [#532](https://github.com/PHPOffice/PhpSpreadsheet/issues/532) -## [1.2.1] - 2018-04-10 +## 1.2.1 - 2018-04-10 ### Fixed - Plain text and richtext mixed in same cell can be read [#442](https://github.com/PHPOffice/PhpSpreadsheet/issues/442) -## [1.2.0] - 2018-03-04 +## 1.2.0 - 2018-03-04 ### Added @@ -416,7 +439,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Select correct cell when calling freezePane [#389](https://github.com/PHPOffice/PhpSpreadsheet/issues/389) - `setStrikethrough()` did not set the font [#403](https://github.com/PHPOffice/PhpSpreadsheet/issues/403) -## [1.1.0] - 2018-01-28 +## 1.1.0 - 2018-01-28 ### Added @@ -434,7 +457,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Support XML file without styles [#331](https://github.com/PHPOffice/PhpSpreadsheet/pull/331) - Cell coordinates which are already a range cause an exception [#319](https://github.com/PHPOffice/PhpSpreadsheet/issues/319) -## [1.0.0] - 2017-12-25 +## 1.0.0 - 2017-12-25 ### Added @@ -453,7 +476,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Constant `TYPE_DOUGHTNUTCHART` is now `TYPE_DOUGHNUTCHART`. -## [1.0.0-beta2] - 2017-11-26 +## 1.0.0-beta2 - 2017-11-26 ### Added @@ -491,7 +514,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - `PhpSpreadsheet\Style` => `PhpSpreadsheet\Style\Style` - `PhpSpreadsheet\Worksheet` => `PhpSpreadsheet\Worksheet\Worksheet` -## [1.0.0-beta] - 2017-08-17 +## 1.0.0-beta - 2017-08-17 ### Added diff --git a/composer.json b/composer.json index d4810ce6..d0379949 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,8 @@ "markbaker/complex": "^1.4", "markbaker/matrix": "^1.2", "psr/simple-cache": "^1.0", - "guzzlehttp/guzzle": "^7.0" + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0" }, "require-dev": { "dompdf/dompdf": "^0.8.5", diff --git a/composer.lock b/composer.lock index 99de82bf..266608f2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,211 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b7ea4dea7ce2e1c2299029fe978d2173", + "content-hash": "931b86c12c78e665f1766ea922f95e0b", "packages": [ - { - "name": "guzzlehttp/guzzle", - "version": "7.0.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "2d9d3c186a6637a43193e66b097c50e4451eaab2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/2d9d3c186a6637a43193e66b097c50e4451eaab2", - "reference": "2d9d3c186a6637a43193e66b097c50e4451eaab2", - "shasum": "" - }, - "require": { - "ext-json": "*", - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.6.1", - "php": "^7.2.5", - "psr/http-client": "^1.0" - }, - "provide": { - "psr/http-client-implementation": "1.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.0", - "ext-curl": "*", - "php-http/client-integration-tests": "dev-phpunit8", - "phpunit/phpunit": "^8.5.5", - "psr/log": "^1.1" - }, - "suggest": { - "ext-curl": "Required for CURL handler support", - "ext-intl": "Required for Internationalized Domain Name (IDN) support", - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "7.0-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://sagikazarmark.hu" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "psr-18", - "psr-7", - "rest", - "web service" - ], - "time": "2020-06-27T10:33:25+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "v1.3.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "shasum": "" - }, - "require": { - "php": ">=5.5.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "time": "2016-12-20T10:07:11+00:00" - }, - { - "name": "guzzlehttp/psr7", - "version": "1.6.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" - }, - "suggest": { - "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Schultze", - "homepage": "https://github.com/Tobion" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "psr-7", - "request", - "response", - "stream", - "uri", - "url" - ], - "time": "2019-07-01T23:21:34+00:00" - }, { "name": "maennchen/zipstream-php", "version": "2.1.0", @@ -482,20 +279,20 @@ }, { "name": "psr/http-client", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/http-client.git", - "reference": "496a823ef742b632934724bf769560c2a5c7c44e" + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/496a823ef742b632934724bf769560c2a5c7c44e", - "reference": "496a823ef742b632934724bf769560c2a5c7c44e", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", "shasum": "" }, "require": { - "php": "^7.0", + "php": "^7.0 || ^8.0", "psr/http-message": "^1.0" }, "type": "library", @@ -527,7 +324,59 @@ "psr", "psr-18" ], - "time": "2018-10-30T23:29:13+00:00" + "time": "2020-06-29T06:28:15+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "time": "2019-04-30T12:38:16+00:00" }, { "name": "psr/http-message", @@ -627,46 +476,6 @@ ], "time": "2017-10-23T01:57:42+00:00" }, - { - "name": "ralouphie/getallheaders", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "time": "2019-03-08T08:55:37+00:00" - }, { "name": "symfony/polyfill-mbstring", "version": "v1.17.1", @@ -4382,5 +4191,6 @@ "ext-zip": "*", "ext-zlib": "*" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } diff --git a/docs/topics/settings.md b/docs/topics/settings.md index 4463ceeb..d28a9996 100644 --- a/docs/topics/settings.md +++ b/docs/topics/settings.md @@ -43,3 +43,20 @@ More details of the features available once a locale has been set, including a list of the languages and locales currently supported, can be found in [Locale Settings for Formulae](./recipes.md#locale-settings-for-formulae). + +## HTTP client + +In order to use the `WEBSERVICE` function in formulae, you must configure an +HTTP client. Assuming you chose Guzzle 7, this can be done like: + + +```php +use GuzzleHttp\Client; +use Http\Factory\Guzzle\RequestFactory; +use PhpOffice\PhpSpreadsheet\Settings; + +$client = new Client(); +$requestFactory = new RequestFactory(); + +Settings::setHttpClient($client, $requestFactory); +``` diff --git a/src/PhpSpreadsheet/Calculation/Web.php b/src/PhpSpreadsheet/Calculation/Web.php index 9f0faf99..5cfd2ea8 100644 --- a/src/PhpSpreadsheet/Calculation/Web.php +++ b/src/PhpSpreadsheet/Calculation/Web.php @@ -2,7 +2,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; -use GuzzleHttp\Psr7\Request; use PhpOffice\PhpSpreadsheet\Settings; use Psr\Http\Client\ClientExceptionInterface; @@ -31,7 +30,8 @@ class Web // Get results from the the webservice $client = Settings::getHttpClient(); - $request = new Request('GET', $url); + $requestFactory = Settings::getRequestFactory(); + $request = $requestFactory->createRequest('GET', $url); try { $response = $client->sendRequest($request); @@ -43,7 +43,7 @@ class Web return Functions::VALUE(); // cURL error } - $output = (string) $response->getBody(); + $output = $response->getBody()->getContents(); if (strlen($output) > 32767) { return Functions::VALUE(); // Output not a string or too long } diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 2fe85b6f..d59e4744 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -682,7 +682,26 @@ class Html extends BaseReader return; } - $cellStyle = $sheet->getStyle($column . $row); + if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) { + $columnTo = $column; + for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) { + ++$columnTo; + } + $range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1); + $cellStyle = $sheet->getStyle($range); + } elseif (isset($attributeArray['rowspan'])) { + $range = $column . $row . ':' . $column . ($row + (int) $attributeArray['rowspan'] - 1); + $cellStyle = $sheet->getStyle($range); + } elseif (isset($attributeArray['colspan'])) { + $columnTo = $column; + for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) { + ++$columnTo; + } + $range = $column . $row . ':' . $columnTo . $row; + $cellStyle = $sheet->getStyle($range); + } else { + $cellStyle = $sheet->getStyle($column . $row); + } // add color styles (background & text) from dom element,currently support : td & th, using ONLY inline css style with RGB color $styles = explode(';', $attributeArray['style']); diff --git a/src/PhpSpreadsheet/Settings.php b/src/PhpSpreadsheet/Settings.php index 15218c72..cfa50573 100644 --- a/src/PhpSpreadsheet/Settings.php +++ b/src/PhpSpreadsheet/Settings.php @@ -2,11 +2,11 @@ namespace PhpOffice\PhpSpreadsheet; -use GuzzleHttp\Client; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Chart\Renderer\IRenderer; use PhpOffice\PhpSpreadsheet\Collection\Memory; use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; use Psr\SimpleCache\CacheInterface; class Settings @@ -47,9 +47,14 @@ class Settings /** * The HTTP client implementation to be used for network request. * - * @var ClientInterface + * @var null|ClientInterface */ - private static $client; + private static $httpClient; + + /** + * @var null|RequestFactoryInterface + */ + private static $requestFactory; /** * Set the locale code to use for formula translations and any special formatting. @@ -169,9 +174,19 @@ class Settings /** * Set the HTTP client implementation to be used for network request. */ - public static function setHttpClient(ClientInterface $httpClient): void + public static function setHttpClient(ClientInterface $httpClient, RequestFactoryInterface $requestFactory): void { - self::$client = $httpClient; + self::$httpClient = $httpClient; + self::$requestFactory = $requestFactory; + } + + /** + * Unset the HTTP client configuration. + */ + public static function unsetHttpClient(): void + { + self::$httpClient = null; + self::$requestFactory = null; } /** @@ -179,10 +194,25 @@ class Settings */ public static function getHttpClient(): ClientInterface { - if (!self::$client) { - self::$client = new Client(); - } + self::assertHttpClient(); - return self::$client; + return self::$httpClient; + } + + /** + * Get the HTTP request factory. + */ + public static function getRequestFactory(): RequestFactoryInterface + { + self::assertHttpClient(); + + return self::$requestFactory; + } + + private static function assertHttpClient(): void + { + if (!self::$httpClient || !self::$requestFactory) { + throw new Exception('HTTP client must be configured via Settings::setHttpClient() to be able to use WEBSERVICE function.'); + } } } diff --git a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php index 80431c4d..8e339207 100644 --- a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php @@ -9,15 +9,23 @@ use PHPUnit\Framework\TestCase; class CalculationTest extends TestCase { + private $compatibilityMode; + + private $locale; + protected function setUp(): void { + $this->compatibilityMode = Functions::getCompatibilityMode(); + $calculation = Calculation::getInstance(); + $this->locale = $calculation->getLocale(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); } protected function tearDown(): void { + Functions::setCompatibilityMode($this->compatibilityMode); $calculation = Calculation::getInstance(); - $calculation->setLocale('en_us'); + $calculation->setLocale($this->locale); } /** diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php index 8f4639eb..482e068d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php @@ -9,13 +9,29 @@ use PHPUnit\Framework\TestCase; class DayTest extends TestCase { + private $compatibilityMode; + + private $returnDateType; + + private $excelCalendar; + protected function setUp(): void { + $this->compatibilityMode = Functions::getCompatibilityMode(); + $this->returnDateType = Functions::getReturnDateType(); + $this->excelCalendar = Date::getExcelCalendar(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); } + protected function tearDown(): void + { + Functions::setCompatibilityMode($this->compatibilityMode); + Functions::setReturnDateType($this->returnDateType); + Date::setExcelCalendar($this->excelCalendar); + } + /** * @dataProvider providerDAY * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php index 26e621ec..65b698e3 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php @@ -8,11 +8,19 @@ use PHPUnit\Framework\TestCase; class CountTest extends TestCase { + private $compatibilityMode; + protected function setUp(): void { + $this->compatibilityMode = Functions::getCompatibilityMode(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); } + protected function tearDown(): void + { + Functions::setCompatibilityMode($this->compatibilityMode); + } + /** * @dataProvider providerBasicCOUNT * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php index 70ea7526..cf22df02 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class CharTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerCHAR * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php index 6aedb599..31dcc5e6 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class CleanTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerCLEAN * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php index ec9f26d6..9c19f347 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class CodeTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerCODE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php index 18a2d684..068e7d8f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ConcatenateTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerCONCATENATE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php index 4a0f6013..1d482589 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class DollarTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerDOLLAR * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php index 09d45a32..92d3935c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ExactTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerEXACT * @@ -33,10 +15,6 @@ class ExactTest extends TestCase */ public function testEXACT($expectedResult, ...$args): void { - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(' '); - StringHelper::setCurrencyCode('$'); - $result = TextData::EXACT(...$args); self::assertSame($expectedResult, $result); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php index 38203a33..d4b1b77d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class FindTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerFIND * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php index 53e6a513..0cbaf80c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class FixedTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerFIXED * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php index 9a033ae7..e69a3fa0 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class LeftTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerLEFT * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php index af784163..bca2b389 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class LenTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerLEN * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php index 6ad522d8..9ba677c7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class LowerTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerLOWER * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php index df02575f..4c19248a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class MidTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerMID * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php index 006e4ce1..c186bb0b 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class NumberValueTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerNUMBERVALUE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php index d799b395..aae0e696 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ProperTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerPROPER * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php index ff3d58bb..ff9236e6 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ReplaceTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerREPLACE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php index a89ea6ed..50fc86dc 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class RightTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerRIGHT * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php index 919ec0fb..7bb92e83 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class SearchTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerSEARCH * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php index d1884fd8..2a9d1012 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class SubstituteTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerSUBSTITUTE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php index 1ce989b4..c7606c05 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class TTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerT * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php index 7eec585c..e8fb404d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class TextJoinTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerTEXTJOIN * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php index eab517cc..8d7b238b 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class TextTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerTEXT * @@ -32,11 +14,6 @@ class TextTest extends TestCase */ public function testTEXT($expectedResult, ...$args): void { - // Enforce decimal and thousands separator values to UK/US, and currency code to USD - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - $result = TextData::TEXTFORMAT(...$args); self::assertEquals($expectedResult, $result); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php index 24ede75f..91890ded 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class TrimTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerTRIM * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php index 1600f37c..13fb0b86 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class UpperTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerUPPER * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php index a5083b22..355193de 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php @@ -2,27 +2,30 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ValueTest extends TestCase { + private $currencyCode; + + private $decimalSeparator; + + private $thousandsSeparator; + protected function setUp(): void { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); + $this->currencyCode = StringHelper::getCurrencyCode(); + $this->decimalSeparator = StringHelper::getDecimalSeparator(); + $this->thousandsSeparator = StringHelper::getThousandsSeparator(); } protected function tearDown(): void { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); + StringHelper::setCurrencyCode($this->currencyCode); + StringHelper::setDecimalSeparator($this->decimalSeparator); + StringHelper::setThousandsSeparator($this->thousandsSeparator); } /** diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php index acc83cff..2aff7b3d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php @@ -2,47 +2,46 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Web; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\ClientException; -use GuzzleHttp\Exception\ConnectException; -use GuzzleHttp\Handler\MockHandler; -use GuzzleHttp\HandlerStack; -use GuzzleHttp\Psr7\Request; -use GuzzleHttp\Psr7\Response; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Web; use PhpOffice\PhpSpreadsheet\Settings; use PHPUnit\Framework\TestCase; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; class WebServiceTest extends TestCase { - protected static $client; - - public static function setUpBeforeClass(): void + protected function tearDown(): void { - // Prevent URL requests being sent out - $mock = new MockHandler([ - new ClientException('This is not a valid URL', new Request('GET', 'test'), new Response()), - new ConnectException('This is a 404 error', new Request('GET', 'test')), - new Response('200', [], str_repeat('a', 40000)), - new Response('200', [], 'This is a test'), - ]); - - $handlerStack = HandlerStack::create($mock); - self::$client = new Client(['handler' => $handlerStack]); - } - - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); + Settings::unsetHttpClient(); } /** * @dataProvider providerWEBSERVICE */ - public function testWEBSERVICE(string $expectedResult, string $url): void + public function testWEBSERVICE(string $expectedResult, string $url, ?array $responseData): void { - Settings::setHttpClient(self::$client); + if ($responseData) { + $body = $this->createMock(StreamInterface::class); + $body->expects(self::atMost(1))->method('getContents')->willReturn($responseData[1]); + + $response = $this->createMock(ResponseInterface::class); + $response->expects(self::once())->method('getStatusCode')->willReturn($responseData[0]); + $response->expects(self::atMost(1))->method('getBody')->willReturn($body); + + $client = $this->createMock(ClientInterface::class); + $client->expects(self::once())->method('sendRequest')->willReturn($response); + + $request = $this->createMock(RequestInterface::class); + + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->expects(self::atMost(1))->method('createRequest')->willReturn($request); + + Settings::setHttpClient($client, $requestFactory); + } + $result = Web::WEBSERVICE($url); self::assertEquals($expectedResult, $result); } @@ -51,4 +50,28 @@ class WebServiceTest extends TestCase { return require 'tests/data/Calculation/Web/WEBSERVICE.php'; } + + public function testWEBSERVICEReturnErrorWhenClientThrows(): void + { + $exception = $this->createMock(\Psr\Http\Client\ClientExceptionInterface::class); + + $client = $this->createMock(ClientInterface::class); + $client->expects(self::once())->method('sendRequest')->willThrowException($exception); + + $request = $this->createMock(RequestInterface::class); + + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->expects(self::atMost(1))->method('createRequest')->willReturn($request); + + Settings::setHttpClient($client, $requestFactory); + + $result = Web::WEBSERVICE('https://example.com'); + self::assertEquals('#VALUE!', $result); + } + + public function testWEBSERVICEThrowsIfNotClientConfigured(): void + { + $this->expectExceptionMessage('HTTP client must be configured via Settings::setHttpClient() to be able to use WEBSERVICE function.'); + Web::WEBSERVICE('https://example.com'); + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php index 4412215a..dfa01822 100644 --- a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php @@ -10,16 +10,22 @@ use PHPUnit\Framework\TestCase; class FunctionsTest extends TestCase { + private $compatibilityMode; + + private $returnDate; + protected function setUp(): void { + $this->compatibilityMode = Functions::getCompatibilityMode(); + $this->returnDate = Functions::getReturnDateType(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); } protected function tearDown(): void { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); + Functions::setCompatibilityMode($this->compatibilityMode); + Functions::setReturnDateType($this->returnDate); } public function testCompatibilityMode(): void diff --git a/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php b/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php index 936092d4..630a2944 100644 --- a/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php +++ b/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php @@ -13,6 +13,26 @@ use PHPUnit\Framework\TestCase; class AdvancedValueBinderTest extends TestCase { + private $currencyCode; + + private $decimalSeparator; + + private $thousandsSeparator; + + protected function setUp(): void + { + $this->currencyCode = StringHelper::getCurrencyCode(); + $this->decimalSeparator = StringHelper::getDecimalSeparator(); + $this->thousandsSeparator = StringHelper::getThousandsSeparator(); + } + + protected function tearDown(): void + { + StringHelper::setCurrencyCode($this->currencyCode); + StringHelper::setDecimalSeparator($this->decimalSeparator); + StringHelper::setThousandsSeparator($this->thousandsSeparator); + } + public function provider() { $currencyUSD = NumberFormat::FORMAT_CURRENCY_USD_SIMPLE; diff --git a/tests/PhpSpreadsheetTests/Reader/HtmlTest.php b/tests/PhpSpreadsheetTests/Reader/HtmlTest.php index b0994a33..636aaa94 100644 --- a/tests/PhpSpreadsheetTests/Reader/HtmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/HtmlTest.php @@ -424,4 +424,35 @@ class HtmlTest extends TestCase self::assertEquals(10, $style->getAlignment()->getIndent()); unlink($filename); } + + public function testBorderWithRowspanAndColspan(): void + { + $html = '
NOT SPANNED | +SPANNED | +|
NOT SPANNED | +