From 0d63a5b79cb1678e05c95993682b4a062f705104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Thu, 28 Oct 2021 19:37:04 +0200 Subject: [PATCH] add code --- README.md | 36 ++++---------------------------- check | 2 -- composer.json | 17 ++++----------- docker-compose.yml | 12 ----------- src/REPLACEServiceProvider.php | 32 ---------------------------- src/helpers.php | 32 ++++++++++++++++++++++++++++ tests/Pest.php | 2 +- tests/Pest/ExampleTest.php | 9 -------- tests/Pest/SimpleArrayTest.php | 15 +++++++++++++ tests/Pest/UsesTraitTest.php | 29 +++++++++++++++++++++++++ tests/Pest/VariadicArrayTest.php | 11 ++++++++++ tests/TestCase.php | 9 +------- 12 files changed, 97 insertions(+), 109 deletions(-) delete mode 100644 docker-compose.yml delete mode 100644 src/REPLACEServiceProvider.php create mode 100644 src/helpers.php delete mode 100644 tests/Pest/ExampleTest.php create mode 100644 tests/Pest/SimpleArrayTest.php create mode 100644 tests/Pest/UsesTraitTest.php create mode 100644 tests/Pest/VariadicArrayTest.php diff --git a/README.md b/README.md index 5760ca0..8ab4945 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,7 @@ -# REPLACE +# archtechx/helpers -Simple and flexible package template. +A collection of helpers we commonly use in packages or applications. -# Usage +Documentation will come later, currently not intended for public use. -- Replace all occurances of `REPLACE` (case sensitive) with the name of the package namespace. E.g. the `Foo` in `ArchTech\Foo`. - - Also do this for file names, e.g. `REPLACEServiceProvider.php`. -- Replace all occurances of `replace` with the name of the package on composer, e.g. the `bar` in `archtechx/bar`. -- If MySQL is not needed, remove `docker-compose.yml`, remove the line that runs docker from `./check`, and remove it from the `.github/ci.yml` file. - - If SQLite is wanted, change `DB_CONNECTION` in `phpunit.xml` to `sqlite`, and `DB_DATABASE` to `:memory:`. - ---- - -## Installation - -```sh -composer require archtechx/replace -``` - -## Usage - -```php -// ... -``` - -## Development - -Run all checks locally: - -```sh -./check -``` - -Code style will be automatically fixed by php-cs-fixer. +Breaking changes may occur, and renamings are likely. diff --git a/check b/check index bd77490..3d24b54 100755 --- a/check +++ b/check @@ -43,8 +43,6 @@ else offer_run './vendor/bin/phpstan analyse' fi -(MYSQL_PORT=3307 docker-compose up -d > /dev/null 2>/dev/null) || true - if (./vendor/bin/pest > /dev/null 2>/dev/null); then echo '✅ PEST OK' else diff --git a/composer.json b/composer.json index 3064ad3..7e9d189 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "archtechx/replace", - "description": "", + "name": "archtechx/helpers", + "description": "A collection of helpers we commonly use.", "type": "library", "license": "MIT", "authors": [ @@ -10,13 +10,11 @@ } ], "autoload": { - "psr-4": { - "ArchTech\\REPLACE\\": "src/" - } + "files": ["src/helpers.php"] }, "autoload-dev": { "psr-4": { - "ArchTech\\REPLACE\\Tests\\": "tests/" + "ArchTech\\Helpers\\Tests\\": "tests/" } }, "require": { @@ -28,12 +26,5 @@ "nunomaduro/larastan": "^0.6.10", "pestphp/pest": "^1.2", "pestphp/pest-plugin-laravel": "^1.0" - }, - "extra": { - "laravel": { - "providers": [ - "ArchTech\\REPLACE\\PackageServiceProvider" - ] - } } } diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 45edba6..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3' -services: - mysql: - image: mysql:5.7 - environment: - MYSQL_ROOT_PASSWORD: password - MYSQL_DATABASE: main - MYSQL_USER: user - MYSQL_PASSWORD: password - MYSQL_TCP_PORT: ${MYSQL_PORT} - ports: - - "${MYSQL_PORT}:${MYSQL_PORT}" diff --git a/src/REPLACEServiceProvider.php b/src/REPLACEServiceProvider.php deleted file mode 100644 index c819ff7..0000000 --- a/src/REPLACEServiceProvider.php +++ /dev/null @@ -1,32 +0,0 @@ -loadViewsFrom(__DIR__ . '/../assets/views', 'replace'); - - // $this->publishes([ - // __DIR__ . '/../assets/views' => resource_path('views/vendor/replace'), - // ], 'replace-views'); - - // $this->mergeConfigFrom( - // __DIR__ . '/../assets/replace.php', - // 'replace' - // ); - - // $this->publishes([ - // __DIR__ . '/../assets/replace.php' => config_path('replace.php'), - // ], 'replace-config'); - } -} diff --git a/src/helpers.php b/src/helpers.php new file mode 100644 index 0000000..930a70a --- /dev/null +++ b/src/helpers.php @@ -0,0 +1,32 @@ +in('Pest'); +uses(ArchTech\Helpers\Tests\TestCase::class)->in('Pest'); /* |-------------------------------------------------------------------------- diff --git a/tests/Pest/ExampleTest.php b/tests/Pest/ExampleTest.php deleted file mode 100644 index 5d10dd3..0000000 --- a/tests/Pest/ExampleTest.php +++ /dev/null @@ -1,9 +0,0 @@ -toBeTrue(); -}); - -it('fails', function () { - expect(false)->toBeTrue(); -}); diff --git a/tests/Pest/SimpleArrayTest.php b/tests/Pest/SimpleArrayTest.php new file mode 100644 index 0000000..9eeacf9 --- /dev/null +++ b/tests/Pest/SimpleArrayTest.php @@ -0,0 +1,15 @@ +expect(is_simple_array(['foo', 'bar']))->toBeFalse() + ->expect(is_simple_array([['foo'], ['bar']]))->toBeFalse(); + +test("arrays containing a non-array aren't simple arrays") + ->expect( + is_simple_array(['foo']) + )->toBeFalse(); + +test("arrays containing a single array are simple arrays") + ->expect( + is_simple_array([['foo', 'bar']]) + )->toBeTrue(); diff --git a/tests/Pest/UsesTraitTest.php b/tests/Pest/UsesTraitTest.php new file mode 100644 index 0000000..fcaead4 --- /dev/null +++ b/tests/Pest/UsesTraitTest.php @@ -0,0 +1,29 @@ +toBeTrue(); + expect(uses_trait(Foo::class, SecondTrait::class))->toBeFalse(); +}); + +it('checks recursively', function () { + expect(uses_trait(Bar::class, FirstTrait::class))->toBeTrue(); // inherited + expect(uses_trait(Bar::class, SecondTrait::class))->toBeTrue(); +}); + +it('accepts both objects and classes', function () { + expect(uses_trait(new Foo, FirstTrait::class))->toBeTrue(); + expect(uses_trait(new Foo, SecondTrait::class))->toBeFalse(); +}); + +trait FirstTrait {} +trait SecondTrait {} + +class Foo +{ + use FirstTrait; +} + +class Bar extends Foo +{ + use SecondTrait; +} diff --git a/tests/Pest/VariadicArrayTest.php b/tests/Pest/VariadicArrayTest.php new file mode 100644 index 0000000..9a083f2 --- /dev/null +++ b/tests/Pest/VariadicArrayTest.php @@ -0,0 +1,11 @@ +expect( + variadic_array([['foo', 'bar']]) + )->toBe(['foo', 'bar']); + +it('returns the array if a non-simple array is supplied') + ->expect( + variadic_array(['foo', 'bar']) + )->toBe(['foo', 'bar']); diff --git a/tests/TestCase.php b/tests/TestCase.php index ee3c5db..229c0df 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,16 +1,9 @@