1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
<?php
/**
* Mockery
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://github.com/padraic/mockery/master/LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to padraic@php.net so we can send you a copy immediately.
*
* @category Mockery
* @package Mockery
* @subpackage UnitTests
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
*/
namespace Mockery\Generator;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
class MockConfigurationTest extends TestCase
{
#[Test]
public function blackListedMethodsShouldNotBeInListToBeMocked()
{
$config = new MockConfiguration(array("Mockery\Generator\\TestSubject"), array("foo"));
$methods = $config->getMethodsToMock();
$this->assertCount(1, $methods);
$this->assertEquals("bar", $methods[0]->getName());
}
#[Test]
public function blackListsAreCaseInsensitive()
{
$config = new MockConfiguration(array("Mockery\Generator\\TestSubject"), array("FOO"));
$methods = $config->getMethodsToMock();
$this->assertCount(1, $methods);
$this->assertEquals("bar", $methods[0]->getName());
}
#[Test]
public function onlyWhiteListedMethodsShouldBeInListToBeMocked()
{
$config = new MockConfiguration(array("Mockery\Generator\\TestSubject"), array(), array('foo'));
$methods = $config->getMethodsToMock();
$this->assertCount(1, $methods);
$this->assertEquals("foo", $methods[0]->getName());
}
#[Test]
public function whitelistOverRulesBlackList()
{
$config = new MockConfiguration(array("Mockery\Generator\\TestSubject"), array("foo"), array("foo"));
$methods = $config->getMethodsToMock();
$this->assertCount(1, $methods);
$this->assertEquals("foo", $methods[0]->getName());
}
#[Test]
public function whiteListsAreCaseInsensitive()
{
$config = new MockConfiguration(array("Mockery\Generator\\TestSubject"), array(), array("FOO"));
$methods = $config->getMethodsToMock();
$this->assertCount(1, $methods);
$this->assertEquals("foo", $methods[0]->getName());
}
#[Test]
public function finalMethodsAreExcluded()
{
$config = new MockConfiguration(array("Mockery\Generator\\ClassWithFinalMethod"));
$methods = $config->getMethodsToMock();
$this->assertCount(1, $methods);
$this->assertEquals("bar", $methods[0]->getName());
}
#[Test]
public function shouldIncludeMethodsFromAllTargets()
{
$config = new MockConfiguration(array("Mockery\\Generator\\TestInterface", "Mockery\\Generator\\TestInterface2"));
$methods = $config->getMethodsToMock();
$this->assertCount(2, $methods);
}
#[Test]
public function shouldThrowIfTargetClassIsFinal()
{
$this->expectException(\Mockery\Exception::class);
$config = new MockConfiguration(array("Mockery\\Generator\\TestFinal"));
$config->getTargetClass();
}
#[Test]
public function shouldTargetIteratorAggregateIfTryingToMockTraversable()
{
$config = new MockConfiguration(array("\\Traversable"));
$interfaces = $config->getTargetInterfaces();
$this->assertCount(1, $interfaces);
$first = array_shift($interfaces);
$this->assertEquals("IteratorAggregate", $first->getName());
}
#[Test]
public function shouldTargetIteratorAggregateIfTraversableInTargetsTree()
{
$config = new MockConfiguration(array("Mockery\Generator\TestTraversableInterface"));
$interfaces = $config->getTargetInterfaces();
$this->assertCount(2, $interfaces);
$this->assertEquals("IteratorAggregate", $interfaces[0]->getName());
$this->assertEquals("Mockery\Generator\TestTraversableInterface", $interfaces[1]->getName());
}
#[Test]
public function shouldBringIteratorToHeadOfTargetListIfTraversablePresent()
{
$config = new MockConfiguration(array("Mockery\Generator\TestTraversableInterface2"));
$interfaces = $config->getTargetInterfaces();
$this->assertCount(2, $interfaces);
$this->assertEquals("Iterator", $interfaces[0]->getName());
$this->assertEquals("Mockery\Generator\TestTraversableInterface2", $interfaces[1]->getName());
}
#[Test]
public function shouldBringIteratorAggregateToHeadOfTargetListIfTraversablePresent()
{
$config = new MockConfiguration(array("Mockery\Generator\TestTraversableInterface3"));
$interfaces = $config->getTargetInterfaces();
$this->assertCount(2, $interfaces);
$this->assertEquals("IteratorAggregate", $interfaces[0]->getName());
$this->assertEquals("Mockery\Generator\TestTraversableInterface3", $interfaces[1]->getName());
}
}
interface TestTraversableInterface extends \Traversable
{
}
interface TestTraversableInterface2 extends \Traversable, \Iterator
{
}
interface TestTraversableInterface3 extends \Traversable, \IteratorAggregate
{
}
final class TestFinal
{
}
interface TestInterface
{
public function foo();
}
interface TestInterface2
{
public function bar();
}
class TestSubject
{
public function foo()
{
}
public function bar()
{
}
}
class ClassWithFinalMethod
{
final public function foo()
{
}
public function bar()
{
}
}
|