<commit_before><?php
/**
 * @package ex-sklik
 * @copyright 2015 Keboola
 * @author <NAME> <<EMAIL>>
 */
namespace Keboola\SklikExtractor;

class ApiTest extends AbstractTest
{
    /** @var  Api */
    protected $api;

    public function setUp()
    {
        parent::setUp();

        $this->api = new Api(EX_SK_USERNAME, EX_SK_PASSWORD, EX_SK_API_URL);
    }

    public function testApiLogin()
    {
        $result = $this->api->login();
        $this->assertArrayHasKey('status', $result);
        $this->assertEquals(200, $result['status']);
        $this->assertArrayHasKey('session', $result);
        $this->assertNotEmpty($result['session']);
    }

    public function testApiLogout()
    {
        $result = $this->api->logout();
        $this->assertArrayHasKey('status', $result);
        $this->assertEquals(200, $result['status']);
    }

    public function testApiGetListLimit()
    {
        $result = $this->api->getListLimit();
        $this->assertGreaterThan(0, $result);
    }

    public function testApiGetAccounts()
    {
        $result = $this->api->getAccounts();
        $this->assertCount(1, $result);
        $this->assertArrayHasKey('userId', $result[0]);
        $this->assertArrayHasKey('username', $result[0]);
        $this->assertEquals(EX_SK_USERNAME, $result[0]['username']);
    }

    public function testApiGetCampaigns()
    {
        $campaignName = uniqid();
        $campaignId = $this->createCampaign($campaignName);

        $result = $this->api->getCampaigns((int)EX_SK_USER_ID);
        $this->assertGreaterThan(1, count($result));
        $campaignFound = false;
        foreach ($result as $r) {
            $this->assertArrayHasKey('id', $r);
            $this->assertArrayHasKey('name', $r);
            if ($r['id'] == $campaignId) {
                $this->assertEquals($campaignName, $r['name']);
                $campaignFound = true;
            }
        }
        $this->assertTrue($campaignFound);
    }

    public function testApiGetStats()
    {
        $campaignName = uniqid();
        $campaignId = $this->createCampaign($campaignName);

        $date = \DateTime::createFromFormat('Y-m-d H:i:s', date('Y-m-d 00:00:01'));
        $result = $this->api->getStats(EX_SK_USER_ID, [$campaignId], $date, $date);
        $this->assertCount(1, $result);
        $this->assertArrayHasKey('stats', $result[0]);
        $this->assertCount(1, $result[0]['stats']);
        $this->assertArrayHasKey('conversions', $result[0]['stats'][0]);
        $this->assertArrayHasKey('clicks', $result[0]['stats'][0]);
    }
}<commit_msg>Fix missing argument in tests<commit_after><?php
/**
 * @package ex-sklik
 * @copyright 2015 Keboola
 * @author <NAME> <<EMAIL>>
 */
namespace Keboola\SklikExtractor;

class ApiTest extends AbstractTest
{
    /** @var  Api */
    protected $api;

    public function setUp()
    {
        parent::setUp();

        $this->api = new Api(EX_SK_USERNAME, EX_SK_PASSWORD, EX_SK_API_URL);
    }

    public function testApiLogin()
    {
        $result = $this->api->login();
        $this->assertArrayHasKey('status', $result);
        $this->assertEquals(200, $result['status']);
        $this->assertArrayHasKey('session', $result);
        $this->assertNotEmpty($result['session']);
    }

    public function testApiLogout()
    {
        $result = $this->api->logout();
        $this->assertArrayHasKey('status', $result);
        $this->assertEquals(200, $result['status']);
    }

    public function testApiGetListLimit()
    {
        $result = $this->api->getListLimit();
        $this->assertGreaterThan(0, $result);
    }

    public function testApiGetAccounts()
    {
        $result = $this->api->getAccounts();
        $this->assertCount(1, $result);
        $this->assertArrayHasKey('userId', $result[0]);
        $this->assertArrayHasKey('username', $result[0]);
        $this->assertEquals(EX_SK_USERNAME, $result[0]['username']);
    }

    public function testApiGetCampaigns()
    {
        $campaignName = uniqid();
        $campaignId = $this->createCampaign($campaignName);

        $result = $this->api->getCampaigns((int)EX_SK_USER_ID);
        $this->assertGreaterThan(1, count($result));
        $campaignFound = false;
        foreach ($result as $r) {
            $this->assertArrayHasKey('id', $r);
            $this->assertArrayHasKey('name', $r);
            if ($r['id'] == $campaignId) {
                $this->assertEquals($campaignName, $r['name']);
                $campaignFound = true;
            }
        }
        $this->assertTrue($campaignFound);
    }

    public function testApiGetStats()
    {
        $campaignName = uniqid();
        $campaignId = $this->createCampaign($campaignName);
        $impresshionShare = false;

        $date = \DateTime::createFromFormat('Y-m-d H:i:s', date('Y-m-d 00:00:01'), $impresshionShare);
        $result = $this->api->getStats(EX_SK_USER_ID, [$campaignId], $date, $date);
        $this->assertCount(1, $result);
        $this->assertArrayHasKey('stats', $result[0]);
        $this->assertCount(1, $result[0]['stats']);
        $this->assertArrayHasKey('conversions', $result[0]['stats'][0]);
        $this->assertArrayHasKey('clicks', $result[0]['stats'][0]);
    }
}
{'fraction_non_alphanumeric': 0.17704354469060352, 'fraction_numerical': 0.01145912910618793, 'mean_word_length': 2.842259721203228, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 81, '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': '7545258', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1631, 'n_words': 257}