Skip to content

Commit

Permalink
fix: Reduce flakiness of SitemapLockTest
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Oct 5, 2024
1 parent e02916c commit 1d51a16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
10 changes: 0 additions & 10 deletions .phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -39625,16 +39625,6 @@ parameters:
count: 1
path: tests/Unit/Bundle/SitemapBundle/Service/UrlFilterTest.php

-
message: "#^Method Shopware\\\\Tests\\\\Unit\\\\Bundle\\\\SitemapBundle\\\\SitemapLockTest\\:\\:testAcquireLockDefaultFalse\\(\\) has no return type specified\\.$#"
count: 1
path: tests/Unit/Bundle/SitemapBundle/SitemapLockTest.php

-
message: "#^Method Shopware\\\\Tests\\\\Unit\\\\Bundle\\\\SitemapBundle\\\\SitemapLockTest\\:\\:testAcquireLockWorks\\(\\) has no return type specified\\.$#"
count: 1
path: tests/Unit/Bundle/SitemapBundle/SitemapLockTest.php

-
message: "#^Method Shopware\\\\Tests\\\\Unit\\\\Bundle\\\\SitemapBundle\\\\SitemapNameGeneratorTest\\:\\:testPathGeneration\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
29 changes: 14 additions & 15 deletions tests/Unit/Bundle/SitemapBundle/SitemapLockTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* Shopware 5
* Copyright (c) shopware AG
Expand All @@ -24,7 +26,9 @@
namespace Shopware\Tests\Unit\Bundle\SitemapBundle;

use DateTime;
use DateTimeInterface;
use DateTimeZone;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shopware\Bundle\SitemapBundle\Service\SitemapLock;
use Shopware\Bundle\StoreFrontBundle\Service\Core\CoreCache;
Expand All @@ -33,38 +37,28 @@
class SitemapLockTest extends TestCase
{
/**
* @var CoreCache
* @var CoreCache&MockObject
*/
private $cacheMock;
private CoreCache $cacheMock;

/**
* @var int
*/
private $lifeTime;
private int $lifeTime;

public function setUp(): void
{
parent::setUp();

$this->lifeTime = 3600;

$data = sprintf('Locked: %s', (new DateTime('NOW', new DateTimeZone('UTC')))->format(DateTime::ATOM));

$this->cacheMock = $this->getMockBuilder(CoreCache::class)
->disableOriginalConstructor()
->setMethods(['save', 'fetch'])
->getMock();

$this->cacheMock->method('fetch')
->with('sitemap-exporter-running-1')
->willReturn(false);

$this->cacheMock->method('save')
->with('sitemap-exporter-running-1', $data, $this->lifeTime)
->willReturn(false);
}

public function testAcquireLockDefaultFalse()
public function testAcquireLockDefaultFalse(): void
{
$shop = new ShopMock();
$shop->id = 1;
Expand All @@ -73,8 +67,13 @@ public function testAcquireLockDefaultFalse()
static::assertFalse($lock->isLocked($shop));
}

public function testAcquireLockWorks()
public function testAcquireLockWorks(): void
{
$data = sprintf('Locked: %s', (new DateTime('NOW', new DateTimeZone('UTC')))->format(DateTimeInterface::ATOM));
$this->cacheMock->method('save')
->with('sitemap-exporter-running-1', $data, $this->lifeTime)
->willReturn(false);

$shop = new ShopMock();
$shop->id = 1;

Expand Down

0 comments on commit 1d51a16

Please sign in to comment.