Skip to content

Commit

Permalink
PHPLIB-1450: Consolidate and improve skipping of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Oct 2, 2024
1 parent fb7b3ec commit b0269f6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 156 deletions.
35 changes: 31 additions & 4 deletions tests/UnifiedSpecTests/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ final class Operation

private ?string $saveResultAsEntity = null;

private static array $unsupportedOperations = [
self::OBJECT_TEST_RUNNER => [
'assertNumberConnectionsCheckedOut' => 'PHP does not implement CMAP',
'createEntities' => 'createEntities is not implemented (PHPC-1760)',
],
Client::class => [
'clientBulkWrite' => 'clientBulkWrite is not implemented (PHPLIB-847)',
'listDatabaseObjects' => 'listDatabaseObjects is not implemented',
],
Cursor::class => ['iterateOnce' => 'iterateOnce is not implemented (PHPC-1760)'],
Database::class => [
'createCommandCursor' => 'commandCursor API is not yet implemented (PHPLIB-1077)',
'listCollectionObjects' => 'listCollectionObjects is not implemented',
'runCursorCommand' => 'commandCursor API is not yet implemented (PHPLIB-1077)',
],
Collection::class => ['listIndexNames' => 'listIndexNames is not implemented'],
];

public function __construct(stdClass $o, private Context $context)
{
$this->entityMap = $context->getEntityMap();
Expand Down Expand Up @@ -166,6 +184,7 @@ private function execute()
$object = $this->entityMap[$this->object];
assertIsObject($object);

$this->skipIfOperationIsNotSupported($object::class);
$this->context->setActiveClient($this->entityMap->getRootClientIdOf($this->object));

switch ($object::class) {
Expand Down Expand Up @@ -235,10 +254,6 @@ private function executeForChangeStream(ChangeStream $changeStream)

private function executeForClient(Client $client)
{
if ($this->name === 'clientBulkWrite') {
Assert::markTestSkipped('clientBulkWrite operation is not implemented');
}

$args = $this->prepareArguments();
Util::assertArgumentsBySchema(Client::class, $this->name, $args);

Expand Down Expand Up @@ -811,6 +826,8 @@ private function executeForBucket(Bucket $bucket)

private function executeForTestRunner()
{
$this->skipIfOperationIsNotSupported(self::OBJECT_TEST_RUNNER);

$args = $this->prepareArguments();
Util::assertArgumentsBySchema(self::OBJECT_TEST_RUNNER, $this->name, $args);

Expand Down Expand Up @@ -963,6 +980,16 @@ private function prepareArguments(): array
return Util::prepareCommonOptions($args);
}

private function skipIfOperationIsNotSupported(string $executingObjectName): void
{
$skipReason = self::$unsupportedOperations[$executingObjectName][$this->name] ?? null;
if (! $skipReason) {
return;
}

Assert::markTestSkipped($skipReason);
}

private static function prepareBulkWriteRequest(stdClass $request): array
{
$request = (array) $request;
Expand Down
Loading

0 comments on commit b0269f6

Please sign in to comment.