Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF][Symfony2][Symfony]problem z testowaniem usług / service
szypi1989
post
Post #1





Grupa: Zarejestrowani
Postów: 207
Pomógł: 0
Dołączył: 7.09.2010

Ostrzeżenie: (0%)
-----


Mam nadzieje, że mnie zrozumiecie. Otóż mam problem z testowaniem service . Te service ma parametry , które są wstrzykiwane . Znów te service składa się 2 następnych service (bo one tam do tego głównego service są wstrzykiwane).
Te 2 następne service znów mają jakieś elementy wstrzykiwane . I irytuje mnie to , że muszę jawnie tak wrzucać paramtery / obiekty, bo w testach nie można wstrzykiwać. Czy istnieje jakiś sposób aby to obejść?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
szypi1989
post
Post #2





Grupa: Zarejestrowani
Postów: 207
Pomógł: 0
Dołączył: 7.09.2010

Ostrzeżenie: (0%)
-----


No super . Dzięki. A wiesz może jak przetestować funkcję , która używa danych z requesta? Bo wtedy test mi wrzuca błąd ponieważ żadne dane nie są wysyłane?
Nie wiem , czy wiesz o co chodzi .
Mam tutaj dla przykładu kawałek klasy service:
  1. class FetchMsgSql {
  2.  
  3. protected $entityManager;
  4. protected $qb;
  5. protected $parameters;
  6. protected $array_par;
  7. private $requestStack;
  8.  
  9. public function __construct(EntityManager $em, RequestStack $requestStack) {
  10. $this->requestStack = $requestStack;
  11. $this->entityManager = $em;
  12. $this->qb = $em->createQueryBuilder();
  13. }
  14.  
  15. // create results based on data from the request table
  16. // converting data to the form of query
  17. public function getSql() {
  18. $this->qb->select('a')->from('AppBundle:Cars', 'a');
  19. // starts the build_condition function if a query was sent from the searchAction action and the knppaginaton object uses the search function
  20. // search == 1 -> when you view the pages by knppagination and knppagination is supposed to store the results
  21. // search == 1 -> results from the request table are attached during the search engine save in the sortable_link.html view
  22. (($this->requestStack->getCurrentRequest()->query->get('search') == "1") || ($this->requestStack->getCurrentRequest()->getRealMethod() == 'POST') ) ? $this->qb->setParameters($this->build_condition()) : NULL;
  23. $dql = $this->qb->getQuery()->getDQL();
  24. //< convert the dql object to the query form
  25. foreach ($this->qb->getParameters() as $index => $param) {
  26. $dql = str_replace(":" . $param->getName(), $param->getValue(), $dql);
  27. $dql = str_replace("LIKE " . $param->getValue(), "LIKE '" . $param->getValue() . "'", $dql);
  28. }
  29. // >
  30. $query = $this->entityManager->createQuery($dql);
  31. return $query;
  32. }


I Chciałbym przetestować funkcję getSql() . No ale w testach nie mogę, bo nie mam tych danych z requestu. Musiałbym jakoś je ustawić wcześniej .
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 4.10.2025 - 15:21