41 Commits

Author SHA1 Message Date
michael-grunder
8f8a49bec2 Tests for VCARD, VDIM, and VINFO. 2025-09-01 09:41:12 -07:00
michael-grunder
8d369f4d62 Implement GEOSEARCH[STORE] BYPOLYGON.
Valkey 9.0.0 implemented a new variant of `GEOSEARCH` where you supply
the verticies to an arbitrary polygon.

Since we can't modify the `geosearch` prototype using it is a little
wonky (you need to just pass empty strings for position and unit).

```php
$redis->geosearch('ca:cities', '', [
    -121.90, 39.65, -121.77, 39.65, -121.77, 39.80, -121.90, 39.80
], '');
$redis->geosearchstore('ca:cities', 'dst', '', [
    -121.90, 39.65, -121.77, 39.65, -121.77, 39.80, -121.90, 39.80
], '');
```
2025-08-24 06:37:51 -07:00
michael-grunder
a2eef77f44 Implement Valkey >= 8.1 IFEQ set option
Implement the new `IFEQ` `SET` option that will be included in `Valkey`
8.1.

See: valkey-io/valkey#1324
2025-01-20 08:04:27 -08:00
Remi Collet
bff3a22e9d fix implicit nullable (8.4) 2024-09-23 11:08:56 -07:00
michael-grunder
6673b5b2be SRANDMEMBER can return any type because of serialization. 2024-07-13 23:12:25 -07:00
Michael Grunder
b1771defdc More unit test utility functions/usage. (#2509)
* More unit  test utility functions/usage.

* Add `assertKeyEquals` and `assertKeyEqualsWeak` as we test key values
  hundreds of places in `RedisTest.php`

* We are almost always using `$this->redis` when we want to run an
  assertion that needs access to the client, so make this argument
  optional and default to `$this->redis`.

* Update a few more assertions to use our new methods.

* Various minor fixes/tweaks.

* Update RedisTest.php

typo
2024-06-18 14:53:22 -07:00
michael-grunder
b808cc60ed Update tests so they can run in php-cgi.
This probably isn't a very common scenerio since we've never had someone
ask it in a decade, but it was very simple to get them working.

Primarily we just needed to test for `STDTOUT`/`STDERR` and use
`__DIR__` instead of `$_SERVER['PHP_SELF']`.

Fixes #2507
2024-06-17 11:46:44 -07:00
michael-grunder
dab6a62d34 Code formatting 2024-05-31 12:15:54 -07:00
michael-grunder
c6cd665bde Code formatting 2024-05-30 12:10:46 -07:00
michael-grunder
78b70ca8f4 More test refactoring.
* Switch remaining old-style PHP 5.4 `Array(...)` declarations to `[...]`
* Update variable names getting rid hungarian notation prefixes (e.g.
  `str_`, `i_`, etc).
* Allow cluster seeds to be passed on the command-line instead of soley
  relying on either a node environment variable or our
  tests/nodes/nodemap file.  This should make it easier to run ad-hoc
  cluster tests by specifying just a single seed.
* Add some diagnostics for when we can't find a suitable cluster to run
  our tests against indicating exactly where we looked for the env var
  and node file.
* Refactor RedisArray tests to use our newer TestSuite assertions.
* Allow `RedisArray` ports to be specified on the command-line as well.
* Various formatting fixes.
* More robust KeyDB detection.
2024-05-29 23:02:29 -07:00
michael-grunder
0d89e92889 Spelling fixes 2024-05-28 21:05:08 -07:00
michael-grunder
3c125b09f4 More unit test cleanup.
* Tighten up `assertTrue` and `assertFalse` such that they test that
  passed arguments `===` `true` and `===` `false` respectively, instead
  of testing for truth-like or false-like.

* Start modernizing our unit tests to use explicit types for arguments,
  return types, member variables, etc.

* Multiple assertion fixes that were exposed when making `assertTrue`
  and `assertFalse` more explicit.

* Some formatting cleanup to style for incorrect indentation, etc, that
  had crept in over many years.

* Add some more assertion helpers like `assertNull`, `assertGT`,
  `assertGTE`, `assertLT`, and `assertLTE`.
2024-05-28 20:13:12 -07:00
michael-grunder
18b0da727b Update unit test assertions.
Our tests have a ton of instances where we do something like:

```php
$this->assert(TRUE === $this->redis->command1());
$this->assert($this->redis->command2() === 42);
```

Which should be written like this:

```php
$this->assertTrue($this->command1());
$this->assertEquals(42, $this->command2());
```

Additionally it changes some assertions to use more relevant assertions
like `assertInArray` rather than `assertTrue(in_array())`.

* Add `assertEqualsCanonicalizing` assertion similar to what PHPUnit
  has.

* Add `assertStringContains` helper assertion.
2024-05-27 20:49:46 -07:00
Michael Grunder
b88e72b1e6 Refactor session tests (#2492)
* Refactor session tests

* Update these external scripts to take formal arguments with `getopt` to
  make it more straightforward what each of the currently positional
  arguments are actually for.

* Create small helper classes for invoking these external scripts.
  Instead of `startSessionProcess` that takes a dozen argument all but
  three of which have defaults, we can use a construct like this:

  ```php
  $runner = $this->sessionRunner()
      ->maxExecutionTime(300)
      ->lockingEnabled(true)
      ->lockWaitTime(-1)
      ->lockExpires(0)
      ->data($data)
      ->compression($name);

  // Invokes startSession.php with above args.
  $result = $runner->execFg();

  // Invokes regenerateSessionId.php with above args
  $new_id = $runner->regenerateId();

  // Invokes getSessionData.php for this session ID.
  $data = $runner->getData();
  ```

* Add a bit of logic to TestSuite to dump more information about the
  source of an assertion to make it easier to track down problems when
  we assert outside of a top level public `test_*` method.

* Create a few new assertions like `assertKeyExists` and
  `assertKeyMissing` which will generate much nicer assertions as
  opposed to

```php
$this->assertTrue($this->redis->exists($some_key));
```

* If our externally spawned session scripts fail output the exact call
  that was made along with all arguments as well as the output that we
  received to make it easier to narrow down.

* snake_case -> camelCase
2024-05-23 09:43:36 -07:00
michael-grunder
c0d6f04298 Minor improvements to some session tests. 2024-05-09 20:45:07 -07:00
michael-grunder
d9c48b788d KeyDB: Get our tests passing against KeyDB.
This commit fixes our unit tests so they also pass against the KeyDB
server.  We didn't ned to change all that much.  Most of it was just
adding a version/keydb check.

The only change to PhpRedis itself was to relax the reply requirements
for XAUTOCLAIM.  Redis 7.0.0 added a third "these elements were recently
removed" reply which KeyDB does not have.

Fixes #2466
2024-03-22 07:47:43 -07:00
michael-grunder
3dbc2bd814 Don't use deprecated string interpolation syntax. 2024-03-18 15:14:18 -07:00
michael-grunder
9b90c03bd0 Update WAITAOF test to use different assertion + add debug info
* Add what value failed to pass our callback assertion so we can see
  what we actually got from the server.

* WAITAOF requires Redis >= 7.2.0 so don't run it if the server is older
  than that.
2024-02-20 12:00:54 -08:00
michael-grunder
5f6ce414c3 Update tests to allow users to use a custom class.
Add a mechanism that allows users to specify an arbitrary class name, in
combination with a search path so that PhpRedis unit tests can be run
against a different client.

Additionally, this commit allows multiple classes to be invoked in one
test execution either by passing multiple `--class` arguments, or a
class argument with a comma separated value.
2023-09-19 11:57:49 -07:00
Remi Collet
fea19b5229 fix testObject for redis 7.2 2023-03-23 14:43:31 -07:00
Pavlo Yatsukhnenko
f08e4f02db Fix 'PHP Deprecated: strtolower(): Passing null' warning 2021-12-07 09:31:19 +02:00
Pavlo Yatsukhnenko
042fa19e85 Fix 'PHP Deprecated: Creation of dynamic property' warning 2021-12-01 20:27:21 +02:00
michael-grunder
4cb4cd0ee2 Separate compression and create utility methods
This commit splits compression and serialization into two distinct parts
and adds some utility functions so the user can compress/uncompress
or pack/unpack data explicily.

See #1939
2021-06-22 10:16:23 -07:00
Michael Grunder
a311cc4ec3 Support for Redis 6 ACLs (#1791)
Add support for Redis 6 ACLs in the `Redis`, `RedisCluster`, and `RedisArray` classes.

On a related note, it adds a mechanism for users to customize how we generate persistent connection IDs such that they can be grouped in different ways depending on the specific use case required (e.g. it would allow connections to be grouped by username, or by user-defined persistent_id, or both).
2020-06-24 17:00:01 -07:00
Michael Grunder
201a975999 Make unit test authentication configurable (#1748)
Right now cloning the repo and running unit tests will all fail if the
Redis/RedisCluster instances aren't configured with the password
'phpredis'.

This commit simply makes authentication during the tests optional via a
command-line argument.
2020-04-30 21:22:40 -07:00
Pavlo Yatsukhnenko
e37f38a39e requirepass 2020-03-30 13:32:27 +03:00
michael-grunder
c3d83d4460 Create a specific exception for 'test skipped'
I our test suite we were only checking if an exception was an instance
of `RedisException` and marking the test 'SKIPPED' if not.  This was
masking a failure in the RedisCluster test for testMultiExec by showing
it as skipped when it was actually throwing an exception (not being able
to execute the MULTI across the cluster).
2020-01-21 10:07:00 -08:00
michael-grunder
9440f05e19 Switch everything to new array syntax 2019-02-09 14:12:52 -08:00
Michael Grunder
2c9e057236 Streams (#1413)
Streams API
2018-09-29 11:59:01 -07:00
Marius Meissner
d0cada2268 PHPREDIS-1354: Refactored tests to work also with Redis cluster 2018-06-06 09:55:50 +02:00
michael-grunder
d2e203a630 Adds optional COUNT argument to sPop
Fixes #1145
2017-04-16 21:21:31 -07:00
michael-grunder
3012052849 More IPv6 additions
* Modified RedisArray to support IPv6
* Updated general test suite to take an override host
* Updated make-cluster.sh to take an override host
2016-02-12 18:10:50 -08:00
michael-grunder
ab8fa7dad7 Use a static variable for our nodemap file and only open it once
to avoid blowing file descriptors.
2015-05-07 15:52:55 -07:00
michael-grunder
08ecec92a3 Unit test suite improvements and cluster failover test
* Added a test specifically for RedisCluster to test slave failover
  settings.
* Added an option to specifically disable colorization, as well as
  a mechanism to determine if the output is being piped, such that
  we can turn colorization off in that case as well.
2015-05-05 15:18:02 -07:00
michael-grunder
97c9edc3aa Sorted a memory leak in RedisArray and retabbed unit tests 2015-05-05 15:18:01 -07:00
michael-grunder
7ef7d07854 A few minor cluster and unit test fixes
* Fixed getLastError() to look at redisCluster->err, rather than flags
* Fixed serialization bug for zipstr multibulk processing
* Added specific RedisClusterTest tests for SCRIPT and EVALSHA commands

All unit tests passing now!  \o/
2015-05-05 15:16:50 -07:00
michael-grunder
469e8e9377 Various cluster fixes and Unit test updates
* Updated the unit test suite to print each unit test method name we're
  running as we do so, and also with fancy colors :-)
* Added functionality to handle failed transactions, where Redis will send
  us a multi bulk length of -1.  This can happen because of an EXECABORT
  error, or because a watched key was modified during the transaction
* Initialize serialized return value to NULL to avoid segfault
* use strtol not atoi in our long response handler, to handle large values
* Fixed our return value in multi responses
* Fiexed type() command as cluster doesn't still have the '+' prefix when
  checking for what TYPE returns
* Exists should return a BOOLEAN not 1/0
* Fixed sRandMember to work in the context of a MULTI block
* Use "LINDEX" not "LGET" as "LGET" isn't a valid Redis command
* Properly set our slot for the PFCOUNT command
* Many unit test changes such that Redis and RedisCluster are happy using
  mostly the same ones.
2015-05-05 15:16:49 -07:00
michael-grunder
cceb49c5a9 Kill more tabs with fire 2015-05-05 15:16:49 -07:00
michael-grunder
892a322f53 Free the correct values in hset 2015-05-05 15:11:46 -07:00
michael-grunder
0a36429ee7 Add simple options to limit which tests are run 2015-05-05 15:11:46 -07:00
michael-grunder
79cb6a8905 Initial commit reworking unit tests
This commit reworks the unit tests such that all three classes
(Redis, RedisArray, and RedisCluster) can be tested using the
TestRedis.php script.

Now, when running TestRedis.php an option can be passed for which
part of phpredis we would like to test (defaults to Redis).
2015-05-05 15:07:43 -07:00