/**
  * @expectedException \Exception
  * @expectedExceptionMessage cannot be mocked because it it private.
  * @dataProvider allBuilders
  */
 public function testMockingPrivateMethodWillThrowException(MockBuilder $builder, $type)
 {
     if (self::MOCK_INTERFACE === $type) {
         $this->expectFailure('does not exist.');
     }
     $builder->stub(array('myPrivateMethod' => 'bar'))->get();
 }
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Only 2 return values have been provided.
  * @dataProvider allBuilders
  */
 public function testAndReturnWithMultipleArgumentsCanNotBeCalledMoreTimesThatReturnValues(MockBuilder $builder)
 {
     $mock = $builder->stub('myMethod')->andReturn('foo', 'bar')->get();
     $mock->myMethod();
     $mock->myMethod();
     $mock->myMethod();
 }
 /**
  * @dataProvider allBuilders
  */
 public function testAReturnCallbackWillBeProvidedWithOriginalArgs(MockBuilder $builder)
 {
     $mock = $builder->stub('myMethod')->andReturnCallback(function (InvocationInterface $i) {
         return $i->getArguments();
     })->get();
     $this->assert($mock->myMethod('hello'))->equals(array('hello'));
 }
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Property 'doesnt_exist' does not exist for
  * @dataProvider allBuilders
  */
 public function testAnExceptionIsThrownIfPropertyDoesNotExistAtRuntime(MockBuilder $builder, $type)
 {
     if (self::MOCK_INTERFACE === $type) {
         $this->expectFailure("You cannot return a property from an interface (\\Concise\\Mock\\CombinationMockedInterface).");
     }
     $mock = $builder->stub('myMethod')->andReturnProperty('doesnt_exist')->get();
     $mock->myMethod();
 }
 /**
  * @dataProvider mockBuilders
  */
 public function testMockDoesNotEnableConstructorByDefault(MockBuilder $builder, $type)
 {
     if (self::MOCK_INTERFACE === $type) {
         $this->notApplicable();
         return;
     }
     $mock = $builder->get();
     $this->assert($mock->constructorRun)->isFalse;
 }
示例#6
0
 /**
  * @dataProvider allBuilders
  */
 public function testOriginalCloneIsNotModifiedIsNotDisabled(MockBuilder $builder, $type)
 {
     if (self::MOCK_INTERFACE !== $type) {
         $this->expectFailure('Did clone.');
     }
     $mock = $builder->get();
     $cloned = clone $mock;
     $this->assert($cloned)->isAnInstanceOf(get_class($mock));
 }
 /**
  * @dataProvider allBuilders
  * @group #304
  */
 public function testCustomClassNameWillNotActivateClassLoader(MockBuilder $builder)
 {
     spl_autoload_register(function () {
         throw new \Exception("Autoloader should not have been called.");
     });
     $rand = "Concise\\Mock\\Temp" . md5(rand());
     $builder->setCustomClassName($rand)->get();
     $functions = spl_autoload_functions();
     spl_autoload_unregister($functions[count($functions) - 1]);
 }
示例#8
0
 /**
  * @group #182
  * @dataProvider allBuilders
  */
 public function testAndDoWillBeProvidedWithOriginalArgs(MockBuilder $builder)
 {
     $a = array();
     $mock = $builder->stub('myMethod')->andDo(function (InvocationInterface $i) use(&$a) {
         $a = $i->getArguments();
     })->get();
     $mock->myMethod('hello');
     /*$this->assert($a, equals, array('hello'));*/
     $this->assert($a)->equals(array('hello'));
 }
 /**
  * @group #189
  * @dataProvider allBuilders
  */
 public function testExposeAllMethodsWillExposeAllMethods(MockBuilder $builder, $type)
 {
     $this->youCannotExposeAMethodOnAMockThatIsNotNice($type);
     $mock = $builder->exposeAll()->get();
     /*$this->assert($mock->mySecretMethod(), equals, 'abc');*/
     $this->assert($mock->mySecretMethod())->equals('abc');
 }
 /**
  * @dataProvider abstractBuilders
  */
 public function testAbstractMethodsCanHaveRulesAttached(MockBuilder $builder)
 {
     $mock = $builder->stub('myAbstractMethod')->get();
     /*$this->assert($mock->myAbstractMethod(), is_null);*/
     $this->assert($mock->myAbstractMethod())->isNull;
 }
示例#11
0
function mock($class = NULL, array $defaults = array())
{
    $builder = new MockBuilder($class, $defaults);
    return $builder->getMock();
}
 /**
  * @dataProvider allBuilders
  */
 public function testWithParameterCanAcceptAnythingElse(MockBuilder $builder)
 {
     $mock = $builder->expect('myMethod')->with(self::ANYTHING)->andReturn('foo')->get();
     /*$this->assert($mock->myMethod(123), equals, 'foo');*/
     $this->assert($mock->myMethod(123))->equals('foo');
 }
示例#13
0
 /**
  * Get builder for named mock
  * @param string $name
  * @return MockBuilder
  */
 public function getBuilderByName($name)
 {
     return MockBuilder::createFromMock($this->getMockByName($name));
 }
示例#14
0
 /**
  * @group #248
  * @dataProvider allBuilders
  */
 public function testWithIncludingSingleQuotes(MockBuilder $builder)
 {
     $mock = $builder->expect('myMethod')->with("foo'bar")->get();
     $mock->myMethod("foo'bar");
 }
示例#15
0
 /**
  * @dataProvider allBuilders
  */
 public function testSecondMethodOfMultipleStubsReceivesAction(MockBuilder $builder)
 {
     $mock = $builder->stub('myMethod', 'mySecondMethod')->andReturn('foo')->get();
     $this->assert($mock->mySecondMethod())->equals('foo');
 }
示例#16
0
 /**
  * @dataProvider allBuilders
  */
 public function testMockImplementsMockInterface(MockBuilder $builder)
 {
     $mock = $builder->get();
     $this->assert($mock)->isAnInstanceOf('\\Concise\\Mock\\MockInterface');
 }
 /**
  * @dataProvider allBuilders
  */
 public function testMethodsCanReturnSelf(MockBuilder $builder)
 {
     $mock = $builder->stub('myMethod')->andReturnSelf()->get();
     $this->assert($mock->myMethod())->isTheSameAs($mock);
 }
示例#18
0
 /**
  * @dataProvider allBuilders
  */
 public function testMocksCanMockStaticMethods(MockBuilder $builder)
 {
     $mock = $builder->stub(array('myStaticMethod' => 'foo'))->get();
     $this->assert($mock->myStaticMethod())->equals('foo');
 }
 /**
  * @dataProvider allBuilders
  */
 public function testNullPropertiesAreStillFound(MockBuilder $builder, $type)
 {
     if (self::MOCK_INTERFACE === $type) {
         $this->expectFailure("You cannot set a property on an interface");
     }
     $mock = $builder->setProperty('does_not_exist', null)->get();
     $this->assert($this->getProperty($mock, 'does_not_exist'))->isNull;
 }
示例#20
0
 /**
  * @dataProvider allBuilders
  */
 public function testMultipleExpectsThatAreNeverExpected(MockBuilder $builder)
 {
     $builder->expect('myWithMethod', 'myMethod')->never()->get();
 }