<?php 

use PHPUnit\Framework\TestCase;

/**
 * EntityTest Class Doc Comment
 *
 * @package MercadoPago
 */
class InstoreTest extends TestCase
{

    public static function setUpBeforeClass()
    {
        MercadoPago\SDK::cleanCredentials();
        
        if (file_exists(__DIR__ . '/../../.env')) {
            $dotenv = new Dotenv\Dotenv(__DIR__, '../../.env');
            $dotenv->load();
        }
        
        MercadoPago\SDK::setClientId(getenv('CLIENT_ID'));
        MercadoPago\SDK::setClientSecret(getenv('CLIENT_SECRET')); 
    }

    public function testCreatePos() {
        $pos = new MercadoPago\POS();
        $pos->name = "mypointofsale";
        $pos->fixed_amount =true; 
        $pos->external_id = "mypos" . rand(1, 10000);

        $pos->save();
        $this->assertEquals($pos->status, 'active');
        return $pos;
    }

    /**
     * @depends testCreatePos
     */
    public function testUpdatePos(MercadoPago\POS $created_pos) {
        $created_pos->name = "mypointofsalenewname";
        $created_pos->update();

        $pos = MercadoPago\POS::find_by_id($created_pos->id);

        $this->assertEquals($pos->name, 'mypointofsalenewname');
        
    }

    /**
     * @depends testCreatePos 
     */
    public function testSearchPos(MercadoPago\POS $pos) {
        $filters = array(
            "external_id" => $pos->external_id
        );
        $poss = MercadoPago\POS::search($filters);
        $last_pos = end($poss);

        $this->assertEquals($last_pos->external_id, $pos->external_id);
    }

    

    // public function testDeletePos(MercadoPago\POS $pos) {
    //     $pos = new MercadoPago\POS();

    // }

}

?>