Best Prophecy code snippet using or.willReturnArgument
QueryBuilderTest.php
Source:QueryBuilderTest.php  
...222    public function selectQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()223    {224        $this->connection->quoteIdentifier('aField')225            ->shouldBeCalled()226            ->willReturnArgument(0);227        $this->connection->quoteIdentifier('anotherField')228            ->shouldBeCalled()229            ->willReturnArgument(0);230        $this->concreteQueryBuilder->select(Argument::exact('aField'), Argument::exact('anotherField'))231            ->shouldBeCalled()232            ->willReturn($this->subject);233        $this->subject->select('aField', 'anotherField');234    }235    public function quoteIdentifiersForSelectDataProvider()236    {237        return [238            'fieldName' => [239                'fieldName',240                '"fieldName"',241            ],242            'tableName.fieldName' => [243                'tableName.fieldName',244                '"tableName"."fieldName"',245            ],246            'tableName.*' => [247                'tableName.*',248                '"tableName".*',249            ],250            '*' => [251                '*',252                '*',253            ],254            'fieldName AS anotherFieldName' => [255                'fieldName AS anotherFieldName',256                '"fieldName" AS "anotherFieldName"',257            ],258            'tableName.fieldName AS anotherFieldName' => [259                'tableName.fieldName AS anotherFieldName',260                '"tableName"."fieldName" AS "anotherFieldName"',261            ],262            'tableName.fieldName AS anotherTable.anotherFieldName' => [263                'tableName.fieldName AS anotherTable.anotherFieldName',264                '"tableName"."fieldName" AS "anotherTable"."anotherFieldName"',265            ],266        ];267    }268    /**269     * @test270     * @dataProvider quoteIdentifiersForSelectDataProvider271     * @param string $identifier272     * @param string $expectedResult273     */274    public function quoteIdentifiersForSelect($identifier, $expectedResult)275    {276        $this->connection->quoteIdentifier(Argument::cetera())->will(277            function ($args) {278                $platform = new MockPlatform();279                return $platform->quoteIdentifier($args[0]);280            }281        );282        $this->assertSame([$expectedResult], $this->subject->quoteIdentifiersForSelect([$identifier]));283    }284    /**285     * @test286     */287    public function quoteIdentifiersForSelectWithInvalidAlias()288    {289        $this->expectException(\InvalidArgumentException::class);290        $this->expectExceptionCode(1461170686);291        $this->connection->quoteIdentifier(Argument::cetera())->will(292            function ($args) {293                $platform = new MockPlatform();294                return $platform->quoteIdentifier($args[0]);295            }296        );297        $this->subject->quoteIdentifiersForSelect(['aField AS anotherField,someField AS someThing']);298    }299    /**300     * @test301     */302    public function selectDoesNotQuoteStarPlaceholder()303    {304        $this->connection->quoteIdentifier('aField')305            ->shouldBeCalled()306            ->willReturnArgument(0);307        $this->connection->quoteIdentifier('*')308            ->shouldNotBeCalled();309        $this->concreteQueryBuilder->select(Argument::exact('aField'), Argument::exact('*'))310            ->shouldBeCalled()311            ->willReturn($this->subject);312        $this->subject->select('aField', '*');313    }314    /**315     * @test316     */317    public function addSelectQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()318    {319        $this->connection->quoteIdentifier('aField')320            ->shouldBeCalled()321            ->willReturnArgument(0);322        $this->connection->quoteIdentifier('anotherField')323            ->shouldBeCalled()324            ->willReturnArgument(0);325        $this->concreteQueryBuilder->addSelect(Argument::exact('aField'), Argument::exact('anotherField'))326            ->shouldBeCalled()327            ->willReturn($this->subject);328        $this->subject->addSelect('aField', 'anotherField');329    }330    /**331     * @test332     */333    public function addSelectDoesNotQuoteStarPlaceholder()334    {335        $this->connection->quoteIdentifier('aField')336            ->shouldBeCalled()337            ->willReturnArgument(0);338        $this->connection->quoteIdentifier('*')339            ->shouldNotBeCalled();340        $this->concreteQueryBuilder->addSelect(Argument::exact('aField'), Argument::exact('*'))341            ->shouldBeCalled()342            ->willReturn($this->subject);343        $this->subject->addSelect('aField', '*');344    }345    /**346     * @test347     */348    public function selectLiteralDirectlyDelegatesToConcreteQueryBuilder()349    {350        $this->connection->quoteIdentifier(Argument::cetera())351            ->shouldNotBeCalled();352        $this->concreteQueryBuilder->select(Argument::exact('MAX(aField) AS anAlias'))353            ->shouldBeCalled()354            ->willReturn($this->subject);355        $this->subject->selectLiteral('MAX(aField) AS anAlias');356    }357    /**358     * @test359     */360    public function addSelectLiteralDirectlyDelegatesToConcreteQueryBuilder()361    {362        $this->connection->quoteIdentifier(Argument::cetera())363            ->shouldNotBeCalled();364        $this->concreteQueryBuilder->addSelect(Argument::exact('MAX(aField) AS anAlias'))365            ->shouldBeCalled()366            ->willReturn($this->subject);367        $this->subject->addSelectLiteral('MAX(aField) AS anAlias');368    }369    /**370     * @test371     * @todo: Test with alias372     */373    public function deleteQuotesIdentifierAndDelegatesToConcreteQueryBuilder()374    {375        $this->connection->quoteIdentifier('aTable')376            ->shouldBeCalled()377            ->willReturnArgument(0);378        $this->concreteQueryBuilder->delete(Argument::exact('aTable'), Argument::cetera())379            ->shouldBeCalled()380            ->willReturn($this->subject);381        $this->subject->delete('aTable');382    }383    /**384     * @test385     * @todo: Test with alias386     */387    public function updateQuotesIdentifierAndDelegatesToConcreteQueryBuilder()388    {389        $this->connection->quoteIdentifier('aTable')390            ->shouldBeCalled()391            ->willReturnArgument(0);392        $this->concreteQueryBuilder->update(Argument::exact('aTable'), Argument::cetera())393            ->shouldBeCalled()394            ->willReturn($this->subject);395        $this->subject->update('aTable');396    }397    /**398     * @test399     */400    public function insertQuotesIdentifierAndDelegatesToConcreteQueryBuilder()401    {402        $this->connection->quoteIdentifier('aTable')403            ->shouldBeCalled()404            ->willReturnArgument(0);405        $this->concreteQueryBuilder->insert(Argument::exact('aTable'))406            ->shouldBeCalled()407            ->willReturn($this->subject);408        $this->subject->insert('aTable');409    }410    /**411     * @test412     * @todo: Test with alias413     */414    public function fromQuotesIdentifierAndDelegatesToConcreteQueryBuilder()415    {416        $this->connection->quoteIdentifier('aTable')417            ->shouldBeCalled()418            ->willReturnArgument(0);419        $this->concreteQueryBuilder->from(Argument::exact('aTable'), Argument::cetera())420            ->shouldBeCalled()421            ->willReturn($this->subject);422        $this->subject->from('aTable');423    }424    /**425     * @test426     */427    public function joinQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()428    {429        $this->connection->quoteIdentifier('fromAlias')430            ->shouldBeCalled()431            ->willReturnArgument(0);432        $this->connection->quoteIdentifier('join')433            ->shouldBeCalled()434            ->willReturnArgument(0);435        $this->connection->quoteIdentifier('alias')436            ->shouldBeCalled()437            ->willReturnArgument(0);438        $this->concreteQueryBuilder->innerJoin('fromAlias', 'join', 'alias', null)439            ->shouldBeCalled()440            ->willReturn($this->subject);441        $this->subject->join('fromAlias', 'join', 'alias');442    }443    /**444     * @test445     */446    public function innerJoinQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()447    {448        $this->connection->quoteIdentifier('fromAlias')449            ->shouldBeCalled()450            ->willReturnArgument(0);451        $this->connection->quoteIdentifier('join')452            ->shouldBeCalled()453            ->willReturnArgument(0);454        $this->connection->quoteIdentifier('alias')455            ->shouldBeCalled()456            ->willReturnArgument(0);457        $this->concreteQueryBuilder->innerJoin('fromAlias', 'join', 'alias', null)458            ->shouldBeCalled()459            ->willReturn($this->subject);460        $this->subject->innerJoin('fromAlias', 'join', 'alias');461    }462    /**463     * @test464     */465    public function leftJoinQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()466    {467        $this->connection->quoteIdentifier('fromAlias')468            ->shouldBeCalled()469            ->willReturnArgument(0);470        $this->connection->quoteIdentifier('join')471            ->shouldBeCalled()472            ->willReturnArgument(0);473        $this->connection->quoteIdentifier('alias')474            ->shouldBeCalled()475            ->willReturnArgument(0);476        $this->concreteQueryBuilder->leftJoin('fromAlias', 'join', 'alias', null)477            ->shouldBeCalled()478            ->willReturn($this->subject);479        $this->subject->leftJoin('fromAlias', 'join', 'alias');480    }481    /**482     * @test483     */484    public function rightJoinQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()485    {486        $this->connection->quoteIdentifier('fromAlias')487            ->shouldBeCalled()488            ->willReturnArgument(0);489        $this->connection->quoteIdentifier('join')490            ->shouldBeCalled()491            ->willReturnArgument(0);492        $this->connection->quoteIdentifier('alias')493            ->shouldBeCalled()494            ->willReturnArgument(0);495        $this->concreteQueryBuilder->rightJoin('fromAlias', 'join', 'alias', null)496            ->shouldBeCalled()497            ->willReturn($this->subject);498        $this->subject->rightJoin('fromAlias', 'join', 'alias');499    }500    /**501     * @test502     */503    public function setQuotesIdentifierAndDelegatesToConcreteQueryBuilder()504    {505        $this->connection->quoteIdentifier('aField')506            ->shouldBeCalled()507            ->willReturnArgument(0);508        $this->concreteQueryBuilder->createNamedParameter('aValue', Argument::cetera())509            ->shouldBeCalled()510            ->willReturn(':dcValue1');511        $this->concreteQueryBuilder->set('aField', ':dcValue1')512            ->shouldBeCalled()513            ->willReturn($this->subject);514        $this->subject->set('aField', 'aValue');515    }516    /**517     * @test518     */519    public function setWithoutNamedParameterQuotesIdentifierAndDelegatesToConcreteQueryBuilder()520    {521        $this->connection->quoteIdentifier('aField')522            ->shouldBeCalled()523            ->willReturnArgument(0);524        $this->concreteQueryBuilder->createNamedParameter(Argument::cetera())->shouldNotBeCalled();525        $this->concreteQueryBuilder->set('aField', 'aValue')526            ->shouldBeCalled()527            ->willReturn($this->subject);528        $this->subject->set('aField', 'aValue', false);529    }530    /**531     * @test532     */533    public function whereDelegatesToConcreteQueryBuilder()534    {535        $this->concreteQueryBuilder->where('uid=1', 'type=9')536            ->shouldBeCalled()537            ->willReturn($this->subject);538        $this->subject->where('uid=1', 'type=9');539    }540    /**541     * @test542     */543    public function andWhereDelegatesToConcreteQueryBuilder()544    {545        $this->concreteQueryBuilder->andWhere('uid=1', 'type=9')546            ->shouldBeCalled()547            ->willReturn($this->subject);548        $this->subject->andWhere('uid=1', 'type=9');549    }550    /**551     * @test552     */553    public function orWhereDelegatesToConcreteQueryBuilder()554    {555        $this->concreteQueryBuilder->orWhere('uid=1', 'type=9')556            ->shouldBeCalled()557            ->willReturn($this->subject);558        $this->subject->orWhere('uid=1', 'type=9');559    }560    /**561     * @test562     */563    public function groupByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()564    {565        $this->connection->quoteIdentifiers(['aField', 'anotherField'])566            ->shouldBeCalled()567            ->willReturnArgument(0);568        $this->concreteQueryBuilder->groupBy('aField', 'anotherField')569            ->shouldBeCalled()570            ->willReturn($this->subject);571        $this->subject->groupBy('aField', 'anotherField');572    }573    /**574     * @test575     */576    public function addGroupByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()577    {578        $this->connection->quoteIdentifiers(['aField', 'anotherField'])579            ->shouldBeCalled()580            ->willReturnArgument(0);581        $this->concreteQueryBuilder->addGroupBy('aField', 'anotherField')582            ->shouldBeCalled()583            ->willReturn($this->subject);584        $this->subject->addGroupBy('aField', 'anotherField');585    }586    /**587     * @test588     */589    public function setValueQuotesIdentifierAndDelegatesToConcreteQueryBuilder()590    {591        $this->connection->quoteIdentifier('aField')592            ->shouldBeCalled()593            ->willReturnArgument(0);594        $this->concreteQueryBuilder->createNamedParameter('aValue', Argument::cetera())595            ->shouldBeCalled()596            ->willReturn(':dcValue1');597        $this->concreteQueryBuilder->setValue('aField', ':dcValue1')598            ->shouldBeCalled()599            ->willReturn($this->subject);600        $this->subject->setValue('aField', 'aValue');601    }602    /**603     * @test604     */605    public function setValueWithoudNamedParameterQuotesIdentifierAndDelegatesToConcreteQueryBuilder()606    {607        $this->connection->quoteIdentifier('aField')608            ->shouldBeCalled()609            ->willReturnArgument(0);610        $this->concreteQueryBuilder->setValue('aField', 'aValue')611            ->shouldBeCalled()612            ->willReturn($this->subject);613        $this->subject->setValue('aField', 'aValue', false);614    }615    /**616     * @test617     */618    public function valuesQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()619    {620        $this->connection->quoteColumnValuePairs(['aField' => ':dcValue1', 'aValue' => ':dcValue2'])621            ->shouldBeCalled()622            ->willReturnArgument(0);623        $this->concreteQueryBuilder->createNamedParameter(1, Argument::cetera())624            ->shouldBeCalled()625            ->willReturn(':dcValue1');626        $this->concreteQueryBuilder->createNamedParameter(2, Argument::cetera())627            ->shouldBeCalled()628            ->willReturn(':dcValue2');629        $this->concreteQueryBuilder->values(['aField' => ':dcValue1', 'aValue' => ':dcValue2'])630            ->shouldBeCalled()631            ->willReturn($this->subject);632        $this->subject->values(['aField' => 1, 'aValue' => 2]);633    }634    /**635     * @test636     */637    public function valuesWithoutNamedParametersQuotesIdentifiersAndDelegatesToConcreteQueryBuilder()638    {639        $this->connection->quoteColumnValuePairs(['aField' => 1, 'aValue' => 2])640            ->shouldBeCalled()641            ->willReturnArgument(0);642        $this->concreteQueryBuilder->values(['aField' => 1, 'aValue' => 2])643            ->shouldBeCalled()644            ->willReturn($this->subject);645        $this->subject->values(['aField' => 1, 'aValue' => 2], false);646    }647    /**648     * @test649     */650    public function havingDelegatesToConcreteQueryBuilder()651    {652        $this->concreteQueryBuilder->having('uid=1', 'type=9')653            ->shouldBeCalled()654            ->willReturn($this->subject);655        $this->subject->having('uid=1', 'type=9');656    }657    /**658     * @test659     */660    public function andHavingDelegatesToConcreteQueryBuilder()661    {662        $this->concreteQueryBuilder->andHaving('uid=1', 'type=9')663            ->shouldBeCalled()664            ->willReturn($this->subject);665        $this->subject->andHaving('uid=1', 'type=9');666    }667    /**668     * @test669     */670    public function orHavingDelegatesToConcreteQueryBuilder()671    {672        $this->concreteQueryBuilder->orHaving('uid=1', 'type=9')673            ->shouldBeCalled()674            ->willReturn($this->subject);675        $this->subject->orHaving('uid=1', 'type=9');676    }677    /**678     * @test679     */680    public function orderByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()681    {682        $this->connection->quoteIdentifier('aField')683            ->shouldBeCalled()684            ->willReturnArgument(0);685        $this->concreteQueryBuilder->orderBy('aField', null)686            ->shouldBeCalled()687            ->willReturn($this->subject);688        $this->subject->orderBy('aField');689    }690    /**691     * @test692     */693    public function addOrderByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()694    {695        $this->connection->quoteIdentifier('aField')696            ->shouldBeCalled()697            ->willReturnArgument(0);698        $this->concreteQueryBuilder->addOrderBy('aField', 'DESC')699            ->shouldBeCalled()700            ->willReturn($this->subject);701        $this->subject->addOrderBy('aField', 'DESC');702    }703    /**704     * @test705     */706    public function getQueryPartDelegatesToConcreteQueryBuilder()707    {708        $this->concreteQueryBuilder->getQueryPart('from')709            ->shouldBeCalled()710            ->willReturn('aTable');711        $this->subject->getQueryPart('from');712    }713    /**714     * @test715     */716    public function getQueryPartsDelegatesToConcreteQueryBuilder()717    {718        $this->concreteQueryBuilder->getQueryParts()719            ->shouldBeCalled()720            ->willReturn([]);721        $this->subject->getQueryParts();722    }723    /**724     * @test725     */726    public function resetQueryPartsDelegatesToConcreteQueryBuilder()727    {728        $this->concreteQueryBuilder->resetQueryParts(['select', 'from'])729            ->shouldBeCalled()730            ->willReturn($this->subject);731        $this->subject->resetQueryParts(['select', 'from']);732    }733    /**734     * @test735     */736    public function resetQueryPartDelegatesToConcreteQueryBuilder()737    {738        $this->concreteQueryBuilder->resetQueryPart('select')739            ->shouldBeCalled()740            ->willReturn($this->subject);741        $this->subject->resetQueryPart('select');742    }743    /**744     * @test745     */746    public function createNamedParameterDelegatesToConcreteQueryBuilder()747    {748        $this->concreteQueryBuilder->createNamedParameter(5, Argument::cetera())749            ->shouldBeCalled()750            ->willReturn(':dcValue1');751        $this->subject->createNamedParameter(5);752    }753    /**754     * @test755     */756    public function createPositionalParameterDelegatesToConcreteQueryBuilder()757    {758        $this->concreteQueryBuilder->createPositionalParameter(5, Argument::cetera())759            ->shouldBeCalled()760            ->willReturn('?');761        $this->subject->createPositionalParameter(5);762    }763    /**764     * @test765     */766    public function queryRestrictionsAreAddedForSelectOnExecute()767    {768        $GLOBALS['TCA']['pages']['ctrl'] = [769            'tstamp' => 'tstamp',770            'versioningWS' => true,771            'delete' => 'deleted',772            'crdate' => 'crdate',773            'enablecolumns' => [774                'disabled' => 'hidden',775            ],776        ];777        $this->connection->quoteIdentifier(Argument::cetera())778            ->willReturnArgument(0);779        $this->connection->quoteIdentifiers(Argument::cetera())780            ->willReturnArgument(0);781        $connectionBuilder = GeneralUtility::makeInstance(782            \Doctrine\DBAL\Query\QueryBuilder::class,783            $this->connection->reveal()784        );785        $expressionBuilder = GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal());786        $this->connection->getExpressionBuilder()787            ->willReturn($expressionBuilder);788        $subject = GeneralUtility::makeInstance(789            QueryBuilder::class,790            $this->connection->reveal(),791            null,792            $connectionBuilder793        );794        $subject->select('*')795            ->from('pages')796            ->where('uid=1');797        $expectedSQL = 'SELECT * FROM pages WHERE (uid=1) AND ((pages.deleted = 0) AND (pages.hidden = 0))';798        $this->connection->executeQuery($expectedSQL, Argument::cetera())799            ->shouldBeCalled();800        $subject->execute();801    }802    /**803     * @test804     */805    public function queryRestrictionsAreAddedForCountOnExecute()806    {807        $GLOBALS['TCA']['pages']['ctrl'] = [808            'tstamp' => 'tstamp',809            'versioningWS' => true,810            'delete' => 'deleted',811            'crdate' => 'crdate',812            'enablecolumns' => [813                'disabled' => 'hidden',814            ],815        ];816        $this->connection->quoteIdentifier(Argument::cetera())817            ->willReturnArgument(0);818        $this->connection->quoteIdentifiers(Argument::cetera())819            ->willReturnArgument(0);820        $connectionBuilder = GeneralUtility::makeInstance(821            \Doctrine\DBAL\Query\QueryBuilder::class,822            $this->connection->reveal()823        );824        $expressionBuilder = GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal());825        $this->connection->getExpressionBuilder()826            ->willReturn($expressionBuilder);827        $subject = GeneralUtility::makeInstance(828            QueryBuilder::class,829            $this->connection->reveal(),830            null,831            $connectionBuilder832        );833        $subject->count('uid')834            ->from('pages')835            ->where('uid=1');836        $expectedSQL = 'SELECT COUNT(uid) FROM pages WHERE (uid=1) AND ((pages.deleted = 0) AND (pages.hidden = 0))';837        $this->connection->executeQuery($expectedSQL, Argument::cetera())838            ->shouldBeCalled();839        $subject->execute();840    }841    /**842     * @test843     */844    public function queryRestrictionsAreReevaluatedOnSettingsChangeForGetSQL()845    {846        $GLOBALS['TCA']['pages']['ctrl'] = [847            'tstamp' => 'tstamp',848            'versioningWS' => true,849            'delete' => 'deleted',850            'crdate' => 'crdate',851            'enablecolumns' => [852                'disabled' => 'hidden',853            ],854        ];855        $this->connection->quoteIdentifier(Argument::cetera())856            ->willReturnArgument(0);857        $this->connection->quoteIdentifiers(Argument::cetera())858            ->willReturnArgument(0);859        $this->connection->getExpressionBuilder()860            ->willReturn(GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal()));861        $concreteQueryBuilder = GeneralUtility::makeInstance(862            \Doctrine\DBAL\Query\QueryBuilder::class,863            $this->connection->reveal()864        );865        $subject = GeneralUtility::makeInstance(866            QueryBuilder::class,867            $this->connection->reveal(),868            null,869            $concreteQueryBuilder870        );871        $subject->select('*')872            ->from('pages')873            ->where('uid=1');874        $expectedSQL = 'SELECT * FROM pages WHERE (uid=1) AND ((pages.deleted = 0) AND (pages.hidden = 0))';875        $this->assertSame($expectedSQL, $subject->getSQL());876        $subject->getRestrictions()->removeAll()->add(new DeletedRestriction());877        $expectedSQL = 'SELECT * FROM pages WHERE (uid=1) AND (pages.deleted = 0)';878        $this->assertSame($expectedSQL, $subject->getSQL());879    }880    /**881     * @test882     */883    public function queryRestrictionsAreReevaluatedOnSettingsChangeForExecute()884    {885        $GLOBALS['TCA']['pages']['ctrl'] = [886            'tstamp' => 'tstamp',887            'versioningWS' => true,888            'delete' => 'deleted',889            'crdate' => 'crdate',890            'enablecolumns' => [891                'disabled' => 'hidden',892            ],893        ];894        $this->connection->quoteIdentifier(Argument::cetera())895            ->willReturnArgument(0);896        $this->connection->quoteIdentifiers(Argument::cetera())897            ->willReturnArgument(0);898        $this->connection->getExpressionBuilder()899            ->willReturn(GeneralUtility::makeInstance(ExpressionBuilder::class, $this->connection->reveal()));900        $concreteQueryBuilder = GeneralUtility::makeInstance(901            \Doctrine\DBAL\Query\QueryBuilder::class,902            $this->connection->reveal()903        );904        $subject = GeneralUtility::makeInstance(905            QueryBuilder::class,906            $this->connection->reveal(),907            null,908            $concreteQueryBuilder909        );910        $subject->select('*')911            ->from('pages')...GeneratorDefaultTest.php
Source:GeneratorDefaultTest.php  
...54        $this->obfuscator55            ->expects($this->any())56            ->method('cleanParamsForLog')57            ->withAnyParameters()58            ->willReturnArgument(0);59        $this->namedParameterProvider->expects($this->any())->method('get')->willReturnArgument(2);60        $this->assertEquals(61            $this->fixtureProvider->getSimpleExceptionExpected(),62            $this->subjectUnderTest->generate($this->fixtureProvider->getSimpleException())63        );64    }65    public function testExceptionWithPreviousExceptionsProducesProperStackTrace()66    {67        $this->obfuscator68            ->expects($this->any())69            ->method('cleanParamsForLog')70            ->withAnyParameters()71            ->willReturnArgument(0);72        $this->namedParameterProvider->expects($this->any())->method('get')->willReturnArgument(2);73        $this->assertEquals(74            $this->fixtureProvider->getExceptionWithPreviousExceptionsExpected(),75            $this->subjectUnderTest->generate($this->fixtureProvider->getExceptionWithPreviousExceptions())76        );77    }78    public function testStackTraceGenerationWithMissingFileAndLine()79    {80        $this->obfuscator81            ->expects($this->any())82            ->method('cleanParamsForLog')83            ->withAnyParameters()84            ->willReturnArgument(0);85        $this->namedParameterProvider->expects($this->any())->method('get')->willReturnArgument(2);86        $this->assertEquals(87            $this->fixtureProvider->getExceptionWithMissingFileAndLineExpected(),88            $this->subjectUnderTest->generate($this->fixtureProvider->getExceptionWithMissingFileAndLineFixture())89        );90    }91    public function testStackTraceGenerationWithMissingClassAndType()92    {93        $this->obfuscator94            ->expects($this->any())95            ->method('cleanParamsForLog')96            ->withAnyParameters()97            ->willReturnArgument(0);98        $this->namedParameterProvider->expects($this->any())->method('get')->willReturnArgument(2);99        $this->assertEquals(100            $this->fixtureProvider->getExceptionWithMissingClassAndTypeExpected(),101            $this->subjectUnderTest->generate($this->fixtureProvider->getExceptionWithMissingClassAndTypeFixture())102        );103    }104    public function testStackTraceGenerationWithFunction()105    {106        $this->obfuscator107            ->expects($this->any())108            ->method('cleanParamsForLog')109            ->withAnyParameters()110            ->willReturnArgument(0);111        $this->namedParameterProvider->expects($this->any())->method('get')->willReturnArgument(2);112        $this->assertEquals(113            $this->fixtureProvider->getExceptionWithMissingFunctionExpected(),114            $this->subjectUnderTest->generate($this->fixtureProvider->getExceptionWithMissingFunctionFixture())115        );116    }117    public function testStackTraceGenerationWithArgs()118    {119        $this->obfuscator120            ->expects($this->any())121            ->method('cleanParamsForLog')122            ->withAnyParameters()123            ->willReturnArgument(0);124        $this->namedParameterProvider->expects($this->any())->method('get')->willReturnArgument(2);125        $this->assertEquals(126            $this->fixtureProvider->getExceptionWithMissingArgsExpected(),127            $this->subjectUnderTest->generate($this->fixtureProvider->getExceptionWithMissingArgsFixture())128        );129    }130    public function testDepthLimitIsHonoured()131    {132        $this->obfuscator133            ->expects($this->any())134            ->method('cleanParamsForLog')135            ->withAnyParameters()136            ->willReturnArgument(0);137        $this->namedParameterProvider->expects($this->any())->method('get')->willReturnArgument(2);138        $this->assertEquals(139            $this->fixtureProvider->getExceptionWithPreviousExceptionsDepth2Expected(),140            $this->subjectUnderTest->generate($this->fixtureProvider->getExceptionWithPreviousExceptions(), 2)141        );142    }143    public function testNamedParameterProviderAndObfuscatorIsCalled()144    {145        // build arguments for $this->fixtureProvider->get() from ShopgateLibraryException fixture146        list($args1, $args2, $args3, $args4) = $this->fixtureProvider->buildMockFromTraceFixture(147            $this->fixtureProvider->getTraceFixture('ShopgateLibraryExceptionStub')148        );149        // build arguments for $this->fixtureProvider->get() from LoginException fixture150        list($args5, $args6, $args7, $args8, $args9) = $this->fixtureProvider->buildMockFromTraceFixture(151            $this->fixtureProvider->getTraceFixture('LoginException')...willReturnArgument
Using AI Code Generation
1$mock = $this->getMockBuilder('stdClass')2             ->setMethods(array('doSomething'))3             ->getMock();4$mock->expects($this->any())5     ->method('doSomething')6     ->will($this->returnValueArgument(0));7$this->assertEquals('foo', $mock->doSomething('foo'));8$mock = $this->getMockBuilder('stdClass')9             ->setMethods(array('doSomething'))10             ->getMock();11$mock->expects($this->any())12     ->method('doSomething')13     ->will($this->returnValueSelf());14$this->assertSame($mock, $mock->doSomething());15$mock = $this->getMockBuilder('stdClass')16             ->setMethods(array('doSomething'))17             ->getMock();18$map = array(19    array('foo', 'bar'),20    array('baz', 'bam')21);22$mock->expects($this->any())23     ->method('doSomething')24     ->will($this->returnValueMap($map));25$this->assertEquals('bar', $mock->doSomething('foo'));26$this->assertEquals('bam', $mock->doSomething('baz'));27$mock = $this->getMockBuilder('stdClass')28             ->setMethods(array('doSomething'))29             ->getMock();30$mock->expects($this->any())31     ->method('doSomething')32     ->will($this->returnCallback('str_rot13'));33$this->assertEquals('sbbone', $mock->doSomething('foobar'));34$mock = $this->getMockBuilder('stdClass')35             ->setMethods(array('doSomething'))willReturnArgument
Using AI Code Generation
1$mock->expects($this->any())2     ->method('doSomething')3     ->will($this->returnValue('foo'));4$mock->expects($this->any())5     ->method('doSomething')6     ->will($this->returnValue('foo'));7$mock->expects($this->any())8     ->method('doSomething')9     ->will($this->returnValue('foo'));10$mock->expects($this->any())11     ->method('doSomething')12     ->will($this->returnValue('foo'));13$mock->expects($this->any())14     ->method('doSomething')15     ->will($this->returnValue('foo'));16$mock->expects($this->any())17     ->method('doSomething')18     ->will($this->returnValue('foo'));19$mock->expects($this->any())20     ->method('doSomething')21     ->will($this->returnValue('foo'));22$mock->expects($this->any())23     ->method('doSomething')24     ->will($this->returnValue('foo'));25$mock->expects($this->any())26     ->method('doSomething')27     ->will($this->returnValue('foo'));28$mock->expects($this->any())29     ->method('doSomething')30     ->will($this->returnValue('foo'));31$mock->expects($this->any())32     ->method('doSomething')33     ->will($this->returnValue('foo'));willReturnArgument
Using AI Code Generation
1$mock = $this->getMockBuilder('Foo')2             ->setMethods(['doSomething'])3             ->getMock();4$mock->expects($this->once())5     ->method('doSomething')6     ->willReturnArgument(0);7$this->assertSame('foo', $mock->doSomething('foo'));8.                                                                   1 / 1 (100%)9OK (1 test, 1 assertion)willReturnArgument
Using AI Code Generation
1$mock->expects($this->any())2     ->method('someMethod')3     ->will($this->returnValueArgument(2));4$mock->expects($this->any())5     ->method('someMethod')6     ->will($this->returnValueArgument(2));7$mock->expects($this->any())8     ->method('someMethod')9     ->will($this->returnValueArgument(2));10$mock->expects($this->any())11     ->method('someMethod')12     ->will($this->returnValueArgument(2));13$mock->expects($this->any())14     ->method('someMethod')15     ->will($this->returnValueArgument(2));16$mock->expects($this->any())17     ->method('someMethod')18     ->will($this->returnValueArgument(2));19$mock->expects($this->any())20     ->method('someMethod')21     ->will($this->returnValueArgument(2));22$mock->expects($this->any())23     ->method('someMethod')24     ->will($this->returnValueArgument(2));25$mock->expects($this->any())26     ->method('someMethod')27     ->will($this->returnValueArgument(2));28$mock->expects($this->any())29     ->method('someMethod')30     ->will($this->returnValueArgument(2));31$mock->expects($this->any())32     ->method('someMethod')33     ->will($this->returnValueArgument(2));willReturnArgument
Using AI Code Generation
1$or = $this->getMockBuilder('or')->getMock();2$or->method('or')->will($this->returnArgument(0));3$and = $this->getMockBuilder('and')->getMock();4$and->method('and')->will($this->returnArgument(0));5$not = $this->getMockBuilder('not')->getMock();6$not->method('not')->will($this->returnArgument(0));7$xor = $this->getMockBuilder('xor')->getMock();8$xor->method('xor')->will($this->returnArgument(0));9$nor = $this->getMockBuilder('nor')->getMock();10$nor->method('nor')->will($this->returnArgument(0));11$nand = $this->getMockBuilder('nand')->getMock();12$nand->method('nand')->will($this->returnArgument(0));13$xnor = $this->getMockBuilder('xnor')->getMock();14$xnor->method('xnor')->will($this->returnArgument(0));15$or = $this->getMockBuilder('or')->getMock();16$or->method('or')->will($this->returnArgument(0));17$and = $this->getMockBuilder('and')->getMock();18$and->method('and')->will($this->returnArgument(0));19$not = $this->getMockBuilder('not')->getMock();20$not->method('not')->will($this->returnArgument(0));21$xor = $this->getMockBuilder('xor')->getMock();22$xor->method('xor')->will($this->returnArgument(0));23$nor = $this->getMockBuilder('nor')->getMock();24$nor->method('nor')->will($this->returnArgument(0));25$nand = $this->getMockBuilder('nandwillReturnArgument
Using AI Code Generation
1class or {2    public function willReturnArgument($a) {3        return $a;4    }5}6require_once('2.php');7$or = new or();8echo $or->willReturnArgument('Hello World');9class or {10    public function willReturnArgument($a) {11        return $a;12    }13}14require_once('2.php');15$or = new or();16echo $or->willReturnArgument('Hello World');17class or {18    public function willReturnArgument($a) {19        return $a;20    }21}22require_once('2.php');23$or = new or();24echo $or->willReturnArgument('Hello World');25class or {26    public function willReturnArgument($a) {27        return $a;28    }29}30require_once('2.php');31$or = new or();32echo $or->willReturnArgument('Hello World');33class or {34    public function willReturnArgument($a) {35        return $a;36    }37}38require_once('2.php');39$or = new or();40echo $or->willReturnArgument('Hello World');41class or {42    public function willReturnArgument($a) {43        return $a;44    }45}46require_once('2.php');47$or = new or();48echo $or->willReturnArgument('Hello World');49class or {50    public function willReturnArgument($a) {51        return $a;52    }53}54require_once('2.php');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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with willReturnArgument on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!
