gluon-web-remote

Web remote Administration for big size of gluon routers
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-web-remote.git
Log | Files | Refs | README

ScalarComparatorTest.php (4736B)


      1 <?php
      2 /*
      3  * This file is part of the Comparator package.
      4  *
      5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
      6  *
      7  * For the full copyright and license information, please view the LICENSE
      8  * file that was distributed with this source code.
      9  */
     10 
     11 namespace SebastianBergmann\Comparator;
     12 
     13 /**
     14  * @coversDefaultClass SebastianBergmann\Comparator\ScalarComparator
     15  *
     16  */
     17 class ScalarComparatorTest extends \PHPUnit_Framework_TestCase
     18 {
     19     private $comparator;
     20 
     21     protected function setUp()
     22     {
     23         $this->comparator = new ScalarComparator;
     24     }
     25 
     26     public function acceptsSucceedsProvider()
     27     {
     28         return array(
     29           array("string", "string"),
     30           array(new ClassWithToString, "string"),
     31           array("string", new ClassWithToString),
     32           array("string", null),
     33           array(false, "string"),
     34           array(false, true),
     35           array(null, false),
     36           array(null, null),
     37           array("10", 10),
     38           array("", false),
     39           array("1", true),
     40           array(1, true),
     41           array(0, false),
     42           array(0.1, "0.1")
     43         );
     44     }
     45 
     46     public function acceptsFailsProvider()
     47     {
     48         return array(
     49           array(array(), array()),
     50           array("string", array()),
     51           array(new ClassWithToString, new ClassWithToString),
     52           array(false, new ClassWithToString),
     53           array(tmpfile(), tmpfile())
     54         );
     55     }
     56 
     57     public function assertEqualsSucceedsProvider()
     58     {
     59         return array(
     60           array("string", "string"),
     61           array(new ClassWithToString, new ClassWithToString),
     62           array("string representation", new ClassWithToString),
     63           array(new ClassWithToString, "string representation"),
     64           array("string", "STRING", true),
     65           array("STRING", "string", true),
     66           array("String Representation", new ClassWithToString, true),
     67           array(new ClassWithToString, "String Representation", true),
     68           array("10", 10),
     69           array("", false),
     70           array("1", true),
     71           array(1, true),
     72           array(0, false),
     73           array(0.1, "0.1"),
     74           array(false, null),
     75           array(false, false),
     76           array(true, true),
     77           array(null, null)
     78         );
     79     }
     80 
     81     public function assertEqualsFailsProvider()
     82     {
     83         $stringException = 'Failed asserting that two strings are equal.';
     84         $otherException = 'matches expected';
     85 
     86         return array(
     87           array("string", "other string", $stringException),
     88           array("string", "STRING", $stringException),
     89           array("STRING", "string", $stringException),
     90           array("string", "other string", $stringException),
     91           // https://github.com/sebastianbergmann/phpunit/issues/1023
     92           array('9E6666666','9E7777777', $stringException),
     93           array(new ClassWithToString, "does not match", $otherException),
     94           array("does not match", new ClassWithToString, $otherException),
     95           array(0, 'Foobar', $otherException),
     96           array('Foobar', 0, $otherException),
     97           array("10", 25, $otherException),
     98           array("1", false, $otherException),
     99           array("", true, $otherException),
    100           array(false, true, $otherException),
    101           array(true, false, $otherException),
    102           array(null, true, $otherException),
    103           array(0, true, $otherException)
    104         );
    105     }
    106 
    107     /**
    108      * @covers       ::accepts
    109      * @dataProvider acceptsSucceedsProvider
    110      */
    111     public function testAcceptsSucceeds($expected, $actual)
    112     {
    113         $this->assertTrue(
    114           $this->comparator->accepts($expected, $actual)
    115         );
    116     }
    117 
    118     /**
    119      * @covers       ::accepts
    120      * @dataProvider acceptsFailsProvider
    121      */
    122     public function testAcceptsFails($expected, $actual)
    123     {
    124         $this->assertFalse(
    125           $this->comparator->accepts($expected, $actual)
    126         );
    127     }
    128 
    129     /**
    130      * @covers       ::assertEquals
    131      * @dataProvider assertEqualsSucceedsProvider
    132      */
    133     public function testAssertEqualsSucceeds($expected, $actual, $ignoreCase = false)
    134     {
    135         $exception = null;
    136 
    137         try {
    138             $this->comparator->assertEquals($expected, $actual, 0.0, false, $ignoreCase);
    139         }
    140 
    141         catch (ComparisonFailure $exception) {
    142         }
    143 
    144         $this->assertNull($exception, 'Unexpected ComparisonFailure');
    145     }
    146 
    147     /**
    148      * @covers       ::assertEquals
    149      * @dataProvider assertEqualsFailsProvider
    150      */
    151     public function testAssertEqualsFails($expected, $actual, $message)
    152     {
    153         $this->setExpectedException(
    154           'SebastianBergmann\\Comparator\\ComparisonFailure', $message
    155         );
    156         $this->comparator->assertEquals($expected, $actual);
    157     }
    158 }