PHP Classes

File: tests/phpunit/WeakSternTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Stern PHP Type Safety   tests/phpunit/WeakSternTest.php   Download  
File: tests/phpunit/WeakSternTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Stern PHP Type Safety
Make class function calls invoke strict versions
Author: By
Last change:
Date: 3 years ago
Size: 1,932 bytes
 

Contents

Class file image Download
<?php

class WeakSternTest extends \PHPUnit\Framework\TestCase
{
    public function
testWeakBool()
    {
       
$weak = new \ParagonIE\SternTests\Weak();
       
$this->assertSame(true, $weak->weakBool(true));
       
$this->assertSame(false, $weak->weakBool(false));
        try {
           
$weak->weakBool(null);
           
$this->fail('Expected a TypeError');
        } catch (
Error $ex) {
           
$this->assertTrue($ex instanceof TypeError);
        }
        try {
           
$weak->weakBool(0);
           
$this->fail('Expected a TypeError');
        } catch (
Error $ex) {
           
$this->assertTrue($ex instanceof TypeError);
        }
    }

    public function
testWeakFloat()
    {
       
$weak = new \ParagonIE\SternTests\Weak();
       
$this->assertSame(123.45, $weak->weakFloat(123.45));
       
$this->assertSame(12345.0, $weak->weakFloat(12345.0));

        try {
           
$weak->weakFloat('123.44');
           
$this->fail('Expected a TypeError');
        } catch (
Error $ex) {
           
$this->assertTrue($ex instanceof TypeError);
        }
    }

    public function
testWeakInt()
    {
       
$weak = new \ParagonIE\SternTests\Weak();
       
$this->assertSame(12345, $weak->weakInt(12344));

        try {
           
$weak->weakInt('12344');
           
$this->fail('Expected a TypeError');
        } catch (
Error $ex) {
           
$this->assertTrue($ex instanceof TypeError);
        }
    }

    public function
testWeakString()
    {
       
$weak = new \ParagonIE\SternTests\Weak();
       
$this->assertSame('nccyr', $weak->weakString('apple'));
       
$this->assertSame('NCCYR', $weak->weakString('APPLE'));
       
$this->assertSame('12345', $weak->weakString('12345'));

        try {
           
$weak->weakString(12345);
           
$this->fail('Expected a TypeError');
        } catch (
Error $ex) {
           
$this->assertTrue($ex instanceof TypeError);
        }
    }

}