Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fd936f5
tests: added tests for Search/Index module
Kallyan01 May 8, 2026
f63d296
tests: added tests for Search/Search module
Kallyan01 May 8, 2026
f7d866a
tests: improved tests for Search/Search module
Kallyan01 May 8, 2026
c089dfb
fix: resolved phpcs errors
Kallyan01 May 8, 2026
1cbec4a
tests: improved tests for Search/Watcher module
Kallyan01 May 8, 2026
3994c0f
tests: improved tests for Search/Settings module
Kallyan01 May 8, 2026
861d9c3
fix: resolved PHPCS errors
Kallyan01 May 8, 2026
37c3bee
tests: enhance error handling tests for Index and Search modules
Kallyan01 May 8, 2026
424dce4
tests: enhance WatcherTest to intercept Algolia SDK requests and vali…
Kallyan01 May 11, 2026
9a6730c
fix: resolved PHPCS errors
Kallyan01 May 11, 2026
89562cb
tests: enhance Algolia SDK request interception and add new tests for…
Kallyan01 May 12, 2026
72fdc71
tests: enhance IndexTest to validate error handling for SDK exception…
Kallyan01 May 12, 2026
faac006
chore: added minor testcase fixes
Kallyan01 May 12, 2026
d9e8ebe
Merge branch 'main' into test/search-phpunit-tests
Kallyan01 May 12, 2026
daab8dc
tests: remove unwanted comments in IndexTest, SearchTest, SettingsTes…
Kallyan01 May 18, 2026
af78be2
tests: refactor IndexTest and SearchTest for improved credential hand…
Kallyan01 May 21, 2026
88798b9
Merge branch 'main' into test/search-phpunit-tests
Kallyan01 May 21, 2026
37794dd
tests: add integration tests for Algolia reindexing on site type chan…
Kallyan01 May 21, 2026
34d94e2
fix: phpcs errors resolved
Kallyan01 May 21, 2026
c5f46ea
refactor: clean up test teardown methods by removing redundant option…
Kallyan01 May 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions tests/php/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,68 @@ protected function checkRequirements(): void { // phpcs:ignore Generic.CodeAnaly
parent::checkRequirements();
}

/**
* Intercept Algolia SDK HTTP calls and collect request paths.
*
* @param array<int, string> $recorded_paths Paths captured from outgoing SDK requests.
* @param (callable(string): string)|null $body_for_path Optional callback to provide a response body for a given request path.
* @param string|null $throw_on_path_segment Optional path segment that triggers a RuntimeException when matched.
*/
public function mock_algolia_http_client( array &$recorded_paths, ?callable $body_for_path = null, ?string $throw_on_path_segment = null ): void {
\OneSearch\Vendor\Algolia\AlgoliaSearch\Algolia::setHttpClient(
new class( $recorded_paths, $body_for_path, $throw_on_path_segment ) implements \OneSearch\Vendor\Algolia\AlgoliaSearch\Http\HttpClientInterface {
/** @var array<int, string> */
private array $paths;

/** @var (callable(string): string)|null */
private $body_for_path;

/** @var string|null */
private ?string $throw_on_path_segment;

/**
* @param array<int, string> $paths Reference to the array that records intercepted request paths.
* @param (callable(string): string)|null $body_for_path Optional callback to generate mock response bodies.
* @param string|null $throw_on_path_segment Optional path segment that triggers a RuntimeException when matched.
*/
public function __construct( array &$paths, ?callable $body_for_path, ?string $throw_on_path_segment ) {
$this->paths = &$paths;
$this->body_for_path = $body_for_path;
$this->throw_on_path_segment = $throw_on_path_segment;
}

/**
* {@inheritDoc}
*
* @param \OneSearch\Vendor\Psr\Http\Message\RequestInterface $request The PSR-7 request.
* @param mixed $timeout Request timeout.
* @param mixed $connect_timeout Connection timeout.
* @throws \RuntimeException When the configured path segment is encountered.
*/
public function sendRequest( \OneSearch\Vendor\Psr\Http\Message\RequestInterface $request, mixed $timeout, mixed $connect_timeout ): \OneSearch\Vendor\Psr\Http\Message\ResponseInterface { // phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
$path = (string) $request->getUri()->getPath();
$this->paths[] = $path;

if ( null !== $this->throw_on_path_segment && str_contains( $path, $this->throw_on_path_segment ) ) {
throw new \RuntimeException( 'forced test exception' );
}

if ( null !== $this->body_for_path ) {
$body = (string) call_user_func( $this->body_for_path, $path );
} elseif ( str_contains( $path, '/task/' ) ) {
$body = '{"status":"published","pendingTask":false}';
} elseif ( str_contains( $path, '/query' ) ) {
$body = '{"hits":[{"objectID":"1"}],"nbHits":1,"page":0,"hitsPerPage":20}';
} else {
$body = '{"taskID":1,"updatedAt":"2024-01-01T00:00:00.000Z"}';
}

// @phpstan-ignore return.type
return new \OneSearch\Vendor\Algolia\AlgoliaSearch\Http\Psr7\Response( 200, [], $body );
}
}
);
}

// Add any common setup or utility methods for tests here.
}
Loading
Loading