Best Prophecy code snippet using or.shouldBeCalledOnce
CachedInstallationTest.php
Source:CachedInstallationTest.php
...142 /**143 * Installation should not fail if no cache directory is set.144 */145 public function testNoCacheDir() {146 $this->installProcedure->shouldBeCalledOnce();147 $this->updateProcedure->shouldNotBeCalled();148 $this->cachedInstall149 ->setCacheDir(NULL)150 ->install($this->installer, $this->updater);151 $this->assertSiteInstalled();152 $this->assertSiteNotCached($this->cachedInstall->getInstallCacheId());153 $this->assertSiteNotCached($this->cachedInstall->getUpdateCacheId());154 }155 /**156 * Test uncacheable install.157 *158 * If the setup is not cacheable the whole procedure is execute and no159 * cache directory is created.160 */161 public function testUncacheableInstall() {162 $this->installProcedure->shouldBeCalledOnce();163 $this->updateProcedure->shouldNotBeCalled();164 $this->cachedInstall = new CachedInstallation(165 $this->appRoot . '/drupal',166 'sites/default',167 'LOCK',168 'mysql://localhost:3306#drupal',169 'PREFIX'170 );171 $this->cachedInstall->setCacheDir($this->appRoot . '/cache');172 $this->cachedInstall->setConfigDir($this->appRoot . '/config');173 $this->cachedInstall->install($this->installer, $this->updater);174 $this->assertSiteInstalled();175 $this->assertSiteNotCached($this->cachedInstall->getInstallCacheId());176 $this->assertSiteNotCached($this->cachedInstall->getUpdateCacheId());177 }178 /**179 * Test install without configuration.180 *181 * If there is no config directory, only execute the install procedure and182 * cache it accordingly.183 */184 public function testCacheableInstallWithoutConfig() {185 $this->installProcedure->shouldBeCalledOnce();186 $this->updateProcedure->shouldNotBeCalled();187 $this->cachedInstall188 ->setConfigDir(NULL)189 ->install($this->installer, $this->updater);190 $this->cachedInstall->install($this->installer, $this->updater);191 $this->assertSiteInstalled();192 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());193 $this->assertSiteNotCached($this->cachedInstall->getUpdateCacheId());194 }195 /**196 * Test install with configuration.197 *198 * Should effectively create two cached directories. One for the installation199 * and one for the update.200 *201 */202 public function testCacheableInstallWithConfig() {203 $this->installProcedure->shouldBeCalledOnce();204 $this->updateProcedure->shouldNotBeCalled();205 $this->cachedInstall->install($this->installer, $this->updater);206 $this->cachedInstall->install($this->installer, $this->updater);207 $this->assertSiteInstalled();208 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());209 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());210 }211 /**212 * Test writing of the persistent cache.213 */214 public function testWriteToPersistentCache() {215 $this->installProcedure->shouldBeCalledOnce();216 $this->updateProcedure->shouldNotBeCalled();217 $this->cachedInstall218 ->setInstallCache('../install-cache.zip')219 ->install($this->installer, $this->updater);220 $this->assertSiteInstalled();221 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());222 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());223 $this->assertFileExists($this->appRoot . '/install-cache.zip');224 }225 /**226 * Test loading from the persistent cache.227 */228 public function testRestoreFromPersistentCache() {229 $this->installProcedure->shouldNotBeCalled();230 $this->updateProcedure->shouldBeCalledOnce();231 file_put_contents($this->appRoot . '/install-cache.zip', 'foo');232 $this->cachedInstall233 ->setInstallCache('../install-cache.zip')234 ->install($this->installer, $this->updater);235 $this->assertSiteInstalled();236 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());237 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());238 }239 /**240 * Test profile change.241 *242 * If the install profile is different, a entirely new site install should243 * be invoked.244 */245 public function testProfileChange() {246 $this->installProcedure->shouldBeCalledTimes(2);247 $this->updateProcedure->shouldNotBeCalled();248 $this->cachedInstall->install($this->installer, $this->updater);249 $this->cachedInstall->setProfile('standard');250 $this->cachedInstall->install($this->installer, $this->updater);251 $this->assertSiteInstalled();252 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());253 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());254 }255 /**256 * Test config directory change.257 *258 * If the config directory is different, a entirely new site install should259 * be invoked.260 */261 public function testConfigDirChange() {262 $this->installProcedure->shouldBeCalledTimes(2);263 $this->updateProcedure->shouldNotBeCalled();264 $this->cachedInstall->install($this->installer, $this->updater);265 $this->cachedInstall->setConfigDir($this->appRoot . '/config/b');266 $this->cachedInstall->install($this->installer, $this->updater);267 $this->assertSiteInstalled();268 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());269 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());270 }271 /**272 * Test language change.273 *274 * If the install language is different, a entirely new site install should275 * be invoked.276 */277 public function testLangCodeChange() {278 $this->installProcedure->shouldBeCalledTimes(2);279 $this->updateProcedure->shouldNotBeCalled();280 $this->cachedInstall->install($this->installer, $this->updater);281 $this->cachedInstall->setLangCode('de');282 $this->cachedInstall->install($this->installer, $this->updater);283 $this->assertSiteInstalled();284 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());285 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());286 }287 /**288 * Test setup class change.289 *290 * If the setup class is different, a entirely new site install should291 * be invoked.292 */293 public function testSetupClassChange() {294 $this->installProcedure->shouldBeCalledTimes(2);295 $this->updateProcedure->shouldNotBeCalled();296 $this->cachedInstall->install($this->installer, $this->updater);297 $this->cachedInstall->setSetupClass('bar');298 $this->cachedInstall->install($this->installer, $this->updater);299 $this->assertSiteInstalled();300 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());301 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());302 }303 /**304 * Test config change.305 *306 * If the contents of the configuration directory change, an update should be307 * invoked.308 */309 public function testConfigChange() {310 $this->installProcedure->shouldBeCalledOnce();311 $this->updateProcedure->shouldBeCalledOnce();312 $this->cachedInstall->install($this->installer, $this->updater);313 file_put_contents($this->appRoot . '/config/a/foo.yml', 'bar');314 $this->cachedInstall->install($this->installer, $this->updater);315 $this->assertSiteInstalled();316 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());317 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());318 }319 /**320 * Test update hook changes.321 *322 * If the contents of a *.install, *.post_update.php or *.yml files change,323 * an update should be invoked.324 */325 public function testInstallFileChanges() {326 $this->installProcedure->shouldBeCalledOnce();327 $this->updateProcedure->shouldBeCalledOnce();328 $this->cachedInstall->install($this->installer, $this->updater);329 file_put_contents($this->appRoot . '/drupal/modules/x/x.install', 'bar');330 $this->cachedInstall->install($this->installer, $this->updater);331 $this->assertSiteInstalled();332 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());333 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());334 }335 /**336 * Test update hook changes.337 *338 * If the contents of a *.install, *.post_update.php or *.yml files change,339 * an update should be invoked.340 */341 public function testUpdateFileChanges() {342 $this->installProcedure->shouldBeCalledOnce();343 $this->updateProcedure->shouldBeCalledOnce();344 $this->cachedInstall->install($this->installer, $this->updater);345 file_put_contents($this->appRoot . '/drupal/modules/x/x.post_update.php', 'bar');346 $this->cachedInstall->install($this->installer, $this->updater);347 $this->assertSiteInstalled();348 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());349 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());350 }351 /**352 * Test *.yml changes.353 *354 * If the contents of a *.install, *.post_update.php or *.yml files change,355 * an update should be invoked.356 */357 public function testYmlFileChanges() {358 $this->installProcedure->shouldBeCalledOnce();359 $this->updateProcedure->shouldBeCalledOnce();360 $this->cachedInstall->install($this->installer, $this->updater);361 file_put_contents($this->appRoot . '/drupal/modules/x/x.routing.yml', 'bar');362 $this->cachedInstall->install($this->installer, $this->updater);363 $this->assertSiteInstalled();364 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());365 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());366 }367 /**368 * Test code changes changes.369 *370 * If any other371 */372 public function testCodeChanges() {373 $this->installProcedure->shouldBeCalledOnce();374 $this->updateProcedure->shouldBeCalledOnce();375 $this->cachedInstall->install($this->installer, $this->updater);376 file_put_contents($this->appRoot . '/config/a/foo.yml', 'bar');377 $this->cachedInstall->install($this->installer, $this->updater);378 $this->assertSiteInstalled();379 $this->assertSiteCached($this->cachedInstall->getInstallCacheId());380 $this->assertSiteCached($this->cachedInstall->getUpdateCacheId());381 }382}...
RefIndexTest.php
Source:RefIndexTest.php
...138 ->getMock();139 $refIndex->expects(self::once())->method('getExistingTables')->willReturn($existingTables);140 $queryBuilderProphet = $this->getQueryBuilderProphet('sys_refindex');141 $queryBuilderMock = $queryBuilderProphet->reveal();142 $queryBuilderProphet->delete('sys_refindex')->shouldBeCalledOnce()->willReturn($queryBuilderMock);143 $queryBuilderProphet->where('`tablename` NOT IN (:dcValue1)')->shouldBeCalledOnce()->willReturn($queryBuilderMock);144 $queryBuilderProphet->execute()->shouldBeCalledOnce();145 $queryBuilderProphet->createNamedParameter($existingTables, Connection::PARAM_STR_ARRAY)->willReturn(':dcValue1');146 $this->callInaccessibleMethod($refIndex, 'deleteLostIndexes');147 }148 /**149 * @test150 */151 public function updateTable()152 {153 $table = 'test_table';154 $records = [['uid' => 1], ['uid' => 2]];155 $referenceIndexMock = $this->getMockBuilder(ReferenceIndex::class)156 ->disableOriginalConstructor()157 ->setMethods(['updateRefIndexTable'])158 ->getMock();159 $referenceIndexMock->expects(self::exactly(2))->method('updateRefIndexTable')->withConsecutive(160 [$table, 1, false],161 [$table, 2, false]162 );163 $refIndex = $this->getMockBuilder(RefIndex::class)164 ->setMethods(['getReferenceIndex', 'getDeletableRecUidListFromTable'])165 ->getMock();166 $refIndex->method('getReferenceIndex')->willReturn($referenceIndexMock);167 $refIndex->method('getDeletableRecUidListFromTable')->willReturn([0]);168 $testTableQueryBuilderProphet = $this->getQueryBuilderProphet($table);169 $selectQueryBuilderMock = $testTableQueryBuilderProphet->reveal();170 $statementProphet = $this->prophesize(Statement::class);171 $statementProphet->fetchAll(FetchMode::ASSOCIATIVE)->shouldBeCalledOnce()->willReturn($records);172 $testTableQueryBuilderProphet->select('uid')->shouldBeCalledOnce()->willReturn($selectQueryBuilderMock);173 $testTableQueryBuilderProphet->from($table)->shouldBeCalledOnce()->willReturn($selectQueryBuilderMock);174 $testTableQueryBuilderProphet->execute()->shouldBeCalledOnce()->willReturn($statementProphet->reveal());175 $refTableQueryBuilderProphet = $this->getQueryBuilderProphet('sys_refindex');176 $refTableQueryBuilderMock = $refTableQueryBuilderProphet->reveal();177 $refTableQueryBuilderProphet->delete('sys_refindex')->shouldBeCalledOnce()->willReturn($refTableQueryBuilderMock);178 $refTableQueryBuilderProphet->where('`tablename` = :dcValue1')->shouldBeCalledOnce()->willReturn($refTableQueryBuilderMock);179 $refTableQueryBuilderProphet->andWhere('`recuid` IN (:dcValue2)')->shouldBeCalledOnce()->willReturn($refTableQueryBuilderMock);180 $refTableQueryBuilderProphet->execute()->shouldBeCalledOnce();181 $refTableQueryBuilderProphet->createNamedParameter($table, PDO::PARAM_STR)->willReturn(':dcValue1');182 $refTableQueryBuilderProphet->createNamedParameter([0], Connection::PARAM_INT_ARRAY)->willReturn(':dcValue2');183 $this->callInaccessibleMethod($refIndex, 'updateTable', $table);184 }185 /**186 * @test187 */188 public function getDeletableRecUidListFromTable()189 {190 $table = 'test_table';191 $refIndex = $this->getMockBuilder(RefIndex::class)->getMock();192 $testTableQueryBuilderProphet = $this->getQueryBuilderProphet($table);193 $testTableQueryBuilderProphet->getSQL()->shouldBeCalledOnce()->willReturn('SELECT `uid` FROM `test_table`');194 $selectQueryBuilderMock = $testTableQueryBuilderProphet->reveal();195 $testTableQueryBuilderProphet->select('uid')->shouldBeCalledOnce()->willReturn($selectQueryBuilderMock);196 $testTableQueryBuilderProphet->from($table)->shouldBeCalledOnce()->willReturn($selectQueryBuilderMock);197 $statementProphet = $this->prophesize(Statement::class);198 $statementProphet->fetchAll(FetchMode::ASSOCIATIVE)->shouldBeCalledOnce()->willReturn([]);199 $refTableQueryBuilderProphet = $this->getQueryBuilderProphet('sys_refindex');200 $refTableQueryBuilderMock = $refTableQueryBuilderProphet->reveal();201 $refTableQueryBuilderProphet->select('recuid')->shouldBeCalledOnce()->willReturn($refTableQueryBuilderMock);202 $refTableQueryBuilderProphet->from('sys_refindex')->shouldBeCalledOnce()->willReturn($refTableQueryBuilderMock);203 $refTableQueryBuilderProphet->where('`tablename` = :dcValue1')->shouldBeCalledOnce()->willReturn($refTableQueryBuilderMock);204 $refTableQueryBuilderProphet->andWhere('`recuid` NOT IN (SELECT `uid` FROM `test_table`)')->shouldBeCalledOnce()->willReturn($refTableQueryBuilderMock);205 $refTableQueryBuilderProphet->groupBy('recuid')->shouldBeCalledOnce()->willReturn($refTableQueryBuilderMock);206 $refTableQueryBuilderProphet->execute()->shouldBeCalledOnce()->willReturn($statementProphet->reveal());207 $refTableQueryBuilderProphet->createNamedParameter($table, PDO::PARAM_STR)->willReturn(':dcValue1');208 self::assertSame([0], $this->callInaccessibleMethod($refIndex, 'getDeletableRecUidListFromTable', $table));209 }210 /**211 * @param string $table212 * @return ObjectProphecy|QueryBuilder213 */214 private function getQueryBuilderProphet(string $table)215 {216 $connectionProphet = $this->prophesize(Connection::class);217 $connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {218 return '`' . $arguments[0] . '`';219 });220 $queryRestrictionProphet = $this->prophesize(QueryRestrictionContainerInterface::class);...
OptinControllerTest.php
Source:OptinControllerTest.php
...63 * @test64 */65 public function validationActionWithoutKey()66 {67 $this->request->hasArgument('key')->willReturn(false)->shouldBeCalledOnce();68 $this->view->assign('success', false)->shouldBeCalledOnce();69 $this->controller->validationAction();70 }71 /**72 * @test73 */74 public function validationActionWithInvalidKey()75 {76 $this->request->hasArgument('key')->willReturn(true)->shouldBeCalledOnce();77 $this->request->getArgument('key')->willReturn('optinkey')->shouldBeCalledOnce();78 $this->optinManager->getOptinByKey('optinkey')->willThrow(new LogicException())->shouldBeCalledOnce();79 $this->view->assign('success', false)->shouldBeCalledOnce();80 $this->controller->validationAction();81 }82 /**83 * @test84 */85 public function validationActionWithValidKey()86 {87 $this->request->hasArgument('key')->willReturn(true)->shouldBeCalledOnce();88 $this->request->getArgument('key')->willReturn('optinkey')->shouldBeCalledOnce();89 $optin = new Optin();90 $this->optinManager->getOptinByKey('optinkey')->willReturn($optin)->shouldBeCalledOnce();91 $this->optinManager->validateByKey('optinkey')->shouldBeCalledOnce();92 $this->eventDispatcher->dispatch(Argument::type(OptinValidationSuccessEvent::class))->willReturnArgument()->shouldBeCalledOnce();93 $this->view->assign('optin', $optin)->shouldBeCalledOnce();94 $this->view->assign('success', true)->shouldBeCalledOnce();95 $this->controller->validationAction();96 }97}...
shouldBeCalledOnce
Using AI Code Generation
1$mock = $this->getMockBuilder('or')->getMock();2$mock->expects($this->once())->method('shouldBeCalledOnce');3$mock->shouldBeCalledOnce();4$mock = $this->getMockBuilder('or')->getMock();5$mock->expects($this->once())->method('shouldBeCalledTwice');6$mock->shouldBeCalledTwice();7$mock = $this->getMockBuilder('or')->getMock();8$mock->expects($this->once())->method('shouldBeCalledThrice');9$mock->shouldBeCalledThrice();10$mock = $this->getMockBuilder('or')->getMock();11$mock->expects($this->once())->method('shouldBeCalledTimes');12$mock->shouldBeCalledTimes();13$mock = $this->getMockBuilder('or')->getMock();14$mock->expects($this->once())->method('shouldBeCalled');15$mock->shouldBeCalled();16$mock = $this->getMockBuilder('or')->getMock();17$mock->expects($this->once())->method('shouldBeCalledBefore');18$mock->shouldBeCalledBefore();19$mock = $this->getMockBuilder('or')->getMock();20$mock->expects($this->once())->method('shouldBeCalledAfter');21$mock->shouldBeCalledAfter();22$mock = $this->getMockBuilder('or')->getMock();23$mock->expects($this->once())->method('shouldBeCalledBeforeOrEqual');24$mock->shouldBeCalledBeforeOrEqual();25$mock = $this->getMockBuilder('or')->getMock();26$mock->expects($this->once())->method('shouldBeCalledAfterOrEqual');27$mock->shouldBeCalledAfterOrEqual();28$mock = $this->getMockBuilder('or')->getMock();29$mock->expects($this->once())->method('shouldBeCalledBetween');30$mock->shouldBeCalledBetween();31$mock = $this->getMockBuilder('or')->getMock();32$mock->expects($this->once())->
shouldBeCalledOnce
Using AI Code Generation
1$mock = Mockery::mock('overload:or');2$mock->shouldReceive('shouldBeCalledOnce')->once();3$mock->shouldBeCalledOnce();4$mock = Mockery::mock('overload:or');5$mock->shouldReceive('shouldBeCalledOnce')->once();6$mock->shouldBeCalledOnce();7{8 public function setUp()9 {10 $this->mock = Mockery::mock('overload:or');11 }12 public function test1()13 {14 $this->mock->shouldReceive('shouldBeCalledOnce')->once();15 $this->mock->shouldBeCalledOnce();16 }17 public function test2()18 {19 $this->mock->shouldReceive('shouldBeCalledOnce')->once();20 $this->mock->shouldBeCalledOnce();21 }22 public function test3()23 {24 $this->mock->shouldReceive('shouldBeCalledOnce')->once();25 $this->mock->shouldBeCalledOnce();26 }27}
shouldBeCalledOnce
Using AI Code Generation
1$mock = Mockery::mock('overload:or');2$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');3$mock = Mockery::mock('overload:and');4$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');5$mock = Mockery::mock('overload:not');6$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');7$mock = Mockery::mock('overload:xor');8$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');9$mock = Mockery::mock('overload:nor');10$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');11$mock = Mockery::mock('overload:nand');12$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');13$mock = Mockery::mock('overload:xnor');14$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');15$mock = Mockery::mock('overload:nor');16$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');17$mock = Mockery::mock('overload:nand');18$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');19$mock = Mockery::mock('overload:xnor');20$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');21$mock = Mockery::mock('overload:nor');22$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');23$mock = Mockery::mock('overload:nand');24$mock->shouldReceive('shouldBeCalledOnce')->with('foo')->andReturn('bar');
shouldBeCalledOnce
Using AI Code Generation
1$mock->shouldBeCalledOnce()->willReturn('bar');2$mock->shouldBeCalledOnce()->willReturn('foo');3$mock->shouldBeCalledOnce()->willReturn('foo2');4$mock->shouldBeCalledOnce()->willReturn('bar2');5$mock->shouldBeCalledOnce()->willReturn('foo3');6$mock->shouldBeCalledOnce()->willReturn('bar3');7$mock->shouldBeCalledOnce()->willReturn('foo4');8$mock->shouldBeCalledOnce()->willReturn('bar4');9$mock->shouldBeCalledOnce()->willReturn('foo5');10$mock->shouldBeCalledOnce()->willReturn('bar5');11$mock->shouldBeCalledOnce()->willReturn('foo6');12$mock->shouldBeCalledOnce()->willReturn('bar6');13$mock->shouldBeCalledOnce()->willReturn('foo7');14$mock->shouldBeCalledOnce()->willReturn('bar7');15$mock->shouldBeCalledOnce()->willReturn('foo8');16$mock->shouldBeCalledOnce()->willReturn('bar8');17$mock->shouldBeCalledOnce()->willReturn('foo9');18$mock->shouldBeCalledOnce()->willReturn('bar9');19$mock->shouldBeCalledOnce()->willReturn('foo10');
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 shouldBeCalledOnce 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!!