Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmejias committed Jan 1, 2022
1 parent 5a686a1 commit 80f797b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
39 changes: 28 additions & 11 deletions tests/MockVeilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AdrianMejias\Tests;

use AdrianMejias\Tests\Veils\FooVeil;
use AdrianMejias\Tests\Veils\MyTestClass;
use AdrianMejias\Tests\Veils\NoAccessorVeil;
use AdrianMejias\Tests\Veils\NoInstanceVeil;
use AdrianMejias\Veil\Exceptions\NoAccessorFoundException;
Expand Down Expand Up @@ -52,7 +53,7 @@ public function it_can_get_a_list_of_all_veils()
$mock = mock(Veil::class);
$mock->shouldReceive('add')->once()->with([
'Foo' => FooVeil::class,
])->andReturn(new Veil);
])->andReturnSelf();
$mock->shouldReceive('all')->once()->andReturn([
'Foo' => FooVeil::class,
]);
Expand All @@ -70,10 +71,10 @@ public function it_can_get_a_list_of_registered_veils_as_array()
{
/** @var \Mockery\MockInterface|\Mockery\LegacyMockInterface|\AdrianMejias\Veil\Veil */
$mock = mock(Veil::class);
$mock->shouldReceive('register')->once()->andReturn(new Veil);
$mock->shouldReceive('register')->once()->andReturnSelf();
$mock->shouldReceive('add')->once()->with([
'Foo' => FooVeil::class,
])->andReturn(new Veil);
])->andReturnSelf();
$mock->shouldReceive('registered')->once()->andReturn([
'Foo' => FooVeil::class,
]);
Expand All @@ -92,9 +93,9 @@ public function it_can_get_a_list_of_registered_veils_as_key_value()
{
/** @var \Mockery\MockInterface|\Mockery\LegacyMockInterface|\AdrianMejias\Veil\Veil */
$mock = mock(Veil::class);
$mock->shouldReceive('register')->once()->andReturn(new Veil);
$mock->shouldReceive('register')->once()->andReturnSelf();
$mock->shouldReceive('add')->once()
->with('Foo', FooVeil::class)->andReturn(new Veil);
->with('Foo', FooVeil::class)->andReturnSelf();
$mock->shouldReceive('registered')->once()->andReturn([
'Foo' => FooVeil::class,
]);
Expand All @@ -104,6 +105,22 @@ public function it_can_get_a_list_of_registered_veils_as_key_value()
$mock->registered();
}

/**
* @test
* @covers \AdrianMejias\Veil\Veil
* @covers \AdrianMejias\Veil\VeilAbstract
*/
public function it_can_call_method()
{
/** @var \Mockery\MockInterface|\Mockery\LegacyMockInterface|\AdrianMejias\Tests\Veils\FooVeil */
$mock = mock(FooVeil::class);
$mock->shouldReceive([
'getVeilInstance' => new MyTestClass,
'bar' => 'hi',
]);
$mock->getVeilInstance()->bar();
}

/**
* @test
* @covers \AdrianMejias\Veil\Veil
Expand All @@ -114,9 +131,9 @@ public function it_can_throw_exception_for_accessor_not_found()
{
/** @var \Mockery\MockInterface|\Mockery\LegacyMockInterface|\AdrianMejias\Veil\Veil */
$mock = mock(Veil::class);
$mock->shouldReceive('register')->once()->andReturn(new Veil);
$mock->shouldReceive('register')->once()->andReturnSelf();
$mock->shouldReceive('add')->once()
->with('NoAccessor', NoAccessorVeil::class)->andReturn(new Veil);
->with('NoAccessor', NoAccessorVeil::class)->andReturnSelf();
$mock->shouldReceive('registered')->once()->andReturn([
'NoAccessor' => NoAccessorVeil::class,
]);
Expand All @@ -139,9 +156,9 @@ public function it_can_throw_exception_for_instance_not_found()
{
/** @var \Mockery\MockInterface|\Mockery\LegacyMockInterface|\AdrianMejias\Veil\Veil */
$mock = mock(Veil::class);
$mock->shouldReceive('register')->once()->andReturn(new Veil);
$mock->shouldReceive('register')->once()->andReturnSelf();
$mock->shouldReceive('add')->once()
->with('NoInstance', NoInstanceVeil::class)->andReturn(new Veil);
->with('NoInstance', NoInstanceVeil::class)->andReturnSelf();
$mock->shouldReceive('registered')->once()->andReturn([
'NoInstance' => NoInstanceVeil::class,
]);
Expand All @@ -164,9 +181,9 @@ public function it_can_throw_exception_for_instance_method_not_found()
{
/** @var \Mockery\MockInterface|\Mockery\LegacyMockInterface|\AdrianMejias\Veil\Veil */
$mock = mock(Veil::class);
$mock->shouldReceive('register')->once()->andReturn(new Veil);
$mock->shouldReceive('register')->once()->andReturnSelf();
$mock->shouldReceive('add')->once()
->with('Foo', FooVeil::class)->andReturn(new Veil);
->with('Foo', FooVeil::class)->andReturnSelf();
$mock->shouldReceive('registered')->once()->andReturn([
'Foo' => FooVeil::class,
]);
Expand Down
35 changes: 35 additions & 0 deletions tests/VeilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace AdrianMejias\Tests;

use AdrianMejias\Tests\Veils\FooVeil;
use AdrianMejias\Veil\Exceptions\NoAccessorFoundException;
use AdrianMejias\Veil\Exceptions\NoInstanceFoundException;
use AdrianMejias\Veil\Exceptions\NoInstanceMethodFoundException;
use AdrianMejias\Veil\Veil;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -178,4 +180,37 @@ public function it_can_throw_exception_for_instance_method_not_found()
$this->expectException(NoInstanceMethodFoundException::class);
\Foo::noExist();
}

/**
* @test
* @covers \AdrianMejias\Veil\Exceptions\NoAccessorFoundException
*/
public function it_can_throw_no_accessor_found_exception()
{
$this->expectException(NoAccessorFoundException::class);

throw new NoAccessorFoundException();
}

/**
* @test
* @covers \AdrianMejias\Veil\Exceptions\NoInstanceFoundException
*/
public function it_can_throw_no_instance_found_exception()
{
$this->expectException(NoInstanceFoundException::class);

throw new NoInstanceFoundException();
}

/**
* @test
* @covers \AdrianMejias\Veil\Exceptions\NoInstanceMethodFoundException
*/
public function it_can_throw_no_instance_method_found_exception()
{
$this->expectException(NoInstanceMethodFoundException::class);

throw new NoInstanceMethodFoundException();
}
}

0 comments on commit 80f797b

Please sign in to comment.