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: Using --prefer-lowest option instead (#10)

Use phpunit:^8 as default test engine
Format and add new test for Premier
Update for version 2.0
Date: 11 months ago
Size: 5,009 bytes
 

Contents

Class file image Download
<?php

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

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

class
FactoryTest extends TestCase
{
    private
$templates = [];

   
/**
     * Prepare setup before tests.
     * @throws ReflectionException
     */
   
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 testSiimpleTemplate()
    {
       
$template = TemplateFactory::create(Templates::SIIMPLE);
       
$this->assertEquals('Tamtamchik\SimpleFlash\Templates\SiimpleTemplate', 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());
        }
    }
}

For more information send a message to info at phpclasses dot org.