<commit_before><?php


namespace Tappleby\OAuth2\Storage;

use Mockery as m;

class RefreshTokenStorageTest extends \PHPUnit_Framework_TestCase {

	protected function tearDown() {
		m::close();
	}

  protected function getRefreshToken() {
    $tk = m::mock('Tappleby\OAuth2\Models\RefreshTokenInterface');
    $tk->shouldReceive('getScopes')->andReturn(array('foo', 'bar'));
    $tk->shouldIgnoreMissing();

    return $tk;
  }

  public function testReturnsNullOnInvalidToken()
  {
    $refreshTokenRepo = m::mock('Tappleby\OAuth2\Repositories\RefreshTokenRepositoryInterface');
    $refreshTokenRepo->shouldReceive('find')->once()->with(1)->andReturnNull();

    $refreshTokenStorage = new RefreshTokenStorage($refreshTokenRepo);

    $this->assertNull( $refreshTokenStorage->getRefreshToken(1) );
  }

  public function testReturnsValidTokenData()
  {
    $refreshTokenRepo = m::mock('Tappleby\OAuth2\Repositories\RefreshTokenRepositoryInterface');
    $refreshTokenRepo->shouldReceive('find')->once()->with(1)->andReturn( $this->getRefreshToken() );

    $refreshTokenStorage = new RefreshTokenStorage($refreshTokenRepo);

    $tk = $refreshTokenStorage->getRefreshToken(1);
    $this->assertInternalType('array', $tk);

    $this->assertArrayHasKey('client_id', $tk);
    $this->assertArrayHasKey('user_id', $tk);
    $this->assertArrayHasKey('expires', $tk);
    $this->assertArrayHasKey('scope', $tk);
    $this->assertEquals('foo bar', $tk['scope']);
  }

  public function testSetRefreshToken()
  {<commit_msg>Use RefreshTokenBasic instead of mock, update valid data test to check tokens values<commit_after><?php


namespace Tappleby\OAuth2\Storage;

use Mockery as m;
use Tappleby\OAuth2\Models\RefreshTokenBasic;

class RefreshTokenStorageTest extends \PHPUnit_Framework_TestCase {

	protected function tearDown() {
		m::close();
	}

  protected function getRefreshToken() {
	  return new RefreshTokenBasic(
			'foo_id', 'foo_client', 'foo_user', 1337, array('foo', 'bar')
	  );
  }

  public function testReturnsNullOnInvalidToken()
  {
    $refreshTokenRepo = m::mock('Tappleby\OAuth2\Repositories\RefreshTokenRepositoryInterface');
    $refreshTokenRepo->shouldReceive('find')->once()->with(1)->andReturnNull();

    $refreshTokenStorage = new RefreshTokenStorage($refreshTokenRepo);

    $this->assertNull( $refreshTokenStorage->getRefreshToken(1) );
  }

  public function testReturnsValidTokenData()
  {
    $refreshTokenRepo = m::mock('Tappleby\OAuth2\Repositories\RefreshTokenRepositoryInterface');
    $refreshTokenRepo->shouldReceive('find')->once()->with(1)->andReturn( $this->getRefreshToken() );

    $refreshTokenStorage = new RefreshTokenStorage($refreshTokenRepo);

    $tk = $refreshTokenStorage->getRefreshToken(1);
    $this->assertInternalType('array', $tk);

	  $this->assertEquals('foo_client', $tk['client_id']);
	  $this->assertEquals('foo_user', $tk['user_id']);
	  $this->assertEquals(1337, $tk['expires']);
    $this->assertEquals('foo bar', $tk['scope']);
  }

  public function testSetRefreshToken()
  {
{'fraction_non_alphanumeric': 0.15177398160315375, 'fraction_numerical': 0.00788436268068331, 'mean_word_length': 5.827354260089686, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6269284', 'n_tokens_mistral': 945, 'n_tokens_neox': 916, 'n_words': 142}