public setCustomer ( Sonata\Component\Customer\CustomerInterface $customer = null ) | ||
$customer | Sonata\Component\Customer\CustomerInterface |
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'); }
/** * @return void */ public function testOrder() { $basket = new Basket(); $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface'); $billingAddress = $this->getMock('Sonata\\Component\\Customer\\AddressInterface'); $deliveryMethod = $this->getMock('Sonata\\Component\\Delivery\\ServiceDeliveryInterface'); $deliveryMethod->expects($this->exactly(2))->method('isAddressRequired')->will($this->returnValue(true)); $deliveryAddress = $this->getMock('Sonata\\Component\\Customer\\AddressInterface'); $paymentMethod = $this->getMock('Sonata\\Component\\Payment\\PaymentInterface'); $basket->setCustomer($customer); $basket->setBillingAddress($billingAddress); $basket->setDeliveryMethod($deliveryMethod); $basket->setDeliveryAddress($deliveryAddress); $basket->setPaymentMethod($paymentMethod); $currency = new Currency(); $currency->setLabel('EUR'); $basket->setCurrency($currency); $order = $this->getBasketTransform()->transformIntoOrder($basket); $this->assertInstanceOf('Sonata\\Component\\Order\\OrderInterface', $order, '::transformIntoOrder() returns an OrderInstance object'); }