Ejemplo n.º 1
0
 /**
  * @test
  */
 public function it_gets_a_product_collection_filtered_by_sku()
 {
     $wps = new Sdk();
     $wps->addMockResults([new Response(200, [], json_encode($wps->productsResponse()))]);
     $products = $wps->product()->where('sku', '12-1234')->get();
     $this->assertEquals(['/products?sku=12-1234'], $wps->getRequestUris());
     $this->assertInstanceOf(Illuminate\Support\Collection::class, $products);
     $this->assertContainsOnlyInstancesOf(Product::class, $products);
     $this->assertEquals(1, $products[0]->id);
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function it_syncs_products_on_a_site()
 {
     $wps = new Sdk();
     $response = $wps->productsResponse();
     $response['data'] = array_reverse($response['data']);
     $wps->addMockResults([new Response(200, [], json_encode($wps->siteResponse(1))), new Response(200, [], json_encode($response))]);
     $site = $wps->site()->find(1);
     $site->products()->sync([2, 1]);
     $keys = $site->products->map(function ($item, $key) {
         return $item->getKey();
     });
     $this->assertEquals(['/sites/1/', '/sites/1/products/'], $wps->getRequestUris());
     $this->assertEquals([null, '[{"id":2},{"id":1}]'], $wps->getRequestBodies());
     $this->assertContainsOnlyInstancesOf(Wps\Models\Product::class, $site->products);
     $this->assertEquals([2, 1], $keys->toArray());
 }