From 80f797be61d3cc71f11dc95001849e7ee22b8609 Mon Sep 17 00:00:00 2001 From: Adrian Mejias Date: Sat, 1 Jan 2022 01:04:00 -0600 Subject: [PATCH] wip --- tests/MockVeilsTest.php | 39 ++++++++++++++++++++++++++++----------- tests/VeilsTest.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/tests/MockVeilsTest.php b/tests/MockVeilsTest.php index 9d26c65..9d779a4 100644 --- a/tests/MockVeilsTest.php +++ b/tests/MockVeilsTest.php @@ -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; @@ -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, ]); @@ -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, ]); @@ -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, ]); @@ -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 @@ -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, ]); @@ -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, ]); @@ -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, ]); diff --git a/tests/VeilsTest.php b/tests/VeilsTest.php index 2d66d31..c7d45a4 100644 --- a/tests/VeilsTest.php +++ b/tests/VeilsTest.php @@ -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; @@ -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(); + } }