PHP Classes
elePHPant
Icontem

File: Falcraft/examples/Data/Types/Type.php

Recommend this page to a friend!
  Classes of Asher Wolfstein  >  Abstract Data Types  >  Falcraft/examples/Data/Types/Type.php  >  Download  
File: Falcraft/examples/Data/Types/Type.php
Role: Example script
Content type: text/plain
Description: Type Classifications Example
Class: Abstract Data Types
Set of abstract data types as pure PHP classes
Author: By
Last change:
Date: 3 years ago
Size: 2,693 bytes
 

Contents

Class file image Download
<?php

namespace Falcraft\tests\Data\Types;

require_once(
'../../../Data/Types/Type.php');
require_once(
'../../../Data/Types/Range.php');

use
Falcraft\Data\Types;
use
Falcraft\Data\Types\Type;

echo
"Falcraft\\Data\\Types\\Type.php Test\n";
echo
"---------------------------------\n\n";

"Testing Type Enumeration Existence -> ";

$success = false;

try {
    if (
class_exists('Falcraft\\Data\\Types\\Type')) {
       
$success = true;
    }
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
"Instantiate and List Constants -> \n";

$success = true;

try {
   
$type = new Types\Type();
   
$constants = $type->getConstants();
   
var_dump( $constants );
} catch (\
Exception $e) {
   
$success = false;
}

echo
"\nImproper Instantiation -> ";

$fail = true;

try
{
   
$testType = new Types\Type(23);
   
$fail = false;
} catch (\
UnexpectedValueException $e) {
   
}

if (
$fail) {
    echo
"Failure!\n";
} else {
    echo
"Success...\n";
}

echo
"Test getValueType() -> ";

$null = null;
$bool = true;
$int = 5;
$string = 'data';
$array = array('key' => 'value');
$object = new \stdClass();
$typedObject = new Types\Range();
function
testCustomFunction() { return; };
$closure = function() { return; };

echo
"\nDefined User Functions:\n\n";

$fs = get_defined_functions();
$fs = $fs['user'];
var_dump($fs);

echo
"\nNull -- ";
if (
Type\getValueType($null)->get() === Types\Type::BASIC_NULL) {
    echo
"Matched\n";
} else {
    echo
"Mismatched\n";
}

echo
"Bool -- ";
if (
Type\getValueType($bool)->get() === Types\Type::BASIC_BOOL) {
    echo
"Matched\n";
} else {
    echo
"Mismatched\n";
}

echo
"Int -- ";
if (
Type\getValueType($int)->get() === Types\Type::BASIC_INT) {
    echo
"Matched\n";
} else {
    echo
"Mismatched\n";
}

echo
"String -- ";
if (
Type\getValueType($string)->get() === Types\Type::BASIC_STRING) {
    echo
"Matched\n";
} else {
    echo
"Mismatched\n";
}

echo
"Array -- ";
if (
Type\getValueType($array)->get() === Types\Type::BASIC_ARRAY) {
    echo
"Matched\n";
} else {
    echo
"Mismatched\n";
}

echo
"Object -- ";
if (
Type\getValueType($object)->get() === Types\Type::BASIC_OBJECT) {
    echo
"Matched\n";
} else {
    echo
"Mismatched\n";
}

echo
"Function -- ";
if (
Type\getValueType('Falcraft\\tests\\Data\\Types\\testCustomFunction')->get()
        ===
Types\Type::BASIC_FUNCTION ) {
    echo
"Matched\n";
} else {
    echo
"Mismatched\n";
}

echo
"Closure -- ";
if (
Type\getValueType($closure)->get() === Types\Type::BASIC_CLOSURE) {
    echo
"Matched\n";
} else {
    echo
"Mismatched\n";
}
   
echo
"Typed Object (Range) -- ";
var_dump(Type\getValueType($typedObject));