Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Move protobuf code to core #442

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions src/PhpPact/Plugins/Protobuf/Driver/Pact/ProtobufPactDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace PhpPact\Plugins\Protobuf\Driver\Pact;

use PhpPact\Plugin\Driver\Pact\AbstractPluginPactDriver;

class ProtobufPactDriver extends AbstractPluginPactDriver
{
protected function getPluginName(): string
{
return 'protobuf';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace PhpPact\Plugins\Protobuf\Factory;

use PhpPact\Config\PactConfigInterface;
use PhpPact\Consumer\Driver\Interaction\MessageDriver;
use PhpPact\Consumer\Driver\Interaction\MessageDriverInterface;
use PhpPact\Consumer\Factory\MessageDriverFactoryInterface;
use PhpPact\Consumer\Registry\Pact\PactRegistry;
use PhpPact\FFI\Client;
use PhpPact\Plugins\Protobuf\Driver\Pact\ProtobufPactDriver;
use PhpPact\Plugins\Protobuf\Registry\Interaction\ProtobufMessageRegistry;

class ProtobufMessageDriverFactory implements MessageDriverFactoryInterface
{
public function create(PactConfigInterface $config): MessageDriverInterface
{
$client = new Client();
$pactRegistry = new PactRegistry($client);
$pactDriver = new ProtobufPactDriver($client, $config, $pactRegistry);
$messageRegistry = new ProtobufMessageRegistry($client, $pactRegistry);

return new MessageDriver($client, $pactDriver, $messageRegistry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace PhpPact\Plugins\Protobuf\Factory;

use PhpPact\Consumer\Registry\Pact\PactRegistry;
use PhpPact\FFI\Client;
use PhpPact\Plugins\Protobuf\Driver\Pact\ProtobufPactDriver;
use PhpPact\Plugins\Protobuf\Registry\Interaction\ProtobufSyncMessageRegistry;
use PhpPact\Plugins\Protobuf\Service\GrpcMockServer;
use PhpPact\Standalone\MockService\MockServerConfigInterface;
use PhpPact\SyncMessage\Driver\Interaction\SyncMessageDriver;
use PhpPact\SyncMessage\Driver\Interaction\SyncMessageDriverInterface;
use PhpPact\SyncMessage\Factory\SyncMessageDriverFactoryInterface;

class ProtobufSyncMessageDriverFactory implements SyncMessageDriverFactoryInterface
{
public function create(MockServerConfigInterface $config): SyncMessageDriverInterface
{
$client = new Client();
$pactRegistry = new PactRegistry($client);
$pactDriver = new ProtobufPactDriver($client, $config, $pactRegistry);
$grpcMockServer = new GrpcMockServer($client, $pactRegistry, $config);
$syncMessageRegistry = new ProtobufSyncMessageRegistry($client, $pactRegistry);

return new SyncMessageDriver($pactDriver, $syncMessageRegistry, $grpcMockServer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace PhpPact\Plugins\Protobuf\Registry\Interaction\Body;

use PhpPact\Consumer\Registry\Interaction\MessageRegistryInterface;
use PhpPact\Consumer\Registry\Interaction\Part\RequestPartTrait;
use PhpPact\FFI\ClientInterface;
use PhpPact\Plugin\Registry\Interaction\Body\AbstractPluginBodyRegistry;

class ProtobufMessageContentsRegistry extends AbstractPluginBodyRegistry
{
use RequestPartTrait;

public function __construct(
protected ClientInterface $client,
private MessageRegistryInterface $messageRegistry
) {
parent::__construct($client);
}

protected function getInteractionId(): int
{
return $this->messageRegistry->getId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace PhpPact\Plugins\Protobuf\Registry\Interaction;

use PhpPact\Consumer\Registry\Interaction\Body\BodyRegistryInterface;
use PhpPact\Consumer\Registry\Interaction\MessageRegistry;
use PhpPact\Consumer\Registry\Pact\PactRegistryInterface;
use PhpPact\FFI\ClientInterface;
use PhpPact\Plugins\Protobuf\Registry\Interaction\Body\ProtobufMessageContentsRegistry;

class ProtobufMessageRegistry extends MessageRegistry
{
public function __construct(
ClientInterface $client,
PactRegistryInterface $pactRegistry,
?BodyRegistryInterface $messageContentsRegistry = null
) {
parent::__construct($client, $pactRegistry, $messageContentsRegistry ?? new ProtobufMessageContentsRegistry($client, $this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace PhpPact\Plugins\Protobuf\Registry\Interaction;

use PhpPact\Consumer\Registry\Interaction\Body\BodyRegistryInterface;
use PhpPact\Consumer\Registry\Pact\PactRegistryInterface;
use PhpPact\FFI\ClientInterface;
use PhpPact\Plugins\Protobuf\Registry\Interaction\Body\ProtobufMessageContentsRegistry;
use PhpPact\SyncMessage\Registry\Interaction\SyncMessageRegistry;

class ProtobufSyncMessageRegistry extends SyncMessageRegistry
{
public function __construct(
ClientInterface $client,
PactRegistryInterface $pactRegistry,
?BodyRegistryInterface $messageContentsRegistry = null
) {
parent::__construct($client, $pactRegistry, $messageContentsRegistry ?? new ProtobufMessageContentsRegistry($client, $this));
}
}
13 changes: 13 additions & 0 deletions src/PhpPact/Plugins/Protobuf/Service/GrpcMockServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace PhpPact\Plugins\Protobuf\Service;

use PhpPact\Consumer\Service\MockServer;

class GrpcMockServer extends MockServer
{
protected function getTransport(): string
{
return 'grpc';
}
}