<commit_before><?php

use CommerceSignals\API;
use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 *  Basic test on the API class to make sure we have
 *  all known methods and they are responding as needed
 *
 *  @author <NAME>
 */
class ApiTest extends PHPUnit_Framework_TestCase {

  use HttpMockTrait;

  public $authToken = [
    'access_token' => '<PASSWORD>',
    'token_type' => 'bearer',
    'refresh_token' => '<PASSWORD>',
    'expires_in' => 899,
    'scope' => 'read write',
    'jti' => '999888777',
  ];

  public static function setUpBeforeClass() {
    static::setUpHttpMockBeforeClass('8082', 'localhost');
  }

  public static function tearDownAfterClass() {
    static::tearDownHttpMockAfterClass();
  }

  public function setUp() {
    $this->setUpHttpMock();

    $this->http->mock
      ->when()
        ->callback(
            function (Request $request) {
              return
                $request->getMethod() === 'POST' &&
                $request->getPathInfo() === '/oauth/token' &&
                $request->headers->has('authorization') &&
                $request->request->has('grant_type') &&
                $request->request->has('assertion');
            }
        )
      ->then()
        ->body(json_encode(SELF::AUTH_TOKEN))
        ->end();
  }

  public function tearDown() {
    $this->tearDownHttpMock();
  }

  public function testAuthToken() {
    $this->http->setUp();

    $api = new API('http://localhost:8082', [
      'apiKey' => '123456',
      'cert' => file_get_contents(__DIR__ . '/fake-cert.pem'),
    ]);

    $this->assertSame($api->getToken()->access_token, $api->getToken()->access_token);
  }
}<commit_msg>check the token response to make sure it matches<commit_after><?php

use CommerceSignals\API;
use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 *  Basic test on the API class to make sure we have
 *  all known methods and they are responding as needed
 *
 *  @author <NAME>
 */
class ApiTest extends PHPUnit_Framework_TestCase {

  use HttpMockTrait;

  public $authToken = [
    'access_token' => '1234567890',
    'token_type' => 'bearer',
    'refresh_token' => '<PASSWORD>',
    'expires_in' => 899,
    'scope' => 'read write',
    'jti' => '999888777',
  ];

  public static function setUpBeforeClass() {
    static::setUpHttpMockBeforeClass('8082', 'localhost');
  }

  public static function tearDownAfterClass() {
    static::tearDownHttpMockAfterClass();
  }

  public function setUp() {
    $this->setUpHttpMock();

    $this->http->mock
      ->when()
        ->callback(
            function (Request $request) {
              return
                $request->getMethod() === 'POST' &&
                $request->getPathInfo() === '/oauth/token' &&
                $request->headers->has('authorization') &&
                $request->request->has('grant_type') &&
                $request->request->has('assertion');
            }
        )
      ->then()
        ->body(json_encode($this->authToken))
        ->end();
  }

  public function tearDown() {
    $this->tearDownHttpMock();
  }

  public function testAuthToken() {
    $this->http->setUp();

    $api = new API('http://localhost:8082', [
      'apiKey' => '123456',
      'cert' => file_get_contents(__DIR__ . '/fake-cert.pem'),
    ]);

    $this->assertSame($api->getToken()->access_token, $this->authToken['access_token']);
  }
}
{'fraction_non_alphanumeric': 0.159476760367381, 'fraction_numerical': 0.017255775118285556, 'mean_word_length': 2.795142555438226, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 72, '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': '5417584', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1094, 'n_words': 212}