/** * @param string|null $classOrInterface * @return \Prophecy\Prophecy\ObjectProphecy * @throws \LogicException */ protected function prophesize($classOrInterface = null) { if (null === $this->prophet) { throw new \LogicException(sprintf('The setUp method of %s must be called to initialize Prophecy.', __CLASS__)); } return $this->prophet->prophesize($classOrInterface); }
protected function getAnnotationsExtractorResults() { $extractorResultProphecy = $this->prophet->prophesize('Team3\\PayU\\PropertyExtractor\\ExtractorResult'); $extractorResultProphecy->getPropertyName()->willReturn($this->getPropertyName()); $extractorResultProphecy->getValue()->willReturn($this->getValue()); return [$extractorResultProphecy]; }
/** * Create a binary mock. * * @param $name * @param $supported * @param $exists */ public function createBinary($name, $supported, $exists) { $binary = $this->prophet->prophesize('Peridot\\WebDriverManager\\Binary\\BinaryInterface'); $binary->isSupported()->willReturn($supported); $binary->getName()->willReturn($name); $binary->exists(Argument::any())->willReturn($exists); return $binary; }
/** * Mock the flashmessenger * * @param $flashMessenger */ protected function mockFlashMessenger($flashMessenger) { $prophet = new Prophet(); $serviceManager = $prophet->prophesize('\\Zend\\ServiceManager\\ServiceManager'); $pluginManager = $prophet->prophesize('\\Zend\\Mvc\\Controller\\PluginManager'); $serviceManager->get('ControllerPluginManager')->willReturn($pluginManager); $pluginManager->get('flashmessenger')->willReturn($flashMessenger->getWrappedObject()); $this->createService($serviceManager); }
public function it_should_not_replace_request_param_if_format_is_not_supported() { $requestParam = $this->prophet->prophesize('Symfony\\Component\\HttpFoundation\\ParameterBag'); $request = Request::create('/'); $request->request = $requestParam->reveal(); $requestParam->replace(Argument::any())->shouldNotBeCalled(); $this->decoderProvider->supports(Argument::any())->willReturn(false); $this->__invoke($request); }
public function let() { $this->prophet = new Prophet(); $this->routes = $this->prophet->prophesize('Symfony\\Component\\Routing\\RouteCollection'); $this->formatNegotiator = $this->prophet->prophesize('FOS\\Rest\\Util\\FormatNegotiator'); $this->route = $this->prophet->prophesize('Symfony\\Component\\Routing\\Route'); $this->route->getOption(RouteOptions::REST)->willReturn(true); $this->routes->get(Argument::any())->willReturn($this->route->reveal()); $this->beConstructedWith($this->routes->reveal(), $this->formatNegotiator->reveal()); }
public function setUp() { unset($GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone']); $prophet = new Prophet(); $this->packageManagerProphecy = $prophet->prophesize(PackageManager::class); $this->dbProphecy = $prophet->prophesize(\TYPO3\CMS\Core\Database\DatabaseConnection::class); $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal(); $this->updateWizard = new UpdateWizard(); ExtensionManagementUtility::setPackageManager($this->packageManagerProphecy->reveal()); }
/** * */ protected function setUp() { $prophet = new Prophet(); $this->prophet = $prophet; $this->formatter = $this->prophet->prophesize(FormatterInterface::class); $this->writer = $this->prophet->prophesize(WriterInterface::class); $this->dumper = new Dumper(); $this->dumper->setFormatter($this->formatter->reveal()); $this->dumper->setWriter($this->writer->reveal()); }
public function let() { $this->prophet = new Prophet(); $this->route = $this->prophet->prophesize('Symfony\\Component\\Routing\\Route'); $this->routes = $this->prophet->prophesize('Symfony\\Component\\Routing\\RouteCollection'); $this->event = $this->prophet->prophesize('Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEvent'); $this->route->getOption(RouteOptions::REST)->willReturn(true); $this->routes->get(Argument::any())->willReturn($this->route->reveal()); $this->beConstructedWith($this->routes->reveal()); }
public function it_can_match_repeating_multiple_segments() { $prophet = new Prophet(); $httpProphecy = $prophet->prophesize('Zend\\Uri\\Http'); $httpProphecy->getPath()->willReturn('/a/foo/bar/b/c/bar/bass/d'); $requestProphecy = $prophet->prophesize('Zend\\Http\\PhpEnvironment\\Request'); $requestProphecy->getUri()->willReturn($httpProphecy->reveal()); $this->beConstructedWith('/a[section]/b/c[other_section]/d', ['section' => '/[a-zA-Z][a-zA-Z0-9_-]+', 'other_section' => '/[a-zA-Z][a-zA-Z0-9_-]+'], ['controller' => 'Controller', 'action' => 'create']); $this->match($requestProphecy->reveal())->shouldReturnAnInstanceOf('Zend\\Mvc\\Router\\Http\\RouteMatch'); }
public function let() { $this->prophet = new Prophet(); $this->route = $this->prophet->prophesize('Symfony\\Component\\Routing\\Route'); $this->routes = $this->prophet->prophesize('Symfony\\Component\\Routing\\RouteCollection'); $this->annotationResourceOption = $this->prophet->prophesize('SDispatcher\\Common\\AnnotationResourceOption'); $this->route->getOption(RouteOptions::REST)->willReturn(true); $this->routes->get(Argument::any())->willReturn($this->route->reveal()); $this->beConstructedWith($this->routes->reveal(), $this->annotationResourceOption->reveal()); }
function it_matches_a_belongs_to_many_relationship() { $p = new Prophet(); $related = $p->prophesize('PhpSpec\\Laravel\\Test\\Example'); $belongsTo = $p->prophesize('Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany'); $belongsTo->getRelated()->willReturn($related->reveal()); $this->positiveMatch('name', $belongsTo->reveal(), array('belongsToMany', 'PhpSpec\\Laravel\\Test\\Example')); $this->shouldThrow('PhpSpec\\Exception\\Example\\FailureException')->during('positiveMatch', array('name', $belongsTo->reveal(), array('belongsToMany', 'PhpSpec\\Laravel\\Test\\OtherExample'))); $this->negativeMatch('name', $belongsTo->reveal(), array('belongsToMany', 'PhpSpec\\Laravel\\Test\\OtherExample')); $this->shouldThrow('PhpSpec\\Exception\\Example\\FailureException')->during('negativeMatch', array('name', $belongsTo->reveal(), array('belongsToMany', 'PhpSpec\\Laravel\\Test\\Example'))); }
/** * Test Create, Endpoint, Get/Set methods. */ public function testRootEntity() { $root = Root::create(); $this->assertInstanceOf('Shoko\\TwitchApiBundle\\Model\\Entity\\Root', $root); $this->assertEquals(null, $root->getToken()); $token = $this->prophet->prophesize('Shoko\\TwitchApiBundle\\Model\\ValueObject\\Token'); $this->assertEquals($token->reveal(), $root->setToken($token->reveal())->getToken()); $this->assertEquals(array(), $root->getLinks()); $link = 'some_link'; $this->assertEquals([$link], $root->setLinks([$link])->getLinks()); }
public function testNoopNext() { $prophet = new Prophet(); $reqProphecy = $prophet->prophesize(ServerRequestInterface::class); $resProphecy = $prophet->prophesize(ResponseInterface::class); $req = $reqProphecy->reveal(); $res = $resProphecy->reveal(); /** @noinspection PhpParamsInspection */ $returnValue = NimoUtility::noopNext($req, $res); $this->assertSame($res, $returnValue); }
/** * @param CollaboratorManager $collaborators * @param \ReflectionMethod $beforeMethod */ private function createMissingCollabolators(CollaboratorManager $collaborators, \ReflectionMethod $beforeMethod) { foreach ($beforeMethod->getParameters() as $parameter) { if (!$collaborators->has($parameter->getName())) { $collaborator = new Collaborator($this->prophet->prophesize()); if (null !== ($class = $parameter->getClass())) { $collaborator->beADoubleOf($class->getName()); } $collaborators->set($parameter->getName(), $collaborator); } } }
/** * @param array $config */ protected function mockConfig($config) { // Create mocks $prophet = new Prophet(); $helperSet = $prophet->prophesize('\\Symfony\\Component\\Console\\Helper\\HelperSet'); $helper = $prophet->prophesize('\\Phpro\\SmartCrud\\Console\\Helper\\ConfigHelper'); // Add logic $helper->getConfig()->willReturn($config); $helper->getApplicationConfig()->willReturn($config); $helperSet->get('Config')->willReturn($helper); $this->setHelperSet($helperSet); }
public function it_is_initializable() { $prophet = new Prophet(); $httpProphecy = $prophet->prophesize('Zend\\Uri\\Http'); $httpProphecy->getPath()->willReturn('/b'); $requestProphecy = $prophet->prophesize('Zend\\Http\\PhpEnvironment\\Request'); $requestProphecy->getUri()->willReturn($httpProphecy->reveal()); $partProphecy = $prophet->prophesize('Tohmua\\RepeatingSegment\\Part\\Part'); $parts = [$partProphecy->reveal(), $partProphecy->reveal(), $partProphecy->reveal()]; $this->beConstructedWith($requestProphecy, $parts); $this->shouldHaveType('Tohmua\\RepeatingSegment\\RegexGenerator\\RegexGenerator'); }
protected function mockApplicationConfig($configKey, $config) { // Create mocks $prophet = new Prophet(); $helperSet = $prophet->prophesize('\\Symfony\\Component\\Console\\Helper\\HelperSet'); $helper = $prophet->prophesize('\\Phpro\\SmartCrud\\Console\\Helper\\ServiceManagerHelper'); $serviceManager = $prophet->prophesize('\\Zend\\ServiceManager\\ServiceManager'); // Add logic $serviceManager->get($configKey)->willReturn($config); $helper->getServiceManager()->willReturn($serviceManager); $helperSet->get('serviceManager')->willReturn($helper); $this->setHelperSet($helperSet); }
public function it_should_update_response_if_json_is_supported() { $headers = $this->prophet->prophesize('Symfony\\Component\\HttpFoundation\\ParameterBag'); $headers->set('Content-Type', 'application/json')->shouldBeCalled(); $this->response->headers = $headers->reveal(); $this->route->getOption(Argument::any())->willReturn('json'); $this->encoder->supportsEncoding('json')->willReturn(true); $this->encoder->encode(Argument::cetera())->willReturn(''); $this->response->getContent()->willReturn(''); $this->response->setContent(Argument::any())->shouldBeCalled(); $request = Request::create('/'); $this->__invoke($request, $this->response->reveal())->shouldReturn(null); }
/** * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator */ public function mockConfig($serviceLocator) { $prophet = new Prophet(); $config = ['mvc-auth-token-authentication-listener' => ['TokenListener' => ['adapter' => 'TokenAdapter']]]; $serviceLocator->has('Config')->willReturn(true); $serviceLocator->get('Config')->willReturn($config); $adapter = $prophet->prophesize('\\Phpro\\MvcAuthToken\\Adapter\\AdapterInterface'); $serviceLocator->has('TokenAdapter')->willReturn(true); $serviceLocator->get('TokenAdapter')->willReturn($adapter); $tokenServer = $prophet->prophesize('\\Phpro\\MvcAuthToken\\TokenServer'); $serviceLocator->has('Phpro\\MvcAuthToken\\TokenServer')->willReturn(true); $serviceLocator->get('Phpro\\MvcAuthToken\\TokenServer')->willReturn($tokenServer); }
public function testGettersAndSetters() { $this->prophet = new Prophet(); $token = Token::create(); $this->assertEquals(null, $token->getAuthorization()); $this->assertEquals(null, $token->getUserName()); $this->assertEquals(false, $token->isValid()); $authorization = $this->prophet->prophesize('Shoko\\TwitchApiBundle\\Model\\ValueObject\\Authorization'); $token->setAuthorization($authorization->reveal())->setUserName('some_username')->setValid(false); $this->assertInstanceOf('Shoko\\TwitchApiBundle\\Model\\ValueObject\\Authorization', $token->getAuthorization()); $this->assertEquals('some_username', $token->getUserName()); $this->assertEquals(false, $token->isValid()); }
public function testExecute() { $this->client = $this->getClient(); $mockedProducer = $this->prophet->prophesize('\\OldSound\\RabbitMqBundle\\RabbitMq\\Producer'); $container = $this->client->getContainer(); $container->set('old_sound_rabbit_mq.weaving_the_web_amqp.twitter.user_status_producer', $mockedProducer); $this->commandClass = $this->getParameter('weaving_the_web_amqp.produce_lists_members_command.class'); $this->setUpApplicationCommand(); $this->commandTester = $this->getCommandTester('wtw:amqp:tw:prd:lm'); $options = ['command' => $this->getCommandName(), '--screen_name' => 'Firefox', '--list' => 'Type']; $this->commandTester->execute($options); $commandDisplay = $this->commandTester->getDisplay(); $this->assertNotContains('Exception', $commandDisplay); }
public function it_finds_the_instagram_code(ElementInterface $element) { $prophet = new Prophet(); $anchor = $prophet->prophesize('Predmond\\HtmlToAmp\\Element'); $anchor->getAttribute('href')->willReturn('https://www.instagram.com/p/AAA-aaa/'); $sibling = $prophet->prophesize('Predmond\\HtmlToAmp\\Element'); $sibling->getAttribute('href')->willReturn(''); $parent = $prophet->prophesize('Predmond\\HtmlToAmp\\Element'); $parent->getAttribute('href')->willReturn(''); $parent->getChildren()->willReturn([$anchor, $sibling]); $element->getAttribute('href')->willReturn(''); $element->getChildren()->willReturn([$parent]); $this->getEmbedShortcode($element)->shouldBe('AAA-aaa'); }
/** * @BeforeScenario */ public function setup() { $this->prophet = new Prophet(); $this->commandBus = $this->prophet->prophesize(CommandBusAdapterInterface::class); $this->commandIdGenerator = $this->prophet->prophesize(CommandIdGeneratorInterface::class); $this->commandIdGenerator->generateId(Argument::any())->willReturn('test_command_id'); $this->queueResolver = $this->prophet->prophesize(QueueResolverInterface::class); $this->queueResolver->resolveQueueName(Argument::any())->willReturn('test_queue'); $this->clock = $this->prophet->prophesize(ClockInterface::class); $implementation = $this->getImplementation(); $this->implementation = new Implementation($this->queueResolver->reveal(), $implementation->getCommandSerializer(), $this->commandIdGenerator->reveal(), $implementation->getQueueDriver(), $implementation->getSchedulerDriver(), $this->clock->reveal(), $this->commandBus->reveal(), new NullLogger()); $this->implementation->getQueueDriver()->deleteQueue('test_queue'); $this->implementation->getSchedulerDriver()->clearSchedule(); }
private function mockDb() { $prophet = new Prophet(); $db = $prophet->prophesize('App\\Database\\PDODatabase'); $db->willImplement('App\\Database\\Database'); $dbStatement = $prophet->prophesize('PDOStatement'); $dbStatement->execute(["test", 1099, "test text"])->willReturn(true); $dbStatement->execute([1])->willReturn(true); $dbStatement->fetch(\PDO::FETCH_ASSOC)->willReturn(['id' => 1, 'name' => 'test', 'price' => 1099, 'description' => 'some test data']); $dbStatement->execute([1, "Philip", 1099, "some test data", 1, "test", 1099, "some test data"])->willReturn(true); $db->prepare('INSERT INTO `products`(`name`, `price`, `description`) VALUES (?, ?, ?)')->willReturn($dbStatement); $db->prepare('SELECT `id`, `name`, `price`, `description` FROM `products` WHERE `id` = ?')->willReturn($dbStatement); $db->prepare('UPDATE `products` SET `id` = ?, `name` = ?, `price` = ?, `description` = ? WHERE `id` = ? AND `name` = ? AND `price` = ? AND `description` = ?')->willReturn($dbStatement); return $db->reveal(); }
/** * @return \Phpro\MailManager\Mail\MailInterface */ protected function getMailStub() { $prophet = new Prophet(); /** @var \Phpro\MailManager\Mail\MailInterface $mail */ $mail = $prophet->prophesize('Phpro\\MailManager\\Mail\\MailInterface'); $headers = $prophet->prophesize('Zend\\Mail\\Headers'); $mail->getTo()->willReturn(['*****@*****.**' => 'me']); $mail->getCc()->willReturn(['*****@*****.**' => 'me']); $mail->getBcc()->willReturn(['*****@*****.**' => 'me']); $mail->getFrom()->willReturn(['*****@*****.**' => 'me']); $mail->getSubject()->willReturn('Subject'); $mail->getHeaders()->willReturn($headers); $mail->getAttachments()->willReturn(['name' => '/tmp/file.txt']); return $mail->reveal(); }
function let(Laravel $laravel, ExampleNode $example, SpecificationInterface $context) { $this->beConstructedWith($laravel); $p = new Prophet(); $this->refMethod = $p->prophesize('ReflectionMethod'); $this->refMethod->invokeArgs(Argument::type('PhpSpec\\SpecificationInterface'), Argument::type('array'))->shouldBeCalled(); $refClass = $p->prophesize('ReflectionClass'); $refClass->hasMethod('setLaravel')->willReturn(true); $refClass->hasMethod('setLaravel')->shouldBeCalled(); $refClass->getMethod('setLaravel')->willReturn($this->refMethod->reveal()); $refClass->getMethod('setLaravel')->shouldBeCalled(); $specNode = $p->prophesize('PhpSpec\\Loader\\Node\\SpecificationNode'); $specNode->getClassReflection()->willReturn($refClass->reveal()); $example->getSpecification()->willReturn($specNode->reveal()); }
/** * @param Payment $payment * @param TransactionDetails $transactionDetails * * @dataProvider dataProvider */ public function testXMLGeneration($payment, $transactionDetails) { $prophet = new Prophet(); $orderService = $prophet->prophesize('Checkdomain\\TeleCash\\IPG\\API\\Service\\OrderService'); $sellHosted = new SellHostedData($orderService->reveal(), $payment, $transactionDetails); $document = $sellHosted->getDocument(); $document->appendChild($sellHosted->getElement()); $elementCCType = $document->getElementsByTagName('ns1:CreditCardTxType'); $this->assertEquals(1, $elementCCType->length, 'Expected element CreditCardTxType not found'); $children = []; /** @var \DOMNode $child */ foreach ($elementCCType->item(0)->childNodes as $child) { $children[$child->nodeName] = $child->nodeValue; } $this->assertArrayHasKey('ns1:Type', $children, 'Expected element Type not found'); $this->assertEquals('sale', $children['ns1:Type'], 'Type did not match'); $elementPayment = $document->getElementsByTagName('ns1:Payment'); $this->assertEquals(1, $elementPayment->length, 'Expected element Payment not found'); if ($transactionDetails !== null) { $elementDetails = $document->getElementsByTagName('ns2:TransactionDetails'); $this->assertEquals(1, $elementDetails->length, 'Expected element TransactionDetails not found'); } else { $elementDetails = $document->getElementsByTagName('ns2:TransactionDetails'); $this->assertEquals(0, $elementDetails->length, 'Unexpected element TransactionDetails was found'); } }
/** * Mock the authorization service * * @param bool $isAllowed */ protected function mockAuthorizeService($isAllowed = true) { $prophet = new Prophet(); $authorizeService = $prophet->prophesize('\\BjyAuthorize\\Service\\Authorize'); $authorizeService->isAllowed(Argument::cetera())->willReturn($isAllowed); $this->mockListenerFactory($authorizeService->reveal()); }
/** * @test */ public function it_should_handle_multiple_messages() { // Create 2 messages $wholeMessageLength = 0 + \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::INT_32_LENGTH + \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::HEADER_LENGTH; $buffer1 = new \TrafficCophp\ByteBuffer\Buffer($wholeMessageLength); $buffer1->writeInt32LE(18, 0); $buffer1->writeInt8(\Madkom\EventStore\Client\Domain\Socket\Message\MessageType::PING, \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::MESSAGE_TYPE_OFFSET); $buffer1->writeInt8(\Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::FLAGS_NONE, \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::FLAG_OFFSET); $buffer1->write(hex2bin('12350000000000000000000000000000'), \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::CORRELATION_ID_OFFSET); $buffer2 = new \TrafficCophp\ByteBuffer\Buffer($wholeMessageLength); $buffer2->writeInt32LE(18, 0); $buffer2->writeInt8(\Madkom\EventStore\Client\Domain\Socket\Message\MessageType::PING, \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::MESSAGE_TYPE_OFFSET); $buffer2->writeInt8(\Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::FLAGS_NONE, \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::FLAG_OFFSET); $buffer2->write(hex2bin('12350000000000000000000000000000'), \Madkom\EventStore\Client\Domain\Socket\Message\MessageConfiguration::CORRELATION_ID_OFFSET); $messageType = $this->internalProphet->prophesize('Madkom\\EventStore\\Client\\Domain\\Socket\\Message\\MessageType'); $messageType->getType()->willReturn(\Madkom\EventStore\Client\Domain\Socket\Message\MessageType::PING); $this->socketMessage->getMessageType()->willReturn($messageType->reveal()); $this->socketMessage->reveal(); $buffer = (string) $buffer1 . (string) $buffer2; $this->messageDecomposer->decomposeMessage((string) $buffer1)->willReturn($this->socketMessage); $socketMessages = $this->streamHandler->handle($buffer); PHPUnit_Framework_Assert::assertEquals(2, sizeof($socketMessages)); foreach ($socketMessages as $socketMessage) { PHPUnit_Framework_Assert::assertInstanceOf('Madkom\\EventStore\\Client\\Domain\\Socket\\Message\\SocketMessage', $socketMessage); } }