-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
275 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
spec/Provider/GiftCardChannelConfigurationProviderSpec.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Setono\SyliusGiftCardPlugin\Provider; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use PhpSpec\ObjectBehavior; | ||
use Setono\SyliusGiftCardPlugin\Factory\GiftCardConfigurationFactoryInterface; | ||
use Setono\SyliusGiftCardPlugin\Model\GiftCardChannelConfiguration; | ||
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfiguration; | ||
use Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProvider; | ||
use Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProviderInterface; | ||
use Setono\SyliusGiftCardPlugin\Repository\GiftCardConfigurationRepositoryInterface; | ||
use Sylius\Component\Channel\Model\ChannelInterface; | ||
use Sylius\Component\Locale\Context\LocaleContextInterface; | ||
use Sylius\Component\Locale\Model\LocaleInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
|
||
final class GiftCardConfigurationProviderSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, | ||
GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, | ||
LocaleContextInterface $localeContext, | ||
RepositoryInterface $localeRepository, | ||
ManagerRegistry $managerRegistry | ||
) { | ||
$this->beConstructedWith($giftCardConfigurationRepository, $giftCardConfigurationFactory, $localeContext, $localeRepository, $managerRegistry); | ||
} | ||
|
||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldBeAnInstanceOf(GiftCardConfigurationProvider::class); | ||
} | ||
|
||
public function it_implements_gift_card_configuration_provider_interface(): void | ||
{ | ||
$this->shouldImplement(GiftCardConfigurationProviderInterface::class); | ||
} | ||
|
||
public function it_provides_configuration_from_channel_and_locale( | ||
GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, | ||
ChannelInterface $channel, | ||
LocaleInterface $locale | ||
): void { | ||
$configuration = new GiftCardConfiguration(); | ||
$giftCardConfigurationRepository->findOneByChannelAndLocale($channel, $locale)->willReturn($configuration); | ||
|
||
$this->getConfiguration($channel, $locale)->shouldReturn($configuration); | ||
} | ||
|
||
public function it_provides_default_configuration_if_none_found( | ||
GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, | ||
GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, | ||
ChannelInterface $channel, | ||
LocaleInterface $locale, | ||
ManagerRegistry $managerRegistry, | ||
EntityManagerInterface $entityManager | ||
) { | ||
$managerRegistry->getManagerForClass(GiftCardConfiguration::class)->willReturn($entityManager); | ||
$giftCardConfigurationRepository->findOneByChannelAndLocale($channel, $locale)->willReturn(null); | ||
|
||
$configuration = new GiftCardConfiguration(); | ||
$configuration->addChannelConfiguration(new GiftCardChannelConfiguration()); | ||
$giftCardConfigurationRepository->findDefault()->willReturn($configuration); | ||
|
||
$this->getConfiguration($channel, $locale)->shouldReturn($configuration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Doctrine\ORM; | ||
|
||
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; | ||
use Setono\SyliusGiftCardPlugin\Repository\GiftCardConfigurationRepositoryInterface; | ||
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; | ||
use Sylius\Component\Channel\Model\ChannelInterface; | ||
use Sylius\Component\Locale\Model\LocaleInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
class GiftCardConfigurationRepository extends EntityRepository implements GiftCardConfigurationRepositoryInterface | ||
{ | ||
public function findOneByChannelAndLocale(ChannelInterface $channel, LocaleInterface $locale): ?GiftCardConfigurationInterface | ||
{ | ||
$obj = $this->createQueryBuilder('o') | ||
->join('o.channelConfigurations', 'c') | ||
->andWhere('c.channel = :channel') | ||
->andWhere('c.locale = :locale') | ||
->setParameters([ | ||
'channel' => $channel, | ||
'locale' => $locale, | ||
]) | ||
->getQuery() | ||
->getOneOrNullResult() | ||
; | ||
|
||
Assert::nullOrIsInstanceOf($obj, GiftCardConfigurationInterface::class); | ||
|
||
return $obj; | ||
} | ||
|
||
public function findDefault(): ?GiftCardConfigurationInterface | ||
{ | ||
return $this->findOneBy([ | ||
'default' => true, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.