PHP Classes

File: tests/FactoryTest.php

Recommend this page to a friend!
  Classes of Yuriy Tkachenko   Simple Flash Messages   tests/FactoryTest.php   Download  
File: tests/FactoryTest.php
Role: Unit test script
Content type: text/plain
Description: test factory
Class: Simple Flash Messages
Display message with different CSS frameworks
Author: By
Last change: Update code
Date: 1 year ago
Size: 4,935 bytes
 

Contents

Class file image Download
<?php

namespace Tamtamchik\SimpleFlash\Test;

use
PHPUnit\Framework\TestCase;
use
Tamtamchik\SimpleFlash\Exceptions\FlashTemplateNotFoundException;
use
Tamtamchik\SimpleFlash\Flash;
use
Tamtamchik\SimpleFlash\TemplateFactory;
use
Tamtamchik\SimpleFlash\Templates;
use function
Tamtamchik\SimpleFlash\flash;

require_once
__DIR__ . '/../vendor/autoload.php';
require_once
'BadTemplate.php';

class
FactoryTest extends TestCase
{
    public static function
setUpBeforeClass(): void
   
{
       
flash()->clear();
    }

    private
$templates = [];

   
/**
     * Prepare setup before tests.
     */
   
protected function setUp(): void
   
{
       
$templatesReflection = new \ReflectionClass('Tamtamchik\\SimpleFlash\\Templates');
       
$this->templates = $templatesReflection->getConstants();
    }

   
/**
     * Base create function.
     *
     * @param $name
     * @throws FlashTemplateNotFoundException
     */
   
private function _testTemplate($name)
    {
       
$template = TemplateFactory::create($name);

       
$flash = new Flash();

       
$flash->setTemplate($template);

       
$msg = $template->wrapMessage('Testing templates');
       
$text = $template->wrapMessages($msg, 'info');

       
$content = $flash->info('Testing templates')->display();

       
$this->assertStringContainsString($text, $content);

        unset(
$flash);
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testTemplates()
    {
        foreach (
$this->templates as $template) {
           
$this->_testTemplate($template);
        }
       
$this->_testTemplate(Templates::BASE);
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testDefaultTemplate()
    {
       
$template = TemplateFactory::create();
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\BootstrapTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testBootstrapTemplate()
    {
       
$template = TemplateFactory::create(Templates::BOOTSTRAP);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\BootstrapTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testFoundationTemplate()
    {
       
$template = TemplateFactory::create(Templates::FOUNDATION);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\FoundationTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testSemanticTemplate()
    {
       
$template = TemplateFactory::create(Templates::SEMANTIC);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\SemanticTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testUiKitTemplate()
    {
       
$template = TemplateFactory::create(Templates::UIKIT);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\UikitTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testBulmaTemplate()
    {
       
$template = TemplateFactory::create(Templates::BULMA);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\BulmaTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testMaterializeTemplate()
    {
       
$template = TemplateFactory::create(Templates::MATERIALIZE);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\MaterializeTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testSpectreTemplate()
    {
       
$template = TemplateFactory::create(Templates::SPECTRE);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\SpectreTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testTailwindTemplate()
    {
       
$template = TemplateFactory::create(Templates::TAILWIND);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\TailwindTemplate', get_class($template));
    }

   
/**
     * @test
     * @throws FlashTemplateNotFoundException
     */
   
public function testPrimerTemplate()
    {
       
$template = TemplateFactory::create(Templates::PRIMER);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\PrimerTemplate', get_class($template));
    }

   
/** @test */
   
public function testNotFoundTemplate()
    {
        try {
           
TemplateFactory::create('ABCTemplate');
        } catch (
FlashTemplateNotFoundException $e) {
           
$this->assertStringContainsString('Template "ABCTemplate" not found!', $e->getMessage());
        }
    }
}