Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Fast)ArrayDecorator - Emit expected exception when using WP and stri…
…ct PSR-16 Suppose someone calls `ArrayDecorator::get()` or `FastArrayDecorator::get()` with an invalid key (e.g. passing `float` or an `array` instead of a `string`). This patch improves error-reporting for that scenario. This is primarily about fixing multiple test failures in `E2E_Cache_ArrayDecoratorTest` reported on `wp-demo`. These generally look like ``` 1) E2E_Cache_ArrayDecoratorTest::testGetInvalidKeys with data set #1 (true) array_key_exists(): The first argument should be either a string or an integer /Users/totten/bknix/build/wpmaster/wp-content/plugins/civicrm/civicrm/CRM/Utils/Cache/ArrayDecorator.php:102 /Users/totten/bknix/build/wpmaster/wp-content/plugins/civicrm/civicrm/packages/Cache/IntegrationTests/LegacySimpleCacheTest.php:409 /Users/totten/bknix/civicrm-buildkit/extern/phpunit5/phpunit5.phar:598 ``` Before ------ The ArrayDecorator first checks its front cache (`array_key_exists`) to see if the key is defined. In the `wp-demo` environment, this produces a warning and causes the test to fail. The condition *is* erroneous, but PSR-16 specifies that the error should be reported as exception. After ----- The condition is reported as the expected exception. The test passes on `wp-demo`. Comment ------- This brings the code in `(Fast)ArrayDecorator.php` into alignment with most of the other `CRM/Utils/Cache/*.php` drivers; in most drivers, it is typical to validate the key at the start of most functions.
- Loading branch information