/**
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  * @param \Doctrine\Common\Annotations\AnnotationReader $annotationReader
  * @param \FSi\Bundle\AdminBundle\Finder\AdminClassFinder $adminClassFinder
  */
 function it_registers_annotated_admin_classes_as_services($container, $annotationReader, $adminClassFinder)
 {
     $container->getParameter('kernel.bundles')->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\MyBundle', 'FSi\\Bundle\\AdminBundle\\FSiAdminBundle', 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'));
     $baseDir = __DIR__ . '/../../../../../..';
     $adminClassFinder->findClasses(array(realpath($baseDir . '/spec/fixtures/Admin'), realpath($baseDir . '/Admin')))->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement'));
     $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(null);
     $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(new Element(array()));
     $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/spec/fixtures/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled();
     $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled();
     $container->addDefinitions(Argument::that(function ($definitions) {
         if (count($definitions) !== 1) {
             return false;
         }
         /** @var \Symfony\Component\DependencyInjection\Definition $definition */
         $definition = $definitions[0];
         if ($definition->getClass() !== 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement') {
             return false;
         }
         if (!$definition->hasTag('admin.element')) {
             return false;
         }
         return true;
     }))->shouldBeCalled();
     $this->process($container);
 }
 function it_adds_new_entity_with_field_set(MapBuilder $builder, ResourceRepository $repository, TextType $resource)
 {
     $resource->getName()->willReturn('resources_group.resource_a.en');
     $repository->get('resources_group.resource_a.en')->willReturn(null);
     $builder->getResource(Argument::type('string'))->willReturn($resource);
     $resource->getResourceProperty()->willReturn('textValue');
     $repository->add(Argument::allOf(Argument::type('spec\\FSi\\Bundle\\ResourceRepositoryBundle\\Repository\\ResourceEntity'), Argument::which('getTextValue', 'text')))->shouldBeCalled();
     $this->set('resources_group.resource_a', 'text');
 }
 function it_dispatches_ExampleEvent_with_failed_status_if_example_throws_exception(EventDispatcherInterface $dispatcher, ExampleNode $example, ReflectionMethod $exampReflection, SpecificationInterface $context)
 {
     $example->isPending()->willReturn(false);
     $exampReflection->getParameters()->willReturn(array());
     $exampReflection->invokeArgs($context, array())->willThrow('RuntimeException');
     $dispatcher->dispatch('beforeExample', Argument::any())->shouldBeCalled();
     $dispatcher->dispatch('afterExample', Argument::which('getResult', ExampleEvent::BROKEN))->shouldBeCalled();
     $this->run($example);
 }
示例#4
0
 public function it_uploads_speech(UrlGenerator $generator, ClientInterface $client, SpeechContentInterface $speech, StreamInterface $uploadedStream, ResponseInterface $response, Uri $generatedUri)
 {
     $speech->getStream()->willReturn($uploadedStream);
     $speech->getContentType()->willReturn(null);
     $generator->generate($speech)->willReturn($generatedUri);
     $client->upload(Argument::type('Psr\\Http\\Message\\RequestInterface'))->willReturn($response);
     $this->upload($speech)->shouldReturn($response);
     $client->upload(Argument::type('Psr\\Http\\Message\\RequestInterface'))->shouldHaveBeenCalled();
     $client->upload(Argument::which('getBody', $uploadedStream->getWrappedObject()))->shouldHaveBeenCalled();
 }
 function it_decorates_expectation_with_broken_event(ExpectationInterface $expectation, EventDispatcherInterface $dispatcher)
 {
     $alias = 'be';
     $subject = new \stdClass();
     $arguments = array();
     $expectation->match(Argument::cetera())->willThrow('\\RuntimeException');
     $dispatcher->dispatch('beforeExpectation', Argument::type('PhpSpec\\Event\\ExpectationEvent'))->shouldBeCalled();
     $dispatcher->dispatch('afterExpectation', Argument::which('getResult', ExpectationEvent::BROKEN))->shouldBeCalled();
     $this->shouldThrow('\\RuntimeException')->duringMatch($alias, $subject, $arguments);
 }
