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

MockBuilderTest.php (5859B)


      1 <?php
      2 /**
      3  * PHPUnit
      4  *
      5  * Copyright (c) 2010-2013, Sebastian Bergmann <sb@sebastian-bergmann.de>.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  *
     12  *   * Redistributions of source code must retain the above copyright
     13  *     notice, this list of conditions and the following disclaimer.
     14  *
     15  *   * Redistributions in binary form must reproduce the above copyright
     16  *     notice, this list of conditions and the following disclaimer in
     17  *     the documentation and/or other materials provided with the
     18  *     distribution.
     19  *
     20  *   * Neither the name of Sebastian Bergmann nor the names of his
     21  *     contributors may be used to endorse or promote products derived
     22  *     from this software without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  *
     37  * @package    PHPUnit_MockObject
     38  * @author     Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
     39  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
     40  * @copyright  2010-2013 Sebastian Bergmann <sb@sebastian-bergmann.de>
     41  * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
     42  * @link       http://github.com/sebastianbergmann/phpunit-mock-objects
     43  * @since      File available since Release 1.0.0
     44  */
     45 
     46 require_once 'PHPUnit/Framework/TestCase.php';
     47 
     48 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Mockable.php';
     49 
     50 /**
     51  * @package    PHPUnit_MockObject
     52  * @author     Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
     53  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
     54  * @copyright  2010-2013 Sebastian Bergmann <sb@sebastian-bergmann.de>
     55  * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
     56  * @link       http://github.com/sebastianbergmann/phpunit-mock-objects
     57  * @since      File available since Release 1.0.0
     58  */
     59 class Framework_MockBuilderTest extends PHPUnit_Framework_TestCase
     60 {
     61     public function testMockBuilderRequiresClassName()
     62     {
     63         $spec = $this->getMockBuilder('Mockable');
     64         $mock = $spec->getMock();
     65         $this->assertTrue($mock instanceof Mockable);
     66     }
     67 
     68     public function testByDefaultMocksAllMethods()
     69     {
     70         $spec = $this->getMockBuilder('Mockable');
     71         $mock = $spec->getMock();
     72         $this->assertNull($mock->mockableMethod());
     73         $this->assertNull($mock->anotherMockableMethod());
     74     }
     75 
     76     public function testMethodsToMockCanBeSpecified()
     77     {
     78         $spec = $this->getMockBuilder('Mockable');
     79         $spec->setMethods(array('mockableMethod'));
     80         $mock = $spec->getMock();
     81         $this->assertNull($mock->mockableMethod());
     82         $this->assertTrue($mock->anotherMockableMethod());
     83     }
     84 
     85     public function testByDefaultDoesNotPassArgumentsToTheConstructor()
     86     {
     87         $spec = $this->getMockBuilder('Mockable');
     88         $mock = $spec->getMock();
     89         $this->assertEquals(array(NULL, NULL), $mock->constructorArgs);
     90     }
     91 
     92     public function testMockClassNameCanBeSpecified()
     93     {
     94         $spec = $this->getMockBuilder('Mockable');
     95         $spec->setMockClassName('ACustomClassName');
     96         $mock = $spec->getMock();
     97         $this->assertTrue($mock instanceof ACustomClassName);
     98     }
     99 
    100     public function testConstructorArgumentsCanBeSpecified()
    101     {
    102         $spec = $this->getMockBuilder('Mockable');
    103         $spec->setConstructorArgs($expected = array(23, 42));
    104         $mock = $spec->getMock();
    105         $this->assertEquals($expected, $mock->constructorArgs);
    106     }
    107 
    108     public function testOriginalConstructorCanBeDisabled()
    109     {
    110         $spec = $this->getMockBuilder('Mockable');
    111         $spec->disableOriginalConstructor();
    112         $mock = $spec->getMock();
    113         $this->assertNull($mock->constructorArgs);
    114     }
    115 
    116     public function testByDefaultOriginalCloneIsPreserved()
    117     {
    118         $spec = $this->getMockBuilder('Mockable');
    119         $mock = $spec->getMock();
    120         $cloned = clone $mock;
    121         $this->assertTrue($cloned->cloned);
    122     }
    123 
    124     public function testOriginalCloneCanBeDisabled()
    125     {
    126         $spec = $this->getMockBuilder('Mockable');
    127         $spec->disableOriginalClone();
    128         $mock = $spec->getMock();
    129         $mock->cloned = FALSE;
    130         $cloned = clone $mock;
    131         $this->assertFalse($cloned->cloned);
    132     }
    133 
    134     public function testCallingAutoloadCanBeDisabled()
    135     {
    136         // it is not clear to me how to test this nor the difference
    137         // between calling it or not
    138         $this->markTestIncomplete();
    139     }
    140 
    141     public function testProvidesAFluentInterface()
    142     {
    143         $spec = $this->getMockBuilder('Mockable')
    144                      ->setMethods(array('mockableMethod'))
    145                      ->setConstructorArgs(array())
    146                      ->setMockClassName('DummyClassName')
    147                      ->disableOriginalConstructor()
    148                      ->disableOriginalClone()
    149                      ->disableAutoload();
    150         $this->assertTrue($spec instanceof PHPUnit_Framework_MockObject_MockBuilder);
    151     }
    152 }