mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 01:20:59 +00:00
Extract FakeClock's temporaryDirPath to a parameter
This commit is contained in:
parent
0d9699f287
commit
a96a700e64
7 changed files with 23 additions and 24 deletions
|
|
@ -13,16 +13,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Behat\Clock;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
|
||||
final class FakeClock implements ClockInterface
|
||||
{
|
||||
private string $temporaryDatePath;
|
||||
|
||||
public function __construct(string $projectDirectory)
|
||||
public function __construct(private string $temporaryDatePath)
|
||||
{
|
||||
$this->temporaryDatePath = $projectDirectory . '/var/temporaryDate.txt';
|
||||
}
|
||||
|
||||
public function sleep(float|int $seconds): void
|
||||
|
|
@ -30,7 +26,7 @@ final class FakeClock implements ClockInterface
|
|||
// Intentionally left blank.
|
||||
}
|
||||
|
||||
public function now(): DateTimeImmutable
|
||||
public function now(): \DateTimeImmutable
|
||||
{
|
||||
if (file_exists($this->temporaryDatePath)) {
|
||||
$dateTime = file_get_contents($this->temporaryDatePath);
|
||||
|
|
|
|||
|
|
@ -17,15 +17,15 @@ use Behat\Behat\Context\Context;
|
|||
|
||||
final class CalendarContext implements Context
|
||||
{
|
||||
public function __construct(private string $projectDirectory)
|
||||
public function __construct(private $temporaryDatePath)
|
||||
{
|
||||
}
|
||||
|
||||
/** @AfterScenario */
|
||||
public function deleteTemporaryDate(): void
|
||||
{
|
||||
if (file_exists($this->projectDirectory . '/var/temporaryDate.txt')) {
|
||||
unlink($this->projectDirectory . '/var/temporaryDate.txt');
|
||||
if (file_exists($this->temporaryDatePath)) {
|
||||
unlink($this->temporaryDatePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use Behat\Behat\Context\Context;
|
|||
|
||||
final class CalendarContext implements Context
|
||||
{
|
||||
public function __construct(private string $projectDirectory)
|
||||
public function __construct(private string $temporaryDatePath)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +26,6 @@ final class CalendarContext implements Context
|
|||
*/
|
||||
public function itIsNow(string $dateTime): void
|
||||
{
|
||||
file_put_contents($this->projectDirectory . '/var/temporaryDate.txt', $dateTime);
|
||||
file_put_contents($this->temporaryDatePath, $dateTime);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
<import resource="services/pages.xml" />
|
||||
</imports>
|
||||
|
||||
<parameters>
|
||||
<parameter key="sylius.behat.clock.fake.temporary_file">%kernel.project_dir%/var/temporaryDate.txt</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<defaults public="true" />
|
||||
|
||||
|
|
@ -111,9 +115,11 @@
|
|||
<tag name="kernel.event_subscriber" />
|
||||
</service>
|
||||
|
||||
<service id="clock" class="Sylius\Behat\Clock\FakeClock">
|
||||
<argument>%kernel.project_dir%</argument>
|
||||
<service id="sylius.behat.clock" class="Sylius\Behat\Clock\FakeClock">
|
||||
<argument>%sylius.behat.clock.fake.temporary_file%</argument>
|
||||
</service>
|
||||
<service id="clock" alias="sylius.behat.clock" />
|
||||
<service id="Symfony\Component\Clock\ClockInterface" alias="sylius.behat.clock" />
|
||||
|
||||
<service id="api_platform.iri_converter" class="Sylius\Behat\Service\Converter\IriConverter" public="false">
|
||||
<argument type="service" id="api_platform.metadata.property.name_collection_factory" />
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<defaults public="true" />
|
||||
|
||||
<service id="sylius.behat.context.hook.calendar" class="Sylius\Behat\Context\Hook\CalendarContext">
|
||||
<argument>%kernel.project_dir%</argument>
|
||||
<argument>%sylius.behat.clock.fake.temporary_file%</argument>
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.hook.doctrine_orm" class="Sylius\Behat\Context\Hook\DoctrineORMContext">
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
</service>
|
||||
|
||||
<service id="sylius.behat.context.setup.calendar" class="Sylius\Behat\Context\Setup\CalendarContext">
|
||||
<argument>%kernel.project_dir%</argument>
|
||||
<argument>%sylius.behat.clock.fake.temporary_file%</argument>
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.setup.cart" class="Sylius\Behat\Context\Setup\CartContext">
|
||||
|
|
|
|||
|
|
@ -15,13 +15,8 @@ namespace Sylius\Tests\Functional;
|
|||
|
||||
use Fidry\AliceDataFixtures\LoaderInterface;
|
||||
use Fidry\AliceDataFixtures\Persistence\PurgeMode;
|
||||
use Sylius\Bundle\PromotionBundle\Criteria\DateRange;
|
||||
use Sylius\Bundle\PromotionBundle\Provider\EligibleCatalogPromotionsProvider;
|
||||
use Sylius\Component\Core\Dashboard\Interval;
|
||||
use Sylius\Component\Core\Dashboard\SalesSummary;
|
||||
use Sylius\Component\Core\Model\CatalogPromotionInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Order\Processor\OrderProcessorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class EligibleCatalogPromotionsProcessorTest extends WebTestCase
|
||||
|
|
@ -45,8 +40,9 @@ class EligibleCatalogPromotionsProcessorTest extends WebTestCase
|
|||
{
|
||||
/** @var EligibleCatalogPromotionsProvider $eligibleCatalogPromotionsProvider */
|
||||
$eligibleCatalogPromotionsProvider = self::$kernel->getContainer()->get('Sylius\Bundle\PromotionBundle\Provider\EligibleCatalogPromotionsProviderInterface');
|
||||
$dateFilePath = self::$kernel->getContainer()->getParameter('sylius.behat.clock.date_file');
|
||||
|
||||
file_put_contents(self::$kernel->getProjectDir() . '/var/temporaryDate.txt', '2021-10-12 00:00:02');
|
||||
file_put_contents($dateFilePath, '2021-10-12 00:00:02');
|
||||
|
||||
$eligibleCatalogPromotions = $eligibleCatalogPromotionsProvider->provide();
|
||||
|
||||
|
|
@ -65,7 +61,7 @@ class EligibleCatalogPromotionsProcessorTest extends WebTestCase
|
|||
$this->assertTrue(in_array($actualDateTime, $expectedDateTimes));
|
||||
}
|
||||
|
||||
unlink(self::$kernel->getProjectDir() . '/var/temporaryDate.txt');
|
||||
unlink($dateFilePath);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
@ -73,8 +69,9 @@ class EligibleCatalogPromotionsProcessorTest extends WebTestCase
|
|||
{
|
||||
/** @var EligibleCatalogPromotionsProvider $eligibleCatalogPromotionsProvider */
|
||||
$eligibleCatalogPromotionsProvider = self::$kernel->getContainer()->get('Sylius\Bundle\PromotionBundle\Provider\EligibleCatalogPromotionsProviderInterface');
|
||||
$dateFilePath = self::$kernel->getContainer()->getParameter('sylius.behat.clock.date_file');
|
||||
|
||||
file_put_contents(self::$kernel->getProjectDir() . '/var/temporaryDate.txt', '2021-10-12 23:59:58');
|
||||
file_put_contents($dateFilePath, '2021-10-12 23:59:58');
|
||||
|
||||
$eligibleCatalogPromotions = $eligibleCatalogPromotionsProvider->provide();
|
||||
|
||||
|
|
@ -92,6 +89,6 @@ class EligibleCatalogPromotionsProcessorTest extends WebTestCase
|
|||
|
||||
$this->assertTrue(($expectedDateTimes == $actualDateTimes));
|
||||
|
||||
unlink(self::$kernel->getProjectDir() . '/var/temporaryDate.txt');
|
||||
unlink($dateFilePath);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue