PHP Classes

File: tests/Fakerino/Test/FakeData/AbstractFakeDataTest.php

Recommend this page to a friend!
  Classes of Nicola Pietroluongo  >  Fakerino  >  tests/Fakerino/Test/FakeData/AbstractFakeDataTest.php  >  Download  
File: tests/Fakerino/Test/FakeData/AbstractFakeDataTest.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: Merge branch 'di-fix' into 0.8.1
Date: 6 years ago
Size: 2,823 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\FakeData;

use
Fakerino\FakeData\AbstractFakeData;

class
FakeDataA extends AbstractFakeData
{
    public function
getDefaultOptions()
    {
        return array(
'defaultOption1' => 1,
           
'defaultOption2' => 2);
    }

    public function
getRequiredOptions()
    {
        return array(
'required1', 'required2');
    }
}

class
FakeDataB extends AbstractFakeData
{
    public function
getDefaultOptions()
    {
        return;
    }

    public function
getRequiredOptions()
    {
        return array(
'required1', 'required2');
    }
}

class
AbstractFakeDataTest extends \PHPUnit_Framework_TestCase
{
    public function
testValidRequiredOptions()
    {
       
$fakeDataA = new FakeDataA(array('required1' => 1, 'required2' => 2));

       
$this->assertInstanceOf('Fakerino\FakeData\FakedataInterface', $fakeDataA);
    }

    public function
testOverrideDefaultOptions()
    {
       
$overrideValue = 2;
       
$overrideKey = 'defaultOption1';
       
$fakeDataA = new FakeDataA(array('required1' => 1, 'required2' => 2, $overrideKey => $overrideValue));
       
$fakeDataAOption = $fakeDataA->getOption($overrideKey);

       
$this->assertEquals($overrideValue, $fakeDataAOption);
    }

    public function
testMissingRequiredOptionException()
    {
       
$this->setExpectedException('Fakerino\FakeData\Exception\MissingRequiredOptionException');

       
$fakeDataA = new FakeDataA(array('defaultOption3' => 3));
    }

    public function
testMissingRequiredOptionExceptionWithEmptyConstructor()
    {
       
$this->setExpectedException('Fakerino\FakeData\Exception\MissingRequiredOptionException');

       
$fakeDataA = new FakeDataA();
       
$fakeDataA->generatedBy();
    }

    public function
testInvalidOptionException()
    {
       
$this->setExpectedException('Fakerino\FakeData\Exception\InvalidOptionException');

       
$fakeDataA = new FakeDataA(array('required1' => 1, 'required2' => 2, 'otherOption'));
    }

    public function
testGeneratedByCall()
    {
       
$fakeDataA = new FakeDataA(array('required1' => 1, 'required2' => 2, 'generatedBy' => 'StringGenerator'));
       
$generators = $fakeDataA->generatedBy();

       
$this->assertEquals('Fakerino\FakeData\Generator\StringGenerator', $generators);
    }

    public function
testWrongDefaultOptionsProvided()
    {
       
$fakeDataA = new FakeDataB(array('required1' => 1, 'required2' => 2));

       
$generators = $fakeDataA->generatedBy();

       
$this->assertEquals('Fakerino\FakeData\Generator\FakeDataBGenerator', $generators);
    }
}

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