示例#6
0
 function it_dispatches_ExampleEvent_with_failed_status_if_example_throws_an_error(EventDispatcherInterface $dispatcher, ExampleNode $example, ReflectionMethod $exampReflection, Specification $context)
 {
     if (!class_exists('\\Error')) {
         throw new SkippingException('The class Error, introduced in PHP 7, does not exist');
     }
     $example->isPending()->willReturn(false);
     $exampReflection->getParameters()->willReturn(array());
     $exampReflection->invokeArgs($context, array())->willThrow('Error');
     $dispatcher->dispatch('beforeExample', Argument::any())->shouldBeCalled();
     $dispatcher->dispatch('afterExample', Argument::which('getResult', ExampleEvent::BROKEN))->shouldBeCalled();
     $this->run($example);
 }
 /**
  * @param \FSi\Bundle\AdminSecurityBundle\Model\UserPasswordResetInterface $user
  * @param \Twig_Environment $twig
  * @param \Twig_Template $template
  * @param \Swift_Mailer $mailer
  * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
  */
 function it_should_render_template($user, $twig, $template, $mailer, $requestStack)
 {
     $request = new Request(array(), array(), array(), array(), array(), array('HTTP_USER_AGENT' => 'user agent', 'REMOTE_ADDR' => '192.168.99.99'));
     $requestStack->getMasterRequest()->willReturn($request);
     $templateParameters = array('user' => $user, 'ip' => '192.168.99.99', 'user_agent' => 'user agent');
     $twig->mergeGlobals($templateParameters)->willReturn($templateParameters);
     $twig->loadTemplate('mailer-template.html.twig')->willReturn($template);
     $template->renderBlock('subject', $templateParameters)->willReturn('subject string');
     $template->renderBlock('body_html', $templateParameters)->willReturn('body string');
     $user->getEmail()->willReturn('*****@*****.**');
     $mailer->send(Argument::allOf(Argument::type('\\Swift_Message'), Argument::which('getSubject', 'subject string'), Argument::which('getTo', array('*****@*****.**' => null)), Argument::which('getFrom', array('*****@*****.**' => null)), Argument::which('getReplyTo', array('*****@*****.**' => null)), Argument::which('getBody', 'body string')))->willReturn(1);
     $this->sendPasswordResetMail($user)->shouldReturn(1);
 }
示例#8
0
 public function test_it_will_return_an_hand_that_matches_the_search_null_otherwise()
 {
     $handSearch = $this->prophesize(HandSearch::class);
     $handSearch->search(Argument::cetera())->willReturn(new Hand(...[]));
     $hand = new Hand(...StaticFixtures::straight());
     $handSearch->search(Argument::which('getFaceValue', 3), Argument::cetera())->willReturn(new Hand(new Card(3, Suit::spades())))->shouldBeCalled();
     $handSearch->search(Argument::which('getFaceValue', 4), Argument::cetera())->willReturn(new Hand(new Card(4, Suit::flowers())))->shouldBeCalled();
     $handSearch->search(Argument::which('getFaceValue', 5), Argument::cetera())->willReturn(new Hand(new Card(5, Suit::spades())))->shouldBeCalled();
     $handSearch->search(Argument::which('getFaceValue', 6), Argument::cetera())->willReturn(new Hand(new Card(6, Suit::spades())))->shouldBeCalled();
     $handSearch->search(Argument::which('getFaceValue', 7), Argument::cetera())->willReturn(new Hand(new Card(7, Suit::spades())))->shouldBeCalled();
     $handSearch->search(Argument::any(), Argument::cetera())->willReturn(null);
     $finder = new StraightFinder($handSearch->reveal());
     $this->assertEquals($hand, $finder->find($hand));
 }
示例#9
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_return_a_result($gateway, $eventManager, $result)
 {
     $entity = new \StdClass();
     $entity->id = 1;
     $postData = null;
     $gateway->loadEntity('entityKey', $entity->id)->shouldBecalled()->willReturn($entity);
     $result->setSuccess(Argument::any())->shouldBeCalled();
     $result->setForm(Argument::any())->shouldNotBeCalled();
     $result->setEntity($entity)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setResult($result);
     $this->run($entity->id, $postData)->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_READ))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_READ))->shouldBeCalled();
 }
