Skip to content

Commit

Permalink
testExposeAllCanBeChained
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Dec 21, 2014
1 parent 7fdf088 commit 8825f46
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/Concise/Mock/MockBuilder.php
Expand Up @@ -510,4 +510,12 @@ public function getClassName()
{
return $this->className;
}

/**
* @return MockBuilder
*/
public function exposeAll()
{
return $this;
}
}
49 changes: 34 additions & 15 deletions tests/Concise/Mock/BuilderExposeTest.php
Expand Up @@ -7,11 +7,23 @@
*/
class BuilderExposeTest extends AbstractBuilderTestCase
{
protected function youCannotExposeAMethodOnAMockThatIsNotNice($type)
{
switch ($type) {
case self::MOCK_INTERFACE:
case self::MOCK_CLASS:
case self::MOCK_ABSTRACT_CLASS:
$this->expectFailure("You cannot expose a method on a mock that is not nice.");
}
}

/**
* @dataProvider niceMockBuilders
* @group #189
* @dataProvider allBuilders
*/
public function testExposeASingleMethod(MockBuilder $builder)
public function testExposeASingleMethod(MockBuilder $builder, $type)
{
$this->youCannotExposeAMethodOnAMockThatIsNotNice($type);
$mock = $builder->expose('mySecretMethod')
->get();
$this->assert($mock->myMethod(), equals, 'abc');
Expand All @@ -20,51 +32,58 @@ public function testExposeASingleMethod(MockBuilder $builder)
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage does not exist.
* @dataProvider niceMockBuilders
* @group #189
* @dataProvider allBuilders
*/
public function testAnExceptionIsThrownIfTheMethodDoesNotExist(MockBuilder $builder)
public function testAnExceptionIsThrownIfTheMethodDoesNotExist(MockBuilder $builder, $type)
{
$this->youCannotExposeAMethodOnAMockThatIsNotNice($type);
$builder->expose('baz')
->get();
}

/**
* @dataProvider niceMockBuilders
* @group #189
* @dataProvider allBuilders
*/
public function testExposeTwoMethodsWithSeparateParameters(MockBuilder $builder)
public function testExposeTwoMethodsWithSeparateParameters(MockBuilder $builder, $type)
{
$this->youCannotExposeAMethodOnAMockThatIsNotNice($type);
$mock = $builder->expose('myMethod', 'mySecondMethod')
->get();
$this->assert($mock->mySecondMethod(), equals, 'bar');
}

/**
* @dataProvider niceMockBuilders
* @group #189
* @dataProvider allBuilders
*/
public function testExposeTwoMethodsByCallingExposeTwice(MockBuilder $builder)
public function testExposeTwoMethodsByCallingExposeTwice(MockBuilder $builder, $type)
{
$this->youCannotExposeAMethodOnAMockThatIsNotNice($type);
$mock = $builder->expose('myMethod')->expose('mySecondMethod')
->get();
$this->assert($mock->myMethod(), equals, 'abc');
}

/**
* @dataProvider niceMockBuilders
* @group #189
* @dataProvider allBuilders
*/
public function testExposeTwoMethodsWithArraySyntax(MockBuilder $builder)
public function testExposeTwoMethodsWithArraySyntax(MockBuilder $builder, $type)
{
$this->youCannotExposeAMethodOnAMockThatIsNotNice($type);
$mock = $builder->expose(array('myMethod', 'mySecondMethod'))
->get();
$this->assert($mock->mySecondMethod(), equals, 'bar');
}

/**
* @expectedException \Exception
* @expectedExceptionMessage You cannot expose a method on a mock that is not nice.
* @dataProvider mockBuilders
* @group #189
* @dataProvider allBuilders
*/
public function testExposeIsNotAllowedOnAMock(MockBuilder $builder)
public function testExposeAllCanBeChained(MockBuilder $builder)
{
$builder->expose('myMethod')->get();
$this->assert($builder->exposeAll(), is_the_same_as, $builder);
}
}

0 comments on commit 8825f46

Please sign in to comment.