Refactoring

This commit is contained in:
dinamiko 2021-09-10 12:16:33 +02:00
parent 12f1a2e40b
commit 05dcf5c4f4
3 changed files with 89 additions and 35 deletions

View file

@ -110,27 +110,6 @@ class PaymentTokenEndpointTest extends TestCase
$this->sut->for_user($id);
}
public function testForUserFailBecauseEmptyTokens()
{
$id = 1;
$token = Mockery::mock(Token::class);
$rawResponse = ['body' => '{"payment_tokens":[]}'];
$this->bearer->shouldReceive('bearer')
->andReturn($token);
$token->shouldReceive('token')
->andReturn('bearer');
$this->ensureRequestForUser($rawResponse, $id);
expect('wp_remote_get')->andReturn($rawResponse);
expect('is_wp_error')->with($rawResponse)->andReturn(false);
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(200);
$this->logger->shouldReceive('log');
$this->expectException(RuntimeException::class);
$this->sut->for_user($id);
}
public function testDeleteToken()
{
$paymentToken = $paymentToken = Mockery::mock(PaymentToken::class);

View file

@ -90,4 +90,72 @@ class PaymentTokenRepositoryTest extends TestCase
$this->sut->delete_token($id, $paymentToken);
}
public function testAllForUserId()
{
$id = 1;
$tokens = [];
$this->endpoint->shouldReceive('for_user')
->with($id)
->andReturn($tokens);
expect('update_user_meta')->with($id, $this->sut::USER_META, $tokens);
$result = $this->sut->all_for_user_id($id);
$this->assertSame($tokens, $result);
}
public function test_AllForUserIdReturnsEmptyArrayIfGettingTokenFails()
{
$id = 1;
$tokens = [];
$this->endpoint
->expects('for_user')
->with($id)
->andThrow(RuntimeException::class);
$result = $this->sut->all_for_user_id($id);
$this->assertSame($tokens, $result);
}
public function testTokensContainCardReturnsTrue()
{
$source = new \stdClass();
$card = new \stdClass();
$source->card = $card;
$token = Mockery::mock(PaymentToken::class);
$tokens = [$token];
$token->shouldReceive('source')->andReturn($source);
$this->assertTrue($this->sut->tokens_contains_card($tokens));
}
public function testTokensContainCardReturnsFalse()
{
$tokens = [];
$this->assertFalse($this->sut->tokens_contains_card($tokens));
}
public function testTokensContainPayPalReturnsTrue()
{
$source = new \stdClass();
$paypal = new \stdClass();
$source->paypal = $paypal;
$token = Mockery::mock(PaymentToken::class);
$tokens = [$token];
$token->shouldReceive('source')->andReturn($source);
$this->assertTrue($this->sut->tokens_contains_paypal($tokens));
}
public function testTokensContainPayPalReturnsFalse()
{
$tokens = [];
$this->assertFalse($this->sut->tokens_contains_paypal($tokens));
}
}