function let(ObjectManager $om, ObjectRepository $or)
 {
     // It is not possible to mock internal classes with final constructor
     $this->beConstructedWith(new \SimpleXMLElement('<row></row>'), $om);
     $om->getRepository(Argument::type('string'))->willReturn($or);
     $or->findOneBy(Argument::type('array'))->willReturn();
 }
示例#2
2
 function it_builds_form_with_proper_fields(FormBuilder $builder)
 {
     $builder->add('name', 'text', Argument::any())->shouldBeCalled()->willReturn($builder);
     $builder->add('abbreviation', 'text', Argument::any())->shouldBeCalled()->willReturn($builder);
     $builder->addEventSubscriber(Argument::type(AddCodeFormSubscriber::class))->shouldBeCalled()->willReturn($builder);
     $this->buildForm($builder, []);
 }
 function it_marks_a_variant_group_as_updated_when_its_attributes_are_removed_or_updated($registry, EntityManager $em, ProductTemplateInterface $productTemplate, GroupInterface $group, GroupRepositoryInterface $groupRepo)
 {
     $productTemplate->getId()->willReturn(956);
     $registry->getRepository(Argument::type('string'))->willReturn($groupRepo);
     $groupRepo->getVariantGroupByProductTemplate($productTemplate)->willReturn($group);
     $this->guessUpdates($em, $productTemplate, UpdateGuesserInterface::ACTION_UPDATE_ENTITY)->shouldReturn([$group]);
 }
 function it_lists_user_notifications_linked_to_the_current_user(UserInterface $user, UserNotification $userNotification, Request $request, $manager, $context, $templating)
 {
     $context->getUser()->willReturn($user);
     $manager->getUserNotifications($user, Argument::cetera())->willReturn([$userNotification]);
     $templating->renderResponse('PimNotificationBundle:Notification:list.json.twig', ['userNotifications' => [$userNotification]], Argument::type('Symfony\\Component\\HttpFoundation\\JsonResponse'))->shouldBeCalled();
     $this->listAction($request);
 }
 public function it_should_add_default_options_when_making_a_call($client, $request)
 {
     $request->getOptions()->shouldBeCalled()->willReturn([]);
     $request->setOptions(Argument::type('array'))->shouldBeCalled();
     $client->makeCall($request->getWrappedObject()->getFullUrl(), $request->getWrappedObject()->getHeaders(), [])->shouldBeCalled()->willReturn(['headers' => [], 'status' => 200, 'body' => '{"pubstatus": "usable", "_links": {"parent": {"href": "/", "title": "home"}, "collection": {"href": "items", "title": "items"}, "self": {"href": "items/tag:example.com,0001:newsml_BRE9A607", "title": "Item"}}, "body_text": "Andromeda and Milky Way will collide in about 2 billion years", "type": "text", "language": "en", "versioncreated": "2015-03-09T16:32:23+0000", "uri": "http://api.master.dev.superdesk.org/items/tag%3Aexample.com%2C0001%3Anewsml_BRE9A607", "version": "2", "headline": "Andromeda on a collision course"}']);
     $this->makeApiCall($request);
 }
 function let(MetadataRendererInterface $universalRenderer, OptionsResolver $optionsResolver, PropertyAccessorInterface $propertyAccessor)
 {
     $this->beConstructedWith($universalRenderer, $optionsResolver, $propertyAccessor);
     $optionsResolver->setDefaults(Argument::type('array'))->willReturn($optionsResolver);
     $optionsResolver->setAllowedValues(Argument::any(), Argument::type('array'))->willReturn($optionsResolver);
     $optionsResolver->setAllowedTypes(Argument::any(), Argument::any())->willReturn($optionsResolver);
 }
示例#7
1
 function it_builds_form(FormBuilder $builder, FormFactoryInterface $factory)
 {
     $builder->add('type', 'sylius_promotion_rule_choice', Argument::type('array'))->willReturn($builder);
     $builder->getFormFactory()->willReturn($factory);
     $builder->addEventSubscriber(Argument::type(BuildRuleFormSubscriber::class))->shouldBeCalled();
     $this->buildForm($builder, ['configuration_type' => 'configuration_form_type']);
 }
示例#8
0
 function it_should_add_rule_event_subscriber(FormBuilder $builder, FormFactoryInterface $factory)
 {
     $builder->getFormFactory()->willReturn($factory);
     $builder->add(Argument::any(), Argument::cetera())->willReturn($builder);
     $builder->addEventSubscriber(Argument::type(BuildRuleFormSubscriber::class))->willReturn($builder);
     $this->buildForm($builder, array());
 }
 function it_lists_user_notifications_linked_to_the_current_user($userNotifRepository, $context, $templating, UserInterface $user, UserNotificationInterface $userNotification, Request $request)
 {
     $context->getUser()->willReturn($user);
     $userNotifRepository->findBy(['user' => $user], ['id' => 'DESC'], 10, null)->willReturn([$userNotification]);
     $templating->renderResponse('PimNotificationBundle:Notification:list.json.twig', ['userNotifications' => [$userNotification]], Argument::type('Symfony\\Component\\HttpFoundation\\JsonResponse'))->shouldBeCalled();
     $this->listAction($request);
 }
示例#10
0
 /**
  * @dataProvider methodProvider
  */
 public function testCallBasicMethods($method, $args, $expectedArgs)
 {
     $this->requestWrapper->send(Argument::type('callable'), $expectedArgs, Argument::type('array'))->willReturn($this->successMessage);
     $grpc = new Grpc();
     $grpc->setRequestWrapper($this->requestWrapper->reveal());
     $this->assertEquals($this->successMessage, $grpc->{$method}($args));
 }
示例#11
0
 function it_should_build_form_with_proper_fields(FormBuilder $builder)
 {
     $builder->add('description', 'textarea', Argument::any())->shouldBeCalled()->willReturn($builder);
     $builder->add('parent', 'sylius_permission_choice', Argument::any())->shouldBeCalled()->willReturn($builder);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, Argument::type('closure'))->shouldBeCalled()->willReturn($builder);
     $this->buildForm($builder, array());
 }
 public function testListenerShouldReturnBadRequestException()
 {
     $event = $this->prophesize(GetResponseForExceptionEvent::class);
     $event->getException()->willReturn(new ParamValidationFailedException(new ConstraintViolationList()));
     $event->setException(Argument::type(BadRequestHttpException::class))->shouldBeCalled();
     $this->listener->onKernelException($event->reveal());
 }
 function it_render_template_with_paginator(EngineInterface $templating, Response $response, GalleryManagerInterface $galleryManager, AdapterInterface $adapter)
 {
     $galleryManager->createPagerfantaAdapter()->willReturn($adapter);
     $adapter->getNbResults()->willReturn(5);
     $templating->renderResponse('FSiGalleryBundle:Gallery:list.html.twig', Argument::allOf(Argument::withEntry('galleries', Argument::type('Pagerfanta\\Pagerfanta')), Argument::withEntry('preview_photos_count', 4)))->willReturn($response);
     $this->listAction(2)->shouldReturn($response);
 }
示例#14
0
 function it_tries_to_remove_a_coupon_and_catches_exception_in_case_of_failure(SharedStorageInterface $sharedStorage, RepositoryInterface $couponRepository, CouponInterface $coupon)
 {
     $coupon->getId()->willReturn(5);
     $couponRepository->remove($coupon)->willThrow(ForeignKeyConstraintViolationException::class);
     $sharedStorage->set('last_exception', Argument::type(ForeignKeyConstraintViolationException::class))->shouldBeCalled();
     $this->iTryToDeleteCoupon($coupon);
 }
示例#15
0
 function it_builds_a_form(FormBuilderInterface $builder)
 {
     $builder->add('id', 'text', Argument::type('array'))->willReturn($builder);
     $builder->add('title', 'text', Argument::type('array'))->willReturn($builder);
     $builder->add('body', 'textarea', Argument::type('array'))->willReturn($builder);
     $this->buildForm($builder);
 }
 /**
  * @return CacheItemPoolInterface
  * @throws \LogicException
  *
  * @link https://gist.github.com/scaytrase/3cf9c5ece4218280669c
  */
 private function createCache()
 {
     static $items = [];
     $cache = $this->prophesize(CacheItemPoolInterface::class);
     $that = $this;
     $cache->getItem(Argument::type('string'))->will(function ($args) use(&$items, $that) {
         $key = $args[0];
         if (!array_key_exists($key, $items)) {
             $item = $that->prophesize(CacheItemInterface::class);
             $item->getKey()->willReturn($key);
             $item->isHit()->willReturn(false);
             $item->get()->willReturn(null);
             $item->set(Argument::any())->will(function ($args) use($item) {
                 $item->get()->willReturn($args[0]);
             });
             $item->expiresAfter(Argument::type('int'))->willReturn($item);
             $item->expiresAfter(Argument::exact(null))->willReturn($item);
             $item->expiresAfter(Argument::type(\DateInterval::class))->willReturn($item);
             $item->expiresAt(Argument::type(\DateTimeInterface::class))->willReturn($item);
             $items[$key] = $item;
         }
         return $items[$key]->reveal();
     });
     $cache->save(Argument::type(CacheItemInterface::class))->will(function ($args) use(&$items) {
         $item = $args[0];
         $items[$item->getKey()]->isHit()->willReturn(true);
     });
     return $cache->reveal();
 }
示例#17
0
 function it_should_build_form_with_proper_fields(FormBuilder $builder)
 {
     $builder->add('description', 'textarea', Argument::any())->shouldBeCalled()->willReturn($builder);
     $builder->addEventSubscriber(Argument::type(AddCodeFormSubscriber::class))->shouldBeCalled()->willReturn($builder);
     $builder->addEventSubscriber(Argument::type(AddParentFormSubscriber::class))->shouldBeCalled()->willReturn($builder);
     $this->buildForm($builder, []);
 }
 function it_builds_form(LocaleProviderInterface $localeProvider, FormBuilderInterface $builder)
 {
     $localeProvider->getDefinedLocalesCodes()->willReturn(['pl_PL', 'en_EN', 'en_GB']);
     $localeProvider->getDefaultLocaleCode()->willReturn('en_EN');
     $builder->addEventSubscriber(Argument::type(ResourceTranslationsSubscriber::class))->shouldBeCalled()->willReturn($builder);
     $this->buildForm($builder, ['type' => 'text']);
 }
 function let(ManagerRegistry $managerRegistry, TranslatableListener $translatableListener, ObjectManager $manager, ClassMetadata $translatableMetadata)
 {
     $managerRegistry->getManagerForClass(Argument::type('string'))->willReturn($manager);
     $translatableListener->getExtendedMetadata($manager, Argument::type('string'))->willReturn($translatableMetadata);
     $translatableListener->getLocale()->willReturn('en');
     $this->beConstructedWith($managerRegistry, $translatableListener, new PropertyAccessor());
 }
    function it_generates_class_method_from_resource($io, $tpl, $fs, ResourceInterface $resource)
    {
        $codeWithoutMethod = <<<CODE
<?php

namespace Acme;

class App
{
}

CODE;
        $codeWithMethod = <<<CODE
<?php

namespace Acme;

class App
{
METHOD
}

CODE;
        $values = array('%name%' => 'setName', '%arguments%' => '$argument1');
        $resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
        $resource->getSrcClassname()->willReturn('Acme\\App');
        $tpl->render('method', $values)->willReturn(null);
        $tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
        $fs->getFileContents('/project/src/Acme/App.php')->willReturn($codeWithoutMethod);
        $fs->putFileContents('/project/src/Acme/App.php', $codeWithMethod)->shouldBeCalled();
        $this->generate($resource, array('name' => 'setName', 'arguments' => array('everzet')));
    }
 public function let(RowBuilderFactory $rowBuilderFactory, ColumnIndexTransformer $columnIndexTransformer, ValueTransformer $valueTransformer, RowBuilder $rowBuilder)
 {
     $startWith = function ($startString) {
         return function ($string) use($startString) {
             return $startString === substr($string, 0, strlen($startString));
         };
     };
     $columnIndexTransformer->transform(Argument::that($startWith('A')))->willReturn(0);
     $columnIndexTransformer->transform(Argument::that($startWith('B')))->willReturn(1);
     $columnIndexTransformer->transform(Argument::that($startWith('C')))->willReturn(2);
     $columnIndexTransformer->transform(Argument::that($startWith('D')))->willReturn(3);
     $row = null;
     $rowBuilderFactory->create()->will(function () use($rowBuilder, &$row) {
         $row = [];
         return $rowBuilder;
     });
     $rowBuilder->addValue(Argument::type('int'), Argument::type('array'))->will(function ($args) use(&$row) {
         $row[$args[0]] = $args[1];
     });
     $rowBuilder->getData()->will(function () use(&$row) {
         return $row;
     });
     $this->beConstructedWith($rowBuilderFactory, $columnIndexTransformer, $valueTransformer, __DIR__ . '/fixtures/sheet.xml', []);
     $valueTransformer->transform(Argument::type('string'), Argument::type('string'), Argument::type('string'))->will(function ($args) {
         return $args;
     });
 }
示例#22
0
 function it_builds_a_form(FormBuilderInterface $builder)
 {
     $builder->add('name', null, Argument::type('array'))->shouldBeCalled()->willReturn($builder);
     $builder->add('parent', null, Argument::type('array'))->shouldBeCalled()->willReturn($builder);
     $builder->add('content', 'sylius_static_content_choice', Argument::type('array'))->shouldBeCalled()->willReturn($builder);
     $this->buildForm($builder);
 }
 /**
  * @param mixed $params
  * @param bool $isArray
  * @return JsonRpcClient
  */
 private function getProphetClient($params, $isArray)
 {
     $guzzle = $this->prophesize(ClientInterface::class);
     $self = $this;
     $guzzle->sendAsync(Argument::type(RequestInterface::class))->will(function ($args) use($self, $params, $isArray) {
         /** @var RequestInterface $request */
         $request = $args[0];
         $content = $request->getBody()->getContents();
         $data = json_decode($content);
         if ($isArray) {
             $self::assertTrue(is_array($data));
             $self::assertNotEmpty($data);
             $data = array_shift($data);
         }
         $self::assertEquals(JSON_ERROR_NONE, json_last_error());
         $self::assertObjectHasAttribute('id', $data);
         $self::assertObjectHasAttribute('method', $data);
         $self::assertObjectHasAttribute('params', $data);
         $self::assertObjectHasAttribute('jsonrpc', $data);
         $self::assertEquals('test', $data->id);
         $self::assertEquals('2.0', $data->jsonrpc);
         $self::assertEquals('test', $data->method);
         $self::assertEquals($params, $data->params);
         return new Promise(function () {
         }, function () {
         });
     });
     return new JsonRpcClient($guzzle->reveal(), new Uri('http://localhost/'));
 }
 function its_method_set_port_should_throw_an_exception_on_invalid_port_value()
 {
     $this->shouldThrow('\\Superdesk\\ContentApiSdk\\Exception\\InvalidArgumentException')->duringSetPort(Argument::is(null));
     $this->shouldThrow('\\Superdesk\\ContentApiSdk\\Exception\\InvalidArgumentException')->duringSetPort(Argument::type('string'));
     $this->shouldThrow('\\Superdesk\\ContentApiSdk\\Exception\\InvalidArgumentException')->duringSetPort(Argument::type('array'));
     $this->shouldThrow('\\Superdesk\\ContentApiSdk\\Exception\\InvalidArgumentException')->duringSetPort(Argument::type('object'));
 }
