Best Prophecy code snippet using or.shouldHaveBeenCalledOnce
DomainServiceTest.php
Source:DomainServiceTest.php
...36 $getRepo = $this->em->getRepository(Domain::class)->willReturn($repo->reveal());37 $findDomains = $repo->findDomains($apiKey)->willReturn($domains);38 $result = $this->domainService->listDomains($apiKey);39 self::assertEquals($expectedResult, $result);40 $getRepo->shouldHaveBeenCalledOnce();41 $findDomains->shouldHaveBeenCalledOnce();42 }43 public function provideExcludedDomains(): iterable44 {45 $default = DomainItem::forDefaultDomain('default.com', new EmptyNotFoundRedirectConfig());46 $adminApiKey = ApiKey::create();47 $domainSpecificApiKey = ApiKey::fromMeta(48 ApiKeyMeta::withRoles(RoleDefinition::forDomain(Domain::withAuthority('')->setId('123'))),49 );50 yield 'empty list without API key' => [[], [$default], null];51 yield 'one item without API key' => [52 [Domain::withAuthority('bar.com')],53 [$default, DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com'))],54 null,55 ];56 yield 'multiple items without API key' => [57 [Domain::withAuthority('foo.com'), Domain::withAuthority('bar.com')],58 [59 $default,60 DomainItem::forNonDefaultDomain(Domain::withAuthority('foo.com')),61 DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com')),62 ],63 null,64 ];65 yield 'empty list with admin API key' => [[], [$default], $adminApiKey];66 yield 'one item with admin API key' => [67 [Domain::withAuthority('bar.com')],68 [$default, DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com'))],69 $adminApiKey,70 ];71 yield 'multiple items with admin API key' => [72 [Domain::withAuthority('foo.com'), Domain::withAuthority('bar.com')],73 [74 $default,75 DomainItem::forNonDefaultDomain(Domain::withAuthority('foo.com')),76 DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com')),77 ],78 $adminApiKey,79 ];80 yield 'empty list with domain-specific API key' => [[], [], $domainSpecificApiKey];81 yield 'one item with domain-specific API key' => [82 [Domain::withAuthority('bar.com')],83 [DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com'))],84 $domainSpecificApiKey,85 ];86 yield 'multiple items with domain-specific API key' => [87 [Domain::withAuthority('foo.com'), Domain::withAuthority('bar.com')],88 [89 DomainItem::forNonDefaultDomain(Domain::withAuthority('foo.com')),90 DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com')),91 ],92 $domainSpecificApiKey,93 ];94 }95 /** @test */96 public function getDomainThrowsExceptionWhenDomainIsNotFound(): void97 {98 $find = $this->em->find(Domain::class, '123')->willReturn(null);99 $this->expectException(DomainNotFoundException::class);100 $find->shouldBeCalledOnce();101 $this->domainService->getDomain('123');102 }103 /** @test */104 public function getDomainReturnsEntityWhenFound(): void105 {106 $domain = Domain::withAuthority('');107 $find = $this->em->find(Domain::class, '123')->willReturn($domain);108 $result = $this->domainService->getDomain('123');109 self::assertSame($domain, $result);110 $find->shouldHaveBeenCalledOnce();111 }112 /**113 * @test114 * @dataProvider provideFoundDomains115 */116 public function getOrCreateAlwaysPersistsDomain(?Domain $foundDomain, ?ApiKey $apiKey): void117 {118 $authority = 'example.com';119 $repo = $this->prophesize(DomainRepositoryInterface::class);120 $repo->findOneByAuthority($authority, $apiKey)->willReturn($foundDomain);121 $getRepo = $this->em->getRepository(Domain::class)->willReturn($repo->reveal());122 $persist = $this->em->persist($foundDomain ?? Argument::type(Domain::class));123 $flush = $this->em->flush();124 $result = $this->domainService->getOrCreate($authority, $apiKey);125 if ($foundDomain !== null) {126 self::assertSame($result, $foundDomain);127 }128 $getRepo->shouldHaveBeenCalledOnce();129 $persist->shouldHaveBeenCalledOnce();130 $flush->shouldHaveBeenCalledOnce();131 }132 /** @test */133 public function getOrCreateThrowsExceptionForApiKeysWithDomainRole(): void134 {135 $authority = 'example.com';136 $domain = Domain::withAuthority($authority)->setId('1');137 $apiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forDomain($domain)));138 $repo = $this->prophesize(DomainRepositoryInterface::class);139 $repo->findOneByAuthority($authority, $apiKey)->willReturn(null);140 $getRepo = $this->em->getRepository(Domain::class)->willReturn($repo->reveal());141 $this->expectException(DomainNotFoundException::class);142 $getRepo->shouldBeCalledOnce();143 $this->em->persist(Argument::cetera())->shouldNotBeCalled();144 $this->em->flush()->shouldNotBeCalled();145 $this->domainService->getOrCreate($authority, $apiKey);146 }147 /**148 * @test149 * @dataProvider provideFoundDomains150 */151 public function configureNotFoundRedirectsConfiguresFetchedDomain(?Domain $foundDomain, ?ApiKey $apiKey): void152 {153 $authority = 'example.com';154 $repo = $this->prophesize(DomainRepositoryInterface::class);155 $repo->findOneByAuthority($authority, $apiKey)->willReturn($foundDomain);156 $getRepo = $this->em->getRepository(Domain::class)->willReturn($repo->reveal());157 $persist = $this->em->persist($foundDomain ?? Argument::type(Domain::class));158 $flush = $this->em->flush();159 $result = $this->domainService->configureNotFoundRedirects($authority, NotFoundRedirects::withRedirects(160 'foo.com',161 'bar.com',162 'baz.com',163 ), $apiKey);164 if ($foundDomain !== null) {165 self::assertSame($result, $foundDomain);166 }167 self::assertEquals('foo.com', $result->baseUrlRedirect());168 self::assertEquals('bar.com', $result->regular404Redirect());169 self::assertEquals('baz.com', $result->invalidShortUrlRedirect());170 $getRepo->shouldHaveBeenCalledOnce();171 $persist->shouldHaveBeenCalledOnce();172 $flush->shouldHaveBeenCalledOnce();173 }174 public function provideFoundDomains(): iterable175 {176 $domain = Domain::withAuthority('');177 $adminApiKey = ApiKey::create();178 $authorApiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forAuthoredShortUrls()));179 yield 'domain not found and no API key' => [null, null];180 yield 'domain found and no API key' => [$domain, null];181 yield 'domain not found and admin API key' => [null, $adminApiKey];182 yield 'domain found and admin API key' => [$domain, $adminApiKey];183 yield 'domain not found and author API key' => [null, $authorApiKey];184 yield 'domain found and author API key' => [$domain, $authorApiKey];185 }186}...
InstallationCommandsRunnerTest.php
Source:InstallationCommandsRunnerTest.php
...68 $writeErrorMsg = $this->io->error(Argument::containingString(sprintf('%s_error', $name)));69 $writeSuccessMsg = $this->io->writeln(' <info>Success!</info>');70 $writeSkipMsg = $this->io->writeln(' <comment>Skipped</comment>');71 self::assertTrue($this->commandsRunner->execPhpCommand($name, $this->io->reveal()));72 $run->shouldHaveBeenCalledOnce();73 $writeInitMsg->shouldHaveBeenCalledOnce();74 $writeRunningMsg->shouldHaveBeenCalledOnce();75 $writeErrorMsg->shouldNotHaveBeenCalled();76 $writeSuccessMsg->shouldHaveBeenCalledOnce();77 $writeSkipMsg->shouldNotHaveBeenCalled();78 }79 public function provideCommandNames(): array80 {81 return [['foo'], ['bar']];82 }83 /** @test */84 public function returnsErrorWhenProcessIsNotProperlyRun(): void85 {86 $name = 'foo';87 $command = ['php', $name, 'something'];88 $process = $this->createProcessMock(false);89 $run = $this->processHelper->run($this->io->reveal(), $command)->willReturn(90 $process->reveal(),91 );92 $writeInitMsg = $this->io->write(sprintf('%s_init', $name));93 $writeRunningMsg = $this->io->write(94 Argument::containingString(sprintf('Running "%s"', implode(' ', $command))),95 false,96 OutputInterface::VERBOSITY_VERBOSE,97 );98 $writeErrorMsg = $this->io->error(Argument::containingString(sprintf('%s_error', $name)));99 $writeSuccessMsg = $this->io->writeln(' <info>Success!</info>');100 $writeSkipMsg = $this->io->writeln(' <comment>Skipped</comment>');101 self::assertFalse($this->commandsRunner->execPhpCommand($name, $this->io->reveal()));102 $run->shouldHaveBeenCalledOnce();103 $writeInitMsg->shouldHaveBeenCalledOnce();104 $writeRunningMsg->shouldHaveBeenCalledOnce();105 $writeErrorMsg->shouldHaveBeenCalledOnce();106 $writeSuccessMsg->shouldNotHaveBeenCalled();107 $writeSkipMsg->shouldNotHaveBeenCalled();108 }109 /** @test */110 public function skipsNullCommands(): void111 {112 $name = 'null_command';113 $command = ['php', $name, 'something'];114 $run = $this->processHelper->run(Argument::cetera());115 $writeInitMsg = $this->io->write(sprintf('%s_init', $name));116 $writeRunningMsg = $this->io->write(117 Argument::containingString(sprintf('Running "%s"', implode(' ', $command))),118 false,119 OutputInterface::VERBOSITY_VERBOSE,120 );121 $writeErrorMsg = $this->io->error(Argument::containingString(sprintf('%s_error', $name)));122 $writeSuccessMsg = $this->io->writeln(' <info>Success!</info>');123 $writeSkipMsg = $this->io->writeln(' <comment>Skipped</comment>');124 self::assertTrue($this->commandsRunner->execPhpCommand($name, $this->io->reveal()));125 $run->shouldNotHaveBeenCalled();126 $writeInitMsg->shouldHaveBeenCalledOnce();127 $writeRunningMsg->shouldNotHaveBeenCalled();128 $writeErrorMsg->shouldNotHaveBeenCalled();129 $writeSuccessMsg->shouldNotHaveBeenCalled();130 $writeSkipMsg->shouldHaveBeenCalledOnce();131 }132 private function createProcessMock(bool $isSuccessful): ObjectProphecy133 {134 $process = $this->prophesize(Process::class);135 $process->isSuccessful()->willReturn($isSuccessful);136 return $process;137 }138}...
RebuyCopySubscriberTest.php
Source:RebuyCopySubscriberTest.php
...50 {51 $event = $this->setupProphecies();52 $event->isRuleBundleException()->willReturn(true);53 $this->mappingErrorSubscriber->onCopyError($event->reveal());54 $this->repository->findOneByIdentifier(Argument::any())->shouldHaveBeenCalledOnce();55 $this->entityWithValuesBuilder->addOrReplaceValue(56 Argument::any(),57 Argument::any(),58 Argument::any(),59 Argument::any(),60 Argument::any()61 )->shouldHaveBeenCalledOnce();62 }63 /**64 * @test65 */66 public function onMappableCopierEvent_throws_exception_when_mapping_attribute_does_not_exist()67 {68 $event = $this->setupProphecies(false);69 $event->isRuleBundleException()->willReturn(true);70 $this->expectException(AttributeNotFoundException::class);71 $this->mappingErrorSubscriber->onCopyError($event->reveal());72 $this->entityWithValuesBuilder->addOrReplaceValue(73 Argument::any(),74 Argument::any(),75 Argument::any(),76 Argument::any(),77 Argument::any()78 )->shouldHaveBeenCalledOnce();79 }80 /**81 * @return ObjectProphecy|RebuyCopyEvent82 */83 private function setupProphecies($mappingAttributeExists = true)84 {85 $event = $this->prophesizeMappableCopierEvent();86 $attribute = $this->prophesize(AttributeInterface::class);87 $this->repository88 ->findOneByIdentifier('')89 ->willReturn($mappingAttributeExists ? $attribute->reveal() : null);90 $toValue = $this->prophesize(ValueInterface::class);91 $toValue->__toString()->willReturn('');92 $toEntity = $this->prophesize(EntityWithValuesInterface::class);...
shouldHaveBeenCalledOnce
Using AI Code Generation
1$mock->shouldHaveBeenCalledOnce();2$mock->shouldHaveBeenCalledOnce();3$mock->shouldHaveBeenCalledOnce();4$mock->shouldHaveBeenCalledOnce();5$mock->shouldHaveBeenCalledOnce();6$mock->shouldHaveBeenCalledOnce();7$mock->shouldHaveBeenCalledOnce();8$mock->shouldHaveBeenCalledOnce();9$mock->shouldHaveBeenCalledOnce();10$mock->shouldHaveBeenCalledOnce();11$mock->shouldHaveBeenCalledOnce();12$mock->shouldHaveBeenCalledOnce();13$mock->shouldHaveBeenCalledOnce();14$mock->shouldHaveBeenCalledOnce();15$mock->shouldHaveBeenCalledOnce();16$mock->shouldHaveBeenCalledOnce();17$mock->shouldHaveBeenCalledOnce();18$mock->shouldHaveBeenCalledOnce();
shouldHaveBeenCalledOnce
Using AI Code Generation
1$mock->shouldHaveBeenCalledOnce();2$mock->shouldHaveBeenCalledOnce();3$mock->shouldHaveBeenCalledOnce();4$mock->shouldHaveBeenCalledOnce();5$mock->shouldHaveBeenCalledOnce();6$mock->shouldHaveBeenCalledOnce();7$mock = Mockery::mock('alias:ClassA', 'alias:ClassB', 'alias:ClassC');8$mock->shouldReceive('shouldHaveBeenCalledOnce')->andReturn(true);
shouldHaveBeenCalledOnce
Using AI Code Generation
1$mock->shouldHaveBeenCalledOnce();2$mock->shouldHaveBeenCalled();3$mock->shouldNotHaveBeenCalled();4$mock->shouldHaveBeenCalledWith('test');5$mock->shouldHaveBeenCalledOnceWith('test');6$mock->shouldHaveBeenCalledTimes(2);7$mock->shouldHaveBeenCalledOnceTimes(2);8$mock->shouldHaveBeenCalledWithTimes('test', 2);9$mock->shouldHaveBeenCalledOnceWithTimes('test', 2);10$mock->shouldHaveBeenCalledOnceWith('test');11$mock->shouldHaveBeenCalledWith('test');12$mock->shouldHaveBeenCalledOnceWith('test');13$mock->shouldHaveBeenCalledWith('test');14$mock->shouldHaveBeenCalledOnceWith('test');15$mock->shouldHaveBeenCalledWith('test');16$mock->shouldHaveBeenCalledOnceWith('test');17$mock->shouldHaveBeenCalledWith('test');18$mock->shouldHaveBeenCalledOnceWith('test');19$mock->shouldHaveBeenCalledWith('test');20$mock->shouldHaveBeenCalledOnceWith('test');21$mock->shouldHaveBeenCalledWith('test');
shouldHaveBeenCalledOnce
Using AI Code Generation
1$or = new Or;2$or->shouldHaveBeenCalledOnce();3$or = new Or;4$or->shouldHaveBeenCalledOnce();5$or = new Or;6$or->shouldHaveBeenCalledOnce();7$or = new Or;8$or->shouldHaveBeenCalledOnce();9$or = new Or;10$or->shouldHaveBeenCalledOnce();11$or = new Or;12$or->shouldHaveBeenCalledOnce();13$or = new Or;14$or->shouldHaveBeenCalledOnce();15$or = new Or;16$or->shouldHaveBeenCalledOnce();17$or = new Or;18$or->shouldHaveBeenCalledOnce();19$or = new Or;20$or->shouldHaveBeenCalledOnce();21$or = new Or;22$or->shouldHaveBeenCalledOnce();23$or = new Or;24$or->shouldHaveBeenCalledOnce();25$or = new Or;26$or->shouldHaveBeenCalledOnce();27$or = new Or;28$or->shouldHaveBeenCalledOnce();29$or = new Or;30$or->shouldHaveBeenCalledOnce();
shouldHaveBeenCalledOnce
Using AI Code Generation
1$or->shouldHaveBeenCalledOnce();2$or->shouldHaveBeenCalledOnceWith(array('x', 'y'));3$and->shouldHaveBeenCalledOnce();4$and->shouldHaveBeenCalledOnceWith(array('x', 'y'));5$not->shouldHaveBeenCalledOnce();6$not->shouldHaveBeenCalledOnceWith(array('x', 'y'));7$method->shouldHaveBeenCalledOnce();8$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));9$method->shouldHaveBeenCalledOnce();10$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));11$method->shouldHaveBeenCalledOnce();12$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));13$method->shouldHaveBeenCalledOnce();14$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));15$method->shouldHaveBeenCalledOnce();16$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));17$method->shouldHaveBeenCalledOnce();18$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));19$method->shouldHaveBeenCalledOnce();20$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));21$method->shouldHaveBeenCalledOnce();22$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));23$method->shouldHaveBeenCalledOnce();24$method->shouldHaveBeenCalledOnceWith(array('x', 'y'));
shouldHaveBeenCalledOnce
Using AI Code Generation
1$mock = Mockery::mock('alias:or');2$mock->shouldReceive('get')->once()->andReturn('foo');3$mock = Mockery::mock('alias:and');4$mock->shouldReceive('get')->once()->andReturn('foo');5$mock = Mockery::mock('alias:not');6$mock->shouldReceive('get')->once()->andReturn('foo');7$mock = Mockery::mock('alias:xor');8$mock->shouldReceive('get')->once()->andReturn('foo');9$mock = Mockery::mock('alias:nor');10$mock->shouldReceive('get')->once()->andReturn('foo');11$mock = Mockery::mock('alias:nand');12$mock->shouldReceive('get')->once()->andReturn('foo');13$mock = Mockery::mock('alias:nor');14$mock->shouldReceive('get')->once()->andReturn('foo');15$mock = Mockery::mock('alias:nor');16$mock->shouldReceive('get')->once()->andReturn('foo');17$mock = Mockery::mock('alias:nor');18$mock->shouldReceive('get')->once()->andReturn('foo');19$mock = Mockery::mock('alias:nor');20$mock->shouldReceive('get')->once()->andReturn('foo');21$mock = Mockery::mock('alias:nor');22$mock->shouldReceive('get')->once()->andReturn('foo');23$mock = Mockery::mock('alias:nor');24$mock->shouldReceive('get')->once()->andReturn('foo');25$mock = Mockery::mock('alias:nor');26$mock->shouldReceive('get')->once()->andReturn('foo');
shouldHaveBeenCalledOnce
Using AI Code Generation
1$or = new Or;2$or->shouldReceive('get')->once()->andReturn('foo');3$or->get();4$or->get();5$or->shouldHaveBeenCalledOnce();6$or = new Or;7$or->shouldReceive('get')->once()->andReturn('foo');8$or->get();9$or->get();10$or->shouldHaveBeenCalledOnce();
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 shouldHaveBeenCalledOnce 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!!