<commit_before><?php
/**
 * This file is part of the ImboClient package
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE file that was
 * distributed with this source code.
 */

namespace ImboClientTest;

use ImboClient\ImboClient,
    Guzzle\Tests\GuzzleTestCase,
    Guzzle\Http\Exception\ServerErrorResponseException;

/**
 * @package Test suite
 * @author <NAME> <<EMAIL>>
 */
class ImboClientTest extends GuzzleTestCase {
    /**
     * @var ImboClient
     */
    private $client;

    /**
     * @var string
     */
    private $baseUrl = 'http://imbo';

    /**
     * @var string
     */
    private $publicKey = 'christer';

    /**
     * @var string
     */
    private $privateKey = 'test';

    /**
     * Set up the client
     */
    public function setUp() {
        $config = array(
            'baseUrl' => $this->baseUrl,
            'publicKey' => $this->publicKey,
            'privateKey' => $this->privateKey,
        );

        $this->client = ImboClient::factory($config);
    }

    /**
     * Tear down the client
     */
    public function tearDown() {
        $this->client = null;
    }

    /**
     * @covers ImboClient\ImboClient::getServerStatus
     */
    public function testCanFetchServerStatusWhenEverythingIsOk() {
        $this->setMockResponse($this->client, 'status_ok');
        $status = $this->client->getServerStatus();
        $this->assertInstanceOf('DateTime', $status->getDate());
        $this->assertTrue($status->getDatabaseStatus());
        $this->assertTrue($status->getStorageStatus());
    }

    /**
     * @covers ImboClient\ImboClient::getServerStatus
     */
    public function testCanFetchServerStatusWhenDatabaseIsDown() {
        $this->setMockResponse($this->client, 'status_database_down');

        try {
            $this->client->getServerStatus();
            $this->fail('Client did not throw any exception');
        } catch (ServerErrorResponseException $e) {
            $result = $e->getResponse()->json();

            $this->assertSame('Database error', $e->getResponse()->getReasonPhrase());
            $this->assertFalse($result['database']);
            $this->assertTrue($result['storage']);
        }
    }

    /**
     * @covers ImboClient\ImboClient::getServerStatus
     */
    public function testCanFetchServerStatusWhenStorageIsDown() {
        $this->setMockResponse($this->client, 'status_storage_down');

        try {
            $this->client->getServerStatus();
            $this->fail('Client did not throw any exception');
        } catch (ServerErrorResponseException $e) {
            $result = $e->getResponse()->json();

            $this->assertSame('Storage error', $e->getResponse()->getReasonPhrase());
            $this->assertTrue($result['database']);
            $this->assertFalse($result['storage']);
        }
    }

    /**
     * @covers ImboClient\ImboClient::getServerStatus
     */
    public function testCanFetchServerStatusWhenDatabaseAndStorageIsDown() {
        $this->setMockResponse($this->client, 'status_database_and_storage_down');

        try {
            $this->client->getServerStatus();
            $this->fail('Client did not throw any exception');
        } catch (ServerErrorResponseException $e) {
            $result = $e->getResponse()->json();

            $this->assertSame('Database and storage error', $e->getResponse()->getReasonPhrase());
            $this->assertFalse($result['database']);
            $this->assertFalse($result['storage']);
        }
    }

    /**
     * @covers ImboClient\ImboClient::getUserInfo
     */
    public function testCanFetchUserInformation() {
        $this->setMockResponse($this->client, 'user_ok');
        $user = $this->client->getUserInfo();
        $this->assertSame('christer', $user->getPublicKey());
        $this->assertSame(11, $user->getNumImages());
        $this->assertSame('2013-04-09 07:00:18', $user->getLastModified()->format('Y-m-d H:i:s'));
    }
}<commit_msg>Updated test case<commit_after><?php
/**
 * This file is part of the ImboClient package
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE file that was
 * distributed with this source code.
 */

namespace ImboClientTest;

use ImboClient\ImboClient,
    Guzzle\Tests\GuzzleTestCase,
    Guzzle\Http\Exception\ServerErrorResponseException;

/**
 * @package Test suite
 * @author <NAME> <<EMAIL>>
 * @covers ImboClient\ImboClient
 */
class ImboClientTest extends GuzzleTestCase {
    /**
     * @var ImboClient
     */
    private $client;

    /**
     * @var string
     */
    private $baseUrl = 'http://imbo';

    /**
     * @var string
     */
    private $publicKey = 'christer';

    /**
     * @var string
     */
    private $privateKey = 'test';

    /**
     * Set up the client
     */
    public function setUp() {
        $config = array(
            'serverUrls' => array($this->baseUrl),
            'publicKey' => $this->publicKey,
            'privateKey' => $this->privateKey,
        );

        $this->client = ImboClient::factory($config);
    }

    /**
     * Tear down the client
     */
    public function tearDown() {
        $this->client = null;
    }

    public function testCanFetchServerStatusWhenEverythingIsOk() {
        $this->setMockResponse($this->client, 'status_ok');

        $status = $this->client->getServerStatus();
        $this->assertInstanceOf('DateTime', $status['date']);
        $this->assertSame('2013-04-30 06:01:19', $status['date']->format('Y-m-d H:i:s'));
        $this->assertTrue($status['database']);
        $this->assertTrue($status['storage']);
    }

    public function testCanFetchServerStatusWhenDatabaseIsDown() {
        $this->setMockResponse($this->client, 'status_database_down');

        $status = $this->client->getServerStatus();

        $this->assertFalse($status['database']);
        $this->assertTrue($status['storage']);
        $this->assertSame(500, $status['status']);
        $this->assertSame('Database error', $status['message']);
    }

    public function testCanFetchServerStatusWhenStorageIsDown() {
        $this->setMockResponse($this->client, 'status_storage_down');

        $status = $this->client->getServerStatus();

        $this->assertTrue($status['database']);
        $this->assertFalse($status['storage']);
        $this->assertSame(500, $status['status']);
        $this->assertSame('Storage error', $status['message']);
    }

    public function testCanFetchServerStatusWhenDatabaseAndStorageIsDown() {
        $this->setMockResponse($this->client, 'status_database_and_storage_down');

        $status = $this->client->getServerStatus();

        $this->assertFalse($status['database']);
        $this->assertFalse($status['storage']);
        $this->assertSame(500, $status['status']);
        $this->assertSame('Database and storage error', $status['message']);
    }

    public function testCanFetchUserInformation() {
        $this->setMockResponse($this->client, 'user_ok');

        $user = $this->client->getUserInfo();

        $this->assertSame('christer', $user['publicKey']);
        $this->assertSame(11, $user['numImages']);
        $this->assertInstanceOf('DateTime', $user['lastModified']);
        $this->assertSame('2013-04-09 07:00:18', $user['lastModified']->format('Y-m-d H:i:s'));
    }
}
{'fraction_non_alphanumeric': 0.162994999324233, 'fraction_numerical': 0.007433436950939316, 'mean_word_length': 2.820340733092411, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 130, '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': '6121722', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2113, 'n_words': 371}