PHP Classes

File: tests/Unit/Customs/ImageOverlayTest.php

Recommend this page to a friend!
  Packages of Amirreza Ebrahimi   HeroQR Powerful PHP QR Code Library to generate PNG, SVG, PDF, Logos Ready to Use with Laravel   tests/Unit/Customs/ImageOverlayTest.php   Download  
File: tests/Unit/Customs/ImageOverlayTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: HeroQR Powerful PHP QR Code Library to generate PNG, SVG, PDF, Logos Ready to Use with Laravel
Generate QR code images in several formats
Author: By
Last change: Update of tests/Unit/Customs/ImageOverlayTest.php
Date: 6 months ago
Size: 1,588 bytes
 

Contents

Class file image Download
<?php

namespace HeroQR\Tests\Unit\Customs;

use
HeroQR\Customs\ImageOverlay;
use
PHPUnit\Framework\{Attributes\Test,TestCase};

/**
 * Class ImageOverlayTest
 * Tests the ImageOverlay class.
 */
class ImageOverlayTest extends TestCase
{
    private
string $validBackgroundKey;
    private
string $validOverlayKey;

   
/**
     * Setup method
     */
   
protected function setUp(): void
   
{
       
$this->validBackgroundKey = 'M' . mt_rand(1, 4);
       
$this->validOverlayKey = 'C' . mt_rand(1, 4);
    }

   
/**
     * Test the constructor with valid keys
     */
    #[Test]
   
public function isConstructorWithValidKeys(): void
   
{
       
$imageOverlay = new ImageOverlay($this->validBackgroundKey, $this->validOverlayKey);
       
$this->assertInstanceOf(ImageOverlay::class, $imageOverlay);
    }

   
/**
     * Test the constructor with invalid keys
     */
    #[Test]
   
public function isConstructorWithInvalidKeys(): void
   
{
       
$this->expectException(\InvalidArgumentException::class);
       
$this->expectExceptionMessageMatches('/Invalid key \'.+\' provided. Valid keys are : .+/');

        new
ImageOverlay('InvalidKey', 'AnotherInvalidKey', []);
    }

   
/**
     * Test saving the image with valid paths
     */
    #[Test]
   
public function isSaveImage(): void
   
{
       
$imageOverlay = new ImageOverlay($this->validBackgroundKey, $this->validOverlayKey, []);
       
$outputPath = __DIR__ . '/output.png';
       
$imageOverlay->saveImage($outputPath);

       
$this->assertFileExists($outputPath);

        @
unlink($outputPath);
    }
}