Since: 2.1
Author: Benjamin Eberlei (kontakt@beberlei.de)
Author: Jonathan Wage (jonwage@gmail.com)
 /**
  * @param $data
  * @return AbstractDefaultTypedAddress
  */
 protected function createAddress($data)
 {
     /** @var Country $country */
     $country = $this->countryRepository->findOneBy(['iso2Code' => $data['country']]);
     if (!$country) {
         throw new \RuntimeException('Can\'t find country with ISO ' . $data['country']);
     }
     /** @var Region $region */
     $region = $this->regionRepository->findOneBy(['country' => $country, 'code' => $data['state']]);
     if (!$region) {
         throw new \RuntimeException(printf('Can\'t find region with country ISO %s and code %s', $data['country'], $data['state']));
     }
     $types = [];
     $typesFromData = explode(',', $data['types']);
     foreach ($typesFromData as $type) {
         $types[] = $this->addressTypeRepository->find($type);
     }
     $defaultTypes = [];
     $defaultTypesFromData = explode(',', $data['defaultTypes']);
     foreach ($defaultTypesFromData as $defaultType) {
         $defaultTypes[] = $this->addressTypeRepository->find($defaultType);
     }
     $address = $this->getNewAddressEntity();
     $address->setTypes(new ArrayCollection($types));
     $address->setDefaults(new ArrayCollection($defaultTypes))->setPrimary(true)->setLabel('Primary address')->setCountry($country)->setStreet($data['street'])->setCity($data['city'])->setRegion($region)->setPostalCode($data['zipCode']);
     return $address;
 }
    function it_converts_node_to_street_entry_with_updating_existing_one(ObjectManager $om, ObjectRepository $or, Street $street)
    {
        $xml = <<<EOT
<row>
    <col name="WOJ">02</col>
    <col name="POW">23</col>
    <col name="GMI">09</col>
    <col name="RODZ_GMI">2</col>
    <col name="SYM">0884849</col>
    <col name="SYM_UL">10268</col>
    <col name="CECHA">ul.</col>
    <col name="NAZWA_1">Księżycowa </col>
    <col name="NAZWA_2"/>
    <col name="STAN_NA">2013-10-10</col>
</row>
EOT;
        $place = new Place(884849);
        $place->setName('City');
        $or->findOneBy(array('id' => '0884849'))->shouldBeCalled()->willReturn($place);
        $or->findOneBy(array('id' => '10268', 'place' => $place))->shouldBeCalled()->willReturn($street);
        $street->setName('Księżycowa')->shouldBeCalled()->willReturn($street);
        $street->setAdditionalName('')->shouldBeCalled()->willReturn($street);
        $street->setType('ul.')->shouldBeCalled()->willReturn($street);
        $this->beConstructedWith(new \SimpleXMLElement($xml), $om);
        $this->convertToEntity()->shouldBeLike($street->getWrappedObject());
    }
 /**
  * {@inheritDoc}
  */
 public function getRoles()
 {
     $result = $this->objectRepository->findAll();
     $roles = array();
     // Pass One: Build each object
     foreach ($result as $role) {
         if (!$role instanceof RoleInterface) {
             continue;
         }
         $roleId = $role->getRoleId();
         $parent = null;
         if ($role instanceof HierarchicalRoleInterface && ($parent = $role->getParent())) {
             $parent = $parent->getRoleId();
         }
         $roles[$roleId] = new Role($roleId, $parent);
     }
     // Pass Two: Re-inject parent objects to preserve hierarchy
     /* @var $roleObj \BjyAuthorize\Acl\Role */
     foreach ($roles as $roleObj) {
         $parentRoleObj = $roleObj->getParent();
         if ($parentRoleObj && $parentRoleObj->getRoleId()) {
             $roleObj->setParent($roles[$parentRoleObj->getRoleId()]);
         }
     }
     return array_values($roles);
 }
 /**
  * Here we read rules from DB and put them into a form that BjyAuthorize's Controller.php understands
  */
 public function getRules()
 {
     $rules = array();
     // initialize the rules array
     //
     // get the doctrine shemaManager
     $schemaManager = $this->objectManager->getConnection()->getSchemaManager();
     // check if the roles table exists, if it does not, do not bother querying
     if ($schemaManager->tablesExist(array('roles')) === true) {
         //read from object store a set of (role, controller, action)
         $result = $this->objectRepository->findAll();
         // if a result set exists
         if (count($result)) {
             //transform to object BjyAuthorize will understand
             foreach ($result as $key => $role) {
                 $roleId = $role->getRoleId();
                 // check if any resource access has been defined before
                 // if it has, continue with normal operations
                 // else, allow access to this first user
                 if (!$role->getResources()) {
                     continue;
                 }
                 foreach ($role->getResources() as $rle) {
                     $this->defaultRules['allow'][] = [[$roleId], $rle->getControllerId(), []];
                 }
             }
         }
     }
     return $this->defaultRules;
 }
 protected function buildAdminEntity($value, Toponym $toponym)
 {
     /* @var $admin \Giosh94mhz\GeonamesBundle\Entity\Admin1 */
     $admin = $this->repository->find($toponym) ?: new Admin1($toponym);
     $admin->setCode($value[5])->setCountryCode($value[4])->setName($value[1])->setAsciiName($value[2]);
     return $admin;
 }
Example #6
0
 private function checkDuplicity(Category $category)
 {
     $duplicate = $this->repository->findOneBy(['path' => $category->getPath()]);
     if ($duplicate !== null) {
         throw new EntityDuplicateException(sprintf('Category with path %s already exists.', $category->getPath()));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function loadChoiceList($value = null)
 {
     if ($this->choiceList) {
         return $this->choiceList;
     }
     return $this->choiceList = $this->factory->createListFromChoices($this->repository->findAll(), $value);
 }
 public function testFindSchedules()
 {
     $limit = 2;
     $offset = 1;
     $this->repository->expects($this->once())->method('findBy')->with(array(), array(), $limit, $offset);
     $this->subject->findSchedules($limit, $offset);
 }
 public function buildEntity($value)
 {
     $parent = null;
     $child = null;
     try {
         /* @var $parent \Giosh94mhz\GeonamesBundle\Entity\Toponym */
         $parent = $this->toponymRepository->find($value[0]);
         /* @var $child \Giosh94mhz\GeonamesBundle\Entity\Toponym */
         $child = $this->toponymRepository->find($value[1]);
         if (!$parent || !$child) {
             throw new MissingToponymException("HierarchyLink not imported due to missing toponym '{$value['0']}=>{$value['1']}'");
         }
         /* @var $link \Giosh94mhz\GeonamesBundle\Entity\HierarchyLink */
         $link = $this->repository->find(array('parent' => $parent->getId(), 'child' => $child->getId())) ?: new HierarchyLink($parent, $child);
         $link->setType($value[2]);
         return $link;
     } catch (\Exception $e) {
         if ($parent !== null) {
             $this->om->detach($parent);
         }
         if ($child !== null) {
             $this->om->detach($child);
         }
         throw $e;
     }
 }
 /**
  * @expectedException \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException
  */
 public function testFindWithInvalidObject()
 {
     $this->loader->expects($this->atLeastOnce())->method('mapPathToId')->with('/foo/bar')->will($this->returnValue(1337));
     $this->loader->expects($this->never())->method('getStreamFromImage');
     $this->om->expects($this->atLeastOnce())->method('find')->with(null, 1337)->will($this->returnValue(null));
     $this->loader->find('/foo/bar');
 }
Example #11
0
 /**
  * @param string $paymentMethod
  *
  * @return array
  */
 public function get($paymentMethod)
 {
     if (!isset($this->settings[$paymentMethod])) {
         $this->settings[$paymentMethod] = $this->repository->getSettingsForMethodArray($paymentMethod);
     }
     return $this->settings[$paymentMethod];
 }
 /**
  * @{inheritdoc}
  */
 public function get($id = null)
 {
     if (null !== $id) {
         return $this->repository->find($id);
     }
     return $this->repository->findAll();
 }
Example #13
0
 /**
  * Try to get from local property if exist or load from database afterwards
  *
  * @param string $code
  *
  * @return Region|Null
  */
 protected function tryGetMRByCode($code)
 {
     if (!isset($this->MRIdentityMap[$code]) && !array_key_exists($code, $this->MRIdentityMap)) {
         $this->MRIdentityMap[$code] = $this->repository->findOneBy(['combinedCode' => $code]);
     }
     return $this->MRIdentityMap[$code];
 }
 /**
  * @{inheritdoc}
  */
 public function get($id = null)
 {
     if (null !== $id) {
         return $this->repository->find($id);
     }
     return $this->manager->findUsers();
 }
Example #15
0
 public function findById($userId)
 {
     if (false === $this->authorizationService->isGranted('user.admin')) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     return $this->objectRepository->find($userId);
 }
Example #16
0
 private function checkDuplicity(User $user)
 {
     $duplicate = $this->repository->findOneBy(['email' => $user->getEmail()]);
     if ($duplicate !== null) {
         throw new EntityDuplicateException(sprintf('User with e-mail %s already exists.', $user->getEmail()));
     }
 }
 public function testFindSchedules()
 {
     $limit = 5;
     $offset = 10;
     $this->repository->expects($this->once())->method('findBy')->with(array('isActive' => true), array(), $limit, $offset)->willReturn('foobar');
     $result = $this->subject->findSchedules($limit, $offset);
     $this->assertSame('foobar', $result);
 }
 /**
  * @param Rfc $rfc
  * @param array $voteDiff
  */
 public function notify(Rfc $rfc, array $voteDiff)
 {
     foreach ($this->emailSubscriberRepository->findAll() as $subscriber) {
         $email = $this->twig->render('rfc.twig', ['rfcName' => $rfc->getName(), 'details' => $voteDiff['details'], 'changeLog' => $voteDiff['changeLog'], 'voteDiffs' => $voteDiff['votes'], 'rfcVotes' => $rfc->getVotes(), 'unsubscribeUrl' => sprintf('%s/unsubscribe/%s', $this->config->get('app.url'), $subscriber->getUnsubscribeToken())]);
         $message = $this->mailer->createMessage()->setSubject(sprintf('%s updated!', $rfc->getName()))->setFrom('notifier@php-rfc-digestor.com')->setTo($subscriber->getEmail())->setBody($email, 'text/html');
         $this->mailer->send($message);
     }
 }
 /**
  * {@inheritdoc}
  *
  * @throws \RuntimeException if the identifier is not set
  */
 public function findModuleByIdentity($identity)
 {
     $field = $this->getModularIdentifier();
     if (null == $field) {
         throw new \RuntimeException('The module manager is missing a modular identifier.');
     }
     return $this->repository->findOneBy([$field => $identity]);
 }
 function it_does_reverse_transform_identifiers_to_array_of_entities(ObjectRepository $repository, FakeEntity $entityOne, FakeEntity $entityTwo)
 {
     $value = array(1, 2);
     $entityOne->getId()->willReturn(1);
     $entityTwo->getId()->willReturn(2);
     $repository->findBy(array('id' => $value))->shouldBeCalled()->willReturn(array($entityOne, $entityTwo));
     $this->reverseTransform($value)->shouldReturn(array($entityOne, $entityTwo));
 }
 function it_searches_book_by_isbn_number(BookInterface $book, ObjectRepository $doctrineRepository)
 {
     $isbn = new Isbn('978-1-56619-909-4');
     $doctrineRepository->findOneBy(array('isbn.number' => $isbn))->willReturn($book);
     $this->searchByIsbn($isbn)->shouldBeLike(SearchResults::fromArrayOfBooks(array($book->getWrappedObject())));
     $doctrineRepository->findOneBy(array('isbn.number' => $isbn))->willReturn(null);
     $this->searchByIsbn($isbn)->shouldBeLike(SearchResults::asEmpty());
 }
 function it_returns_all_methods_eligible_for_given_subject(ObjectRepository $methodRepository, ShippingMethodEligibilityCheckerInterface $eligibilityChecker, ShippingSubjectInterface $subject, ShippingMethodInterface $method1, ShippingMethodInterface $method2, ShippingMethodInterface $method3)
 {
     $methods = [$method1, $method2, $method3];
     $methodRepository->findBy(['enabled' => true])->shouldBeCalled()->willReturn($methods);
     $eligibilityChecker->isEligible($subject, $method1)->shouldBeCalled()->willReturn(true);
     $eligibilityChecker->isEligible($subject, $method2)->shouldBeCalled()->willReturn(true);
     $eligibilityChecker->isEligible($subject, $method3)->shouldBeCalled()->willReturn(false);
     $this->getSupportedMethods($subject)->shouldReturn([$method1, $method2]);
 }
 public function testGetNextValueWithNotExistingSequenceReturnsNextValue()
 {
     $sequenceName = 'ABC';
     $this->repository->expects($this->once())->method('findOneBy')->with(array('name' => $sequenceName))->willReturn(null);
     $this->objectManager->expects($this->any())->method('persist');
     $this->objectManager->expects($this->any())->method('flush');
     $result = $this->subject->getNextValue($sequenceName);
     $this->assertEquals(1, $result);
 }
Example #24
0
 /**
  * @param $categoryName
  * @return Category
  */
 public function getProductsByCategoryName($categoryName)
 {
     try {
         $category = $this->repository->findOneBy(['name' => $categoryName, 'isActive' => 1]);
     } catch (\Exception $e) {
         $category = new Category(self::CATEGORY_NOT_FOUND);
     }
     return $category;
 }
Example #25
0
 /**
  * This is used to return a from to rate and is used in the cron section
  * @param $fromCurrency
  * @param $toCurrency
  * @return null|object
  */
 public function findFromToRate($fromCurrency, $toCurrency)
 {
     //Check if the rate exists
     $exRateObject = $this->exRateRepository->findOneBy(array('fromCurrency' => $fromCurrency, 'toCurrency' => $toCurrency));
     if (!$exRateObject instanceof ExchangeRate) {
         return null;
     }
     return $exRateObject;
 }
 function it_fetches_the_object_from_the_in_memory_cache_the_second_time(ObjectManager $manager, ObjectRepository $repository, \stdClass $object)
 {
     $repository->implement('Pim\\Bundle\\CatalogBundle\\Repository\\ReferableEntityRepositoryInterface');
     $manager->getRepository('Object\\Class')->willReturn($repository);
     $repository->findByReference('foo')->shouldBeCalledTimes(1)->willReturn($object);
     $this->find('Object\\Class', 'foo')->shouldReturn($object);
     $this->find('Object\\Class', 'foo')->shouldReturn($object);
     $this->find('Object\\Class', 'foo')->shouldReturn($object);
 }
 function it_fetches_the_object_from_the_in_memory_cache_the_second_time(ObjectManager $manager, ObjectRepository $repository, \stdClass $object)
 {
     $repository->implement('Akeneo\\Component\\StorageUtils\\Repository\\IdentifiableObjectRepositoryInterface');
     $manager->getRepository('Object\\Class')->willReturn($repository);
     $repository->findOneByIdentifier('foo')->shouldBeCalledTimes(1)->willReturn($object);
     $this->find('Object\\Class', 'foo')->shouldReturn($object);
     $this->find('Object\\Class', 'foo')->shouldReturn($object);
     $this->find('Object\\Class', 'foo')->shouldReturn($object);
 }
 /**
  * @param ObjectRepository $repository
  * @param string           $referenceDataName
  * @param string           $code
  *
  * @throws \LogicException
  *
  * @return int
  */
 protected function resolveOne(ObjectRepository $repository, $referenceDataName, $code)
 {
     //TODO: do not hydrate them, use a scalar result
     $referenceData = $repository->findOneBy(['code' => $code]);
     if (null === $referenceData) {
         throw new \LogicException(sprintf('No reference data "%s" with code "%s" has been found', $referenceDataName, $code));
     }
     return $referenceData->getId();
 }
 function it_partially_fills_backordered_units_and_updates_stock_accordingly(StockableInterface $stockable, InventoryUnitInterface $inventoryUnit1, InventoryUnitInterface $inventoryUnit2, ObjectRepository $repository)
 {
     $stockable->getOnHand()->shouldBeCalled()->willReturn(5);
     $stockable->setOnHand(3)->shouldBeCalled();
     $inventoryUnit1->setInventoryState(InventoryUnitInterface::STATE_SOLD)->shouldBeCalled();
     $inventoryUnit2->setInventoryState(InventoryUnitInterface::STATE_SOLD)->shouldBeCalled();
     $repository->findBy(['stockable' => $stockable, 'inventoryState' => InventoryUnitInterface::STATE_BACKORDERED], ['createdAt' => 'ASC'])->willReturn([$inventoryUnit1, $inventoryUnit2]);
     $this->fillBackorders($stockable);
 }
Example #30
-1
 /**
  * Insert new users
  *
  * @param Collection $users
  */
 private function insertUsers(Collection $users)
 {
     set_time_limit(60);
     $this->manager->getConnection()->getConfiguration()->setSQLLogger(null);
     // Get existan user from DB
     $existantUsers = $this->repository->findBy(['email' => $this->extractEmails($users)->toArray()]);
     // Create an array of emails
     $existantEmails = array_map(function ($user) {
         return $user->getEmail();
     }, $existantUsers);
     unset($existantUsers);
     // Get not existant users ready to import
     $nonExistantUsers = $users->filter(function ($user) use($existantEmails) {
         return !in_array($user->getEmail(), $existantEmails);
     });
     unset($existantEmails);
     foreach ($nonExistantUsers as $user) {
         $user->addRole('ROLE_USER');
         $this->manager->persist($user);
         $this->manager->flush();
         $this->manager->clear();
         $this->manager->detach($user);
         gc_enable();
         gc_collect_cycles();
     }
 }