示例#10
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Zend\Form\Form                               $form
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_handle_valid_data($gateway, $eventManager, $form, $result)
 {
     $entity = new \StdClass();
     $postData = $this->getMockPostData();
     $gateway->loadEntity('entityKey', null)->shouldBecalled()->willReturn($entity);
     $gateway->delete($entity, $postData)->shouldBecalled()->willReturn(true);
     $result->setSuccess(true)->shouldBeCalled();
     $result->setEntity($entity)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setResult($result);
     $this->setForm($form);
     $this->run(null, $this->getMockPostData())->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_DELETE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DELETE))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_DELETE))->shouldBeCalled();
 }
示例#11
0
 public function test()
 {
     $relationProviders = array(new RelationProviderConfiguration('getRelations'), new RelationProviderConfiguration('Class:getRelations'));
     $relations1 = array($relation1 = new Relation('foo'));
     $relations2 = array($relation2 = new Relation('bar'));
     $classMetadataProphecy = $this->prophesize('Hateoas\\Configuration\\Metadata\\ClassMetadataInterface');
     $classMetadataProphecy->getRelationProviders()->willReturn($relationProviders);
     $metadataFactoryProphecy = $this->prophesize('Metadata\\MetadataFactoryInterface');
     $metadataFactoryProphecy->getMetadataForClass('stdClass')->willReturn($classMetadataProphecy->reveal());
     $resolverProphecy = $this->prophesize('Hateoas\\Configuration\\Provider\\Resolver\\RelationProviderResolverInterface');
     $resolverProphecy->getRelationProvider(Argument::which('getName', 'getRelations'), Argument::any())->willReturn(function () use($relations1) {
         return $relations1;
     });
     $resolverProphecy->getRelationProvider(Argument::which('getName', 'Class:getRelations'), Argument::any())->willReturn(function () use($relations2) {
         return $relations2;
     });
     $relationProvider = new RelationProvider($metadataFactoryProphecy->reveal(), $resolverProphecy->reveal());
     $object = new \StdClass();
     $this->assertSame([$relation1, $relation2], $relationProvider->getRelations($object));
 }
 /**
  * @expectedException Google\Cloud\Exception\GoogleException
  */
 public function testThrowsExceptionWithFailedUpload()
 {
     $resumeUriResponse = new Response(200, ['Location' => 'theResumeUri']);
     $this->requestWrapper->send(Argument::which('getMethod', 'POST'), Argument::type('array'))->willReturn($resumeUriResponse);
     $this->requestWrapper->send(Argument::which('getMethod', 'PUT'), Argument::type('array'))->willThrow('Google\\Cloud\\Exception\\GoogleException');
     $uploader = new ResumableUploader($this->requestWrapper->reveal(), $this->stream, 'http://www.example.com');
     $uploader->upload();
 }
示例#13
0
 function it_dispatches_event_when_given_a_labelled_fixture($dispatcher)
 {
     $dispatcher->dispatch('fixture.resolve.Car:kitt', Argument::which('getReference', 'Car:kitt'))->shouldBeCalled();
     $this->set('kitt', new Car());
 }
 function it_applies_more_than_date_range_filter(FilterDatasourceAdapterInterface $datasource, \DateTime $start, \DateTime $end, $utility)
 {
     $start->setTimezone(Argument::allOf(Argument::type('\\DateTimeZone'), Argument::which('getName', 'UTC')))->shouldBeCalled();
     $end->setTimezone(Argument::allOf(Argument::type('\\DateTimeZone'), Argument::which('getName', 'UTC')))->shouldBeCalled();
     $start->format('Y-m-d')->willReturn('1987-05-14');
     $end->format('Y-m-d')->willReturn('2014-01-23');
     $utility->applyFilter($datasource, 'data_name_key', '>', '1987-05-14')->shouldBeCalled();
     $this->apply($datasource, ['value' => ['start' => $start, 'end' => $end], 'type' => DateRangeFilterType::TYPE_MORE_THAN]);
 }
 private function isAnArrayContainingAReferenceAndAPriority($service, $priority)
 {
     return Argument::allOf(Argument::withEntry(0, Argument::allOf(Argument::type('Symfony\\Component\\DependencyInjection\\Reference'), Argument::which('__toString', $service))));
 }
 function it_should_trigger_an_event_before_and_after_operation_execution($dispatcher)
 {
     $operation = new DeleteOperation('dc=foo,dc=bar');
     $dispatcher->dispatch(Argument::which('getName', Event::LDAP_OPERATION_EXECUTE_BEFORE))->shouldBeCalled();
     $dispatcher->dispatch(Argument::which('getName', Event::LDAP_OPERATION_EXECUTE_AFTER))->shouldBeCalled();
     $this->execute($operation);
 }
 public function testIsItemVersioned()
 {
     $item = $this->prophesize('core_kernel_classes_Resource');
     $file = $this->prophesize('core_kernel_classes_Resource');
     $file->hasType(new core_kernel_classes_Class(CLASS_GENERIS_FILE))->willReturn(true);
     $item->getPropertyValues(Argument::which('getUri', TAO_ITEM_CONTENT_PROPERTY))->willReturn(array($file->reveal()));
     $this->assertTrue($this->itemsService->isItemVersioned($item->reveal()));
 }
