/** * @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(); }
/** * @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(); }
/** * @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(); }
/** * @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')); }
/** * @dataProvider allBuilders */ public function testMethodsCanReturnSelf(MockBuilder $builder) { $mock = $builder->stub('myMethod')->andReturnSelf()->get(); $this->assert($mock->myMethod())->isTheSameAs($mock); }
/** * @dataProvider abstractBuilders */ public function testAbstractMethodsCanHaveRulesAttached(MockBuilder $builder) { $mock = $builder->stub('myAbstractMethod')->get(); /*$this->assert($mock->myAbstractMethod(), is_null);*/ $this->assert($mock->myAbstractMethod())->isNull; }
/** * @dataProvider allBuilders */ public function testMocksCanMockStaticMethods(MockBuilder $builder) { $mock = $builder->stub(array('myStaticMethod' => 'foo'))->get(); $this->assert($mock->myStaticMethod())->equals('foo'); }
/** * @dataProvider allBuilders */ public function testWithOnMultipleMethods(MockBuilder $builder) { $mock = $builder->stub('myWithMethod', 'myMethod')->with('foo')->andReturn('foobar')->get(); /*$this->assert($mock->myMethod('foo'), equals, 'foobar');*/ $this->assert($mock->myMethod('foo'))->equals('foobar'); }
/** * @dataProvider allBuilders */ public function testSecondMethodOfMultipleStubsReceivesAction(MockBuilder $builder) { $mock = $builder->stub('myMethod', 'mySecondMethod')->andReturn('foo')->get(); $this->assert($mock->mySecondMethod())->equals('foo'); }