reset() публичный Метод

public reset ( $full = true )
Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function reset($full = true)
 {
     parent::reset($full);
     if ($full) {
         $this->basketElements = new ArrayCollection();
     }
 }
Пример #2
0
 public function testSerialize()
 {
     $product = $this->getMockProduct();
     $basketElement = new BasketElement();
     $basketElement->setProduct('product_code', $product);
     $provider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $manager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $manager->expects($this->any())->method('getClass')->will($this->returnValue('BasketTest_Product'));
     $definition = new ProductDefinition($provider, $manager);
     $pool = new Pool();
     $pool->addProduct('product_code', $definition);
     $basket = new Basket();
     $basket->setProductPool($pool);
     $basket->addBasketElement($basketElement);
     $basket->setDeliveryAddress($this->getMockAddress());
     $basket->setBillingAddress($this->getMockAddress());
     $basket->setCustomer($this->getMock('Sonata\\Component\\Customer\\CustomerInterface'));
     $data = $basket->serialize();
     $this->assertTrue(is_string($data));
     $this->assertStringStartsWith('a:11:', $data, 'the serialized array has 11 elements');
     // Ensuring all needed keys are present
     $expectedKeys = array('basketElements', 'positions', 'deliveryMethodCode', 'paymentMethodCode', 'cptElement', 'options', 'locale', 'currency', 'deliveryAddress', 'billingAddress', 'customer');
     $basketData = unserialize($data);
     foreach ($expectedKeys as $key) {
         $this->assertArrayHasKey($key, $basketData);
     }
     $basket->setDeliveryAddressId(1);
     $basket->setBillingAddressId(2);
     $basket->setCustomerId(3);
     $data = $basket->serialize();
     $this->assertTrue(is_string($data));
     $this->assertStringStartsWith('a:11:', $data, 'the serialized array has 11 elements');
     // Ensuring all needed keys are present
     $expectedKeys = array('basketElements', 'positions', 'deliveryMethodCode', 'paymentMethodCode', 'cptElement', 'options', 'locale', 'currency', 'deliveryAddressId', 'billingAddressId', 'customerId');
     $basketData = unserialize($data);
     foreach ($expectedKeys as $key) {
         $this->assertArrayHasKey($key, $basketData);
     }
     $basket->reset();
     $this->assertTrue(count($basket->getBasketElements()) == 0, '::reset() remove all elements');
     $basket->unserialize($data);
     $this->assertTrue(count($basket->getBasketElements()) == 1, '::unserialize() restore elements');
 }