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

Follow PSR-2 codingsstandards #12 #17

Merged
merged 3 commits into from
Oct 9, 2017
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
9 changes: 3 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ build: off

test_script:
- cmd: C:\tools\php71\php.exe .\vendor\phpunit\phpunit\phpunit -c .\phpunit-all-tests.xml
- appveyor DownloadFile http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar
- cmd: C:\tools\php71\php.exe php-cs-fixer-v2.phar fix -v --dry-run --stop-on-violation --using-cache=no .

on_success:
- echo Success
Expand All @@ -41,12 +43,7 @@ on_failure:
- echo Failure

notifications:
- provider: Webhook
url:
secure: c4xwvfA2YpTyASkpasFt2vA6q4pCxCMoWhfX9/JwBxp6rub4dphj6smGxy+5rnsHcvVU6/FvzVHQo4hoxL5gOA==
on_build_success: false
on_build_failure: true
on_build_status_changed: true

# Email
# - provider: Email
# to:
Expand Down
48 changes: 24 additions & 24 deletions example/site/provider.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<?php
/*
Mock Provider as an example
Mock Provider as an example

*/

if (isset($_GET["amount"])) {
$objects = generate(intval($_GET["amount"]));
} else if (isset($_GET["file"])) {
$fileName = filter_var($_GET["file"], FILTER_SANITIZE_STRING);
$objects = generate(intval($_GET["amount"]));
} elseif (isset($_GET["file"])) {
$fileName = filter_var($_GET["file"], FILTER_SANITIZE_STRING);
$currentDir = dirname(__FILE__);
$relativeDir = $currentDir . DIRECTORY_SEPARATOR . $fileName;
error_log("File get: " . $relativeDir);

$objects = \json_decode(file_get_contents($relativeDir));
} else if (!empty($_POST)) {
} elseif (!empty($_POST)) {
error_log('received post');

$body = '{ "type": "some new type" }';
$body = \json_encode(\json_decode($body));
$objects = \json_decode($body);
}
else {
$objects = generate();
} else {
$objects = generate();
}

header('Content-Type: application/json');
echo json_encode($objects);

function generate($objCount = 3) {
$objects = array();

for($i=0;$i<$objCount;$i++) {
$obj = new \stdClass();
$obj->id = 100 + $i;
$obj->name = sprintf("Type %d", $obj->id);

$objects[] = $obj;
}

$ret = new \stdClass();
$ret->types = $objects;
return $ret;
}
function generate($objCount = 3)
{
$objects = array();

for ($i=0;$i<$objCount;$i++) {
$obj = new \stdClass();
$obj->id = 100 + $i;
$obj->name = sprintf("Type %d", $obj->id);

$objects[] = $obj;
}

$ret = new \stdClass();
$ret->types = $objects;
return $ret;
}
4 changes: 1 addition & 3 deletions example/test/ConsumerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once( __DIR__ . '/MockApiConsumer.php');
require_once(__DIR__ . '/MockApiConsumer.php');

use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -70,7 +70,6 @@ public function testGetBasic()
$hasException = false;
try {
$results = $mockService->VerifyInteractions();

} catch (\PhpPact\PactFailureException $e) {
$hasException = true;
}
Expand Down Expand Up @@ -216,7 +215,6 @@ public function testGetWithMultipleRequests()

$receivedBodyResponse = $clientUnderTest->GetWithBody("http://localhost");
$receivedPathResponse = $clientUnderTest->GetWithPath("http://localhost");

} catch (\PhpPact\PactFailureException $e) {
$hasException = true;
}
Expand Down
2 changes: 1 addition & 1 deletion example/test/MockApiConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ private function sendRequest(\Psr\Http\Message\RequestInterface $httpRequest)
// make actual call to the client
throw new \Exception("Since this is a mock api client, there is no 'real' server. This is where you put your app logic.");
}
}
}
46 changes: 21 additions & 25 deletions example/test/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

