<commit_before><?php
namespace BaseCRM;

use Exception;

/**
 * Parent class for every test case.
 */
class TestCase extends \PHPUnit_Framework_TestCase
{
  protected static $accessToken = null;
  protected static $baseUrl = null;
  protected static $client = null;

  protected static $account = null;
  protected static $associatedContact = null;
  protected static $contact = null;
  protected static $deal = null;
  protected static $dealSource = null;
  protected static $dealUnqualifiedReason = null;
  protected static $lead = null;
  protected static $leadSource = null;
  protected static $leadUnqualifiedReason = null;
  protected static $lineItem = null;
  protected static $lossReason = null;
  protected static $note = null;
  protected static $order = null;
  protected static $product = null;
  protected static $source = null;
  protected static $tag = null;
  protected static $task = null;
  protected static $user = null;

  public static function setUpBeforeClass()
  {
    self::$accessToken = self::getAccessToken();
    self::$baseUrl = self::getBaseUrl();
    self::$client = new Client([
      'accessToken' => self::$accessToken,
      'baseUrl' => self::$baseUrl,
      'userAgent' => "BaseCRM/v2 PHP/" . Configuration::VERSION . '+tests',
      'verbose' => true,
    ]);

    self::$account = self::$client->accounts->self();
    self::$associatedContact = self::createAssociatedContact();
    self::$contact = self::createContact();
    self::$deal = self::createDeal();
    self::$dealSource = self::createDealSource();
    self::$dealUnqualifiedReason = self::createDealUnqualifiedReason();
    self::$lead = self::createLead();
    self::$leadSource = self::createLeadSource();
    self::$lineItem = self::createLineItem();
    self::$lossReason = self::createLossReason();
    self::$note = self::createNote();
    self::$order = self::createOrder();
    self::$product = self::createProduct();
    self::$source = self::createSource();
    self::$tag = self::createTag();
    self::$task = self::createTask();
    self::$user = self::$client->users->self();
  }

  /**
   * @ignore
   */
  protected static function getAccessToken()
  {
    $token = getenv("BASECRM_ACCESS_TOKEN");
    if (!$token) throw new Exception('"BASECRM_ACCESS_TOKEN" environment variable has not been found.');
    return $token;
  }

  protected static function getBaseUrl()
  {
    $url = getenv("BASECRM_BASE_URL");
    if(!$url) $url = "https://api.getbase.com";
    return $url;
  }

  protected static function createAssociatedContact(array $attributes = [])
  {
    $deal_id = self::createDeal()['id'];
    $associatedContact = [
      'role' => "involved",
      'contact_id' => self::createContact()['id'],
    ];
    $associatedContact = self::$client->associatedContacts->create($deal_id, array_merge($associatedContact, $attributes));

    $associatedContact['deal_id'] = $deal_id;
    return $associatedContact;
  }

  protected static function createContact(array $attributes = [])
  {
    $contact = [
      'description' => "I know him via Tom",
      'email' => "<EMAIL>",
      'facebook' => "mjohnson",
      'fax' => "+44-208-1234567",
      'first_name' => 'Mark' . rand(),
      'industry' => "Design Services",
      'is_organization' => false,
      'last_name' => 'Johnson' . rand(),
      'linkedin' => "mjohnson",
      'mobile' => "508-778-6516",
      'name' => 'Design Services Company' . rand(),
      'phone' => "508-778-6516",
      'skype' => "mjohnson",
      'tags' => ["important"],
      'title' => "CEO",
      'twitter' => "mjohnson",
      'website' => "www.designservices.com",
    ];
    $contact = self::$client->contacts->create(array_merge($contact, $attributes));

    return $contact;
  }

  protected static function createDeal(array $attributes = [])
  {
    $deal = [
      'currency' => "EUR",
      'dropbox_email' => "<EMAIL>",
      'hot' => true,
      'name' => 'Website Redesign' . rand(),
      'tags' => ["important"],
      'value' => 1000,
      'contact_id' => self::createContact()['id'],
    ];
    $deal = self::$client->deals->create(array_merge($deal, $attributes));

    return $deal;
  }

  protected static function createDealWithDecimalValue(array $attributes = [])
  {
    $deal = [
      'currency' => "EUR",
      'dropbox_email' => "<EMAIL>",
      'hot' => true,
      'name' => 'Website Redesign with decimal value' . rand(),
      'tags' => ["important"],
      'value' => "11.12",
      'contact_id' => self::createContact()['id'],
    ];

    $originalClient = self::$client;
    self::$client = ""; #$this->getMock('\BaseCRM\Client');

    $deal = self::$client->deals->create(array_merge($deal, $attributes));

    return $deal;
  }

  protected static function createDealSource(array $attributes = [])
  {
    $dealSource = [
      'name' => 'inbound marketing' . rand(),
      'resource_type' => 'deal'
    ];
    $dealSource = self::$client->dealSources->create(array_merge($dealSource, $attributes));

    return $dealSource;
  }

  protected static function createDealUnqualifiedReason(array $attributes = [])
  {
    $dealUnqualifiedReason = [
      'name' => 'Reason of unqualifying deal' . rand(),
    ];
    $dealUnqualifiedReason = self::$client->dealUnqualifiedReasons->create(array_merge($dealUnqualifiedReason, $attributes));

    return $dealUnqualifiedReason;
  }

  protected static function createLead(array $attributes = [])
  {
    $lead = [
      'description' => "I know him via Tom",
      'email' => "<EMAIL>",
      'facebook' => "mjohnson",
      'fax' => "+44-208-1234567",
      'first_name' => 'Mark' . rand(),
      'industry' => "Design Services",
      'last_name' => 'Johnson' . rand(),
      'linkedin' => "mjohnson",
      'mobile' => "508-778-6516",
      'phone' => "508-778-6516",
      'skype' => "mjohnson",
      'status' => "Unqualified",
      'tags' => ["important"],
      'title' => "CEO",
      'twitter' => "mjohnson",
      'website' => "www.designservices.com",
    ];
    $lead = self::$client->leads->create(array_merge($lead, $attributes));

    return $lead;
  }

