From d548941d168ca08f43bef7e67bb270076964b827 Mon Sep 17 00:00:00 2001 From: Adrian Mejias Date: Fri, 31 Dec 2021 22:19:28 -0600 Subject: [PATCH 1/3] wip --- .github/workflows/coveralls.yml | 25 +++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/coveralls.yml diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml new file mode 100644 index 0000000..7b6050c --- /dev/null +++ b/.github/workflows/coveralls.yml @@ -0,0 +1,25 @@ +name: Coveralls + +on: [push, pull_request] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + + - name: Use Node.js 10.x + uses: actions/setup-node@v1 + with: + node-version: 10.x + + - name: npm install, make test-coverage + run: | + npm install + make test-coverage + + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 3fe6540..7a3aff4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Veil -[![security](https://github.com/adrianmejias/veil/actions/workflows/security.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/security.yml) [![tests](https://github.com/adrianmejias/veil/actions/workflows/tests.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/tests.yml) [![PHPStan](https://github.com/adrianmejias/veil/actions/workflows/phpstan.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/phpstan.yml) [![PHP CS Fixer](https://github.com/adrianmejias/veil/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/php-cs-fixer.yml) [![StyleCI](https://github.styleci.io/repos/394644917/shield?branch=main)](https://github.styleci.io/repos/394644917?branch=main) [![Build Status](https://travis-ci.com/adrianmejias/veil.svg?branch=main)](https://travis-ci.com/adrianmejias/veil) [![codecov](https://codecov.io/gh/adrianmejias/veil/branch/main/graph/badge.svg?token=P087FQPJ65)](https://codecov.io/gh/adrianmejias/veil) ![Downloads](https://img.shields.io/packagist/dt/adrianmejias/veil) ![Packagist](https://img.shields.io/packagist/v/adrianmejias/veil) ![License](https://img.shields.io/packagist/l/adrianmejias/veil) ![Liberapay](https://img.shields.io/liberapay/patrons/adrianmejias.svg?logo=liberapay) +[![security](https://github.com/adrianmejias/veil/actions/workflows/security.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/security.yml) [![tests](https://github.com/adrianmejias/veil/actions/workflows/tests.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/tests.yml) [![PHPStan](https://github.com/adrianmejias/veil/actions/workflows/phpstan.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/phpstan.yml) [![PHP CS Fixer](https://github.com/adrianmejias/veil/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/php-cs-fixer.yml) [![StyleCI](https://github.styleci.io/repos/394644917/shield?branch=main)](https://github.styleci.io/repos/394644917?branch=main) [![Build Status](https://travis-ci.com/adrianmejias/veil.svg?branch=main)](https://travis-ci.com/adrianmejias/veil) [![codecov](https://codecov.io/gh/adrianmejias/veil/branch/main/graph/badge.svg?token=P087FQPJ65)](https://codecov.io/gh/adrianmejias/veil) [![Coverage Status](https://coveralls.io/repos/github/adrianmejias/veil/badge.svg?branch=main)](https://coveralls.io/github/adrianmejias/veil?branch=main) ![Downloads](https://img.shields.io/packagist/dt/adrianmejias/veil) ![Packagist](https://img.shields.io/packagist/v/adrianmejias/veil) ![License](https://img.shields.io/packagist/l/adrianmejias/veil) ![Liberapay](https://img.shields.io/liberapay/patrons/adrianmejias.svg?logo=liberapay) Autoloader for custom class instances. From 64454295417fe2e76d7dbf413d38b1bbea5ded71 Mon Sep 17 00:00:00 2001 From: Adrian Mejias Date: Fri, 31 Dec 2021 22:25:08 -0600 Subject: [PATCH 2/3] wip --- .github/workflows/coveralls.yml | 25 ------------------------- README.md | 2 +- 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 .github/workflows/coveralls.yml diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml deleted file mode 100644 index 7b6050c..0000000 --- a/.github/workflows/coveralls.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Coveralls - -on: [push, pull_request] - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - - name: Use Node.js 10.x - uses: actions/setup-node@v1 - with: - node-version: 10.x - - - name: npm install, make test-coverage - run: | - npm install - make test-coverage - - - name: Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 7a3aff4..3fe6540 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Veil -[![security](https://github.com/adrianmejias/veil/actions/workflows/security.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/security.yml) [![tests](https://github.com/adrianmejias/veil/actions/workflows/tests.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/tests.yml) [![PHPStan](https://github.com/adrianmejias/veil/actions/workflows/phpstan.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/phpstan.yml) [![PHP CS Fixer](https://github.com/adrianmejias/veil/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/php-cs-fixer.yml) [![StyleCI](https://github.styleci.io/repos/394644917/shield?branch=main)](https://github.styleci.io/repos/394644917?branch=main) [![Build Status](https://travis-ci.com/adrianmejias/veil.svg?branch=main)](https://travis-ci.com/adrianmejias/veil) [![codecov](https://codecov.io/gh/adrianmejias/veil/branch/main/graph/badge.svg?token=P087FQPJ65)](https://codecov.io/gh/adrianmejias/veil) [![Coverage Status](https://coveralls.io/repos/github/adrianmejias/veil/badge.svg?branch=main)](https://coveralls.io/github/adrianmejias/veil?branch=main) ![Downloads](https://img.shields.io/packagist/dt/adrianmejias/veil) ![Packagist](https://img.shields.io/packagist/v/adrianmejias/veil) ![License](https://img.shields.io/packagist/l/adrianmejias/veil) ![Liberapay](https://img.shields.io/liberapay/patrons/adrianmejias.svg?logo=liberapay) +[![security](https://github.com/adrianmejias/veil/actions/workflows/security.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/security.yml) [![tests](https://github.com/adrianmejias/veil/actions/workflows/tests.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/tests.yml) [![PHPStan](https://github.com/adrianmejias/veil/actions/workflows/phpstan.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/phpstan.yml) [![PHP CS Fixer](https://github.com/adrianmejias/veil/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/adrianmejias/veil/actions/workflows/php-cs-fixer.yml) [![StyleCI](https://github.styleci.io/repos/394644917/shield?branch=main)](https://github.styleci.io/repos/394644917?branch=main) [![Build Status](https://travis-ci.com/adrianmejias/veil.svg?branch=main)](https://travis-ci.com/adrianmejias/veil) [![codecov](https://codecov.io/gh/adrianmejias/veil/branch/main/graph/badge.svg?token=P087FQPJ65)](https://codecov.io/gh/adrianmejias/veil) ![Downloads](https://img.shields.io/packagist/dt/adrianmejias/veil) ![Packagist](https://img.shields.io/packagist/v/adrianmejias/veil) ![License](https://img.shields.io/packagist/l/adrianmejias/veil) ![Liberapay](https://img.shields.io/liberapay/patrons/adrianmejias.svg?logo=liberapay) Autoloader for custom class instances. From 88bf93b43c272cc7ef32b4542b54f064a9337ca7 Mon Sep 17 00:00:00 2001 From: Adrian Mejias Date: Fri, 31 Dec 2021 22:51:13 -0600 Subject: [PATCH 3/3] wip --- README.md | 8 +++--- src/Exceptions/AutoloadRegisterException.php | 26 ++++++++++++++++++++ src/Veil.php | 15 +++++++---- tests/MockVeilsTest.php | 10 ++++---- tests/VeilsTest.php | 16 +++++------- 5 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 src/Exceptions/AutoloadRegisterException.php diff --git a/README.md b/README.md index 3fe6540..cb93dab 100644 --- a/README.md +++ b/README.md @@ -13,18 +13,20 @@ This version supports PHP 8.0. You can install the package via composer: ## Usage ### Example + ```php register(); +// Register the autoloader +$veil = (new Veil)->register(); // An example when setting up a flolder and composer psr-4 // autoload is setup as: "Veils\\": "src/Veils/" +// FooVeil class extends VeilAbstract with instance of loadable class $veil->add([ 'Foo' => Veils\FooVeil::class, // The alias name and abstract class to alias against. ]); diff --git a/src/Exceptions/AutoloadRegisterException.php b/src/Exceptions/AutoloadRegisterException.php new file mode 100644 index 0000000..f42c2b5 --- /dev/null +++ b/src/Exceptions/AutoloadRegisterException.php @@ -0,0 +1,26 @@ + $this->autoload($class); - return spl_autoload_register($callback, true, $prepend); + if (spl_autoload_register($callback, true, $prepend)) { + return $this; + } + + throw new AutoloadRegisterException(); } /** diff --git a/tests/MockVeilsTest.php b/tests/MockVeilsTest.php index a871bc8..b5cd5f4 100644 --- a/tests/MockVeilsTest.php +++ b/tests/MockVeilsTest.php @@ -65,7 +65,7 @@ public function it_can_get_a_list_of_all_veils() public function it_can_get_a_list_of_registered_veils_as_array() { $mock = mock(Veil::class); - $mock->shouldReceive('register')->once()->andReturn(true); + $mock->shouldReceive('register')->once()->andReturn(new Veil); $mock->shouldReceive('add')->once()->with([ 'Foo' => FooVeil::class, ]); @@ -86,7 +86,7 @@ public function it_can_get_a_list_of_registered_veils_as_array() public function it_can_get_a_list_of_registered_veils_as_key_value() { $mock = mock(Veil::class); - $mock->shouldReceive('register')->once()->andReturn(true); + $mock->shouldReceive('register')->once()->andReturn(new Veil); $mock->shouldReceive('add')->once()->with('Foo', FooVeil::class); $mock->shouldReceive('registered')->once()->andReturn([ 'Foo' => FooVeil::class, @@ -113,7 +113,7 @@ public static function getVeilInstance() } }; $mock = Mockery::mock(Veil::class); - $mock->shouldReceive('register')->once()->andReturn(true); + $mock->shouldReceive('register')->once()->andReturn(new Veil); $mock->shouldReceive('add')->once()->with('MockFoo', $mockClass::class); $mock->shouldReceive('registered')->once()->andReturn([ 'MockFoo' => $mockClass::class, @@ -143,7 +143,7 @@ public static function getVeilAccessor() } }; $mock = Mockery::mock(Veil::class); - $mock->shouldReceive('register')->once()->andReturn(true); + $mock->shouldReceive('register')->once()->andReturn(new Veil); $mock->shouldReceive('add')->once()->with('MockFoo', $mockClass::class); $mock->shouldReceive('registered')->once()->andReturn([ 'MockFoo' => $mockClass::class, @@ -166,7 +166,7 @@ public static function getVeilAccessor() public function it_can_throw_exception_for_instance_method_not_found() { $mock = Mockery::mock(Veil::class); - $mock->shouldReceive('register')->once()->andReturn(true); + $mock->shouldReceive('register')->once()->andReturn(new Veil); $mock->shouldReceive('add')->once()->with('Foo', FooVeil::class); $mock->shouldReceive('registered')->once()->andReturn([ 'Foo' => FooVeil::class, diff --git a/tests/VeilsTest.php b/tests/VeilsTest.php index 981c8b8..fef7a3c 100644 --- a/tests/VeilsTest.php +++ b/tests/VeilsTest.php @@ -42,11 +42,11 @@ public function it_can_get_a_list_of_all_veils() */ public function it_can_get_a_list_of_registered_veils_as_array() { - $veil = new Veil; - $this->assertTrue($veil->register()); + $veil = (new Veil)->register(); $veil->add(['Foo' => FooVeil::class]); $registered = $veil->registered(); + $this->assertInstanceOf($veil::class, new Veil); $this->assertSame($registered, ['Foo' => FooVeil::class]); } @@ -57,11 +57,11 @@ public function it_can_get_a_list_of_registered_veils_as_array() */ public function it_can_get_a_list_of_registered_veils_as_key_value() { - $veil = new Veil; - $veil->register(); + $veil = (new Veil)->register(); $veil->add('Foo', FooVeil::class); $registered = $veil->registered(); + $this->assertInstanceOf($veil::class, new Veil); $this->assertSame($registered, ['Foo' => FooVeil::class]); } @@ -72,9 +72,7 @@ public function it_can_get_a_list_of_registered_veils_as_key_value() */ public function it_can_call_method() { - $veil = new Veil; - $veil->register(); - $veil->add('Foo', FooVeil::class); + (new Veil)->register()->add('Foo', FooVeil::class); $this->assertSame(\Foo::bar(), FooVeil::getVeilInstance()->bar()); } @@ -87,9 +85,7 @@ public function it_can_call_method() */ public function it_can_throw_exception_for_method_not_found() { - $veil = new Veil; - $veil->register(); - $veil->add('Foo', FooVeil::class); + (new Veil)->register()->add('Foo', FooVeil::class); $this->expectException(NoInstanceMethodFoundException::class); \Foo::noExist();