diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index bb1747f..b9cf6f7 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -85,19 +85,6 @@ jobs: name: Run PHPStan run: vendor/bin/phpstan analyse -# - -# name: Run PHPSpec -# run: vendor/bin/phpspec run --ansi -f progress --no-interaction - - name: Run PHPUnit run: vendor/bin/phpunit --colors=always - - - - name: Upload Behat logs - uses: actions/upload-artifact@v2 - if: failure() - with: - name: Behat logs - path: etc/build/ - if-no-files-found: ignore diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5132263..c51f477 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,7 @@ --> - + tests @@ -22,5 +22,3 @@ - - diff --git a/src/Command/GmvCommand.php b/src/Command/GmvCommand.php index 1865c3d..86356a7 100644 --- a/src/Command/GmvCommand.php +++ b/src/Command/GmvCommand.php @@ -83,8 +83,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::SUCCESS; } - foreach ($gmvs as $key => $gmv) { - $output->writeln(sprintf('GMV in %s: %s', $key, $gmv)); + foreach ($gmvs as $currencyCode => $gmv) { + $output->writeln(sprintf('GMV in %s: %s', $currencyCode, $gmv)); } return Command::SUCCESS; diff --git a/src/Parser/DateParser.php b/src/Parser/DateParser.php index e9cff63..942ac9d 100644 --- a/src/Parser/DateParser.php +++ b/src/Parser/DateParser.php @@ -23,7 +23,7 @@ public function parseStartOfMonth(string $date): \DateTime throw new \InvalidArgumentException('Invalid date format. Expected format: m/Y.'); } - return $dateTime->modify('first day of this month')->setTime(0, 0, 0); + return $dateTime->modify('first day of this month 00:00:00'); } public function parseEndOfMonth(string $date): \DateTime @@ -34,15 +34,14 @@ public function parseEndOfMonth(string $date): \DateTime throw new \InvalidArgumentException('Invalid date format. Expected format: m/Y.'); } - return $dateTime->modify('last day of this month') - ->setTime(23, 59, 59); + return $dateTime->modify('last day of this month 23:59:59'); } public function getDefaultStartDate(): \DateTime { $now = new \DateTime(); - return (clone $now) + return $now ->modify('first day of -12 months'); } @@ -50,7 +49,7 @@ public function getDefaultEndDate(): \DateTime { $now = new \DateTime(); - return (clone $now) + return $now ->modify('last day of last month'); } } diff --git a/src/Provider/GmvProvider.php b/src/Provider/GmvProvider.php index 1dc6569..32428d9 100644 --- a/src/Provider/GmvProvider.php +++ b/src/Provider/GmvProvider.php @@ -15,6 +15,7 @@ use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface; use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; +use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\OrderCheckoutStates; use Sylius\Component\Core\OrderPaymentStates; @@ -50,7 +51,7 @@ private function findCurrenciesInOrders(\DateTimeInterface $periodStart, \DateTi { $queryBuilder = $this->orderRepository->createQueryBuilder('o'); - $query = $queryBuilder + $currencies = $queryBuilder ->select('o.currencyCode') ->andWhere('o.checkoutCompletedAt >= :periodStart') ->andWhere('o.checkoutCompletedAt <= :periodEnd') @@ -61,9 +62,8 @@ private function findCurrenciesInOrders(\DateTimeInterface $periodStart, \DateTi ->setParameter('completedState', OrderCheckoutStates::STATE_COMPLETED) ->setParameter('cancelledState', OrderPaymentStates::STATE_CANCELLED) ->groupBy('o.currencyCode') - ->getQuery(); - - $currencies = $query->getScalarResult(); + ->getQuery() + ->getScalarResult(); Assert::isArray($currencies); @@ -74,7 +74,7 @@ private function calculateGmvForPeriodAndCurrency(\DateTimeInterface $periodStar { $queryBuilder = $this->orderRepository->createQueryBuilder('o'); - $totalItemsQuery = $queryBuilder + $totalItemsQuery = (int) $queryBuilder ->select('SUM(o.itemsTotal) as totalItems') ->andWhere('o.checkoutCompletedAt >= :periodStart') ->andWhere('o.checkoutCompletedAt <= :periodEnd') @@ -89,7 +89,7 @@ private function calculateGmvForPeriodAndCurrency(\DateTimeInterface $periodStar ->getQuery() ->getSingleScalarResult(); - $totalTaxQuery = $queryBuilder + $totalTaxQuery = (int) $queryBuilder ->select('SUM(adjustment.amount) as totalTaxes') ->leftJoin('o.items', 'items') ->leftJoin('items.units', 'units') @@ -103,14 +103,11 @@ private function calculateGmvForPeriodAndCurrency(\DateTimeInterface $periodStar ->setParameter('periodEnd', $periodEnd) ->setParameter('completedState', OrderCheckoutStates::STATE_COMPLETED) ->setParameter('cancelledState', OrderPaymentStates::STATE_CANCELLED) - ->setParameter('taxType', 'tax') + ->setParameter('taxType', AdjustmentInterface::TAX_ADJUSTMENT) ->setParameter('currencyCode', $currencyCode) ->getQuery() ->getSingleScalarResult(); - $totalItems = (int) $totalItemsQuery; - $totalTaxes = (int) $totalTaxQuery; - - return $totalItems - $totalTaxes; + return $totalItemsQuery - $totalTaxQuery; } } diff --git a/src/Validator/InputParametersValidator.php b/src/Validator/InputParametersValidator.php index 0a25cee..8300c12 100644 --- a/src/Validator/InputParametersValidator.php +++ b/src/Validator/InputParametersValidator.php @@ -21,16 +21,6 @@ public function __construct(private readonly DateParserInterface $dateParser) { } - public function validateDateFormat(string $date): bool - { - return preg_match('/^(0[1-9]|1[0-2])\/\d{4}$/', $date) === 1; - } - - public function validateDates(\DateTime $startDate, \DateTime $endDate): bool - { - return $startDate < $endDate; - } - public function validate(string $periodStart, string $periodEnd): bool { if (!$this->validateDateFormat($periodStart) || !$this->validateDateFormat($periodEnd)) { @@ -42,4 +32,14 @@ public function validate(string $periodStart, string $periodEnd): bool return $this->validateDates($startDate, $endDate); } + + private function validateDateFormat(string $date): bool + { + return preg_match('/^(0[1-9]|1[0-2])\/\d{4}$/', $date) === 1; + } + + private function validateDates(\DateTime $startDate, \DateTime $endDate): bool + { + return $startDate < $endDate; + } } diff --git a/src/Validator/InputParametersValidatorInterface.php b/src/Validator/InputParametersValidatorInterface.php index 6eccdce..e2c8e9e 100644 --- a/src/Validator/InputParametersValidatorInterface.php +++ b/src/Validator/InputParametersValidatorInterface.php @@ -15,9 +15,5 @@ interface InputParametersValidatorInterface { - public function validateDateFormat(string $date): bool; - - public function validateDates(\DateTime $startDate, \DateTime $endDate): bool; - public function validate(string $periodStart, string $periodEnd): bool; } diff --git a/tests/Application/config/config.yaml b/tests/Application/config/config.yaml index 7d06fb0..e2fa1c2 100644 --- a/tests/Application/config/config.yaml +++ b/tests/Application/config/config.yaml @@ -1,25 +1,25 @@ imports: - - { resource: '@SyliusCoreBundle/Resources/config/app/config.yml' } - - { resource: '@SyliusGmvBundle/config/services.xml' } + - { resource: '@SyliusCoreBundle/Resources/config/app/config.yml' } + - { resource: '@SyliusGmvBundle/config/services.xml' } parameters: - locale: en_US + locale: en_US security: - firewalls: - main: - security: false + firewalls: + main: + security: false framework: - test: true - session: - handler_id: null - csrf_protection: ~ - router: - resource: ~ - secret: 'test' + test: true + session: + handler_id: null + csrf_protection: ~ + router: + resource: ~ + secret: 'test' doctrine: - dbal: - driver: pdo_sqlite - path: '%kernel.project_dir%/var/data/test.sqlite' + dbal: + driver: pdo_sqlite + path: '%kernel.project_dir%/var/data/test.sqlite' diff --git a/tests/Functional/GmvProviderTest.php b/tests/Functional/GmvProviderTest.php index 097b573..46429b3 100644 --- a/tests/Functional/GmvProviderTest.php +++ b/tests/Functional/GmvProviderTest.php @@ -15,7 +15,6 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Tools\SchemaTool; -use Sylius\GmvBundle\Parser\DateParserInterface; use Sylius\GmvBundle\Provider\GmvProviderInterface; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -25,15 +24,12 @@ class GmvProviderTest extends KernelTestCase private EntityManagerInterface $entityManager; - private DateParserInterface $dateParser; - protected function setUp(): void { self::bootKernel(['environment' => 'test']); $container = static::getContainer(); $this->entityManager = $container->get('doctrine.orm.entity_manager'); - $this->dateParser = $container->get('sylius_gmv.parser.date'); $this->gmvProvider = $container->get('sylius_gmv.provider.gmv'); $this->createDatabaseSchema(); @@ -46,10 +42,7 @@ public function testGmvNoSales(): void $gmv = $this->gmvProvider->getGmvForPeriod($periodStart, $periodEnd); - $this->assertEquals( - [], - $gmv, - ); + $this->assertEmpty($gmv); } public function testGmvNoShippingNoTaxes(): void