public function testMappingFailsIfNotEnoughFreeCodes() { $this->resetDatabase(); $client = static::createClient(); $container = $client->getContainer(); $em = $container->get('doctrine.orm.entity_manager'); $customer = new Customer(); $customer->setIsActivated(true); $customer->setCouponsHaveBeenSent(false); $customer->setActivationCode('abc'); $customer->setEmail('*****@*****.**'); $customer->setEmployeeNumber('12345'); $customer->setSalesdivision(Customer::SALESDIVISION_MEDIAMARKT_SATURN); $customer->setOptInAccepted(false); $em->persist($customer); $couponcode = new Couponcode(); $couponcode->setCode('111'); $em->flush(); $em->clear(); $cRepo = $em->getRepository('AppBundle\\Entity\\Customer'); $customer = $cRepo->find(1); $m = new CouponMapperService($em); $m->mapNToCustomer(3, $customer); $em->clear(); $cRepo = $em->getRepository('AppBundle\\Entity\\Customer'); $customer = $cRepo->find(1); $codes = $customer->getCouponCodes()->getValues(); $this->assertSame(0, sizeof($codes)); }
public function testExecute() { $kernel = $this->createKernel(); $kernel->boot(); $application = new Application($kernel); $application->setAutoExit(false); $input = new ArgvInput(['', 'doctrine:database:drop', '--no-interaction', '--force', '-q']); $application->run($input); $input = new ArgvInput(['', 'doctrine:database:create', '--no-interaction', '-q']); $application->run($input); $input = new ArgvInput(['', 'doctrine:migrations:migrate', '--no-interaction', '-q']); $application->run($input); $em = $kernel->getContainer()->get('doctrine')->getManager(); $customer = new Customer(); $customer->setEmail('*****@*****.**'); $customer->setActivationCode('abc'); $customer->setEmployeeNumber('1234567890'); $customer->setSalesdivision(Customer::SALESDIVISION_MEDIAMARKT_SATURN); $customer->setIsActivated(true); $customer->setCouponsHaveBeenSent(false); $customer->setOptInAccepted(false); $em->persist($customer); $couponcode = new Couponcode(); $couponcode->setCode('111'); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('222'); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('333'); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('444'); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('555'); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('666'); $em->persist($couponcode); $em->flush(); $application->add(new SendCouponsCommand()); $command = $application->find('app:sendcoupons'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName())); $this->assertSame("example@example.org\n", $commandTester->getDisplay()); $this->assertTrue($customer->getCouponsHaveBeenSent()); $repo = $em->getRepository('AppBundle\\Entity\\Couponcode'); $codes = $repo->findBy(['customer' => 1]); $this->assertSame('111', $codes[0]->getCode()); $this->assertSame('222', $codes[1]->getCode()); $this->assertSame('333', $codes[2]->getCode()); $this->assertSame('444', $codes[3]->getCode()); $this->assertSame('555', $codes[4]->getCode()); $this->assertSame('666', $codes[5]->getCode()); $this->assertSame(6, sizeof($codes)); }
protected function execute(InputInterface $input, OutputInterface $output) { $fn = $input->getArgument('firstName'); $ln = $input->getArgument('lastName'); /** @var DialogHelper $dialog */ $dialog = $this->getHelper('dialog'); $address = $dialog->ask($output, 'Shipping address?'); $p = new Customer($fn, $ln); $p->setShippingAddress($address); $em = $this->getContainer()->get('doctrine.orm.default_entity_manager'); $em->persist($p); $em->flush($p); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $customer = new Customer(); $customer->setFirstname("Bampis"); $customer->setSurname("Sykovaridis"); $customer->setBirthday(new \DateTime()); $customer->setCity("Serres"); $customer->setAddress("Ritsou"); $customer->setEmail("*****@*****.**"); $customer->setPhone("2323232"); $customer->setCountry("Greece"); $manager->persist($customer); $manager->flush(); }
/** * @return Customer */ public function setDataToObject() { $this->object->setLastname($this->getFormattedData('lastname', 'string')); $this->object->setFirstname($this->getFormattedData('firstname', 'string')); $this->object->setEmail($this->getFormattedData('email', 'string')); $this->object->setCustomerGroup($this->getFormattedData('customerGroup', 'string')); $this->object->setCompany($this->getFormattedData('company', 'string')); $this->object->setCity($this->getFormattedData('city', 'string')); $this->object->setCountry($this->getFormattedData('country', 'string')); $this->object->setRegistrationDate($this->getFormattedData('registrationDate', 'date')); parent::setDataToObject(); }
protected function createAndPersistData() { $index = 0; $countries = $this->getReferences('country'); foreach ($this->getReferences('account') as $account) { $index++; $contact = $this->getReference(sprintf('contact_%s', $index)); $customer = new Customer(); $customer->setAccount($account)->setContact($contact); $address1 = $this->createAddress($countries[array_rand($countries)]); $address2 = $this->createAddress($countries[array_rand($countries)]); $customer->addAddress($address1)->addAddress($address2); $this->manager->persist($address1); $this->manager->persist($address2); $this->manager->persist($customer); } }
private function getEntities() { $p = new Person('Sergio', 'Santoro'); $entities[] = $p; $p = new Customer('Sergio', 'Lesta'); $p->setShippingAddress('This is an address'); $entities[] = $p; $p = new Employee('Sergio', 'Franchi'); $p->setDepartement('machinery'); $entities[] = $p; $p = new Engineer('Alberto', 'Grafi'); $p->setDepartement('machinery'); $p->setMainSkill('desing'); $entities[] = $p; $p = new Manager('Sergio', 'Grafi'); $p->setDepartement('recruiting'); $p->setYearsOfExperience(5); $entities[] = $p; return $entities; }
public function testIndexWithExistingAndActivatedCustomerAndCorrectHash() { $client = static::createClient(); $this->resetDatabase(); static::$kernel = static::createKernel(); static::$kernel->boot(); $em = static::$kernel->getContainer()->get('doctrine')->getManager(); $customer = new Customer(); $customer->setEmail('*****@*****.**'); $customer->setActivationCode('abc'); $customer->setEmployeeNumber('456'); $customer->setSalesdivision(Customer::SALESDIVISION_MEDIAMARKT_SATURN); $customer->setIsActivated(true); $customer->setCouponsHaveBeenSent(true); $customer->setOptInAccepted(false); $em->persist($customer); $couponcode = new Couponcode(); $couponcode->setCode('111'); $couponcode->setCustomer($customer); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('222'); $couponcode->setCustomer($customer); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('333'); $couponcode->setCustomer($customer); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('444'); $couponcode->setCustomer($customer); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('555'); $couponcode->setCustomer($customer); $em->persist($couponcode); $couponcode = new Couponcode(); $couponcode->setCode('666'); $couponcode->setCustomer($customer); $em->persist($couponcode); $em->flush(); $secret = static::$kernel->getContainer()->getParameter('secret'); $crawler = $client->request('GET', '/customer/' . $customer->getId() . '/coupons?hash=' . sha1($secret . $customer->getId())); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertContains('Einfach diesen Warengutschein beim Einkauf an der Kasse Ihrer Galeria Kaufhof abgeben', $crawler->filter('body')->text()); }
/** * @Route("/app/test-users", name="homepage") */ public function indexAction() { $em = $this->getDoctrine()->getManager(); $admin = $em->getRepository('AppBundle:Admin')->findOneBy(['email' => '*****@*****.**']); if (empty($admin)) { $admin = new Admin(); $admin->setEmail('*****@*****.**'); $admin->setNickName('super'); $admin->setPassword('test1'); $em->persist($admin); $em->flush(); } $customer = $em->getRepository('AppBundle:Customer')->findOneBy(['email' => '*****@*****.**']); if (empty($customer)) { $customer = new Customer(); $customer->setEmail('*****@*****.**'); $customer->setFirstName('Joe'); $customer->setLastName('Lyy'); $customer->setPassword('customer1'); $em->persist($customer); $em->flush(); } $users = $em->getRepository('AppBundle:User')->findAll(); $str = ''; foreach ($users as $user) { if ($user instanceof Admin) { $str .= "<br>Admin (" . $user->getEmail() . "): " . $user->getNickName(); } if ($user instanceof Customer) { $str .= "<br>Customer (" . $user->getEmail() . "): " . $user->getFirstName() . ' ' . $user->getLastName(); } } return new Response('<html><body' . $str . '</body></html>'); }
/** * @Route("/order") * @Template() */ public function orderAction(Request $request) { // GET requests simply show the Place Order page if ($request->getMethod() == 'GET') { // Prevent XSS and Default to michaels-fav // There is likely a more native way of handling this, such as Symfony Forms switch ($request->query->get('variety')) { case 'meatlovers': case 'vegetarian': case 'michaels-fav': $variety = $request->query->get('variety'); break; default: $variety = 'michaels-fav'; } return $this->render('Order/order.html.twig', array('variety' => $variety)); } elseif ($request->getMethod() == 'POST') { $em = $this->getDoctrine()->getManager(); $customers = $em->getRepository('AppBundle:Customer'); // Does this customer already exist? $customer = $customers->findOneBy(array('lname' => $request->request->get('lname'), 'phone' => $request->request->get('phone'))); // If not, create this customer! if (!$customer) { $customer = new Customer(); $customer->setFname($request->request->get('fname'))->setLname($request->request->get('lname'))->setPhone($request->request->get('phone')); $em->persist($customer); $em->flush(); } // Save the Order for this Customer $order = new Order(); $order->setCustomerId($customer->getId())->setPizzaVariety($request->request->get('variety'))->setToppings($request->request->get('toppings'))->setStatus('Queued'); $em->persist($order); $em->flush(); return $this->redirect('/orders'); } }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $customer1 = new Customer(); $customer1->setName('João Silva'); $customer1->setEmail('*****@*****.**'); $customer1->setUsername('joao'); $customer1->setSalt(md5(uniqid())); $customer1->setAddress($this->getReference('address-customer1')); $encoder = $this->container->get('security.encoder_factory')->getEncoder($customer1); $customer1->setPassword($encoder->encodePassword('123456', $customer1->getSalt())); $customer2 = new Customer(); $customer2->setName('Maria Santos'); $customer2->setEmail('*****@*****.**'); $customer2->setUsername('maria'); $customer2->setSalt(md5(uniqid())); $customer2->setAddress($this->getReference('address-customer2')); $encoder = $this->container->get('security.encoder_factory')->getEncoder($customer2); $customer2->setPassword($encoder->encodePassword('123456', $customer2->getSalt())); $manager->persist($customer1); $manager->persist($customer2); $manager->flush(); $this->addReference('customer1', $customer1); $this->addReference('customer2', $customer2); }
/** * @Route("/get-schedules/{id}", name="customer_get_schedules") */ public function getPersonsSchedulesAction(Customer $customer) { //$term = $request->query->get('term', null); $em = $this->getDoctrine()->getManager(); $schedules = $em->getRepository('AppBundle:Customer')->getSchedules($customer->getId()); $schedules2 = $em->getRepository('AppBundle:Customer')->getSchedulesGroupByServices($customer->getId()); //return new JsonResponse($schedules2); return $this->render('Customer/report.html.twig', array('customer' => $customer, 'schedules' => $schedules, 'schedules2' => $schedules2)); }
/** * Creates a form to delete a Customer entity. * * @param Customer $customer The Customer entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Customer $customer) { return $this->createFormBuilder()->setAction($this->generateUrl('customer_delete', array('id' => $customer->getId())))->setMethod('DELETE')->getForm(); }