How to use shouldBeCalled method of or class

Best Prophecy code snippet using or.shouldBeCalled

QueryBuilderTest.php

Source:QueryBuilderTest.php Github

copy

Full Screen

...61 */62 public function exprReturnsExpressionBuilderForConnection()63 {64 $this->connection->getExpressionBuilder()65 ->shouldBeCalled()66 ->willReturn(GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal()));67 $this->subject->expr();68 }69 /**70 * @test71 */72 public function getTypeDelegatesToConcreteQueryBuilder()73 {74 $this->concreteQueryBuilder->getType()75 ->shouldBeCalled()76 ->willReturn(\Doctrine\DBAL\Query\QueryBuilder::INSERT);77 $this->subject->getType();78 }79 /**80 * @test81 */82 public function getStateDelegatesToConcreteQueryBuilder()83 {84 $this->concreteQueryBuilder->getState()85 ->shouldBeCalled()86 ->willReturn(\Doctrine\DBAL\Query\QueryBuilder::STATE_CLEAN);87 $this->subject->getState();88 }89 /**90 * @test91 */92 public function getSQLDelegatesToConcreteQueryBuilder()93 {94 $this->concreteQueryBuilder->getSQL()95 ->shouldBeCalled()96 ->willReturn('UPDATE aTable SET pid = 7');97 $this->concreteQueryBuilder->getType()98 ->willReturn(2); // Update Type99 $this->subject->getSQL();100 }101 /**102 * @test103 */104 public function setParameterDelegatesToConcreteQueryBuilder()105 {106 $this->concreteQueryBuilder->setParameter(Argument::exact('aField'), Argument::exact(5), Argument::cetera())107 ->shouldBeCalled()108 ->willReturn($this->subject);109 $this->subject->setParameter('aField', 5);110 }111 /**112 * @test113 */114 public function setParametersDelegatesToConcreteQueryBuilder()115 {116 $this->concreteQueryBuilder->setParameters(Argument::exact(['aField' => 'aValue']), Argument::exact([]))117 ->shouldBeCalled()118 ->willReturn($this->subject);119 $this->subject->setParameters(['aField' => 'aValue']);120 }121 /**122 * @test123 */124 public function getParametersDelegatesToConcreteQueryBuilder()125 {126 $this->concreteQueryBuilder->getParameters()127 ->shouldBeCalled()128 ->willReturn(['aField' => 'aValue']);129 $this->subject->getParameters();130 }131 /**132 * @test133 */134 public function getParameterDelegatesToConcreteQueryBuilder()135 {136 $this->concreteQueryBuilder->getParameter(Argument::exact('aField'))137 ->shouldBeCalled()138 ->willReturn('aValue');139 $this->subject->getParameter('aField');140 }141 /**142 * @test143 */144 public function getParameterTypesDelegatesToConcreteQueryBuilder()145 {146 $this->concreteQueryBuilder->getParameterTypes()147 ->shouldBeCalled()148 ->willReturn([]);149 $this->subject->getParameterTypes();150 }151 /**152 * @test153 */154 public function getParameterTypeDelegatesToConcreteQueryBuilder()155 {156 $this->concreteQueryBuilder->getParameterType(Argument::exact('aField'))157 ->shouldBeCalled()158 ->willReturn(Connection::PARAM_STR);159 $this->subject->getParameterType('aField');160 }161 /**162 * @test163 */164 public function setFirstResultDelegatesToConcreteQueryBuilder()165 {166 $this->concreteQueryBuilder->setFirstResult(Argument::cetera())167 ->shouldBeCalled()168 ->willReturn($this->subject);169 $this->subject->setFirstResult(1);170 }171 /**172 * @test173 */174 public function getFirstResultDelegatesToConcreteQueryBuilder()175 {176 $this->concreteQueryBuilder->getFirstResult()177 ->shouldBeCalled()178 ->willReturn(1);179 $this->subject->getFirstResult();180 }181 /**182 * @test183 */184 public function setMaxResultsDelegatesToConcreteQueryBuilder()185 {186 $this->concreteQueryBuilder->setMaxResults(Argument::cetera())187 ->shouldBeCalled()188 ->willReturn($this->subject);189 $this->subject->setMaxResults(1);190 }191 /**192 * @test193 */194 public function getMaxResultsDelegatesToConcreteQueryBuilder()195 {196 $this->concreteQueryBuilder->getMaxResults()197 ->shouldBeCalled()198 ->willReturn(1);199 $this->subject->getMaxResults();200 }201 /**202 * @test203 */204 public function addDelegatesToConcreteQueryBuilder()205 {206 $this->concreteQueryBuilder->add(Argument::exact('select'), Argument::exact('aField'), Argument::cetera())207 ->shouldBeCalled()208 ->willReturn($this->subject);209 $this->subject->add('select', 'aField');210 }211 /**212 * @test213 */214 public function countBuildsExpressionAndCallsSelect()215 {216 $this->concreteQueryBuilder->select(Argument::exact('COUNT(*)'))217 ->shouldBeCalled()218 ->willReturn($this->subject);219 $this->subject->count('*');220 }221 /**222 * @test223 */224 public function selectQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()225 {226 $this->connection->quoteIdentifier('aField')227 ->shouldBeCalled()228 ->willReturnArgument(0);229 $this->connection->quoteIdentifier('anotherField')230 ->shouldBeCalled()231 ->willReturnArgument(0);232 $this->concreteQueryBuilder->select(Argument::exact('aField'), Argument::exact('anotherField'))233 ->shouldBeCalled()234 ->willReturn($this->subject);235 $this->subject->select('aField', 'anotherField');236 }237 public function quoteIdentifiersForSelectDataProvider()238 {239 return [240 'fieldName' => [241 'fieldName',242 '"fieldName"',243 ],244 'tableName.fieldName' => [245 'tableName.fieldName',246 '"tableName"."fieldName"',247 ],248 'tableName.*' => [249 'tableName.*',250 '"tableName".*',251 ],252 '*' => [253 '*',254 '*',255 ],256 'fieldName AS anotherFieldName' => [257 'fieldName AS anotherFieldName',258 '"fieldName" AS "anotherFieldName"',259 ],260 'tableName.fieldName AS anotherFieldName' => [261 'tableName.fieldName AS anotherFieldName',262 '"tableName"."fieldName" AS "anotherFieldName"',263 ],264 'tableName.fieldName AS anotherTable.anotherFieldName' => [265 'tableName.fieldName AS anotherTable.anotherFieldName',266 '"tableName"."fieldName" AS "anotherTable"."anotherFieldName"',267 ],268 ];269 }270 /**271 * @test272 * @dataProvider quoteIdentifiersForSelectDataProvider273 * @param string $identifier274 * @param string $expectedResult275 */276 public function quoteIdentifiersForSelect($identifier, $expectedResult)277 {278 $this->connection->quoteIdentifier(Argument::cetera())->will(279 function ($args) {280 $platform = new MockPlatform();281 return $platform->quoteIdentifier($args[0]);282 }283 );284 $this->assertSame([$expectedResult], $this->subject->quoteIdentifiersForSelect([$identifier]));285 }286 /**287 * @test288 */289 public function quoteIdentifiersForSelectWithInvalidAlias()290 {291 $this->expectException(\InvalidArgumentException::class);292 $this->expectExceptionCode(1461170686);293 $this->connection->quoteIdentifier(Argument::cetera())->will(294 function ($args) {295 $platform = new MockPlatform();296 return $platform->quoteIdentifier($args[0]);297 }298 );299 $this->subject->quoteIdentifiersForSelect(['aField AS anotherField,someField AS someThing']);300 }301 /**302 * @test303 */304 public function selectDoesNotQuoteStarPlaceholder()305 {306 $this->connection->quoteIdentifier('aField')307 ->shouldBeCalled()308 ->willReturnArgument(0);309 $this->connection->quoteIdentifier('*')310 ->shouldNotBeCalled();311 $this->concreteQueryBuilder->select(Argument::exact('aField'), Argument::exact('*'))312 ->shouldBeCalled()313 ->willReturn($this->subject);314 $this->subject->select('aField', '*');315 }316 /**317 * @test318 */319 public function addSelectQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()320 {321 $this->connection->quoteIdentifier('aField')322 ->shouldBeCalled()323 ->willReturnArgument(0);324 $this->connection->quoteIdentifier('anotherField')325 ->shouldBeCalled()326 ->willReturnArgument(0);327 $this->concreteQueryBuilder->addSelect(Argument::exact('aField'), Argument::exact('anotherField'))328 ->shouldBeCalled()329 ->willReturn($this->subject);330 $this->subject->addSelect('aField', 'anotherField');331 }332 /**333 * @test334 */335 public function addSelectDoesNotQuoteStarPlaceholder()336 {337 $this->connection->quoteIdentifier('aField')338 ->shouldBeCalled()339 ->willReturnArgument(0);340 $this->connection->quoteIdentifier('*')341 ->shouldNotBeCalled();342 $this->concreteQueryBuilder->addSelect(Argument::exact('aField'), Argument::exact('*'))343 ->shouldBeCalled()344 ->willReturn($this->subject);345 $this->subject->addSelect('aField', '*');346 }347 /**348 * @test349 */350 public function selectLiteralDirectlyDelegatesToConcreteQueryBuilder()351 {352 $this->connection->quoteIdentifier(Argument::cetera())353 ->shouldNotBeCalled();354 $this->concreteQueryBuilder->select(Argument::exact('MAX(aField) AS anAlias'))355 ->shouldBeCalled()356 ->willReturn($this->subject);357 $this->subject->selectLiteral('MAX(aField) AS anAlias');358 }359 /**360 * @test361 */362 public function addSelectLiteralDirectlyDelegatesToConcreteQueryBuilder()363 {364 $this->connection->quoteIdentifier(Argument::cetera())365 ->shouldNotBeCalled();366 $this->concreteQueryBuilder->addSelect(Argument::exact('MAX(aField) AS anAlias'))367 ->shouldBeCalled()368 ->willReturn($this->subject);369 $this->subject->addSelectLiteral('MAX(aField) AS anAlias');370 }371 /**372 * @test373 * @todo: Test with alias374 */375 public function deleteQuotesIdentifierAndDelegatesToConcreteQueryBuilder()376 {377 $this->connection->quoteIdentifier('aTable')378 ->shouldBeCalled()379 ->willReturnArgument(0);380 $this->concreteQueryBuilder->delete(Argument::exact('aTable'), Argument::cetera())381 ->shouldBeCalled()382 ->willReturn($this->subject);383 $this->subject->delete('aTable');384 }385 /**386 * @test387 * @todo: Test with alias388 */389 public function updateQuotesIdentifierAndDelegatesToConcreteQueryBuilder()390 {391 $this->connection->quoteIdentifier('aTable')392 ->shouldBeCalled()393 ->willReturnArgument(0);394 $this->concreteQueryBuilder->update(Argument::exact('aTable'), Argument::cetera())395 ->shouldBeCalled()396 ->willReturn($this->subject);397 $this->subject->update('aTable');398 }399 /**400 * @test401 */402 public function insertQuotesIdentifierAndDelegatesToConcreteQueryBuilder()403 {404 $this->connection->quoteIdentifier('aTable')405 ->shouldBeCalled()406 ->willReturnArgument(0);407 $this->concreteQueryBuilder->insert(Argument::exact('aTable'))408 ->shouldBeCalled()409 ->willReturn($this->subject);410 $this->subject->insert('aTable');411 }412 /**413 * @test414 * @todo: Test with alias415 */416 public function fromQuotesIdentifierAndDelegatesToConcreteQueryBuilder()417 {418 $this->connection->quoteIdentifier('aTable')419 ->shouldBeCalled()420 ->willReturnArgument(0);421 $this->concreteQueryBuilder->from(Argument::exact('aTable'), Argument::cetera())422 ->shouldBeCalled()423 ->willReturn($this->subject);424 $this->subject->from('aTable');425 }426 /**427 * @test428 */429 public function joinQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()430 {431 $this->connection->quoteIdentifier('fromAlias')432 ->shouldBeCalled()433 ->willReturnArgument(0);434 $this->connection->quoteIdentifier('join')435 ->shouldBeCalled()436 ->willReturnArgument(0);437 $this->connection->quoteIdentifier('alias')438 ->shouldBeCalled()439 ->willReturnArgument(0);440 $this->concreteQueryBuilder->innerJoin('fromAlias', 'join', 'alias', null)441 ->shouldBeCalled()442 ->willReturn($this->subject);443 $this->subject->join('fromAlias', 'join', 'alias');444 }445 /**446 * @test447 */448 public function innerJoinQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()449 {450 $this->connection->quoteIdentifier('fromAlias')451 ->shouldBeCalled()452 ->willReturnArgument(0);453 $this->connection->quoteIdentifier('join')454 ->shouldBeCalled()455 ->willReturnArgument(0);456 $this->connection->quoteIdentifier('alias')457 ->shouldBeCalled()458 ->willReturnArgument(0);459 $this->concreteQueryBuilder->innerJoin('fromAlias', 'join', 'alias', null)460 ->shouldBeCalled()461 ->willReturn($this->subject);462 $this->subject->innerJoin('fromAlias', 'join', 'alias');463 }464 /**465 * @test466 */467 public function leftJoinQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()468 {469 $this->connection->quoteIdentifier('fromAlias')470 ->shouldBeCalled()471 ->willReturnArgument(0);472 $this->connection->quoteIdentifier('join')473 ->shouldBeCalled()474 ->willReturnArgument(0);475 $this->connection->quoteIdentifier('alias')476 ->shouldBeCalled()477 ->willReturnArgument(0);478 $this->concreteQueryBuilder->leftJoin('fromAlias', 'join', 'alias', null)479 ->shouldBeCalled()480 ->willReturn($this->subject);481 $this->subject->leftJoin('fromAlias', 'join', 'alias');482 }483 /**484 * @test485 */486 public function rightJoinQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()487 {488 $this->connection->quoteIdentifier('fromAlias')489 ->shouldBeCalled()490 ->willReturnArgument(0);491 $this->connection->quoteIdentifier('join')492 ->shouldBeCalled()493 ->willReturnArgument(0);494 $this->connection->quoteIdentifier('alias')495 ->shouldBeCalled()496 ->willReturnArgument(0);497 $this->concreteQueryBuilder->rightJoin('fromAlias', 'join', 'alias', null)498 ->shouldBeCalled()499 ->willReturn($this->subject);500 $this->subject->rightJoin('fromAlias', 'join', 'alias');501 }502 /**503 * @test504 */505 public function setQuotesIdentifierAndDelegatesToConcreteQueryBuilder()506 {507 $this->connection->quoteIdentifier('aField')508 ->shouldBeCalled()509 ->willReturnArgument(0);510 $this->concreteQueryBuilder->createNamedParameter('aValue', Argument::cetera())511 ->shouldBeCalled()512 ->willReturn(':dcValue1');513 $this->concreteQueryBuilder->set('aField', ':dcValue1')514 ->shouldBeCalled()515 ->willReturn($this->subject);516 $this->subject->set('aField', 'aValue');517 }518 /**519 * @test520 */521 public function setWithoutNamedParameterQuotesIdentifierAndDelegatesToConcreteQueryBuilder()522 {523 $this->connection->quoteIdentifier('aField')524 ->shouldBeCalled()525 ->willReturnArgument(0);526 $this->concreteQueryBuilder->createNamedParameter(Argument::cetera())->shouldNotBeCalled();527 $this->concreteQueryBuilder->set('aField', 'aValue')528 ->shouldBeCalled()529 ->willReturn($this->subject);530 $this->subject->set('aField', 'aValue', false);531 }532 /**533 * @test534 */535 public function whereDelegatesToConcreteQueryBuilder()536 {537 $this->concreteQueryBuilder->where('uid=1', 'type=9')538 ->shouldBeCalled()539 ->willReturn($this->subject);540 $this->subject->where('uid=1', 'type=9');541 }542 /**543 * @test544 */545 public function andWhereDelegatesToConcreteQueryBuilder()546 {547 $this->concreteQueryBuilder->andWhere('uid=1', 'type=9')548 ->shouldBeCalled()549 ->willReturn($this->subject);550 $this->subject->andWhere('uid=1', 'type=9');551 }552 /**553 * @test554 */555 public function orWhereDelegatesToConcreteQueryBuilder()556 {557 $this->concreteQueryBuilder->orWhere('uid=1', 'type=9')558 ->shouldBeCalled()559 ->willReturn($this->subject);560 $this->subject->orWhere('uid=1', 'type=9');561 }562 /**563 * @test564 */565 public function groupByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()566 {567 $this->connection->quoteIdentifiers(['aField', 'anotherField'])568 ->shouldBeCalled()569 ->willReturnArgument(0);570 $this->concreteQueryBuilder->groupBy('aField', 'anotherField')571 ->shouldBeCalled()572 ->willReturn($this->subject);573 $this->subject->groupBy('aField', 'anotherField');574 }575 /**576 * @test577 */578 public function addGroupByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()579 {580 $this->connection->quoteIdentifiers(['aField', 'anotherField'])581 ->shouldBeCalled()582 ->willReturnArgument(0);583 $this->concreteQueryBuilder->addGroupBy('aField', 'anotherField')584 ->shouldBeCalled()585 ->willReturn($this->subject);586 $this->subject->addGroupBy('aField', 'anotherField');587 }588 /**589 * @test590 */591 public function setValueQuotesIdentifierAndDelegatesToConcreteQueryBuilder()592 {593 $this->connection->quoteIdentifier('aField')594 ->shouldBeCalled()595 ->willReturnArgument(0);596 $this->concreteQueryBuilder->createNamedParameter('aValue', Argument::cetera())597 ->shouldBeCalled()598 ->willReturn(':dcValue1');599 $this->concreteQueryBuilder->setValue('aField', ':dcValue1')600 ->shouldBeCalled()601 ->willReturn($this->subject);602 $this->subject->setValue('aField', 'aValue');603 }604 /**605 * @test606 */607 public function setValueWithoudNamedParameterQuotesIdentifierAndDelegatesToConcreteQueryBuilder()608 {609 $this->connection->quoteIdentifier('aField')610 ->shouldBeCalled()611 ->willReturnArgument(0);612 $this->concreteQueryBuilder->setValue('aField', 'aValue')613 ->shouldBeCalled()614 ->willReturn($this->subject);615 $this->subject->setValue('aField', 'aValue', false);616 }617 /**618 * @test619 */620 public function valuesQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()621 {622 $this->connection->quoteColumnValuePairs(['aField' => ':dcValue1', 'aValue' => ':dcValue2'])623 ->shouldBeCalled()624 ->willReturnArgument(0);625 $this->concreteQueryBuilder->createNamedParameter(1, Argument::cetera())626 ->shouldBeCalled()627 ->willReturn(':dcValue1');628 $this->concreteQueryBuilder->createNamedParameter(2, Argument::cetera())629 ->shouldBeCalled()630 ->willReturn(':dcValue2');631 $this->concreteQueryBuilder->values(['aField' => ':dcValue1', 'aValue' => ':dcValue2'])632 ->shouldBeCalled()633 ->willReturn($this->subject);634 $this->subject->values(['aField' => 1, 'aValue' => 2]);635 }636 /**637 * @test638 */639 public function valuesWithoutNamedParametersQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()640 {641 $this->connection->quoteColumnValuePairs(['aField' => 1, 'aValue' => 2])642 ->shouldBeCalled()643 ->willReturnArgument(0);644 $this->concreteQueryBuilder->values(['aField' => 1, 'aValue' => 2])645 ->shouldBeCalled()646 ->willReturn($this->subject);647 $this->subject->values(['aField' => 1, 'aValue' => 2], false);648 }649 /**650 * @test651 */652 public function havingDelegatesToConcreteQueryBuilder()653 {654 $this->concreteQueryBuilder->having('uid=1', 'type=9')655 ->shouldBeCalled()656 ->willReturn($this->subject);657 $this->subject->having('uid=1', 'type=9');658 }659 /**660 * @test661 */662 public function andHavingDelegatesToConcreteQueryBuilder()663 {664 $this->concreteQueryBuilder->andHaving('uid=1', 'type=9')665 ->shouldBeCalled()666 ->willReturn($this->subject);667 $this->subject->andHaving('uid=1', 'type=9');668 }669 /**670 * @test671 */672 public function orHavingDelegatesToConcreteQueryBuilder()673 {674 $this->concreteQueryBuilder->orHaving('uid=1', 'type=9')675 ->shouldBeCalled()676 ->willReturn($this->subject);677 $this->subject->orHaving('uid=1', 'type=9');678 }679 /**680 * @test681 */682 public function orderByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()683 {684 $this->connection->quoteIdentifier('aField')685 ->shouldBeCalled()686 ->willReturnArgument(0);687 $this->concreteQueryBuilder->orderBy('aField', null)688 ->shouldBeCalled()689 ->willReturn($this->subject);690 $this->subject->orderBy('aField');691 }692 /**693 * @test694 */695 public function addOrderByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()696 {697 $this->connection->quoteIdentifier('aField')698 ->shouldBeCalled()699 ->willReturnArgument(0);700 $this->concreteQueryBuilder->addOrderBy('aField', 'DESC')701 ->shouldBeCalled()702 ->willReturn($this->subject);703 $this->subject->addOrderBy('aField', 'DESC');704 }705 /**706 * @test707 */708 public function getQueryPartDelegatesToConcreteQueryBuilder()709 {710 $this->concreteQueryBuilder->getQueryPart('from')711 ->shouldBeCalled()712 ->willReturn('aTable');713 $this->subject->getQueryPart('from');714 }715 /**716 * @test717 */718 public function getQueryPartsDelegatesToConcreteQueryBuilder()719 {720 $this->concreteQueryBuilder->getQueryParts()721 ->shouldBeCalled()722 ->willReturn([]);723 $this->subject->getQueryParts();724 }725 /**726 * @test727 */728 public function resetQueryPartsDelegatesToConcreteQueryBuilder()729 {730 $this->concreteQueryBuilder->resetQueryParts(['select', 'from'])731 ->shouldBeCalled()732 ->willReturn($this->subject);733 $this->subject->resetQueryParts(['select', 'from']);734 }735 /**736 * @test737 */738 public function resetQueryPartDelegatesToConcreteQueryBuilder()739 {740 $this->concreteQueryBuilder->resetQueryPart('select')741 ->shouldBeCalled()742 ->willReturn($this->subject);743 $this->subject->resetQueryPart('select');744 }745 /**746 * @test747 */748 public function createNamedParameterDelegatesToConcreteQueryBuilder()749 {750 $this->concreteQueryBuilder->createNamedParameter(5, Argument::cetera())751 ->shouldBeCalled()752 ->willReturn(':dcValue1');753 $this->subject->createNamedParameter(5);754 }755 /**756 * @test757 */758 public function createPositionalParameterDelegatesToConcreteQueryBuilder()759 {760 $this->concreteQueryBuilder->createPositionalParameter(5, Argument::cetera())761 ->shouldBeCalled()762 ->willReturn('?');763 $this->subject->createPositionalParameter(5);764 }765 /**766 * @test767 */768 public function queryRestrictionsAreAddedForSelectOnExecute()769 {770 $GLOBALS['TCA']['pages']['ctrl'] = [771 'tstamp' => 'tstamp',772 'versioningWS' => true,773 'delete' => 'deleted',774 'crdate' => 'crdate',775 'enablecolumns' => [776 'disabled' => 'hidden',777 ],778 ];779 $this->connection->quoteIdentifier(Argument::cetera())780 ->willReturnArgument(0);781 $this->connection->quoteIdentifiers(Argument::cetera())782 ->willReturnArgument(0);783 $connectionBuilder = GeneralUtility::makeInstance(784 \Doctrine\DBAL\Query\QueryBuilder::class,785 $this->connection->reveal()786 );787 $expressionBuilder = GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal());788 $this->connection->getExpressionBuilder()789 ->willReturn($expressionBuilder);790 $subject = GeneralUtility::makeInstance(791 QueryBuilder::class,792 $this->connection->reveal(),793 null,794 $connectionBuilder795 );796 $subject->select('*')797 ->from('pages')798 ->where('uid=1');799 $expectedSQL = 'SELECT * FROM pages WHERE (uid=1) AND ((pages.deleted = 0) AND (pages.hidden = 0))';800 $this->connection->executeQuery($expectedSQL, Argument::cetera())801 ->shouldBeCalled();802 $subject->execute();803 }804 /**805 * @test806 */807 public function queryRestrictionsAreAddedForCountOnExecute()808 {809 $GLOBALS['TCA']['pages']['ctrl'] = [810 'tstamp' => 'tstamp',811 'versioningWS' => true,812 'delete' => 'deleted',813 'crdate' => 'crdate',814 'enablecolumns' => [815 'disabled' => 'hidden',816 ],817 ];818 $this->connection->quoteIdentifier(Argument::cetera())819 ->willReturnArgument(0);820 $this->connection->quoteIdentifiers(Argument::cetera())821 ->willReturnArgument(0);822 $connectionBuilder = GeneralUtility::makeInstance(823 \Doctrine\DBAL\Query\QueryBuilder::class,824 $this->connection->reveal()825 );826 $expressionBuilder = GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal());827 $this->connection->getExpressionBuilder()828 ->willReturn($expressionBuilder);829 $subject = GeneralUtility::makeInstance(830 QueryBuilder::class,831 $this->connection->reveal(),832 null,833 $connectionBuilder834 );835 $subject->count('uid')836 ->from('pages')837 ->where('uid=1');838 $expectedSQL = 'SELECT COUNT(uid) FROM pages WHERE (uid=1) AND ((pages.deleted = 0) AND (pages.hidden = 0))';839 $this->connection->executeQuery($expectedSQL, Argument::cetera())840 ->shouldBeCalled();841 $subject->execute();842 }843 /**844 * @test845 */846 public function queryRestrictionsAreReevaluatedOnSettingsChangeForGetSQL()847 {848 $GLOBALS['TCA']['pages']['ctrl'] = [849 'tstamp' => 'tstamp',850 'versioningWS' => true,851 'delete' => 'deleted',852 'crdate' => 'crdate',853 'enablecolumns' => [854 'disabled' => 'hidden',855 ],856 ];857 $this->connection->quoteIdentifier(Argument::cetera())858 ->willReturnArgument(0);859 $this->connection->quoteIdentifiers(Argument::cetera())860 ->willReturnArgument(0);861 $this->connection->getExpressionBuilder()862 ->willReturn(GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal()));863 $concreteQueryBuilder = GeneralUtility::makeInstance(864 \Doctrine\DBAL\Query\QueryBuilder::class,865 $this->connection->reveal()866 );867 $subject = GeneralUtility::makeInstance(868 QueryBuilder::class,869 $this->connection->reveal(),870 null,871 $concreteQueryBuilder872 );873 $subject->select('*')874 ->from('pages')875 ->where('uid=1');876 $expectedSQL = 'SELECT * FROM pages WHERE (uid=1) AND ((pages.deleted = 0) AND (pages.hidden = 0))';877 $this->assertSame($expectedSQL, $subject->getSQL());878 $subject->getRestrictions()->removeAll()->add(new DeletedRestriction());879 $expectedSQL = 'SELECT * FROM pages WHERE (uid=1) AND (pages.deleted = 0)';880 $this->assertSame($expectedSQL, $subject->getSQL());881 }882 /**883 * @test884 */885 public function queryRestrictionsAreReevaluatedOnSettingsChangeForExecute()886 {887 $GLOBALS['TCA']['pages']['ctrl'] = [888 'tstamp' => 'tstamp',889 'versioningWS' => true,890 'delete' => 'deleted',891 'crdate' => 'crdate',892 'enablecolumns' => [893 'disabled' => 'hidden',894 ],895 ];896 $this->connection->quoteIdentifier(Argument::cetera())897 ->willReturnArgument(0);898 $this->connection->quoteIdentifiers(Argument::cetera())899 ->willReturnArgument(0);900 $this->connection->getExpressionBuilder()901 ->willReturn(GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal()));902 $concreteQueryBuilder = GeneralUtility::makeInstance(903 \Doctrine\DBAL\Query\QueryBuilder::class,904 $this->connection->reveal()905 );906 $subject = GeneralUtility::makeInstance(907 QueryBuilder::class,908 $this->connection->reveal(),909 null,910 $concreteQueryBuilder911 );912 $subject->select('*')913 ->from('pages')914 ->where('uid=1');915 $subject->getRestrictions()->removeAll()->add(new DeletedRestriction());916 $expectedSQL = 'SELECT * FROM pages WHERE (uid=1) AND (pages.deleted = 0)';917 $this->connection->executeQuery($expectedSQL, Argument::cetera())918 ->shouldBeCalled();919 $subject->execute();920 $subject->resetRestrictions();921 $expectedSQL = 'SELECT * FROM pages WHERE (uid=1) AND ((pages.deleted = 0) AND (pages.hidden = 0))';922 $this->connection->executeQuery($expectedSQL, Argument::cetera())923 ->shouldBeCalled();924 $subject->execute();925 }926}...

Full Screen

Full Screen

ModuleTest.php

Source:ModuleTest.php Github

copy

Full Screen

...64 $abstractActionController = $this->prophesize('Zend\Mvc\Controller\AbstractActionController');65 $flashMessenger = $this->prophesize('Zend\Mvc\Controller\Plugin\FlashMessenger');66 $pluginManager = $this->prophesize('Zend\Mvc\Controller\PluginManager');67 $sharedEvmAttach->will(function() use ($module, $e, $hasMessages, $abstractActionController, $flashMessenger, $pluginManager) {68 $abstractActionController->getPluginManager()->willReturn($pluginManager)->shouldBeCalled();69 $pluginManager->has('flashMessenger')->willReturn(true)->shouldBeCalled();70 71 if ($hasMessages) {72 $namespace = 'flash';73 $message = 'a message';74 $splQueue = new SplQueue();75 $splQueue->push($message);76 $container = new Container('FlashMessenger');77 $container->offsetSet($namespace, $splQueue);78 $flashMessenger->setNamespace($namespace)79 ->willReturn($flashMessenger)80 ->shouldBeCalled();81 $flashMessenger->addMessage($message)82 ->willReturn($flashMessenger)83 ->shouldBeCalled();84 }85 $abstractActionController->plugin('flashMessenger')86 ->willReturn($flashMessenger)87 ->shouldBeCalled();88 $e->getTarget()89 ->willReturn($abstractActionController)90 ->shouldBeCalled();91 $module->flashMessengerHandler($e->reveal());92 });93 $sharedEvmAttach->shouldBeCalled();94 $eventManager->getSharedManager()95 ->willReturn($sharedEvm)96 ->shouldBeCalled();97 $application->getEventManager()98 ->willReturn($eventManager)99 ->shouldBeCalled();100 $e->getApplication()101 ->willReturn($application)102 ->shouldBeCalled();103 }104 $this->module->onBootstrap($e->reveal());105 }106 107 public function testOnBootstrapWithDoesntHasFlashMessenger()108 {109 $e = $this->prophesize('Zend\Mvc\MvcEvent');110 $application = $this->prophesize('Zend\Mvc\Application');111 $eventManager = $this->prophesize('Zend\EventManager\EventManager');112 $sharedEvm = $this->prophesize('Zend\EventManager\SharedEventManager');113 $sharedEvmAttach = $sharedEvm->attach(114 'Zend\Mvc\Controller\AbstractActionController',115 'dispatch',116 [$this->module, 'flashMessengerHandler'],117 2118 );119 $module = $this->module;120 $abstractActionController = $this->prophesize('Zend\Mvc\Controller\AbstractActionController');121 $flashMessenger = $this->prophesize('Zend\Mvc\Controller\Plugin\FlashMessenger');122 $pluginManager = $this->prophesize('Zend\Mvc\Controller\PluginManager');123 $sharedEvmAttach->will(function() use ($module, $e, $abstractActionController, $flashMessenger, $pluginManager) {124 $abstractActionController->getPluginManager()->willReturn($pluginManager)->shouldBeCalled();125 $pluginManager->has('flashMessenger')->willReturn(false)->shouldBeCalled();126 $e->getTarget()127 ->willReturn($abstractActionController)128 ->shouldBeCalled();129 $module->flashMessengerHandler($e->reveal());130 });131 $sharedEvmAttach->shouldBeCalled();132 $eventManager->getSharedManager()133 ->willReturn($sharedEvm)134 ->shouldBeCalled();135 $application->getEventManager()136 ->willReturn($eventManager)137 ->shouldBeCalled();138 $e->getApplication()139 ->willReturn($application)140 ->shouldBeCalled(); 141 $this->module->onBootstrap($e->reveal());142 }143 /**144 * @covers SanSessionToolbar\Module::getConfig()145 */146 public function testGetConfig()147 {148 $this->assertTrue(is_array($this->module->getConfig()));149 }150 /**151 * @covers SanSessionToolbar\Module::getModuleDependencies()152 */153 public function testGetModuleDependencies()154 {...

Full Screen

Full Screen

shouldBeCalled

Using AI Code Generation

copy

Full Screen

1use PHPUnit\Framework\TestCase;2use PHPUnit\Framework\MockObject\MockObject;3use PHPUnit\Framework\MockObject\Rule\InvokedCount;4use PHPUnit\Framework\MockObject\Rule\InvokedAtIndex;5use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce;6use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount;7use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount;8use PHPUnit\Framework\MockObject\Rule\InvokedRecorder;9use PHPUnit\Framework\MockObject\Rule\InvocationOrder;10use PHPUnit\Framework\MockObject\Rule\InvokedAtMostOnce;11use PHPUnit\Framework\MockObject\Rule\InvokedAtMostOnce;12use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce;13use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount;14use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount;15use PHPUnit\Framework\MockObject\Rule\InvocationOrder;16use PHPUnit\Framework\MockObject\Rule\InvokedAtMostOnce;17use PHPUnit\Framework\MockObject\Rule\InvokedAtMostOnce;18use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce;19use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount;20use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount;21use PHPUnit\Framework\MockObject\Rule\InvocationOrder;22use PHPUnit\Framework\MockObject\Rule\InvokedAtMostOnce;23{24 protected $mock;25 protected function setUp(): void26 {27 $this->mock = $this->createMock(MockObject::class);28 }29 public function testShouldBeCalled()30 {31 $this->mock->expects($this->once())->method('foo')->willReturn('bar');32 $this->mock->foo();33 }34 public function testShouldBeCalledAtLeastOnce()35 {36 $this->mock->expects($this->atLeastOnce())->method('foo')->willReturn('bar');37 $this->mock->foo();38 }39 public function testShouldBeCalledAtLeastOnce2()40 {41 $this->mock->expects($this->atLeastOnce())->method('foo')->willReturn('bar');42 $this->mock->foo();43 }44 public function testShouldBeCalledAtLeastCount()45 {

Full Screen

Full Screen

shouldBeCalled

Using AI Code Generation

copy

Full Screen

1use PHPUnit\Framework\TestCase;2use PHPUnit\Framework\MockObject\MockObject;3use PHPUnit\Framework\MockObject\Rule\InvokedCount;4use PHPUnit\Framework\MockObject\Rule\InvokedAtIndex;5use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce;6use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce;7use PHPUnit\Framework\MockObject\Rule\InvokedAtMostOnce;8use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount;9use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount;10use PHPUnit\Framework\MockObject\Rule\InvokedRecorder;11use PHPUnit\Framework\MockObject\Rule\AnyInvokedCount;12use PHPUnit\Framework\MockObject\Rule\InvocationOrder;13use PHPUnit\Framework\MockObject\Rule\ParametersRule;14use PHPUnit\Framework\MockObject\Rule\InvokedMethodName;15use PHPUnit\Framework\MockObject\Rule\InvokedAtIndex;16use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastOnce;17use PHPUnit\Framework\MockObject\Rule\InvokedAtMostOnce;18use PHPUnit\Framework\MockObject\Rule\InvokedAtLeastCount;19use PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount;20use PHPUnit\Framework\MockObject\Rule\InvokedRecorder;21use PHPUnit\Framework\MockObject\Invocation;22use PHPUnit\Framework\MockObject\Invocation\ObjectInvocation;23use PHPUnit\Framework\MockObject\Invocation\StaticInvocation;24use PHPUnit\Framework\MockObject\Invocation\StaticInvocation;25use PHPUnit\Framework\MockObject\Invocation\ObjectInvocation;26use PHPUnit\Framework\MockObject\Invocation\StaticInvocation;

Full Screen

Full Screen

shouldBeCalled

Using AI Code Generation

copy

Full Screen

1use PHPUnit\Framework\TestCase;2use PHPUnit\Framework\MockObject\MockObject;3{4 private $two;5 private $one;6 public function setUp()7 {8 $this->one = $this->createMock(One::class);9 $this->two = new Two($this->one);10 }11 public function testOne()12 {13 $this->one->expects($this->once())14 ->method('shouldBeCalled')15 ->willReturn(10);16 $this->two->one();17 }18}19{20 private $one;21 public function __construct(One $one)22 {23 $this->one = $one;24 }25 public function one()26 {27 $this->one->shouldBeCalled();28 }29}30{31 public function shouldBeCalled()32 {33 return 10;34 }35}36public function get($id)37{38 return $this->db->table('users')->where('id', $id)->first();39}40public function testGet()41{42 $this->user = factory(User::class)->create();43 $this->user->get($this->user->id);44}45{46 public function __construct()47 {48 }49 public function test()50 {

Full Screen

Full Screen

shouldBeCalled

Using AI Code Generation

copy

Full Screen

1$or = new OrClass();2$or->shouldBeCalled();3$or->shouldBeCalled(1);4$or->shouldBeCalled(2);5$or->shouldBeCalled(3);6$or->shouldBeCalled(4);7$or->shouldBeCalled(5);8$or = new OrClass();9$or->shouldBeCalled();10$or->shouldBeCalled(1);11$or->shouldBeCalled(2);12$or->shouldBeCalled(3);13$or->shouldBeCalled(4);14$or->shouldBeCalled(5);15$or = new OrClass();16$or->shouldBeCalled();17$or->shouldBeCalled(1);18$or->shouldBeCalled(2);19$or->shouldBeCalled(3);20$or->shouldBeCalled(4);21$or->shouldBeCalled(5);22$or = new OrClass();23$or->shouldBeCalled();24$or->shouldBeCalled(1);25$or->shouldBeCalled(2);26$or->shouldBeCalled(3);27$or->shouldBeCalled(4);28$or->shouldBeCalled(5);29$or = new OrClass();30$or->shouldBeCalled();31$or->shouldBeCalled(1);32$or->shouldBeCalled(2);33$or->shouldBeCalled(3);34$or->shouldBeCalled(4);35$or->shouldBeCalled(5);36$or = new OrClass();37$or->shouldBeCalled();38$or->shouldBeCalled(1);39$or->shouldBeCalled(2);40$or->shouldBeCalled(3);41$or->shouldBeCalled(4);42$or->shouldBeCalled(5);43$or = new OrClass();44$or->shouldBeCalled();45$or->shouldBeCalled(1);46$or->shouldBeCalled(2);47$or->shouldBeCalled(3);48$or->shouldBeCalled(4);49$or->shouldBeCalled(5);

Full Screen

Full Screen

shouldBeCalled

Using AI Code Generation

copy

Full Screen

1$stub = $this->getMockBuilder('SomeClass')2 ->setMethods(null)3 ->getMock();4$stub->expects($this->once())5 ->method('someMethod')6 ->with('foo')7 ->willReturn('bar');8$stub = $this->getMockBuilder('SomeClass')9 ->setMethods(null)10 ->getMock();11$stub->expects($this->once())12 ->method('someMethod')13 ->with('foo')14 ->willReturn('bar');15$stub = $this->getMockBuilder('SomeClass')16 ->setMethods(null)17 ->getMock();18$stub->expects($this->once())19 ->method('someMethod')20 ->with('foo')21 ->willReturn('bar');22$stub = $this->getMockBuilder('SomeClass')23 ->setMethods(null)24 ->getMock();25$stub->expects($this->once())26 ->method('someMethod')27 ->with('foo')28 ->willReturn('bar');29$stub = $this->getMockBuilder('SomeClass')30 ->setMethods(null)31 ->getMock();32$stub->expects($this->once())33 ->method('someMethod')34 ->with('foo')35 ->willReturn('bar');36$stub = $this->getMockBuilder('SomeClass')37 ->setMethods(null)38 ->getMock();39$stub->expects($this->once())40 ->method('someMethod')41 ->with('foo')42 ->willReturn('bar');43$stub = $this->getMockBuilder('SomeClass')44 ->setMethods(null)45 ->getMock();46$stub->expects($this->once())47 ->method('someMethod')48 ->with('foo')49 ->willReturn('bar');50$stub = $this->getMockBuilder('SomeClass')51 ->setMethods(null)

Full Screen

Full Screen

shouldBeCalled

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Framework.php';2require_once 'PHPUnit/Extensions/Story/TestCase.php';3require_once 'PHPUnit/Extensions/Story/TestCase/Scenario.php';4require_once 'PHPUnit/Extensions/Story/TestCase/Step.php';5require_once 'PHPUnit/Extensions/Story/TestCase/Step/Result.php';6{7EOT;8 public function testStory()9 {10 $this->runStory();11 }12 public function testScenario()13 {14 $this->runScenario();15 }16 public function testStep()17 {18 $this->runStep();19 }20 public function testStepResult()21 {22 $this->runStepResult();23 }24 public function testShouldBeCalled()25 {26 $this->runShouldBeCalled();27 }28 protected function runStory()29 {30 $story = $this->getStory();31 $this->assertType('PHPUnit_Extensions_Story_Story', $story);32 $this->assertEquals('Story test', $story->getTitle());33 $this->assertEquals(1, count($story->getScenarios()));34 }35 protected function runScenario()36 {37 $scenario = $this->getScenario();38 $this->assertType('PHPUnit_Extensions_Story_TestCase_Scenario', $scenario);39 $this->assertEquals('Test Scenario', $scenario->getTitle());40 $this->assertEquals(3, count($scenario->getSteps()));41 }42 protected function runStep()43 {44 $step = $this->getStep();45 $this->assertType('PHPUnit_Extensions_Story_TestCase_Step', $step);46 $this->assertEquals('Given I have a step', $step->getLine());47 $this->assertEquals('I have a step', $step->getAction());48 $this->assertEquals('Given', $step->getType());49 }50 protected function runStepResult()51 {52 $result = $this->getStepResult();53 $this->assertType('PHPUnit_Extensions_Story_TestCase_Step_Result', $result);54 $this->assertEquals('Then I should get a result', $result->getLine());

Full Screen

Full Screen

shouldBeCalled

Using AI Code Generation

copy

Full Screen

1$mock = Mockery::mock('alias:or');2$mock->shouldReceive('shouldBeCalled')->once()->andReturn(true);3$mock = Mockery::mock('alias:or');4$mock->shouldReceive('shouldBeCalled')->once()->andReturn(true);5$mock = Mockery::mock('alias:or');6$mock->shouldReceive('shouldBeCalled')->once()->andReturn(true);7If you want to create a mock object, you can use the Mockery::mock() method or the Mockery::spy() method. The difference is that the mock object will have the same behavior as the original class, while the spy object will not. If you want to create

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Prophecy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger shouldBeCalled code on LambdaTest Cloud Grid

Execute automation tests with shouldBeCalled on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful