示例#1
0
    public function testChangingToken()
    {
        $accountResponse = '
			{
				"account": {
					"id": 123,
					"name": "myaccount",
					"timezone": "UTC",
					"currency_name": "US Dollar"
				}
			}
		';
        $client = \Mockery::mock(GuzzleClient::class);
        $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), ['headers' => [Transport::TOKEN_PIPEJUMP_NAME => '', Transport::TOKEN_FUTUERSIMPLE_NAME => '']])->andReturn($this->getResponse(200, $accountResponse));
        $baseCrm = new BaseCrm('', $client);
        $baseCrm->getAccount()->get();
        $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), ['headers' => [Transport::TOKEN_PIPEJUMP_NAME => 'astalavista', Transport::TOKEN_FUTUERSIMPLE_NAME => 'astalavista']])->andReturn($this->getResponse(200, $accountResponse));
        $baseCrm->setToken('astalavista');
        $this->assertEquals('astalavista', $baseCrm->getToken());
        $account = $baseCrm->getAccount()->get();
        $client->shouldReceive('request')->once()->with('PUT', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), ['headers' => [Transport::TOKEN_PIPEJUMP_NAME => 'baby', Transport::TOKEN_FUTUERSIMPLE_NAME => 'baby'], 'query' => ['account' => ['name' => 'new_name']]])->andReturn($this->getResponse(200, $accountResponse));
        $account->name = 'new_name';
        $account->getTransport()->setToken('baby');
        $this->assertEquals('baby', $account->getTransport()->getToken());
        $account->save(['name']);
    }
示例#2
0
    public function testCurrencyAlteration()
    {
        $client = \Mockery::mock(GuzzleClient::class);
        $client->shouldReceive('request')->once()->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery())->andReturn($this->getResponse(200, '
				{
					"account": {
						"id": 123,
						"name": "myaccount",
						"timezone": "UTC",
						"currency_name": "US Dollar"
					}
				}
			'));
        $baseCrm = new BaseCrm('', $client);
        $account = $baseCrm->getAccount();
        $this->assertEquals(123, $account->id);
        $this->assertEquals('myaccount', $account->name);
        $this->assertEquals('UTC', $account->timezone);
        $this->assertEquals(Currency::USD(), $account->currency);
        $client->shouldReceive('request')->once()->with('PUT', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), $this->getQuery(['query' => ['account' => ['name' => 'newname', 'currency_id' => Currency::PLN, 'timezone' => 'new_timezone']]]))->andReturn($this->getResponse(200, '
				{
					"account": {
						"id": 123,
						"name": "newname",
						"timezone": "new_timezone",
						"currency_name": "Polish złoty"
					}
				}
			'));
        $account->name = 'newname';
        $account->timezone = 'new_timezone';
        $account->currency = Currency::PLN();
        $account->save();
        $this->assertEquals(123, $account->id);
        $this->assertEquals('newname', $account->name);
        $this->assertEquals('new_timezone', $account->timezone);
        $this->assertEquals(Currency::PLN(), $account->currency);
    }