示例#25
0
 function it_builds_form_with_proper_fields(FormBuilderInterface $builder)
 {
     $builder->add('exchangeRate', 'number', Argument::any())->shouldBeCalled()->willReturn($builder);
     $builder->add('enabled', 'checkbox', Argument::any())->shouldBeCalled()->willReturn($builder);
     $builder->addEventSubscriber(Argument::type(AddCodeFormSubscriber::class))->shouldBeCalled()->willReturn($builder);
     $this->buildForm($builder, []);
 }
 function it_adds_payment_methods_choice_to_the_form(FormEvent $event, FormInterface $form, PaymentInterface $payment)
 {
     $event->getForm()->willReturn($form);
     $event->getData()->willReturn($payment);
     $form->add('method', Argument::type('string'), ['label' => 'sylius.form.checkout.payment_method', 'subject' => $payment, 'expanded' => true])->shouldBeCalled();
     $this->preSetData($event);
 }
 public function TODO_it_can_generate_spec_source_from_class_source($factory, ImprovedClassSource $classSource, ClassType $classType, ImprovedClassSource $specSource)
 {
     $classSource->getClassType()->willReturn($classType);
     $classType->getFullName()->willReturn('Namespace\\Class');
     $factory->create(Argument::type(ClassType::class))->willReturn($specSource);
     $this->generate($classSource)->shouldReturn($specSource);
 }
示例#28
0
 public function testBuildContainer()
 {
     $container = $this->prophesize(self::CONTAINER_CLASS);
     $container->addCompilerPass(Argument::type(self::COMPILER_PASS_CLASS))->shouldBeCalled();
     $bundle = new RestBundle();
     $bundle->build($container->reveal());
 }
 public function testShouldDispatchEvents()
 {
     $notification = Email::create();
     $notifyArg = Argument::allOf(Argument::type(Email::class), Argument::that(function ($arg) use($notification) {
         return $arg !== $notification;
     }));
     $handler = $this->prophesize(NotificationHandlerInterface::class);
     $handler->getName()->willReturn('default');
     $handler->supports(Argument::any())->willReturn(true);
     $handler->notify($notifyArg)->willReturn();
     $handler2 = $this->prophesize(NotificationHandlerInterface::class);
     $handler2->getName()->willReturn('default');
     $handler2->supports(Argument::any())->willReturn(true);
     $handler2->notify($notifyArg)->willReturn();
     $this->dispatcher->dispatch('notifire.pre_notify', Argument::type(PreNotifyEvent::class))->shouldBeCalled();
     $this->dispatcher->dispatch('notifire.notify', Argument::that(function ($arg) use($notification) {
         if (!$arg instanceof NotifyEvent) {
             return false;
         }
         $not = $arg->getNotification();
         return $not !== $notification;
     }))->shouldBeCalledTimes(2);
     $this->dispatcher->dispatch('notifire.post_notify', Argument::type(PostNotifyEvent::class))->shouldBeCalled();
     $this->manager->addHandler($handler->reveal());
     $this->manager->addHandler($handler2->reveal());
     $this->manager->notify($notification);
 }
示例#30
0
 function it_has_options(OptionsResolver $resolver)
 {
     $resolver->setDefaults(Argument::withKey('class'))->shouldBeCalled()->willReturn($resolver);
     $resolver->setNormalizer('class', Argument::type('callable'))->shouldBeCalled()->willReturn($resolver);
     $resolver->setDefaults(Argument::withKey('query_builder'))->shouldBeCalled()->willReturn($resolver);
     $this->configureOptions($resolver);
 }