Skip to content

Commit

Permalink
Merge pull request Sylius#2824 from aRn0D/user_spec
Browse files Browse the repository at this point in the history
[UserBundle] CS fixes and missing specs
  • Loading branch information
Paweł Jędrzejewski committed Jun 10, 2015
2 parents 39d2c93 + d9b4376 commit d0fb20d
Show file tree
Hide file tree
Showing 47 changed files with 757 additions and 181 deletions.
3 changes: 2 additions & 1 deletion src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ sylius_variation:
variant:
model: Sylius\Component\Core\Model\ProductVariant
repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductVariantRepository
form: Sylius\Bundle\CoreBundle\Form\Type\ProductVariantType
form:
default: Sylius\Bundle\CoreBundle\Form\Type\ProductVariantType

sylius_taxation:
classes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ private function prependVariation(ContainerBuilder $container, array $config)
$container->prependExtensionConfig('sylius_variation', array(
'classes' => array(
'product' => array(
'variable' => $config['classes']['product']['model'],
'variant' => array(
'model' => 'Sylius\Component\Product\Model\Variant',
'variable' => $config['classes']['product']['model'],
'variant' => array(
'model' => 'Sylius\Component\Product\Model\Variant',
'controller' => 'Sylius\Bundle\ProductBundle\Controller\VariantController',
'form' => 'Sylius\Bundle\ProductBundle\Form\Type\VariantType'
'form' => array(
'default' => 'Sylius\Bundle\ProductBundle\Form\Type\VariantType'
),
),
'option' => array(
'model' => 'Sylius\Component\Product\Model\Option',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CustomerController extends ResourceController
{
/**
* @param Request $request
*
* @return Response
*/
public function updateProfileAction(Request $request)
Expand Down
13 changes: 7 additions & 6 deletions src/Sylius/Bundle/UserBundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ protected function createResourceForm($type, $resource)
}

/**
* @param Request $request
* @param UserInterface $user
* @param Request $request
* @param UserInterface $user
*
* @return RedirectResponse
*/
Expand Down Expand Up @@ -208,8 +208,8 @@ protected function handleResetPasswordRequest(TokenProviderInterface $generator,
}

/**
* @param UserInterface $user
* @param string $newPassword
* @param UserInterface $user
* @param string $newPassword
*
* @return RedirectResponse
*/
Expand All @@ -233,8 +233,9 @@ protected function handleResetPassword(UserInterface $user, $newPassword)
}

/**
* @param UserInterface $user
* @param string $newPassword
* @param UserInterface $user
* @param string $newPassword
*
* @return RedirectResponse
*/
protected function handleChangePassword(UserInterface $user, $newPassword)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sylius\Bundle\UserBundle\Doctrine\ORM;

use Pagerfanta\Pagerfanta;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Model\UserInterface;

Expand Down Expand Up @@ -50,7 +51,7 @@ public function findForDetailsPage($id)
* @param array $sorting
* @param bool $deleted
*
* @return PagerfantaInterface
* @return Pagerfanta
*/
public function createFilterPaginator($criteria = array(), $sorting = array(), $deleted = false)
{
Expand Down
45 changes: 33 additions & 12 deletions src/Sylius/Bundle/UserBundle/Doctrine/ORM/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Sylius\Bundle\UserBundle\Doctrine\ORM;

use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\QueryBuilder;
use Pagerfanta\PagerfantaInterface;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Model\UserInterface;
Expand Down Expand Up @@ -89,6 +91,7 @@ public function findForDetailsPage($id)
->getQuery()
->getOneOrNullResult()
;

$this->_em->getFilters()->enable('softdeleteable');

return $result;
Expand Down Expand Up @@ -118,6 +121,11 @@ public function countBetweenDates(\DateTime $from, \DateTime $to, $status = null
;
}

/**
* @param array $configuration
*
* @return array
*/
public function getRegistrationStatistic(array $configuration = array())
{
$groupBy = '';
Expand Down Expand Up @@ -145,18 +153,13 @@ public function getRegistrationStatistic(array $configuration = array())
->fetchAll();
}

protected function getCollectionQueryBuilderBetweenDates(\DateTime $from, \DateTime $to)
{
$queryBuilder = $this->getCollectionQueryBuilder();

return $queryBuilder
->andWhere($queryBuilder->expr()->gte('o.createdAt', ':from'))
->andWhere($queryBuilder->expr()->lte('o.createdAt', ':to'))
->setParameter('from', $from)
->setParameter('to', $to)
;
}

/**
* @param string $email
*
* @return mixed
*
* @throws NonUniqueResultException
*/
public function findOneByEmail($email)
{
$queryBuilder = $this->getQueryBuilder();
Expand All @@ -172,4 +175,22 @@ public function findOneByEmail($email)
->getOneOrNullResult()
;
}

/**
* @param \DateTime $from
* @param \DateTime $to
*
* @return QueryBuilder
*/
protected function getCollectionQueryBuilderBetweenDates(\DateTime $from, \DateTime $to)
{
$queryBuilder = $this->getCollectionQueryBuilder();

return $queryBuilder
->andWhere($queryBuilder->expr()->gte('o.createdAt', ':from'))
->andWhere($queryBuilder->expr()->lte('o.createdAt', ':to'))
->setParameter('from', $from)
->setParameter('to', $to)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@
*
* @author Michał Marcinkowski <[email protected]>
*/
class DefaultUsernameListener
class DefaultUsernameORMListener
{
/**
* @param LifecycleEventArgs $event
*/
public function prePersist(LifecycleEventArgs $event)
{
$item = $event->getEntity();
$user = $event->getEntity();

if (!$item instanceof UserInterface) {
if (!$user instanceof UserInterface) {
return;
}
$customer = $item->getCustomer();
if (null !== $customer && $customer->getEmail() !== $item->getUsername()) {
$item->setUsername($customer->getEmail());

$customer = $user->getCustomer();
if (null !== $customer && $customer->getEmail() !== $user->getUsername()) {
$user->setUsername($customer->getEmail());
}
}

Expand All @@ -43,14 +44,15 @@ public function prePersist(LifecycleEventArgs $event)
*/
public function preUpdate(LifecycleEventArgs $event)
{
$item = $event->getEntity();
$customer = $event->getEntity();

if (!$item instanceof CustomerInterface) {
if (!$customer instanceof CustomerInterface) {
return;
}
$user = $item->getUser();
if (null !== $user && $user->getUsername() !== $item->getEmail()) {
$user->setUsername($item->getEmail());

$user = $customer->getUser();
if (null !== $user && $user->getUsername() !== $customer->getEmail()) {
$user->setUsername($customer->getEmail());
$entityManager = $event->getEntityManager();
$entityManager->persist($user);
$entityManager->flush($user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Mailer listener for User actions
* Mailer listener for User actions.
*
* @author Łukasz Chruściel <[email protected]>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class UserDeleteListener
protected $session;

/**
* @param SecurityContextInterface $securityContext
* @param SessionInterface $session
* @param SecurityContextInterface $securityContext
* @param SessionInterface $session
*/
public function __construct(SecurityContextInterface $securityContext, SessionInterface $session)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;

class UserLastLoginListener implements EventSubscriberInterface
class UserLastLoginSubscriber implements EventSubscriberInterface
{
/**
* @var ObjectManager
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/UserBundle/Form/Model/PasswordReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Sylius\Bundle\UserBundle\Form\Model;

/**
* Model class for email validation
* Model class for email validation.
*
* @author Łukasz Chruściel <[email protected]>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CustomerProfileType extends AbstractResourceType
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options = array())
{
$builder
->add('firstName', 'text', array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct($dataClass, array $validationGroups = array(), Repos
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options = array())
{
$builder
->add('firstName', 'text', array(
Expand Down Expand Up @@ -71,7 +71,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
$resolver->setDefaults(array(
'data_class' => $this->dataClass,
'validation_groups' => $this->validationGroups,
'cascade_validation' => true
'cascade_validation' => true,
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/UserBundle/Form/Type/CustomerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('groups', 'sylius_group_choice', array(
'label' => 'sylius.form.customer.groups',
'multiple' => true,
'required' => false
'required' => false,
))
->add('user', 'sylius_user')
;
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/UserBundle/Form/Type/GenderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
CustomerInterface::UNKNOWN_GENDER => ' ',
CustomerInterface::MALE_GENDER => 'sylius.gender.male',
CustomerInterface::FEMALE_GENDER => 'sylius.gender.female',
)
),
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/UserBundle/Form/Type/GroupType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GroupType extends AbstractResourceType
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options = array())
{
$builder
->add('name', 'text', array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Form\FormBuilderInterface;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* @author Łukasz Chruściel <[email protected]>
Expand Down
13 changes: 9 additions & 4 deletions src/Sylius/Bundle/UserBundle/OAuth/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface
* @param ObjectManager $userManager
* @param CanonicalizerInterface $canonicalizer
*/
public function __construct(RepositoryInterface $customerRepository, UserRepositoryInterface $userRepository, RepositoryInterface $oauthRepository, ObjectManager $userManager, CanonicalizerInterface $canonicalizer)
{
public function __construct(
RepositoryInterface $customerRepository,
UserRepositoryInterface $userRepository,
RepositoryInterface $oauthRepository,
ObjectManager $userManager,
CanonicalizerInterface $canonicalizer
) {
parent::__construct($userRepository, $canonicalizer);
$this->customerRepository = $customerRepository;
$this->oauthRepository = $oauthRepository;
Expand Down Expand Up @@ -96,7 +101,7 @@ public function connect(UserInterface $user, UserResponseInterface $response)
}

/**
* Ad-hoc creation of user
* Ad-hoc creation of user.
*
* @param UserResponseInterface $response
*
Expand Down Expand Up @@ -126,7 +131,7 @@ protected function createUserByOAuthUserResponse(UserResponseInterface $response
}

/**
* Attach OAuth sign-in provider account to existing user
* Attach OAuth sign-in provider account to existing user.
*
* @param UserInterface $user
* @param UserResponseInterface $response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @author Łukasz Chruściel <[email protected]>
*/
abstract class UserProvider implements UserProviderInterface
abstract class AbstractUserProvider implements UserProviderInterface
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/UserBundle/Provider/EmailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author Łukasz Chruściel <[email protected]>
*/
class EmailProvider extends UserProvider
class EmailProvider extends AbstractUserProvider
{
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author Łukasz Chruściel <[email protected]>
*/
class UsernameOrEmailProvider extends UserProvider
class UsernameOrEmailProvider extends AbstractUserProvider
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/UserBundle/Provider/UsernameProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author Łukasz Chruściel <[email protected]>
*/
class UsernameProvider extends UserProvider
class UsernameProvider extends AbstractUserProvider
{
/**
* {@inheritDoc}
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Bundle/UserBundle/Reloader/UserReloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use Sylius\Component\User\Model\UserInterface;

/**
* @author Łukasz Chruściel <[email protected]>
*/
* @author Łukasz Chruściel <[email protected]>
*/
class UserReloader implements UserReloaderInterface
{
/**
Expand Down
Loading

0 comments on commit d0fb20d

Please sign in to comment.