  protected static function createLeadSource(array $attributes = [])
  {
    $leadSource = [
      'name' => 'outbound marketing' . rand(),
      'resource_type' => 'lead'
    ];
    $leadSource = self::$client->leadSources->create(array_merge($leadSource, $attributes));<commit_msg>randomize test data<commit_after><?php
namespace BaseCRM;

use Exception;

/**
 * Parent class for every test case.
 */
class TestCase extends \PHPUnit_Framework_TestCase
{
  protected static $accessToken = null;
  protected static $baseUrl = null;
  protected static $client = null;

  protected static $account = null;
  protected static $associatedContact = null;
  protected static $contact = null;
  protected static $deal = null;
  protected static $dealSource = null;
  protected static $dealUnqualifiedReason = null;
  protected static $lead = null;
  protected static $leadSource = null;
  protected static $leadUnqualifiedReason = null;
  protected static $lineItem = null;
  protected static $lossReason = null;
  protected static $note = null;
  protected static $order = null;
  protected static $product = null;
  protected static $source = null;
  protected static $tag = null;
  protected static $task = null;
  protected static $user = null;

  public static function setUpBeforeClass()
  {
    self::$accessToken = self::getAccessToken();
    self::$baseUrl = self::getBaseUrl();
    self::$client = new Client([
      'accessToken' => self::$accessToken,
      'baseUrl' => self::$baseUrl,
      'userAgent' => "BaseCRM/v2 PHP/" . Configuration::VERSION . '+tests',
      'verbose' => true,
    ]);

    self::$account = self::$client->accounts->self();
    self::$associatedContact = self::createAssociatedContact();
    self::$contact = self::createContact();
    self::$deal = self::createDeal();
    self::$dealSource = self::createDealSource();
    self::$dealUnqualifiedReason = self::createDealUnqualifiedReason();
    self::$lead = self::createLead();
    self::$leadSource = self::createLeadSource();
    self::$lineItem = self::createLineItem();
    self::$lossReason = self::createLossReason();
    self::$note = self::createNote();
    self::$order = self::createOrder();
    self::$product = self::createProduct();
    self::$source = self::createSource();
    self::$tag = self::createTag();
    self::$task = self::createTask();
    self::$user = self::$client->users->self();
  }

  /**
   * @ignore
   */
  protected static function getAccessToken()
  {
    $token = getenv("BASECRM_ACCESS_TOKEN");
    if (!$token) throw new Exception('"BASECRM_ACCESS_TOKEN" environment variable has not been found.');
    return $token;
  }

  protected static function getBaseUrl()
  {
    $url = getenv("BASECRM_BASE_URL");
    if(!$url) $url = "https://api.getbase.com";
    return $url;
  }

  protected static function createAssociatedContact(array $attributes = [])
  {
    $deal_id = self::createDeal()['id'];
    $associatedContact = [
      'role' => "involved",
      'contact_id' => self::createContact()['id'],
    ];
    $associatedContact = self::$client->associatedContacts->create($deal_id, array_merge($associatedContact, $attributes));

    $associatedContact['deal_id'] = $deal_id;
    return $associatedContact;
  }

  protected static function createContact(array $attributes = [])
  {
    $contact = [
      'description' => "I know him via Tom",
      'email' => "mark" . rand() . "@designservices.com",
      'facebook' => "mjohnson",
      'fax' => "+44-208-1234567",
      'first_name' => 'Mark' . rand(),
      'industry' => "Design Services",
      'is_organization' => false,
      'last_name' => 'Johnson' . rand(),
      'linkedin' => "mjohnson",
      'mobile' => "508-778-6516",
      'name' => 'Design Services Company' . rand(),
      'phone' => "508-778-6516",
      'skype' => "mjohnson",
      'tags' => ["important"],
      'title' => "CEO",
      'twitter' => "mjohnson",
      'website' => "www.designservices.com",
    ];
    $contact = self::$client->contacts->create(array_merge($contact, $attributes));

    return $contact;
  }

  protected static function createDeal(array $attributes = [])
  {
    $deal = [
      'currency' => "EUR",
      'dropbox_email' => "<EMAIL>",
      'hot' => true,
      'name' => 'Website Redesign' . rand(),
      'tags' => ["important"],
      'value' => 1000,
      'contact_id' => self::createContact()['id'],
    ];
    $deal = self::$client->deals->create(array_merge($deal, $attributes));

    return $deal;
  }

  protected static function createDealWithDecimalValue(array $attributes = [])
  {
    $deal = [
      'currency' => "EUR",
      'dropbox_email' => "<EMAIL>",
      'hot' => true,
      'name' => 'Website Redesign with decimal value' . rand(),
      'tags' => ["important"],
      'value' => "11.12",
      'contact_id' => self::createContact()['id'],
    ];

    $originalClient = self::$client;
    self::$client = ""; #$this->getMock('\BaseCRM\Client');

    $deal = self::$client->deals->create(array_merge($deal, $attributes));

    return $deal;
  }

  protected static function createDealSource(array $attributes = [])
  {
    $dealSource = [
      'name' => 'inbound marketing' . rand(),
      'resource_type' => 'deal'
    ];
    $dealSource = self::$client->dealSources->create(array_merge($dealSource, $attributes));

    return $dealSource;
  }

  protected static function createDealUnqualifiedReason(array $attributes = [])
  {
    $dealUnqualifiedReason = [
      'name' => 'Reason of unqualifying deal' . rand(),
    ];
    $dealUnqualifiedReason = self::$client->dealUnqualifiedReasons->create(array_merge($dealUnqualifiedReason, $attributes));

    return $dealUnqualifiedReason;
  }

  protected static function createLead(array $attributes = [])
  {
    $lead = [
      'description' => "I know him via Tom",
      'email' => "mark" . rand() . "@designservices.com",
      'facebook' => "mjohnson",
      'fax' => "+44-208-1234567",
      'first_name' => 'Mark' . rand(),
      'industry' => "Design Services",
      'last_name' => 'Johnson' . rand(),
      'linkedin' => "mjohnson",
      'mobile' => "508-778-6516",
      'phone' => "508-778-6516",
      'skype' => "mjohnson",
      'status' => "Unqualified",
      'tags' => ["important"],
      'title' => "CEO",
      'twitter' => "mjohnson",
      'website' => "www.designservices.com",
    ];
    $lead = self::$client->leads->create(array_merge($lead, $attributes));

    return $lead;
  }

  protected static function createLeadSource(array $attributes = [])
  {
    $leadSource = [
      'name' => 'outbound marketing' . rand(),
      'resource_type' => 'lead'
    ];
    $leadSource = self::$client->leadSources->create(array_merge($leadSource, $attributes));
{'fraction_non_alphanumeric': 0.1748871946475805, 'fraction_numerical': 0.011358332036720088, 'mean_word_length': 3.508944230094704, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 167, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '3261898', 'n_tokens_mistral': 4170, 'n_tokens_neox': 3961, 'n_words': 847}