Spaces:
No application file
No application file
File size: 1,821 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<?php
namespace Mautic\LeadBundle\Tests\Field;
use Mautic\LeadBundle\Field\FieldList;
use Mautic\LeadBundle\Field\FieldsWithUniqueIdentifier;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class FieldsWithUniqueIdentifierTest extends TestCase
{
/**
* @var MockObject|FieldList
*/
private $fieldList;
/**
* @var FieldsWithUniqueIdentifier
*/
private $fieldsWithUniqueIdentifier;
protected function setUp(): void
{
parent::setUp();
$this->fieldList = $this->createMock(FieldList::class);
$this->fieldsWithUniqueIdentifier = new FieldsWithUniqueIdentifier($this->fieldList);
}
public function testCacheIsUsed(): void
{
$fields = ['cached fields'];
$this->fieldList->expects($this->once())
->method('getFieldList')
->willReturn($fields);
Assert::assertSame($fields, $this->fieldsWithUniqueIdentifier->getFieldsWithUniqueIdentifier(['isPublished' => false]));
// The cache should be used on subsequent requests and a second call to getFieldList not made
Assert::assertSame($fields, $this->fieldsWithUniqueIdentifier->getFieldsWithUniqueIdentifier(['isPublished' => false]));
}
public function testCacheIsNotUsed(): void
{
$fields = ['cached fields'];
$this->fieldList->expects($this->exactly(2))
->method('getFieldList')
->willReturn($fields);
Assert::assertSame($fields, $this->fieldsWithUniqueIdentifier->getLiveFields(['isPublished' => false]));
// The cache should not be used on subsequent requests
Assert::assertSame($fields, $this->fieldsWithUniqueIdentifier->getLiveFields(['isPublished' => false]));
}
}
|