function it_should_create_project(ProjectRepository $projectRepository, EventDispatcherInterface $eventDispatcher, Project $project, CreateProjectAction $action) { $action->getName()->willReturn('Foo bar'); $action->getSlug()->willReturn('foobar'); $action->getDefaultLocale()->willReturn('fr_FR'); $action->getDescription()->willReturn(''); $projectRepository->createNew(Argument::exact(new Slug('foobar')))->willReturn($project); $projectRepository->save($project)->shouldBeCalled(); $eventDispatcher->dispatch(CreateProjectEvent::NAME, Argument::type('Openl10n\\Domain\\Project\\Application\\Event\\CreateProjectEvent'))->shouldBeCalled(); $this->execute($action)->shouldReturn($project); }
function it_should_edit_project(ProjectRepository $projectRepository, EventDispatcherInterface $eventDispatcher, Project $project, EditProjectAction $action) { $action->getProject()->willReturn($project); $action->getName()->willReturn('Foo Bar'); $action->getDefaultLocale()->willReturn('fr_FR'); $action->getDescription()->willReturn('Description'); $project->setName(Argument::exact(new Name('Foo Bar')))->shouldBeCalled(); $project->setDefaultLocale(Argument::exact(Locale::parse('fr_FR')))->shouldBeCalled(); $project->setDescription(Argument::exact('Description'))->shouldBeCalled(); $projectRepository->save($project)->shouldBeCalled(); $eventDispatcher->dispatch(EditProjectEvent::NAME, Argument::type('Openl10n\\Domain\\Project\\Application\\Event\\EditProjectEvent'))->shouldBeCalled(); $this->execute($action)->shouldReturn($project); }
/** * @param object $value * @param Constraint $constraint * * @throws UnexpectedTypeException * @throws ConstraintDefinitionException */ public function validate($value, Constraint $constraint) { if (null === $value || '' === $value) { return; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $value = (string) $value; if (empty($value)) { return; } $project = $this->projectRepository->findOneBySlug(new Slug($value)); if (null !== $project) { $this->context->buildViolation($constraint->message)->addViolation(); } }
function it_should_delete_project(ProjectRepository $projectRepository, EventDispatcherInterface $eventDispatcher, Project $project, DeleteProjectAction $action) { $action->getProject()->willReturn($project); $projectRepository->remove($project)->shouldBeCalled(); $this->execute($action); }