PHP Classes

File: tests/Fakerino/Test/Core/FakeHandler/FileFakerClassTest.php

Recommend this page to a friend!
  Classes of Nicola Pietroluongo   Fakerino   tests/Fakerino/Test/Core/FakeHandler/FileFakerClassTest.php   Download  
File: tests/Fakerino/Test/Core/FakeHandler/FileFakerClassTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Fakerino
Generate fake names and other types of fake data
Author: By
Last change: * Fix nested fake bug
* Fix yml parser bug
* Add tests
* Refactor classes
Date: 8 years ago
Size: 1,935 bytes
 

Contents

Class file image Download
<?php
/**
 * This file is part of the Fakerino package.
 *
 * (c) Nicola Pietroluongo <nik.longstone@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Fakerino\Test\Core\FakeHandler;

use
Fakerino\Configuration\FakerinoConf;
use
Fakerino\Core\FakeElement;
use
Fakerino\Core\FakeHandler\FileFakerClass;

/**
 * @group handler
 */
class FileFakerClassTest extends \PHPUnit_Framework_TestCase
{
    public function
testHandler()
    {
       
$elementToFake = 'Surname';
       
$fakerinoDefaultConf = new FakerinoConf();
       
$fakerinoDefaultConf->loadConfiguration();
       
$fileFakePath = $this->getFileFakePath($fakerinoDefaultConf);
       
$fakeFile = $fileFakePath
           
. strtolower($elementToFake) . '.txt';

       
$handler = new FileFakerClass($fileFakePath);
       
$customClass = new FakeElement($elementToFake);
       
$fileContent = $this->getFileContent($fakeFile);

       
$result = $handler->handle($customClass);
       
$isResultValueExistsInFile = in_array($result, $fileContent);

       
$this->assertInstanceOf('Fakerino\Core\FakeHandler\Handler', $handler);
       
$this->assertInternalType('string', $result);
       
$this->assertTrue($isResultValueExistsInFile);
    }

    private function
cleanExtraChar($val)
    {
        return
preg_replace("/\r|\n/", "", $val);
    }

    private function
getFileFakePath($fakerinoDefaultConf)
    {
        return
$fakerinoDefaultConf->get('fakeFilePath')
        .
DIRECTORY_SEPARATOR
       
. $fakerinoDefaultConf->get('locale')
        .
DIRECTORY_SEPARATOR;
    }

    private function
getFileContent($fakeFile)
    {
       
$fileContentRaw = file($fakeFile);
       
$fileContent = array();
        foreach (
$fileContentRaw as $val) {
           
$fileContent[] = $this->cleanExtraChar($val);
        }

        return
$fileContent;
    }
}