final class ProviderTest extends TestCase
{

public function testServerExists() {

$http = new \Windwalker\Http\HttpClient();
public function testServerExists()
{
$http = new \Windwalker\Http\HttpClient();
$uri = 'http://' . WEB_SERVER_HOST . ':' . WEB_SERVER_PORT . '/provider.php';

$response = $http->get($uri);
Expand All @@ -18,19 +17,18 @@ public function testServerExists() {
$this->assertEquals(200, (int) $status, "Expect a 200 status code");
}

public function testPactProvider() {

public function testPactProvider()
{
$uri = WEB_SERVER_HOST . ':' . WEB_SERVER_PORT;

$httpClient = new \Windwalker\Http\HttpClient();

$pactVerifier = new \PhpPact\PactVerifier($uri);
$hasException = false;
try {
$json = $this->getPactRoot() . DIRECTORY_SEPARATOR . 'mockapiconsumer-mockapiprovider.json';

$json = $this->getPactRoot() . DIRECTORY_SEPARATOR . 'mockapiconsumer-mockapiprovider.json';

$pactVerifier->ProviderState("Test State")
$pactVerifier->ProviderState("Test State")
->ServiceProvider("MockApiProvider", $httpClient)
->HonoursPactWith("MockApiConsumer")
->PactUri($json)
Expand All @@ -39,26 +37,25 @@ public function testPactProvider() {
$pactVerifier->Verify(null, "A GET request to get variable types");

$pactVerifier->Verify(null, "There is something to POST to");

}catch(\PhpPact\PactFailureException $e) {
} catch (\PhpPact\PactFailureException $e) {
$hasException = true;
}
$this->assertFalse($hasException, "Expect Pact to validate.");
}

public function testPactProviderStateSetupTearDown() {

public function testPactProviderStateSetupTearDown()
{
$uri = WEB_SERVER_HOST . ':' . WEB_SERVER_PORT;

$httpClient = new \Windwalker\Http\HttpClient();

$pactVerifier = new \PhpPact\PactVerifier($uri);
$hasException = false;

$setUpFunction = function() {
$setUpFunction = function () {
$fileName = "mock.json";
$currentDir = dirname(__FILE__);
$absolutePath = realpath($currentDir . '/../site/' );
$absolutePath = realpath($currentDir . '/../site/');
$absolutePath .= '/' . $fileName;

$type = new \stdClass();
Expand All @@ -74,10 +71,10 @@ public function testPactProviderStateSetupTearDown() {
file_put_contents($absolutePath, $output);
};

$tearDownFunction = function() {
$tearDownFunction = function () {
$fileName = "mock.json";
$currentDir = dirname(__FILE__);
$absolutePath = realpath($currentDir . '/../site/' );
$absolutePath = realpath($currentDir . '/../site/');
$absolutePath .= '/' . $fileName;

unlink($absolutePath);
Expand All @@ -91,16 +88,15 @@ public function testPactProviderStateSetupTearDown() {
->HonoursPactWith("MockApiConsumer")
->PactUri($json)
->Verify(); // note that this should test all as we can run setup and tear down

}catch(\PhpPact\PactFailureException $e) {
} catch (\PhpPact\PactFailureException $e) {
$hasException = true;
}
$this->assertFalse($hasException, "Expect Pact to validate.");
}

private function getPactRoot()
{
$dir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'pact' . DIRECTORY_SEPARATOR;
return realpath($dir);
}
}
private function getPactRoot()
{
$dir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'pact' . DIRECTORY_SEPARATOR;
return realpath($dir);
}
}
2 changes: 1 addition & 1 deletion example/test/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ function pact_php_example_autoloader($className)
}
}

spl_autoload_register('pact_php_example_autoloader');
spl_autoload_register('pact_php_example_autoloader');
81 changes: 41 additions & 40 deletions example/test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
$command = CraftCommand(WEB_SERVER_HOST, WEB_SERVER_PORT, WEB_SERVER_DOCROOT);

$phandle = popen($command, "r");
$read = stream_get_contents($phandle); //Read the output
$read = stream_get_contents($phandle); //Read the output
pclose($phandle);
$i = 0;
$pid = ExtractProcessIdFromWMIC($read);

echo sprintf(
'%s - Web server started on %s:%d with PID %d',
'%s - Web server started on %s:%d with PID %d',
date('r'),
WEB_SERVER_HOST,
WEB_SERVER_PORT,
WEB_SERVER_HOST,
WEB_SERVER_PORT,
$pid
) . PHP_EOL;

// Kill the web server when the process ends
register_shutdown_function(function() use ($pid) {
sleep(1); // sleep for a few seconds before shutting down
echo sprintf('%s - Killing process with ID %d', date('r'), $pid) . PHP_EOL;
shell_exec("taskkill /F /PID $pid");
register_shutdown_function(function () use ($pid) {
sleep(1); // sleep for a few seconds before shutting down
echo sprintf('%s - Killing process with ID %d', date('r'), $pid) . PHP_EOL;
shell_exec("taskkill /F /PID $pid");
});

/***********************************************
Expand All @@ -39,43 +39,44 @@
*
***********************************************/

function CraftCommand($host, $port, $docroot)
function CraftCommand($host, $port, $docroot)
{
$php = PHP_BINARY;
$fullroot = getcwd() . "/" . $docroot;
$fullroot = str_replace("\\", "/", $fullroot);
//PrintDirectory($fullroot);
$command = "wmic process call create \"$php -S $host:$port -t $fullroot \"";
$php = PHP_BINARY;
$fullroot = getcwd() . "/" . $docroot;
$fullroot = str_replace("\\", "/", $fullroot);
//PrintDirectory($fullroot);
$command = "wmic process call create \"$php -S $host:$port -t $fullroot \"";

return $command;
return $command;
}

function ExtractProcessIdFromWMIC($read)
function ExtractProcessIdFromWMIC($read)
{
$pid = false;
$output = explode("\n",$read);
$pid = false;
$output = explode("\n", $read);

foreach($output as $line) {
if (stripos($line, "ProcessId") !== false) {
$ex = explode("=", $line, 2);
$pid = trim($ex[1]);
$pid = substr($pid, 0, strlen($pid) - 1); // remove ;
return $pid;
}
}
return $pid;
foreach ($output as $line) {
if (stripos($line, "ProcessId") !== false) {
$ex = explode("=", $line, 2);
$pid = trim($ex[1]);
$pid = substr($pid, 0, strlen($pid) - 1); // remove ;
return $pid;
}
}
return $pid;
}

function PrintDirectory($dir) {
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "$entry\n";
}
}
closedir($handle);
}
function PrintDirectory($dir)
{
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "$entry\n";
}
}
closedir($handle);
}
}
// More bootstrap code
// More bootstrap code
2 changes: 1 addition & 1 deletion src/Comparers/ComparisonFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public function getResult()
{
return $this->_result;
}
}
}
3 changes: 1 addition & 2 deletions src/Comparers/ComparisonResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ public function AddChildResult(&$comparisonResult)

$this->_childResults[] = $comparisonResult;
}

}
}
2 changes: 1 addition & 1 deletion src/Comparers/DiffComparisonFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public function __construct($expected, $actual, $message='')
$msg = ($message ? sprintf("Message: %s", $message) : '');
$this->_result = sprintf("Expected: %s, Actual: %s. %s", ($expected ? print_r($expected, true) : "null"), ($actual ? print_r($actual, true) : "null"), $msg);
}
}
}
2 changes: 1 addition & 1 deletion src/Comparers/ErrorMessageComparisonFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public function __construct($errorMessage)
{
$this->_result = $errorMessage;
}
}
}
2 changes: 1 addition & 1 deletion src/Comparers/IComparer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
interface IComparer
{
public function Compare($expected, $actual);
}
}
Loading