| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- declare(strict_types=1);
- namespace App\Tests\Unit\Service\Twig;
- use App\Service\Twig\ToBase64Extension;
- use Path\Path;
- use PHPUnit\Framework\MockObject\MockObject;
- use PHPUnit\Framework\TestCase;
- use Twig\TwigFilter;
- class ToBase64ExtensionTest extends TestCase
- {
- private string $projectDir = '/test/project';
- private function getToBase64ExtensionMockFor(string $methodName): ToBase64Extension|MockObject
- {
- return $this->getMockBuilder(ToBase64Extension::class)
- ->setConstructorArgs([$this->projectDir])
- ->setMethodsExcept([$methodName])
- ->getMock();
- }
- /**
- * @see ToBase64Extension::getFilters()
- */
- public function testGetFilters(): void
- {
- $extension = $this->getToBase64ExtensionMockFor('getFilters');
- $filters = $extension->getFilters();
- $this->assertIsArray($filters);
- $this->assertCount(1, $filters);
- $this->assertInstanceOf(TwigFilter::class, $filters[0]);
- $this->assertSame('img_to_base64', $filters[0]->getName());
- // Test that the callable is correctly set
- $callable = $filters[0]->getCallable();
- $this->assertIsArray($callable);
- $this->assertSame($extension, $callable[0]);
- $this->assertSame('imgToBase64', $callable[1]);
- }
- /**
- * @see ToBase64Extension::imgToBase64()
- */
- public function testImgToBase64WithNonExistentFile(): void
- {
- $extension = $this->getToBase64ExtensionMockFor('imgToBase64');
- // Test with a non-existent file - this should return empty string without file operations
- $result = $extension->imgToBase64('non-existent-image.jpg');
- $this->assertSame('', $result);
- }
- }
|