Skip to content

Commit

Permalink
changed PHPUnit functions to static method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyWendt committed Jul 30, 2015
1 parent 4306d3e commit f24945f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"larapackage/randomid": "~0.0.1",
"larapackage/api": "~0.0.1",
"guzzlehttp/guzzle": "~6.0",
"laravel/framework": "5.1.*",
"phpunit/phpunit": "~4.0"
"laravel/framework": "~5.1",
"phpunit/phpunit": "~4.0",
"psr/http-message": "0.9.*"
}
}
63 changes: 34 additions & 29 deletions src/ApiFeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\MinkExtension\Context\MinkContext;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use OutOfBoundsException;
use OutOfRangeException;
use PHPUnit_Framework_Assert as PhpUnit;

/**
* Defines application features from the specific context.
Expand Down Expand Up @@ -45,7 +48,7 @@ class ApiFeatureContext extends MinkContext implements Context, SnippetAccepting
/**
* The Guzzle HTTP Response.
*
* @var Psr\Http\Message\ResponseInterface
* @var \Psr\Http\Message\ResponseInterface
*/
protected $response;

Expand Down Expand Up @@ -128,7 +131,8 @@ public function iGetAResponse($statusCode)
} else {
$bodyOutput = 'Output is '.$contentType.', which is not JSON and is therefore scary. Run the request manually.';
}
assertSame((int)$statusCode, (int)$this->getResponse()->getStatusCode(), $bodyOutput);

PhpUnit::assertSame((int)$statusCode, (int)$this->getResponse()->getStatusCode(), $bodyOutput);
}

/**
Expand Down Expand Up @@ -227,7 +231,7 @@ public function iShouldNotSeeTheIdsFromTheOriginalRequest()
$lastIds = (array)array_pop($ids);

foreach ($lastIds as $id) {
assertTrue(!in_array($id, $responseIds));
PhpUnit::assertTrue(!in_array($id, $responseIds));
}
}

Expand All @@ -243,7 +247,7 @@ public function iShouldSeeOnlyTheIdsFromTheOriginalPayload()
$responseIds = $this->getIdsFromNestedArray($responsePayload);
sort($requestIds);
sort($responseIds);
assertSame($requestIds, $responseIds);
PhpUnit::assertSame($requestIds, $responseIds);
}

/**
Expand All @@ -258,7 +262,7 @@ public function iShouldSeeTheIdsFromTheOriginalPayload()
$responseIds = $this->getIdsFromNestedArray($responsePayload);

foreach ($requestIds as $id) {
assertTrue(in_array($id, $responseIds));
PhpUnit::assertTrue(in_array($id, $responseIds));
}
}

Expand Down Expand Up @@ -311,7 +315,7 @@ public function iWillRequest($httpMethod, $resource)
*/
public function itIsEmpty()
{
assertEmpty($this->getScopePayload());
PhpUnit::assertEmpty($this->getScopePayload());
}

/**
Expand Down Expand Up @@ -366,7 +370,7 @@ public function thePropertyContainsItems($property, $count)
{
$payload = $this->getScopePayload();

assertCount(
PhpUnit::assertCount(
$count,
$this->arrayGet($payload, $property),
"Asserting the [$property] property contains [$count] items: ".json_encode($payload)
Expand All @@ -381,7 +385,7 @@ public function thePropertyEquals($property, $expectedValue)
$payload = $this->getScopePayload();
$actualValue = $this->arrayGet($payload, $property);

assertEquals(
PhpUnit::assertEquals(
$actualValue,
$expectedValue,
"Asserting the [$property] property in current scope equals [$expectedValue]: ".json_encode($payload)
Expand All @@ -403,10 +407,10 @@ public function thePropertyExists($property)
);

if (is_object($payload)) {
assertTrue(array_key_exists($property, get_object_vars($payload)), $message);
PhpUnit::assertTrue(array_key_exists($property, get_object_vars($payload)), $message);

} else {
assertTrue(array_key_exists($property, $payload), $message);
PhpUnit::assertTrue(array_key_exists($property, $payload), $message);
}
}

Expand All @@ -417,7 +421,7 @@ public function thePropertyIsABoolean($property)
{
$payload = $this->getScopePayload();

assertTrue(
PhpUnit::assertTrue(
gettype($this->arrayGet($payload, $property)) == 'boolean',
"Asserting the [$property] property in current scope [{$this->scope}] is a boolean."
);
Expand All @@ -437,7 +441,7 @@ public function thePropertyIsABooleanEqualling($property, $expectedValue)

$this->thePropertyIsABoolean($property);

assertSame(
PhpUnit::assertSame(
$actualValue,
$expectedValue == 'true',
"Asserting the [$property] property in current scope [{$this->scope}] is a boolean equalling [$expectedValue]."
Expand All @@ -451,7 +455,7 @@ public function thePropertyIsAFloat($property)
{
$payload = $this->getScopePayload();

assertTrue(
PhpUnit::assertTrue(
is_float($this->arrayGet($payload, $property)),
"Asserting the [$property] property in current scope [{$this->scope}] is a float: ".json_encode($payload)
);
Expand All @@ -463,7 +467,7 @@ public function thePropertyIsAFloat($property)
public function thePropertyIsAString($property)
{
$payload = $this->getScopePayload();
assertTrue(
PhpUnit::assertTrue(
is_string($this->arrayGet($payload, $property)),
"Asserting the [$property] property in current scope [{$this->scope}] is a string: ".json_encode($payload)
);
Expand All @@ -480,7 +484,7 @@ public function thePropertyIsAStringEqualling($property, $expectedValue)

$actualValue = $this->arrayGet($payload, $property);

assertSame(
PhpUnit::assertSame(
$actualValue,
$expectedValue,
"Asserting the [$property] property in current scope [{$this->scope}] is a string equalling [$expectedValue]."
Expand Down Expand Up @@ -511,7 +515,7 @@ public function thePropertyIsAnArray($property)

$actualValue = $this->arrayGet($payload, $property);

assertTrue(
PhpUnit::assertTrue(
is_array($actualValue),
"Asserting the [$property] property in current scope [{$this->scope}] is an array: ".json_encode($payload)
);
Expand All @@ -525,7 +529,7 @@ public function thePropertyIsAnEmptyArray($property)
$payload = $this->getScopePayload();
$scopePayload = $this->arrayGet($payload, $property);

assertTrue(
PhpUnit::assertTrue(
is_array($scopePayload) and $scopePayload === [],
"Asserting the [$property] property in current scope [{$this->scope}] is an empty array: ".json_encode($payload)
);
Expand All @@ -538,7 +542,7 @@ public function thePropertyIsAnInteger($property)
{
$payload = $this->getScopePayload();

assertTrue(
PhpUnit::assertTrue(
is_int($this->arrayGet($payload, $property)),
"Asserting the [$property] property in current scope [{$this->scope}] is an integer: ".json_encode($payload)
);
Expand All @@ -554,7 +558,7 @@ public function thePropertyIsAnIntegerEqualling($property, $expectedValue)

$this->thePropertyIsAnInteger($property);

assertSame(
PhpUnit::assertSame(
$actualValue,
(int)$expectedValue,
"Asserting the [$property] property in current scope [{$this->scope}] is an integer equalling [$expectedValue]."
Expand Down Expand Up @@ -586,7 +590,7 @@ public function thePropertyIsAnObject($property)

$actualValue = $this->arrayGet($payload, $property);

assertTrue(
PhpUnit::assertTrue(
is_object($actualValue),
"Asserting the [$property] property in current scope [{$this->scope}] is an object: ".json_encode($payload)
);
Expand All @@ -602,7 +606,7 @@ public function thePropertyIsEither($property, PyStringNode $options)

$valid = explode("\n", (string)$options);

assertTrue(
PhpUnit::assertTrue(
in_array($actualValue, $valid),
sprintf(
"Asserting the [%s] property in current scope [{$this->scope}] is in array of valid options [%s].",
Expand All @@ -619,7 +623,7 @@ public function thePropertyIsNull($property)
{
$payload = $this->getScopePayload();

assertTrue(
PhpUnit::assertTrue(
is_null($this->arrayGet($payload, $property)),
"Asserting the [$property] property in current scope [{$this->scope}] is an null: ".json_encode($payload)
);
Expand All @@ -630,8 +634,8 @@ public function thePropertyIsNull($property)
*/
public function theResponseIsJson()
{
assertSame(strtolower($this->response->getHeader('Content-Type')[0]), 'application/vnd.wps_api.v4+json');
isJson($this->response->getBody());
PhpUnit::assertSame(strtolower($this->response->getHeader('Content-Type')[0]), 'application/vnd.wps_api.v4+json');
PhpUnit::isJson($this->response->getBody());
}

/**
Expand Down Expand Up @@ -692,7 +696,7 @@ protected function assertNullOrType(\Closure $typeTest, $property, \Closure $mes
$propertyValue = $this->arrayGet($payload, $property);
$result = $typeTest($propertyValue);

assertTrue($result, $message($property, $payload));
PhpUnit::assertTrue($result, $message($property, $payload));
}

/**
Expand All @@ -702,8 +706,8 @@ protected function assertNullOrType(\Closure $typeTest, $property, \Closure $mes
protected function compareArrays(array $needle, array $haystack)
{
foreach ($needle as $key => $value) {
assertArrayHasKey($key, $haystack);
assertTrue(in_array($value, $haystack));
PhpUnit::assertArrayHasKey($key, $haystack);
PhpUnit::assertTrue(in_array($value, $haystack));
}
}

Expand Down Expand Up @@ -766,12 +770,13 @@ protected function getIdsFromNestedArray(array $requestPayload)
/**
* Checks the response exists and returns it.
*
* @return Psr\Http\Message\ResponseInterface
* @return \Psr\Http\Message\ResponseInterface
* @throws \Exception
*/
protected function getResponse()
{
if (!$this->response) {
throw new Exception("You must first make a request to check a response.");
throw new \Exception("You must first make a request to check a response.");
}

return $this->response;
Expand Down

0 comments on commit f24945f

Please sign in to comment.