Last active
July 30, 2020 00:57
-
-
Save ismail1432/6231d901ce8771c1fcb56b54b3bf06b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Tests\Behat; | |
final class GithubContext implements Context | |
{ | |
/** @var GithubUserRepository $githubRepo */ | |
private $githubRepo; | |
/** @var App\Entity\User $user */ | |
private $user; | |
/** | |
* @Given The response have the following body: | |
*/ | |
public function theResponseHaveTheFollowingBody(TableNode $tableNode) | |
{ | |
$this->githubRepo = new GithubUserRepository( | |
new MockHttpClient( | |
new MockResponse(json_encode($tableNode->getRowsHash())) | |
,'https://api.github.com') | |
); | |
} | |
/** | |
* @When I fetch a user with username :username | |
*/ | |
public function iFetchAUserWithUsername(string $username) | |
{ | |
$user = $this->githubRepo->findByUsername($username); | |
Assert::notNull($user, sprintf("Unable to fetch a User")); | |
$this->user = $user; | |
} | |
/** | |
* @Then I should have an instance of User with id :id and login :login | |
*/ | |
public function iShouldHaveAnInstanceOfUserWithIdAndLogin(string $id, string $login) | |
{ | |
Assert::isInstanceOf($this->user, User::class, sprintf("Attempted to have a %s, but got a %s", User::class, get_class($this->user))); | |
Assert::eq($this->user->id, $id, sprintf("Wrong value for 'id'")); | |
Assert::eq($this->user->login, $login, sprintf("Wrong value for 'login'")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment