/**
  * @param Symfony\Component\DependencyInjection\ContainerInterface $container
  * @param Doctrine\Common\Persistence\ManagerRegistry $doctrine
  * @param Doctrine\Common\Persistence\ObjectManager $manager
  * @param Doctrine\ORM\EntityRepository $repository
  * @param Doctrine\ORM\QueryBuilder $queryBuilder
  * @param Doctrine\ORM\AbstractQuery $query
  * @param Knp\FriendlyContexts\Doctrine\EntityResolver $resolver
  * @param Knp\FriendlyContexts\Record\Collection\Bag $bag
  * @param Knp\FriendlyContexts\Record\Collection $collection
  * @param Knp\FriendlyContexts\Record\Record $record1
  * @param Knp\FriendlyContexts\Record\Record $record2
  * @param Knp\FriendlyContexts\Utils\Asserter $asserter
  * @param \ReflectionClass $reflectionClass
  **/
 function let($container, $doctrine, $manager, $repository, $queryBuilder, $query, $resolver, $bag, $collection, \ReflectionClass $reflectionClass, $asserter, $record1, $record2, $entity1, $entity2, $entity3)
 {
     $entity1 = 'e1';
     $entity2 = 'e2';
     $entity3 = 'e3';
     $doctrine->getManager()->willReturn($manager);
     $manager->getRepository(Argument::any())->willReturn($repository);
     $repository->createQueryBuilder(Argument::any())->willReturn($queryBuilder);
     $queryBuilder->getQuery()->willReturn($query);
     $queryBuilder->resetDQLParts()->willReturn($queryBuilder);
     $queryBuilder->select('o')->willReturn($queryBuilder);
     $queryBuilder->from(Argument::cetera())->willReturn($queryBuilder);
     $query->getResult()->willReturn([$entity1, $entity2, $entity3]);
     $resolver->resolve($manager, 'entities', Argument::cetera())->willReturn([$reflectionClass]);
     $bag->getCollection(Argument::any())->willReturn($collection);
     $collection->all()->willReturn([$record1, $record2]);
     $collection->attach(Argument::cetera())->willReturn(null);
     $record1->getEntity()->willReturn($entity1);
     $record2->getEntity()->willReturn($entity2);
     $container->has(Argument::any())->willReturn(true);
     $container->get('doctrine')->willReturn($doctrine);
     $container->get('friendly.entity.resolver')->willReturn($resolver);
     $container->get('friendly.entity.resolver')->willReturn($resolver);
     $container->get('friendly.record.bag')->willReturn($bag);
     $container->get('friendly.asserter')->willReturn(new Asserter(new TextFormater()));
     $container->hasParameter('friendly.entities.namespaces')->willReturn(true);
     $container->getParameter('friendly.entities.namespaces')->willReturn([]);
     $this->initialize([], $container);
 }
 public function testParseToArray()
 {
     $structureGenerator = $this->container->get('seg.structure_generator');
     $result = $structureGenerator->parseToArray(Helper::getStructureYaml());
     $this->assertEquals(2, count($result));
     $classesManagers = $structureGenerator->buildEntitiesClassStructure($result);
     $this->assertEquals(2, count($classesManagers));
     foreach ($classesManagers as $classManager) {
         $this->checkCommonClassManager($classManager);
     }
     $userEntity = $classesManagers[0];
     $this->assertEquals(7, $userEntity->getProperties()->count());
     $this->assertEquals(15, $userEntity->getMethods()->count());
     // getters + setters + boolean
     $userEntityInterface = $userEntity->getInterface();
     $this->assertEquals(15, $userEntityInterface->getMethods()->count());
     $userEntityTestClass = $userEntity->getTestClass();
     $this->assertEquals(15, $userEntityTestClass->getMethods()->count());
     $postEntity = $classesManagers[1];
     $this->assertEquals(3, $postEntity->getProperties()->count());
     $this->assertEquals(6, $postEntity->getMethods()->count());
     // getters + setters
     $postEntityInterface = $postEntity->getInterface();
     $this->assertEquals(6, $postEntityInterface->getMethods()->count());
     $postEntityTestClass = $postEntity->getTestClass();
     $this->assertEquals(6, $postEntityTestClass->getMethods()->count());
 }
 /**
  * @param Symfony\Component\DependencyInjection\ContainerInterface $container
  * @param Knp\FriendlyContexts\Page\Resolver\PageClassResolver     $pageResolver
  * @param Behat\Mink\Mink                                          $mink
  * @param Behat\Mink\Session                                       $session
  */
 function let($container, $pageResolver, $mink, $session)
 {
     $container->get('friendly.page.resolver')->willReturn($pageResolver);
     $container->has('friendly.page.resolver')->willReturn(true);
     $this->initialize(['page' => ['namespace' => 'Page\\Namespace']], $container);
     $mink->getSession(Argument::cetera())->willReturn($session);
     $this->setMink($mink);
 }
