PHP Classes

File: test/BasicTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Corner   test/BasicTest.php   Download  
File: test/BasicTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Corner
Implements exceptions and errors with more details
Author: By
Last change:
Date: 4 years ago
Size: 3,210 bytes
 

Contents

Class file image Download
<?php
namespace ParagonIE\Corner\Tests;

use
ParagonIE\Corner\CornerInterface;
use
PHPUnit\Framework\TestCase;

/**
 * Class BasicTest
 * @package ParagonIE\Corner\Tests
 */
class BasicTest extends TestCase
{
    public function
testException()
    {
        try {
            throw new
FooException('test');
        } catch (
CornerInterface $ex) {
           
$this->assertSame('test', $ex->getMessage());
           
$this->assertNotEmpty($ex->getHelpfulMessage());
           
$this->assertSame('https://github.com/paragonie/corner', $ex->getSupportLink());
        }
    }

    public function
testError()
    {
        try {
            throw new
FooError('test');
        } catch (
CornerInterface $ex) {
           
$this->assertSame('test', $ex->getMessage());
           
$this->assertNotEmpty($ex->getHelpfulMessage());
           
$this->assertSame('https://github.com/paragonie/corner', $ex->getSupportLink());
        }
    }

    public function
testSnippet()
    {
        try {
           
/** Canary string: 15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61 */
           
throw new FooException('test');
        } catch (
CornerInterface $ex) {
           
$this->assertStringNotContainsString(
               
'15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61',
               
$ex->getSnippet(0, 0)
            );
           
$this->assertStringNotContainsString(
               
'15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61',
               
$ex->getSnippet(0, 1)
            );
           
$this->assertStringContainsString(
               
'15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61',
               
$ex->getSnippet(1, 0)
            );
           
$this->assertStringNotContainsString(
               
'15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61',
               
$ex->getSnippet(1, 0, 1)
            );
           
$this->assertStringNotContainsString(
               
'15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61',
               
$ex->getSnippet(5, 5, 1)
            );
           
$this->assertStringNotContainsString(
               
'15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61',
               
$ex->getSnippet(5, 5, 2)
            );
           
$this->assertStringNotContainsString(
               
'15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61',
               
$ex->getSnippet(5, 5, 3)
            );
        }

        try {
           
/* We're adding some padding here. */

           
$this->subcall();

           
/* We're adding some padding here. */
       
} catch (CornerInterface $ex) {
           
$this->assertStringNotContainsString(
               
'15f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c61',
               
$ex->getSnippet(1, 1, 1)
            );
           
$this->assertStringContainsString(
               
'subcall()',
               
$ex->getSnippet(1, 1, 1)
            );
        }
    }

    private function
subcall()
    {
       
/** Canary string: 6115f3456a04616adc5b42f3533d41a43aa2bad7eee2e914684ec86c3b84b71c */
       
throw new FooException('test');
    }
}