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

PHPUnit dependency removal #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"php": ">=5.4",
"behat/behat": "~3.0",
"guzzlehttp/guzzle": "4 - 5",
"phpunit/phpunit": "4 - 5"
"beberlei/assert": "^2.4"
},

"require-dev": {
Expand Down
6 changes: 3 additions & 3 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function itShouldPassWith($success, PyStringNode $text)
*/
public function theOutputShouldContain(PyStringNode $text)
{
PHPUnit_Framework_Assert::assertContains($this->getExpectedOutput($text), $this->getOutput());
\Assert\Assertion::contains($this->getOutput(), $this->getExpectedOutput($text));
}

private function getExpectedOutput(PyStringNode $expectedText)
Expand Down Expand Up @@ -162,13 +162,13 @@ public function itShouldFail($success)
echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput();
}

PHPUnit_Framework_Assert::assertNotEquals(0, $this->getExitCode());
\Assert\Assertion::notSame($this->getExitCode(), 0);
} else {
if (0 !== $this->getExitCode()) {
echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput();
}

PHPUnit_Framework_Assert::assertEquals(0, $this->getExitCode());
\Assert\Assertion::same($this->getExitCode(), 0);
}
}

Expand Down
3 changes: 2 additions & 1 deletion features/context.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Feature: client aware context
"""
<?php

use Assert\Assertion;
use Behat\WebApiExtension\Context\ApiClientAwareContext;
use GuzzleHttp\ClientInterface;

Expand All @@ -24,7 +25,7 @@ Feature: client aware context
* @Then /^the client should be set$/
*/
public function theClientShouldBeSet() {
PHPUnit_Framework_Assert::assertInstanceOf('GuzzleHttp\Client', $this->client);
Assertion::isInstanceOf($this->client, 'GuzzleHttp\ClientInterface');
}
}
"""
Expand Down
23 changes: 16 additions & 7 deletions src/Context/WebApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

namespace Behat\WebApiExtension\Context;

use Assert\Assertion;
use Assert\InvalidArgumentException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use PHPUnit_Framework_Assert as Assertions;

/**
* Provides web API description definitions.
Expand Down Expand Up @@ -196,7 +197,7 @@ public function theResponseCodeShouldBe($code)
{
$expected = intval($code);
$actual = intval($this->response->getStatusCode());
Assertions::assertSame($expected, $actual);
Assertion::same($actual, $expected);
}

/**
Expand All @@ -210,7 +211,7 @@ public function theResponseShouldContain($text)
{
$expectedRegexp = '/' . preg_quote($text) . '/i';
$actual = (string) $this->response->getBody();
Assertions::assertRegExp($expectedRegexp, $actual);
Assertion::regex($actual, $expectedRegexp);
}

/**
Expand All @@ -224,7 +225,15 @@ public function theResponseShouldNotContain($text)
{
$expectedRegexp = '/' . preg_quote($text) . '/';
$actual = (string) $this->response->getBody();
Assertions::assertNotRegExp($expectedRegexp, $actual);

try {
Assertion::regex($actual, $expectedRegexp);
} catch (InvalidArgumentException $e) {
return;
}

$message = sprintf('Value "%s" matches expression.', $actual);
throw new InvalidArgumentException($message, Assertion::INVALID_REGEX, null, $actual, ['pattern' => $expectedRegexp]);
}

/**
Expand All @@ -249,10 +258,10 @@ public function theResponseShouldContainJson(PyStringNode $jsonString)
);
}

Assertions::assertGreaterThanOrEqual(count($etalon), count($actual));
Assertion::greaterOrEqualThan(count($actual), count($etalon));
foreach ($etalon as $key => $needle) {
Assertions::assertArrayHasKey($key, $actual);
Assertions::assertEquals($etalon[$key], $actual[$key]);
Assertion::keyExists($actual, $key);
Assertion::eq($actual[$key], $etalon[$key]);
}
}

Expand Down