Beispiel #4
0
 /**
  * @param Symfony\Component\DependencyInjection\ContainerInterface $initialControllerInstance
  * @param string $controllerName
  * @param string $actionName
  * @param array $params
  * @see \Ajax\JsUtils::forward()
  */
 public function forward($initialControllerInstance, $controllerName, $actionName, $params = array())
 {
     $path = $params;
     $request = $initialControllerInstance->get('request_stack')->getCurrentRequest();
     $path['_forwarded'] = $request->attributes;
     $path['_controller'] = $controllerName . ":" . $actionName;
     $subRequest = $request->duplicate([], null, $path);
     $response = $initialControllerInstance->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     return $response->getContent();
 }
 /**
  * 
  * Search restaurants
  * 
  * @param Symfony\Component\HttpFoundation\Request $request
  * @param Symfony\Component\DependencyInjection\ContainerInterface $container
  * 
  * @return \Doctrine\ORM\QueryBuilder
  */
 public function searchRestaurants($request, $container)
 {
     // collect parametres
     $query = $this->createQueryBuilder('restaurant');
     $searchStr = $request->request->get('restaurantSearchStr');
     $categoriesList = $request->request->get('restaurantCategoryList');
     $kitchensList = $request->request->get('restaurantKitchenList');
     $searchCity = $request->request->get('searchCity');
     // set dependency with category and kitchen entitues
     if (!is_null($categoriesList) || !is_null($kitchensList) || $searchStr != "") {
         $query->leftJoin('restaurant.categories', 'category', 'ON restaurant.id = category.id')->leftJoin('restaurant.kitchens', 'kitchen', 'ON restaurant.id = kitchen.id');
     }
     if (!is_null($searchCity) && $searchCity != "") {
         $query->andWhere("restaurant.city = :searchCity")->setParameter('searchCity', $searchCity);
     }
     if (!is_null($searchStr) && $searchStr != "") {
         $searchStrEn = $container->get('common_manager')->translit($searchStr);
         $searchStrRu = $container->get('common_manager')->reverseTranslit($searchStr);
         // using it only in restaurant name
         $searchStrAlternative = $container->get('common_manager')->translateUsingAlternativeAlphabet($searchStr);
         $query->leftJoin('restaurant.city', 'city');
         // format query
         $queryString = "restaurant.name like :searchStr or " . "city.name like :searchStr or " . "restaurant.street like :searchStr or " . "category.name like :searchStr or " . "kitchen.name like :searchStr or ";
         if ($searchStrRu != $searchStr) {
             $queryString .= "restaurant.name like :searchStrRu or " . "city.name like :searchStrRu or " . "restaurant.street like :searchStrRu or " . "category.name like :searchStrRu or " . "kitchen.name like :searchStrRu or ";
         }
         if ($searchStrEn != $searchStr) {
             $queryString .= "restaurant.name like :searchStrEn or " . "city.name like :searchStrEn or " . "restaurant.street like :searchStrEn or " . "category.name like :searchStrEn or " . "kitchen.name like :searchStrEn or ";
         }
         $queryString .= "restaurant.name like :searchStrAlternative";
         $query->andWhere($queryString)->setParameter('searchStr', "%{$searchStr}%");
         if ($searchStrRu != $searchStr) {
             $query->setParameter('searchStrRu', "%{$searchStrRu}%");
         }
         if ($searchStrEn != $searchStr) {
             $query->setParameter('searchStrEn', "%{$searchStrEn}%");
         }
         $query->setParameter('searchStrAlternative', "%{$searchStrAlternative}%");
     }
     if (!is_null($categoriesList) && !empty($categoriesList)) {
         $query->andWhere($query->expr()->in('category.id', $categoriesList));
     }
     if (!is_null($kitchensList) && !empty($kitchensList)) {
         $query->andWhere($query->expr()->in('kitchen.id', $kitchensList));
     }
     $query->orderBy('restaurant.rating', 'DESC');
     return $query;
 }
 /**
  * @param Symfony\Component\DependencyInjection\ContainerInterface $container
  * @param Doctrine\Common\Persistence\ManagerRegistry $doctrine
  * @param Doctrine\Common\Persistence\ObjectManager $manager
  * @param Behat\Behat\Hook\Scope\ScenarioScope $event
  * @param Behat\Gherkin\Node\FeatureNode $feature
  * @param Behat\Gherkin\Node\ScenarioNode $scenario
  * @param Knp\FriendlyContexts\Alice\Loader\Yaml $loader
  **/
 function let($container, $doctrine, $manager, $event, $loader, $feature, $scenario)
 {
     $doctrine->getManager()->willReturn($manager);
     $feature->getTags()->willReturn(['alice(Place)', 'admin']);
     $scenario->getTags()->willReturn(['alice(User)']);
     $event->getFeature()->willReturn($feature);
     $event->getScenario()->willReturn($scenario);
     $loader->load('user.yml')->willReturn([]);
     $loader->load('product.yml')->willReturn([]);
     $loader->load('place.yml')->willReturn([]);
     $loader->getCache()->willReturn([]);
     $loader->clearCache()->willReturn(null);
     $fixtures = ['User' => 'user.yml', 'Product' => 'product.yml', 'Place' => 'place.yml'];
     $config = ['alice' => ['fixtures' => $fixtures, 'dependencies' => []]];
     $container->has(Argument::any())->willReturn(true);
     $container->hasParameter(Argument::any())->willReturn(true);
     $container->get('friendly.alice.loader.yaml')->willReturn($loader);
     $container->get('doctrine')->willReturn($doctrine);
     $container->getParameter('friendly.alice.fixtures')->willReturn($fixtures);
     $container->getParameter('friendly.alice.dependencies')->willReturn([]);
     $this->initialize($config, $container);
 }
 /**
  * @return \Symfony\Component\HttpKernel\KernelInterface
  */
 private function getKernel()
 {
     return $this->container->get('kernel');
 }