-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from facile-it/feature/self-tests
Add self tests to ensure Moka can test itself
- Loading branch information
Showing
11 changed files
with
214 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Tests\Builder; | ||
|
||
use Moka\Builder\ProxyBuilder; | ||
use Moka\Exception\MockNotCreatedException; | ||
use Moka\Proxy\Proxy; | ||
use Moka\Traits\MokaCleanerTrait; | ||
use Moka\Traits\MokaTrait; | ||
use PHPUnit_Framework_MockObject_Generator as MockGenerator; | ||
|
||
class ProxyBuilderSelfTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use MokaTrait; | ||
use MokaCleanerTrait; | ||
|
||
/** | ||
* @var ProxyBuilder | ||
*/ | ||
private $proxyBuilder; | ||
|
||
public function setUp() | ||
{ | ||
$this->proxyBuilder = new ProxyBuilder( | ||
$this->mock(MockGenerator::class)->serve() | ||
); | ||
} | ||
|
||
public function testGetProxySuccess() | ||
{ | ||
$this->decorateSuccessfulMockGenerator(); | ||
|
||
$proxy1 = $this->proxyBuilder->getProxy(\stdClass::class); | ||
$proxy2 = $this->proxyBuilder->getProxy(\stdClass::class); | ||
|
||
$this->assertInstanceOf(Proxy::class, $proxy1); | ||
|
||
$this->assertSame($proxy1, $proxy2); | ||
} | ||
|
||
public function testGetProxySuccessWithAlias() | ||
{ | ||
$this->decorateSuccessfulMockGenerator(); | ||
|
||
$proxy1 = $this->proxyBuilder->getProxy(\stdClass::class, 'bar'); | ||
$proxy2 = $this->proxyBuilder->getProxy(\stdClass::class, 'foo'); | ||
|
||
$this->assertInstanceOf(Proxy::class, $proxy1); | ||
$this->assertInstanceOf(Proxy::class, $proxy2); | ||
|
||
$this->assertNotSame($proxy1, $proxy2); | ||
} | ||
|
||
public function testGetProxyThrowException() | ||
{ | ||
$this->expectException(MockNotCreatedException::class); | ||
|
||
$this->mock(MockGenerator::class)->stub([ | ||
'getMock' => new \Exception() | ||
]); | ||
|
||
$this->proxyBuilder->getProxy(\stdClass::class, 'acme'); | ||
} | ||
|
||
private function decorateSuccessfulMockGenerator() | ||
{ | ||
$this->mock(MockGenerator::class)->stub([ | ||
'getMock' => $this->mock(\stdClass::class)->serve() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Tests\Factory; | ||
|
||
use Moka\Factory\ProxyFactory; | ||
use Moka\Proxy\Proxy; | ||
use Moka\Traits\MokaCleanerTrait; | ||
use Moka\Traits\MokaTrait; | ||
|
||
class ProxyFactorySelfTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use MokaTrait; | ||
use MokaCleanerTrait; | ||
|
||
public function testGet() | ||
{ | ||
$mock1 = ProxyFactory::get($this->mock(\stdClass::class)->serve()); | ||
$mock2 = ProxyFactory::get($this->mock(\stdClass::class)->serve()); | ||
|
||
$this->assertInstanceOf(Proxy::class, $mock1); | ||
$this->assertInstanceOf(Proxy::class, $mock2); | ||
|
||
$this->assertNotSame($mock1, $mock2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Tests\Proxy; | ||
|
||
use Moka\Exception\InvalidIdentifierException; | ||
use Moka\Proxy\Proxy; | ||
use Moka\Proxy\ProxyContainer; | ||
use Moka\Traits\MokaCleanerTrait; | ||
use Moka\Traits\MokaTrait; | ||
|
||
class ProxyContainerSelfTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use MokaTrait; | ||
use MokaCleanerTrait; | ||
|
||
/** | ||
* @var ProxyContainer | ||
*/ | ||
private $proxyContainer; | ||
|
||
public function setUp() | ||
{ | ||
$this->proxyContainer = new ProxyContainer(); | ||
|
||
$this->proxyContainer->set( | ||
'foo', | ||
$this->mock(Proxy::class)->serve() | ||
); | ||
} | ||
|
||
public function testGetSuccess() | ||
{ | ||
$proxy = $this->proxyContainer->get('foo'); | ||
|
||
$this->assertInstanceOf(Proxy::class, $proxy); | ||
} | ||
|
||
public function testGetFailure() | ||
{ | ||
$this->expectException(InvalidIdentifierException::class); | ||
$this->proxyContainer->get('bar'); | ||
} | ||
|
||
public function testHasSuccess() | ||
{ | ||
$this->assertTrue( | ||
$this->proxyContainer->has('foo') | ||
); | ||
} | ||
|
||
public function testHasFailure() | ||
{ | ||
$this->assertFalse( | ||
$this->proxyContainer->has('bar') | ||
); | ||
} | ||
|
||
public function testSet() | ||
{ | ||
$this->proxyContainer->set('acme', $this->mock(Proxy::class)->serve()); | ||
$this->assertInstanceOf( | ||
Proxy::class, | ||
$this->proxyContainer->get('acme') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Tests\Proxy; | ||
|
||
use Moka\Proxy\Proxy; | ||
use Moka\Traits\MokaCleanerTrait; | ||
use Moka\Traits\MokaTrait; | ||
use PHPUnit_Framework_MockObject_MockObject as MockObject; | ||
|
||
class ProxySelfTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use MokaTrait; | ||
use MokaCleanerTrait; | ||
|
||
/** | ||
* @var Proxy | ||
*/ | ||
private $proxy; | ||
|
||
public function setUp() | ||
{ | ||
$this->proxy = new Proxy( | ||
$this->mock(MockFakeClass::class)->serve() | ||
); | ||
} | ||
|
||
public function testServe() | ||
{ | ||
$this->assertInstanceOf(MockObject::class, $this->proxy->serve()); | ||
} | ||
|
||
public function testStubScalarValue() | ||
{ | ||
$this->proxy->stub([ | ||
'isValid' => true | ||
]); | ||
|
||
$this->assertTrue($this->proxy->serve()->isValid()); | ||
} | ||
|
||
public function testStubThrowException() | ||
{ | ||
$this->expectException(\Exception::class); | ||
|
||
$this->proxy->stub([ | ||
'throwException' => new \Exception() | ||
]); | ||
|
||
$this->proxy->serve()->throwException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters