Skip to content

Commit

Permalink
Print provider process's log
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Sep 22, 2023
1 parent d87ffec commit 9289a44
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 70 deletions.
16 changes: 3 additions & 13 deletions example/binary/provider/tests/PactVerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,20 @@

use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PhpPactTest\Helper\ProviderProcess;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

class PactVerifyTest extends TestCase
{
private Process $process;
private ProviderProcess $process;

/**
* Run the PHP build-in web server.
*/
protected function setUp(): void
{
$this->process = new Process(['php', '-S', '127.0.0.1:7202', '-t', __DIR__ . '/../public/']);

$this->process = new ProviderProcess(__DIR__ . '/../public/');
$this->process->start();
$this->process->waitUntil(function (): bool {
$fp = @fsockopen('127.0.0.1', 7202);
$isOpen = is_resource($fp);
if ($isOpen) {
fclose($fp);
}

return $isOpen;
});
}

/**
Expand Down
16 changes: 3 additions & 13 deletions example/json/provider/tests/PactVerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,20 @@
use GuzzleHttp\Psr7\Uri;
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PhpPactTest\Helper\ProviderProcess;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

class PactVerifyTest extends TestCase
{
private Process $process;
private ProviderProcess $process;

/**
* Run the PHP build-in web server.
*/
protected function setUp(): void
{
$this->process = new Process(['php', '-S', '127.0.0.1:7202', '-t', __DIR__ . '/../public/']);

$this->process = new ProviderProcess(__DIR__ . '/../public/');
$this->process->start();
$this->process->waitUntil(function (): bool {
$fp = @fsockopen('127.0.0.1', 7202);
$isOpen = is_resource($fp);
if ($isOpen) {
fclose($fp);
}

return $isOpen;
});
}

/**
Expand Down
18 changes: 3 additions & 15 deletions example/message/provider/tests/PactVerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,20 @@
use PhpPact\Standalone\ProviderVerifier\Model\Config\ProviderTransport;
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PhpPactTest\Helper\ProviderProcess;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

class PactVerifyTest extends TestCase
{
private Process $process;
private ProviderProcess $process;

/**
* Run the PHP build-in web server.
*/
protected function setUp(): void
{
$publicPath = __DIR__ . '/../public/';

$this->process = new Process(['php', '-S', '127.0.0.1:7202', '-t', $publicPath]);

$this->process = new ProviderProcess(__DIR__ . '/../public/');
$this->process->start();
$this->process->waitUntil(function (): bool {
$fp = @fsockopen('127.0.0.1', 7202);
$isOpen = is_resource($fp);
if ($isOpen) {
fclose($fp);
}

return $isOpen;
});
}

/**
Expand Down
16 changes: 3 additions & 13 deletions example/multipart/provider/tests/PactVerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,20 @@

use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PhpPactTest\Helper\ProviderProcess;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

class PactVerifyTest extends TestCase
{
private Process $process;
private ProviderProcess $process;

/**
* Run the PHP build-in web server.
*/
protected function setUp(): void
{
$this->process = new Process(['php', '-S', '127.0.0.1:7202', '-t', __DIR__ . '/../public/']);

$this->process = new ProviderProcess(__DIR__ . '/../public/');
$this->process->start();
$this->process->waitUntil(function (): bool {
$fp = @fsockopen('127.0.0.1', 7202);
$isOpen = is_resource($fp);
if ($isOpen) {
fclose($fp);
}

return $isOpen;
});
}

/**
Expand Down
40 changes: 40 additions & 0 deletions tests/PhpPact/Helper/ProviderProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace PhpPactTest\Helper;

use Symfony\Component\Process\Process;

class ProviderProcess
{
private Process $process;

public function __construct(string $publicPath, private int $port = 7202)
{
$this->process = new Process(['php', '-S', "127.0.0.1:$port", '-t', $publicPath]);
}

public function start(): void
{
$this->process->start(function ($type, $buffer): void {
if (Process::ERR === $type) {
echo 'ERR > '.$buffer;
} else {
echo 'OUT > '.$buffer;
}
});
$this->process->waitUntil(function (): bool {
$fp = @fsockopen('127.0.0.1', $this->port);
$isOpen = is_resource($fp);
if ($isOpen) {
fclose($fp);
}

return $isOpen;
});
}

public function stop(): void
{
$this->process->stop();
}
}
19 changes: 3 additions & 16 deletions tests/PhpPact/Standalone/ProviderVerifier/VerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,20 @@

use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PhpPactTest\Helper\ProviderProcess;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

class VerifierTest extends TestCase
{
/** @var Process */
private Process $process;
private ProviderProcess $process;

/**
* Run the PHP build-in web server.
*/
protected function setUp(): void
{
$publicPath = __DIR__ . '/../../../_public/';

$this->process = new Process(['php', '-S', '127.0.0.1:7202', '-t', $publicPath]);

$this->process = new ProviderProcess(__DIR__ . '/../../../_public/');
$this->process->start();
$this->process->waitUntil(function (): bool {
$fp = @fsockopen('127.0.0.1', 7202);
$isOpen = is_resource($fp);
if ($isOpen) {
fclose($fp);
}

return $isOpen;
});
}

/**
Expand Down

0 comments on commit 9289a44

Please sign in to comment.