assertInstanceOf('RetailCrm\ApiClient', $client); } /** * @group integration */ public function testOrdersCreate() { $client = static::getApiClient(); $externalId = time(); $response = $client->ordersCreate(array( 'firstName' => self::FIRST_NAME, 'externalId' => $externalId, )); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(201, $response->getStatusCode()); $this->assertTrue(is_int($response->getId())); return array( 'id' => $response->getId(), 'externalId' => $externalId, ); } /** * @group integration * @depends testOrdersCreate */ public function testOrdersGet(array $ids) { $client = static::getApiClient(); $response = $client->ordersGet(678678678); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(404, $response->getStatusCode()); $this->assertFalse($response->success); $response = $client->ordersGet($ids['id'], 'id'); $orderById = $response->order; $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertTrue($response->success); $this->assertEquals(self::FIRST_NAME, $response->order['firstName']); $response = $client->ordersGet($ids['externalId'], 'externalId'); $this->assertEquals($orderById['id'], $response->order['id']); return $ids; } /** * @group unit * @expectedException \InvalidArgumentException */ public function testOrdersGetException() { $client = static::getApiClient(); $response = $client->ordersGet(678678678, 'asdf'); } /** * @group integration * @depends testOrdersGet */ public function testOrdersEdit(array $ids) { $client = static::getApiClient(); $response = $client->ordersEdit( array( 'id' => 22342134, 'lastName' => '12345', ), 'id' ); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(404, $response->getStatusCode()); $response = $client->ordersEdit(array( 'externalId' => $ids['externalId'], 'lastName' => '12345', )); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertTrue($response->success); $response = $client->ordersEdit(array( 'externalId' => time(), 'lastName' => '12345', )); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(201, $response->getStatusCode()); $this->assertTrue($response->success); } /** * @group unit * @expectedException \InvalidArgumentException */ public function testOrdersEditException() { $client = static::getApiClient(); $response = $client->ordersEdit(array('id' => 678678678), 'asdf'); } /** * @group integration */ public function testOrdersHistory() { $client = static::getApiClient(); $response = $client->ordersHistory(); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertTrue($response->success); $this->assertTrue(isset($response['orders'])); } /** * @group integration */ public function testOrdersList() { $client = static::getApiClient(); $response = $client->ordersList(); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertTrue($response->isSuccessful()); $this->assertTrue(isset($response['orders'])); $response = $client->ordersList(array(), 1, 300); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertFalse($response->isSuccessful()); $response = $client->ordersList(array('paymentStatus' => 'paid'), 1); $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); $this->assertTrue($response->isSuccessful()); } }