示例#18
0
 function it_notifies_dependency_manager_when_object_with_reference_is_created(Person $person, $dependencyManager, DependencyResolver $resolver)
 {
     $dependencyManager->createResolver($this->object, Argument::type('Closure'))->willReturn($resolver);
     $dependencyManager->createReference(Argument::which('getShortName', 'Animal'), 'monkey')->willReturn('Animal:monkey');
     $resolver->depends('Animal:monkey')->shouldBeCalled();
     $dependencyManager->addResolver(Argument::type('Filler\\DependencyResolver'))->shouldBeCalled();
     $this->depends(function ($b, Animal $monkey) use($person) {
         $b->build($person)->add()->favouriteAnimal($monkey)->end();
     });
     $dependencyManager->set('monkey', Argument::type('spec\\Filler\\Animal'))->shouldBeCalled();
     $this->build('spec\\Filler\\Animal')->add('monkey')->type('monkey')->end();
 }
示例#19
0
 public function testIsGrantedFail()
 {
     $this->setExpectedException('Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException', 'Permission "view" in security context "sulu.media.collection" not granted');
     $this->authorizationChecker->isGranted(['view'], Argument::which('getSecurityContext', 'sulu.media.collection'))->willReturn(false);
     $this->securityChecker->checkPermission('sulu.media.collection', 'view');
 }
示例#20
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Zend\Form\Form                               $form
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_handle_valid_data($gateway, $eventManager, $form, $result)
 {
     $entity = new \StdClass();
     $entity->id = 1;
     $postData = $this->getMockPostData();
     $gateway->loadEntity('entityKey', $entity->id)->shouldBecalled()->willReturn($entity);
     $gateway->update($entity, $postData)->shouldBecalled()->willReturn(true);
     $form->hasValidated()->shouldBeCalled()->willreturn(false);
     $form->bind(Argument::any())->shouldBeCalled();
     $form->bindOnValidate()->shouldBeCalled();
     $form->setData(Argument::exact($this->getMockPostData()))->shouldBeCalled()->willReturn($form);
     $form->isValid()->shouldBeCalled()->willreturn(true);
     $result->setSuccess(true)->shouldBeCalled();
     $result->setForm($form)->shouldBeCalled();
     $result->setEntity($entity)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setForm($form);
     $this->setResult($result);
     $this->run($entity->id, $this->getMockPostData())->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_UPDATE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_UPDATE))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_UPDATE))->shouldBeCalled();
 }
示例#21
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Phpro\SmartCrud\Service\PaginatorServiceFactory $paginatorFactory
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  * @param \Zend\Paginator\Paginator $paginator
  * @param \Phpro\SmartCrud\Query\QueryProviderInterface $queryProvider
  */
 public function it_should_return_a_result($gateway, $eventManager, $paginatorFactory, $result, $paginator, $queryProvider)
 {
     $getData = array();
     $list = array();
     $this->setQueryProvider($queryProvider);
     $gateway->getList('entityKey', $getData, $queryProvider)->willReturn($list);
     $paginatorFactory->createPaginator($list, Argument::cetera())->willReturn($paginator);
     $this->setPaginatorFactory($paginatorFactory);
     $result->setSuccess(Argument::any())->shouldBeCalled();
     $result->setForm(Argument::any())->shouldNotBeCalled();
     $result->setList($paginator)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setResult($result);
     $this->run(Argument::any(), $getData)->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_LIST))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_LIST))->shouldBeCalled();
 }