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));
 }
 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());
 }