/** * @return TicketTimeline|null|object */ protected function getCurrentDayRecord() { if ($this->currentDayRecord) { return $this->currentDayRecord; } $date = new \DateTime('now', new \DateTimeZone('UTC')); $date->setTime(0, 0, 0); $this->currentDayRecord = $this->timelineRepository->findOneBy(['date' => $date]); if (!$this->currentDayRecord) { $this->currentDayRecord = new TicketTimeline($date); } return $this->currentDayRecord; }
/** * @test */ public function testBranchesAreFiltered() { $branches = array(new Branch('DUMM', 'DUMMY_NAME_1', 'DUMMY_DESC_1'), new Branch('DUMMY', 'DUMMY_NAME_2', 'DUMMY_DESC_2')); $pagingInfo = new PagingInfo(1, new FilterPagingProperties()); $command = new FilterBranchesCommand(); $command->name = 'NAME_2'; $this->branchRepository->expects($this->once())->method('filter')->with($this->equalTo(array(array('name', 'like', 'NAME_2'))), $this->equalTo(new FilterPagingProperties()))->will($this->returnValue(array($branches[0]))); $this->apiPagingService->expects($this->once())->method('getPagingInfo')->will($this->returnValue($pagingInfo)); $retrievedBranches = $this->branchServiceImpl->listAllBranches($command); $this->assertNotNull($retrievedBranches); $this->assertTrue(is_array($retrievedBranches)); $this->assertNotEmpty($retrievedBranches); $this->assertEquals($branches[0], $retrievedBranches[0]); }
/** * @test */ public function thatFilters() { $a = new EntityStub(); $b = new EntityStub(); $a->name = "DUMMY_NAME"; $a->id = 1; $b->name = "NOT_DUMMY_NAME"; $b->id = 2; $entities = array($a, $b); $pagingConfig = new FilterPagingProperties(); $conditions = array(array('name', 'eq', 'DUMMY_NAME')); $whereExpr = new \Doctrine\ORM\Query\Expr\Comparison('e.name', 'eq', "'DUMMY_NAME'"); $this->em->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder)); $this->queryBuilder->expects($this->once())->method('select')->with($this->equalTo('e'))->will($this->returnValue($this->queryBuilder)); $this->queryBuilder->expects($this->once())->method('from')->with($this->equalTo($this->classMetadata->name), $this->equalTo('e'))->will($this->returnValue($this->queryBuilder)); $this->queryBuilder->expects($this->atLeastOnce())->method('andWhere')->with($this->equalTo($whereExpr))->will($this->returnValue($this->queryBuilder)); $this->queryBuilder->expects($this->once())->method('addOrderBy')->with($this->equalTo('e.id'), $this->equalTo($pagingConfig->getOrder()))->will($this->returnValue($this->queryBuilder)); $this->queryBuilder->expects($this->once())->method('setFirstResult')->with($this->equalTo(0))->will($this->returnValue($this->queryBuilder)); $this->queryBuilder->expects($this->once())->method('setMaxResults')->with($this->equalTo($pagingConfig->getLimit()))->will($this->returnValue($this->queryBuilder)); $this->queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($this->filterQuery)); $this->queryBuilder->expects($this->any())->method('expr')->will($this->returnValue($this->expressionBuilder)); $this->em->expects($this->any())->method('getExpressionBuilder')->will($this->returnValue($this->expressionBuilder)); $this->expressionBuilder->expects($this->atLeastOnce())->method('literal')->with($this->equalTo('DUMMY_NAME'))->will($this->returnValue("'DUMMY_NAME'")); $this->expressionBuilder->expects($this->atLeastOnce())->method('eq')->with($this->equalTo('e.name'), $this->equalTo("'DUMMY_NAME'"))->will($this->returnValue($whereExpr)); $this->em->expects($this->atLeastOnce())->method('newHydrator')->with($this->equalTo(Query::HYDRATE_OBJECT))->will($this->returnValue($this->objectHydrator)); $this->objectHydrator->expects($this->atLeastOnce())->method('hydrateAll')->will($this->returnValue(array($a))); $filteredEntities = $this->repository->filter($conditions, $pagingConfig); $this->assertNotNull($filteredEntities); $this->assertTrue(is_array($filteredEntities)); $this->assertNotEmpty($filteredEntities); $this->assertEquals($a, $filteredEntities[0]); }
/** * Delete Article * @param int $articleId * @return void */ public function deleteArticle($articleId) { /** @var Article $article */ $article = $this->repository->get($articleId); if (is_null($article)) { throw new ArticleNotFoundException(); } $this->repository->remove($article); }
public function testCommentsFiltered() { $comments = array(new Comment("DUMMY_CONTENT_1", $this->_dummyTicket, $this->createAuthor(), false), new Comment("DUMMY_CONTENT_2", $this->_dummyTicket, $this->createAuthor(), false)); $command = new FilterCommentsCommand(); $command->author = 'oro_1'; $pagingInfo = new PagingInfo(1, new FilterPagingProperties()); $this->commentRepository->expects($this->once())->method('filter')->with($this->equalTo(array(array('author', 'eq', 'oro_1'))), $this->equalTo(new FilterPagingProperties()))->will($this->returnValue(array($comments[1]))); $this->apiPagingService->expects($this->once())->method('getPagingInfo')->will($this->returnValue($pagingInfo)); $retrievedComments = $this->service->listAllComments($command); $this->assertNotNull($retrievedComments); $this->assertTrue(is_array($retrievedComments)); $this->assertNotEmpty($retrievedComments); $this->assertEquals($comments[1], $retrievedComments[0]); }
/** * @@param MoveTicketCommand $command * @return void * @throws \RuntimeException if unable to load required ticket */ public function moveTicket(MoveTicketCommand $command) { $ticket = $this->loadTicketById($command->id); $this->ticketHistoryRepository->store(new TicketHistory($ticket->getId(), $ticket->getKey())); $ticket->move($command->branch); $this->ticketRepository->store($ticket); //Remove old key from history to prevent loop redirects if ($oldHistory = $this->ticketHistoryRepository->findOneByTicketKey($ticket->getKey())) { $this->ticketHistoryRepository->remove($oldHistory); } $this->dispatchEvents($ticket); }