/** */ public function testCreate() { /** @var EntityInterface|ObjectProphecy $entity */ $entity = $this->prophesize('AppBundle\\Entity\\EntityInterface'); $this->repository->create()->willReturn($entity->reveal())->shouldBeCalledTimes(1); $this->assertSame($entity->reveal(), $this->manager->create()); }
public function testItHydrateDataboxWhenInCache() { $databox = $this->prophesize(\databox::class); $this->cache->fetch($this->cacheKey)->willReturn([42 => ['foo' => 'bar']]); $this->repository->find(42)->shouldNotBeCalled(); $this->factory->create(42, ['foo' => 'bar'])->willReturn($databox->reveal()); $this->assertSame($databox->reveal(), $this->sut->find(42)); }
public function testItReturnsNullOnNonExistentDatabox() { $statement = $this->prophesize(Statement::class); $this->connection->prepare('SELECT ord, viewname, label_en, label_fr, label_de, label_nl FROM sbas WHERE sbas_id = :id')->willReturn($statement->reveal()); $statement->execute(['id' => 42])->shouldBeCalled(); $statement->fetch(\PDO::FETCH_ASSOC)->willReturn(false); $statement->closeCursor()->shouldBeCalled(); $this->factory->create(42, Argument::any())->shouldNotBeCalled(); $this->assertNull($this->sut->find(42)); }
/** * @param array $symfonyConstraints * @param array $expected * * @test * @dataProvider validProvider */ public function valid(array $symfonyConstraints, array $expected) { foreach ($symfonyConstraints as $key => $constraint) { $this->factory->create($constraint)->shouldBeCalled()->willReturn($expected[$key]); } $builder = $this->createBuilder(); $builder->configure(['constraints' => $symfonyConstraints]); $parsleyConstraints = $builder->build(); $this->assertInternalType('array', $parsleyConstraints); $this->assertCount(count($expected), $parsleyConstraints); foreach ($parsleyConstraints as $key => $constraint) { $this->assertSame($expected[$key], $constraint); } }
public function testIsCreatingFormWithTransformers() { $fieldOneMock = $this->prophesize('Symfony\\Component\\Form\\FormBuilder'); $formConfiguration = ['foo' => ['field1' => ['enabled' => true, 'type' => 'field1_type', 'transformer' => ['class' => 'Linio\\DynamicFormBundle\\Tests\\Form\\FormFactoryTest\\MockTransformer', 'calls' => [['setUserFormat', ['d/m/Y']], ['setInputFormat', ['Y-m-d']]]]]]]; $bornDateTransformer = new $formConfiguration['foo']['field1']['transformer']['class'](); $bornDateTransformer->setUserFormat(['d/m/Y']); $bornDateTransformer->setInputFormat(['Y-m-d']); $expectedFieldOptions = []; $this->formFactoryMock->createNamedBuilder('foo', 'form', [], [])->willReturn($this->formBuilderMock->reveal()); $this->formBuilderMock->create('field1', 'field1_type', $expectedFieldOptions)->willReturn($fieldOneMock->reveal()); $fieldOneMock->addModelTransformer($bornDateTransformer)->shouldBeCalled(); $this->formBuilderMock->add($fieldOneMock->reveal())->shouldBeCalledTimes(1); $this->formBuilderMock->getForm()->willReturn('foo_form'); $this->formFactory->setFormFactory($this->formFactoryMock->reveal()); $this->formFactory->setConfiguration($formConfiguration); $actual = $this->formFactory->createForm('foo'); $this->assertEquals('foo_form', $actual); }
/** * @param string $formTypeName * @param ObjectProphecy $entity * @param string $method * @param ObjectProphecy $form * @param array $parameters */ protected function prophesizeProcessFormFirstPart($formTypeName, ObjectProphecy $entity, $method, ObjectProphecy $form, array $parameters) { $this->formFactory->create($formTypeName, $entity->reveal(), array('method' => $method))->willReturn($form->reveal())->shouldBeCalledTimes(1); $form->submit($parameters, 'PATCH' !== $method)->shouldBeCalledTimes(1); }
/** * @test */ public function expirationDateIsDefinedIfWhenProvided() { $this->apiKeyService->create(Argument::type(\DateTime::class))->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'api-key:generate', '--expirationDate' => '2016-01-01']); }